<commit_before>require 'spec_helper'

describe ApplicationController do
  describe 'logged_in?' do
    it 'should return false when there is no current user' do
      controller.stub!(:current_person).and_return nil
      controller.should_not be_logged_in
    end

    it 'should return false when there is a current user' do
      controller.stub!(:current_person).and_return Object.new
      controller.should be_logged_in
    end
  end

  describe 'require login' do
    let(:session) { stub 'session' }
    let(:request) { stub 'request', url: :the_url }

    before do
      controller.stub!(:session).and_return session
      controller.stub!(:request).and_return request
      controller.stub!(:root_url).and_return :root_url
    end

    after { controller.require_login }

    it 'should store the initial url in session when not logged in' do
      controller.stub!(:logged_in?).and_return false
      session.should_receive(:[]=).with :initial_url, :the_url
      controller.should_receive(:redirect_to).with :root_url
    end

    it 'should skip redirection when logged in' do
      controller.stub!(:logged_in?).and_return true
      session.should_not_receive :[]=
      controller.should_not_receive :redirect_to
    end
  end
end<commit_msg>added memoisation spec for current_person<commit_after>require 'spec_helper'

describe ApplicationController do
  describe 'logged_in?' do
    it 'should return false when there is no current user' do
      controller.stub!(:current_person).and_return nil
      controller.should_not be_logged_in
    end

    it 'should return false when there is a current user' do
      controller.stub!(:current_person).and_return Object.new
      controller.should be_logged_in
    end
  end

  describe 'require login' do
    let(:session) { stub 'session' }
    let(:request) { stub 'request', url: :the_url }

    before do
      controller.stub!(:session).and_return session
      controller.stub!(:request).and_return request
      controller.stub!(:root_url).and_return :root_url
    end

    after { controller.require_login }

    it 'should store the initial url in session when not logged in' do
      controller.stub!(:logged_in?).and_return false
      session.should_receive(:[]=).with :initial_url, :the_url
      controller.should_receive(:redirect_to).with :root_url
    end

    it 'should skip redirection when logged in' do
      controller.stub!(:logged_in?).and_return true
      session.should_not_receive :[]=
      controller.should_not_receive :redirect_to
    end
  end

  describe 'current_person' do
    it 'should immediately return when @current_person has been determined' do
      controller.instance_variable_set '@current_person', :current_person
      controller.current_person.should == :current_person
    end
  end
end
{'fraction_non_alphanumeric': 0.08419550481626828, 'fraction_numerical': 0.0, 'mean_word_length': 3.627062706270627, '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': '4732263', 'n_tokens_mistral': 819, 'n_tokens_neox': 805, 'n_words': 225}