Spec for #redirect_back_or_to

openid
Marcin Kulik 13 years ago
parent deaf42edad
commit 9e0a6acf55

@ -40,9 +40,14 @@ class ApplicationController < ActionController::Base
session.delete(:return_to)
end
def redirect_back_or_to(default, options = {})
def redirect_back_or_to(default, options = nil)
path = get_stored_location || default
redirect_to path, options
if options
redirect_to path, options
else
redirect_to path
end
end
def forbidden

@ -85,5 +85,25 @@ describe FakeController do
assigns[:location_again].should == 'NOWAI!'
end
end
describe '#redirect_back_or_to' do
context 'when there is no stored location' do
it 'redirects to given location' do
path = double
@controller.should_receive(:redirect_to).with(path)
@controller.send(:redirect_back_or_to, path)
end
end
context 'when there is stored location' do
it 'redirects to stored location' do
stored_path = double
path = double
@controller.stub!(:get_stored_location => stored_path)
@controller.should_receive(:redirect_to).with(stored_path)
@controller.send(:redirect_back_or_to, path)
end
end
end
end

Loading…
Cancel
Save