<commit_before>require 'spec_helper'

describe GroupsController do

  describe 'create' do
    let(:person) { create(:person) }

    context 'with correct params' do
      before do
        controller.stub :authenticate_person!
        @params = { group: { name: 'rubycorns' } }
      end

      it 'creates a new group' do
        expect do
          post :create, @params
        end.to change{ Group.count }.by(1)
      end

      it 'redirects to the root path' do
        post :create, @params
        response.should redirect_to root_path
      end
    end

    context 'with incorrect params' do
      before do
        controller.stub :authenticate_person!
        @params = { group: { name: ''} }
      end

      it 'redirects to the sign in path' do
        post :create, @params
        response.should render_template(:new)
      end
    end
  end

  describe 'edit' do

    let(:group) { create(:group) }
    let(:person) { create(:person) }

    before do
      controller.stub :authenticate_person!
      controller.stub(:current_person).and_return(person)
      Group.stub(:find).and_return(group)
    end

    it 'restricts access if editable is false' do
      group.stub(:is_editable_by?).with(person).and_return(false)
      get :edit, id: 1
      expect(response).to be_redirect
    end

    it 'allows access if editable is true' do
      group.stub(:is_editable_by?).with(person).and_return(true)
      get :edit, id: 1
      expect { get :edit }.to render_template(:edit)
    end<commit_msg>instance variable ---> let statement<commit_after>require 'spec_helper'

describe GroupsController do

  describe 'create' do
    let(:person) { create(:person) }

    context 'with correct params' do
      let(:params) {{ group: { name: 'rubycorns' } }}

      before do
        controller.stub :authenticate_person!
      end

      it 'creates a new group' do
        expect do
          post :create, params
        end.to change{ Group.count }.by(1)
      end

      it 'redirects to the root path' do
        post :create, params
        response.should redirect_to root_path
      end
    end

    context 'with incorrect params' do

      let(:params) {{group: { name: ''}}}

      before do
        controller.stub :authenticate_person!
      end

      it 'redirects to the sign in path' do
        post :create, params
        response.should render_template(:new)
      end
    end
  end

  describe 'edit' do

    let(:group) { create(:group) }
    let(:person) { create(:person) }

    before do
      controller.stub :authenticate_person!
      controller.stub(:current_person).and_return(person)
      Group.stub(:find).and_return(group)
    end

    it 'restricts access if editable is false' do
      group.stub(:is_editable_by?).with(person).and_return(false)
      get :edit, id: 1
      expect(response).to be_redirect
    end

    it 'allows access if editable is true' do
      group.stub(:is_editable_by?).with(person).and_return(true)
      get :edit, id: 1
      expect { get :edit }.to render_template(:edit)
    end
{'fraction_non_alphanumeric': 0.09970578620464204, 'fraction_numerical': 0.001961425302386401, 'mean_word_length': 2.4420697412823396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3942813', 'n_tokens_mistral': 947, 'n_tokens_neox': 913, 'n_words': 268}