test/sinatra.rb in shield-0.1.0 vs test/sinatra.rb in shield-1.0.0.rc1
- old
+ new
@@ -1,29 +1,30 @@
require File.expand_path("helper", File.dirname(__FILE__))
require File.expand_path("user", File.dirname(__FILE__))
class SinatraApp < Sinatra::Base
+ use Shield::Middleware
enable :sessions
helpers Shield::Helpers
get "/public" do
"Public"
end
get "/private" do
- ensure_authenticated(User)
+ error(401) unless authenticated(User)
"Private"
end
get "/login" do
"Login"
end
post "/login" do
if login(User, params[:login], params[:password], params[:remember_me])
- redirect(session[:return_to] || "/")
+ redirect(params[:return] || "/")
else
redirect "/login"
end
end
@@ -48,14 +49,15 @@
end
test "successful logging in" do
get "/private"
- assert_redirected_to "/login"
- assert_equal "/private", session[:return_to]
+ assert_equal "/login?return=%2Fprivate", redirection_url
- post "/login", :login => "quentin", :password => "password"
+ post "/login", :login => "quentin", :password => "password",
+ :return => "/private"
+
assert_redirected_to "/private"
assert 1001 == session["User"]
end
@@ -70,11 +72,10 @@
post "/login", :login => "quentin", :password => "password"
get "/logout"
assert nil == session["User"]
- assert nil == session[:return_to]
end
test "remember functionality" do
post "/login", :login => "quentin", :password => "password", :remember_me => "1"
@@ -82,6 +83,10 @@
get "/logout"
assert_equal nil, session[:remember_for]
end
+end
+
+if $0 == __FILE__
+ SinatraApp.run!
end