<commit_before>require 'rails_helper'

RSpec.describe UsersController, :type => :controller do

  let(:test_user)  { create(:admin) }
  let(:test_user2) { create(:normal_user) }

  before(:each) do
    test_user.organizations << test_user.organization
    test_user.save!
    sign_in test_user
  end

  describe 'GET index' do
    describe 'one organization' do
      it 'gets all users of a single org' do
        org = subject.current_user.organization
        get :index, {:organization_id => org.id}

        expect(assigns(:users)).to eq(org.users)
      end

      it 'get users for one organization with a specific role' do
        org = subject.current_user.organization
        get :index, {:organization_id => org.id, :role => 'admin'}

        expect(assigns(:users)).to eq(org.users.with_role('admin'))
      end

      it 'returns no users if wrong role' do
        org = subject.current_user.organization
        get :index, {:organization_id => org.id, :role => 'fake_role'}

        expect(assigns(:users).count).to eq(0)
      end
    end

    describe 'users from a list of orgs' do
      it 'returns all users' do
        get :index

        users = []
        subject.current_user.organizations.each do |org|
          users << org.users
        end

        users.flatten!.uniq

        expect(assigns(:users)).to eq(users)
      end

      it 'returns all users with a role' do
        get :index, {:role => 'admin'}

        users = []
        subject.current_user.organizations.each do |org|
          users << org.users.with_role('admin')
        end

        users.flatten!.uniq

        expect(assigns(:users)).to eq(users)
      end

      it 'returns no users if wrong role' do
        get :index, {:role => 'fake_role'}

        expect(assigns(:users).count).to eq(0)
      end
    end
  end

  it 'GET show' do
    get :show, {:id => subject.current_user.object_key}

    expect(assigns(:user)).to eq(subject.current_user)
  end

  it 'GET new' do
    get :new

    expect(assigns(:user).organization).to eq(assigns(:organization))
  end

  describe 'GET edit' do
    it 'can view own' do
      get :edit, {:id => subject.current_user.object_key}
      expect(assigns(:user)).to eq(subject.current_user)
    end

    it 'support can view others' do
      get :edit, {:id => test_user2.object_key}
<commit_msg>update test for no longer setting organization on users#new<commit_after>require 'rails_helper'

RSpec.describe UsersController, :type => :controller do

  let(:test_user)  { create(:admin) }
  let(:test_user2) { create(:normal_user) }

  before(:each) do
    test_user.organizations << test_user.organization
    test_user.save!
    sign_in test_user
  end

  describe 'GET index' do
    describe 'one organization' do
      it 'gets all users of a single org' do
        org = subject.current_user.organization
        get :index, {:organization_id => org.id}

        expect(assigns(:users)).to eq(org.users)
      end

      it 'get users for one organization with a specific role' do
        org = subject.current_user.organization
        get :index, {:organization_id => org.id, :role => 'admin'}

        expect(assigns(:users)).to eq(org.users.with_role('admin'))
      end

      it 'returns no users if wrong role' do
        org = subject.current_user.organization
        get :index, {:organization_id => org.id, :role => 'fake_role'}

        expect(assigns(:users).count).to eq(0)
      end
    end

    describe 'users from a list of orgs' do
      it 'returns all users' do
        get :index

        users = []
        subject.current_user.organizations.each do |org|
          users << org.users
        end

        users.flatten!.uniq

        expect(assigns(:users)).to eq(users)
      end

      it 'returns all users with a role' do
        get :index, {:role => 'admin'}

        users = []
        subject.current_user.organizations.each do |org|
          users << org.users.with_role('admin')
        end

        users.flatten!.uniq

        expect(assigns(:users)).to eq(users)
      end

      it 'returns no users if wrong role' do
        get :index, {:role => 'fake_role'}

        expect(assigns(:users).count).to eq(0)
      end
    end
  end

  it 'GET show' do
    get :show, {:id => subject.current_user.object_key}

    expect(assigns(:user)).to eq(subject.current_user)
  end

  it 'GET new' do
    get :new

    expect(assigns(:user).to_json).to eq(User.new.to_json)
  end

  describe 'GET edit' do
    it 'can view own' do
      get :edit, {:id => subject.current_user.object_key}
      expect(assigns(:user)).to eq(subject.current_user)
    end

    it 'support can view others' do
      get :edit, {:id => test_user2.object_key}

{'fraction_non_alphanumeric': 0.11664899257688228, 'fraction_numerical': 0.001696712619300106, 'mean_word_length': 2.4907475943745374, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, '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': '7545989', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1429, 'n_words': 406}