<commit_before>require "spec_helper"

describe OpsController do
  before(:each) do
    set_user_privileges
  end

  describe 'x_button' do
    describe 'corresponding methods are called for allowed actions' do
      OpsController::OPS_X_BUTTON_ALLOWED_ACTIONS.each_pair do |action_name, method|
        it "calls the appropriate method: '#{method}' for action '#{action_name}'" do
          controller.should_receive(method)
          get :x_button, :pressed => action_name
        end
      end
    end

    it 'exception is raised for unknown action' do
      get :x_button, :pressed => 'random_dude', :format => :html
      expect { response }.to render_template('layouts/exception')
    end
  end
end<commit_msg>Create some tests for OpsController::rbac_user_edit.<commit_after>require "spec_helper"

describe OpsController do
  before(:each) do
    set_user_privileges
  end

  describe 'x_button' do
    describe 'corresponding methods are called for allowed actions' do
      OpsController::OPS_X_BUTTON_ALLOWED_ACTIONS.each_pair do |action_name, method|
        it "calls the appropriate method: '#{method}' for action '#{action_name}'" do
          controller.should_receive(method)
          get :x_button, :pressed => action_name
        end
      end
    end

    it 'exception is raised for unknown action' do
      get :x_button, :pressed => 'random_dude', :format => :html
      expect { response }.to render_template('layouts/exception')
    end
  end

  #  def rbac_user_edit
  #
  # def rbac_user_set_record_vars(user)
  describe 'rbac_user_edit' do
    it 'can add a user w/ group' do
      session[:settings] = {:views => {}, :perpage => {:list => 10}}
      session[:edit] = {
        :key => 'rbac_user_edit__new',
        :current => {},
        :new => {
          :name      => 'test7',
          :userid    => 'test7',
          :email     => '<EMAIL>',
          :group     => 'test_group',
          :password  => 'test7',
          :password2 => '<PASSWORD>',
        }
      }

      controller.should_receive(:replace_right_cell)
      get :rbac_user_edit, :button => 'add'
    end

    it 'cannot add a user w/o matching passwords' do
      session[:settings] = {}
      session[:settings] = {:views => {}, :perpage => {:list => 10}}
      session[:edit] = {
        :key => 'rbac_user_edit__new',
        :new => {
          :name      => 'test7',
          :userid    => 'test7',
          :email     => '<EMAIL>',
          :group     => 'test_group',
          :password  => '<PASSWORD>',
          :password2 => '<PASSWORD>',
        }
      }

      controller.should_receive(:render_flash)
      get :rbac_user_edit, :button => 'add'
      flash_messages = assigns(:flash_array)
      flash_messages.first[:message].should == "Password/Verify Password do not match"
      flash_messages.first[:level].should == :error
    end

    it 'cannot add a user w/o group' do
      session[:settings] = {}
      session[:settings] = {:views => {}, :perpage => {:list => 10}}
      session[:edit] = {
        :key => 'rbac_user_edit__new',
        :new => {
          :name      => 'test7',
          :userid    => 'test7',
          :email     => '<EMAIL>',
          :group     => nil,
          :password  => '<PASSWORD>',
          :password2 => '<PASSWORD>',
        }
      }

      controller.should_receive(:render_flash)
      get :rbac_user_edit, :button => 'add'
      flash_messages = assigns(:flash_array)
      flash_messages.first[:message].should == "A User must be assigned to a Group"
      flash_messages.first[:level].should == :error
    end
  end
end
{'fraction_non_alphanumeric': 0.1299638989169675, 'fraction_numerical': 0.004443210219383505, 'mean_word_length': 2.440305635148042, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1450502', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1089, 'n_words': 273}