<commit_before>require 'spec_helper'

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

    # Create a user nad link
    let(:user) { create(:socializer_person) }
    let(:valid_attributes) { { label: 'test', url: 'http://test.org' } }
    let(:link) { user.links.create!(valid_attributes) }

    # 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 link in the database' do
          expect { post :create, person_link: valid_attributes, person_id: user }.to change(PersonLink, :count).by(1)
        end

        it 'redirects to people#show' do
          post :create, person_link: valid_attributes, person_id: user
          expect(response).to redirect_to user
        end
      end

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

    describe 'PATCH #update' do
      context 'with valid attributes' do
        it 'redirects to people#show' do
          patch :update, id: link, person_id: user, person_link: { label: 'updated content' }
          expect(response).to redirect_to user
        end
      end

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

    describe 'DELETE #destroy' do
      it 'deletes the link' do
        link
        expect { delete :destroy, id: link, person_id: user }.to change(PersonLink, :count).by(-1)
      end

      it 'redirects to people#show' do
        delete :destroy, id: link, person_id: user
        expect(response).to redirect_to user
      end
    end
  end
end<commit_msg>People::LinksController: begin testing when not logged in<commit_after>require 'spec_helper'

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

    # Create a user nad link
    let(:user) { create(:socializer_person) }
    let(:valid_attributes) { { label: 'test', url: 'http://test.org' } }
    let(:link) { user.links.create!(valid_attributes) }

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

      describe 'PATCH #update' do
        it 'requires login' do
          patch :update, id: link, person_id: user, person_link: { label: 'updated content' }
          expect(response).to redirect_to root_path
        end
      end

      describe 'DELETE #destroy' do
        it 'requires login' do
          delete :destroy, id: link, person_id: user
          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 link in the database' do
            expect { post :create, person_link: valid_attributes, person_id: user }.to change(PersonLink, :count).by(1)
          end

          it 'redirects to people#show' do
            post :create, person_link: valid_attributes, person_id: user
            expect(response).to redirect_to user
          end
        end

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

      describe 'PATCH #update' do
        context 'with valid attributes' do
          it 'redirects to people#show' do
            patch :update, id: link, person_id: user, person_link: { label: 'updated content' }
            expect(response).to redirect_to user
          end
        end

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

      describe 'DELETE #destroy' do
        it 'deletes the link' do
          link
          expect { delete :destroy, id: link, person_id: user }.to change(PersonLink, :count).by(-1)
        end

        it 'redirects to people#show' do
          delete :destroy, id: link, person_id: user
          expect(response).to redirect_to user
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08605341246290801, 'fraction_numerical': 0.0009130335539831089, 'mean_word_length': 2.32221379833207, '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': '1215883', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1212, 'n_words': 423}