Skip to content
Browse files

[merb-auth-more] #redirect_back respects Merb::Config[:path_prefix]

[#1105 state:resolved]
  • Loading branch information...
1 parent b0bd280 commit a0fb0bf03c2e8be90b782bc4616c626e47440005 @snusnu snusnu committed Oct 27, 2009
View
2 merb-auth/merb-auth-more/lib/merb-auth-more/mixins/redirect_back.rb
@@ -51,7 +51,7 @@ def self.included(base)
def _set_return_to
unless request.exceptions.blank?
session[:return_to] ||= []
- session[:return_to] << request.uri
+ session[:return_to] << "#{Merb::Config[:path_prefix]}#{request.uri}"
session[:return_to]
end
end
View
81 merb-auth/merb-auth-more/spec/mixins/redirect_back_spec.rb
@@ -1,6 +1,44 @@
require File.join(File.dirname(__FILE__), "..", 'spec_helper.rb')
require File.join(File.expand_path(File.dirname(__FILE__)), "..", ".." ,"lib", "merb-auth-more", "mixins", "redirect_back")
+
+describe "every call to redirect_back", :shared => true do
+
+ it "should set the return_to in the session when sent to the exceptions controller from a failed login" do
+ r = request("/go_back")
+ r.status.should == Merb::Controller::Unauthenticated.status
+ r2 = login
+ r2.should redirect_to(@return_to_after_failed_login)
+ end
+
+ it "should not set the return_to in the session when deliberately going to unauthenticated" do
+ r = login
+ r.should redirect_to("/")
+ end
+
+ it "should still redirect to the original even if it's failed many times" do
+ request("/go_back")
+ request("/login", :method => "put", :params => {:pass_auth => false})
+ request("/login", :method => "put", :params => {:pass_auth => false})
+ request("/login", :method => "put", :params => {:pass_auth => false})
+ r = login
+ r.should redirect_to(@return_to_after_failed_login)
+ end
+
+ it "should not redirect back to a previous redirect back after being logged out" do
+ request("/go_back")
+ request("/login", :method => "put", :params => {:pass_auth => false})
+ request("/login", :method => "put", :params => {:pass_auth => false})
+ request("/login", :method => "put", :params => {:pass_auth => false})
+ r = login
+ r.should redirect_to(@return_to_after_failed_login)
+ request("/logout", :method => "delete")
+ r = login
+ r.should redirect_to("/")
+ end
+
+end
+
describe "redirect_back" do
before(:all) do
@@ -60,38 +98,21 @@ def index
def login
request("/login", :method => "put", :params => {:pass_auth => true})
end
-
- it "should set the return_to in the session when sent to the exceptions controller from a failed login" do
- r = request("/go_back")
- r.status.should == Merb::Controller::Unauthenticated.status
- r2 = login
- r2.should redirect_to("/go_back")
- end
-
- it "should not set the return_to in the session when deliberately going to unauthenticated" do
- r = login
- r.should redirect_to("/")
- end
-
- it "should still redirect to the original even if it's failed many times" do
- request("/go_back")
- request("/login", :method => "put", :params => {:pass_auth => false})
- request("/login", :method => "put", :params => {:pass_auth => false})
- request("/login", :method => "put", :params => {:pass_auth => false})
- r = login
- r.should redirect_to("/go_back")
+
+ describe "without Merb::Config[:path_prefix]" do
+ before(:all) do
+ Merb::Config[:path_prefix] = nil
+ @return_to_after_failed_login = '/go_back'
+ end
+ it_should_behave_like 'every call to redirect_back'
end
- it "should not redirect back to a previous redirect back after being logged out" do
- request("/go_back")
- request("/login", :method => "put", :params => {:pass_auth => false})
- request("/login", :method => "put", :params => {:pass_auth => false})
- request("/login", :method => "put", :params => {:pass_auth => false})
- r = login
- r.should redirect_to("/go_back")
- request("/logout", :method => "delete")
- r = login
- r.should redirect_to("/")
+ describe "without Merb::Config[:path_prefix]" do
+ before(:all) do
+ Merb::Config[:path_prefix] = '/myapp'
+ @return_to_after_failed_login = '/myapp/go_back'
+ end
+ it_should_behave_like 'every call to redirect_back'
end
end

0 comments on commit a0fb0bf

Please sign in to comment.
Something went wrong with that request. Please try again.