<commit_before>require 'spec_helper'

module Socializer
  RSpec.describe MembershipsController, type: :controller do
    routes { Socializer::Engine.routes }

    # Create a user, a group, and a membership
    let(:user) { create(:socializer_person) }
    let(:group) { create(:socializer_group, activity_author: user.activity_object) }
    let(:membership) { create(:socializer_membership, group: group, activity_member: user.activity_object) }
    let(:valid_attributes) { { membership: { group_id: group.id } } }

    # Setting the current user
    before { cookies[:user_id] = user.guid }

    it { should use_before_action(:authenticate_user) }

    describe 'POST #create' do
      context 'with valid attributes' do
        it 'saves the new membership in the database' do
          group
          expect { post :create, valid_attributes }.to change(Membership, :count).by(1)
        end

        it 'redirects to groups#show' do
          post :create, valid_attributes
          expect(response).to redirect_to group
        end
      end

      context 'with invalid attributes' do
        it 'is a pending example'
      end
    end

    describe 'DELETE #destroy' do
      it 'deletes the membership' do
        membership
        expect { delete :destroy, id: membership }.to change(Membership, :count).by(-1)
      end
    end
  end
end<commit_msg>MembershipsController: begin testing when not logged in<commit_after>require 'spec_helper'

module Socializer
  RSpec.describe MembershipsController, type: :controller do
    routes { Socializer::Engine.routes }

    # Create a user, a group, and a membership
    let(:user) { create(:socializer_person) }
    let(:group) { create(:socializer_group, activity_author: user.activity_object) }
    let(:membership) { create(:socializer_membership, group: group, activity_member: user.activity_object) }
    let(:valid_attributes) { { membership: { group_id: group.id } } }

    describe 'when not logged in' do
      describe 'POST #create' do
        it 'requires login' do
          post :create, valid_attributes
          expect(response).to redirect_to root_path
        end
      end

      describe 'DELETE #destroy' do
        it 'requires login' do
          delete :destroy, id: membership
          expect(response).to redirect_to root_path
        end
      end
    end

    describe 'when logged in' do
      # Setting the current user
      before { cookies[:user_id] = user.guid }

      it { should use_before_action(:authenticate_user) }

      describe 'POST #create' do
        context 'with valid attributes' do
          it 'saves the new membership in the database' do
            group
            expect { post :create, valid_attributes }.to change(Membership, :count).by(1)
          end

          it 'redirects to groups#show' do
            post :create, valid_attributes
            expect(response).to redirect_to group
          end
        end

        context 'with invalid attributes' do
          it 'is a pending example'
        end
      end

      describe 'DELETE #destroy' do
        it 'deletes the membership' do
          membership
          expect { delete :destroy, id: membership }.to change(Membership, :count).by(-1)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0838946723821188, 'fraction_numerical': 0.001224739742804654, 'mean_word_length': 2.5704918032786885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4439024', 'n_tokens_mistral': 904, 'n_tokens_neox': 882, 'n_words': 289}