diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b6910d2..6d1cbae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -30,8 +30,8 @@ class ApplicationController < ActionController::Base email = session[:email] = params[:override] end - @current_person = Person.find_by_email email - @current_person = Person.create_for_email email unless @current_person + @current_person = Person.find_by_email session[:email] + @current_person = Person.create_for_email session[:email] unless @current_person @current_person end end \ No newline at end of file diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index c3cdaf5..7565997 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -57,12 +57,35 @@ describe ApplicationController do controller.current_person.should be_nil end - it 'should lookup user from email' do - session[:email] = :session_email - Person.stub!(:find_by_email).and_return :person - controller.current_person.should == :person - end + describe 'with session email' do + before { session[:email] = :session_email } - it 'should replace email with override if email is omnipotent an override is given' + it 'should lookup user from session email' do + Person.should_receive(:find_by_email).with(:session_email).and_return :person + controller.current_person.should == :person + end + + it 'should create a new user if one cannot be found from email' do + Person.should_receive(:find_by_email).with(:session_email).and_return nil + Person.should_receive(:create_for_email).with(:session_email).and_return :person + controller.current_person.should == :person + end + + it 'should replace email with override if email is omnipotent an override is given' do + params[:override] = :override_email + Person.should_receive(:find_by_email).with(:override_email).and_return :person + Omnipotence.should_receive(:omnipotent?).with(:session_email).and_return true + controller.current_person.should == :person + session[:email].should == :override_email + end + + it 'should ignore override if email is not omnipotent' do + params[:override] = :override_email + Omnipotence.should_receive(:omnipotent?).with(:session_email).and_return false + Person.should_receive(:find_by_email).with(:session_email).and_return :person + controller.current_person.should == :person + session[:email].should == :session_email + end + end end end \ No newline at end of file