From fd6630267630bf9586286b69d0afe46d43c689e7 Mon Sep 17 00:00:00 2001 From: Arthur Chiu Date: Fri, 20 May 2011 21:13:55 -0700 Subject: [PATCH] [padrino-admin] don't enable sessions in register, generate in admin/app.rb instead --- padrino-admin/lib/padrino-admin/access_control.rb | 3 +-- .../lib/padrino-admin/generators/templates/app.rb.tt | 5 ++++- padrino-admin/test/test_admin_application.rb | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/padrino-admin/lib/padrino-admin/access_control.rb b/padrino-admin/lib/padrino-admin/access_control.rb index a65a54467..7421fac4f 100644 --- a/padrino-admin/lib/padrino-admin/access_control.rb +++ b/padrino-admin/lib/padrino-admin/access_control.rb @@ -12,7 +12,6 @@ module AccessControl class << self def registered(app) app.set :session_id, "_padrino_#{File.basename(Padrino.root)}_#{app.app_name}".to_sym - app.enable :sessions app.helpers Padrino::Admin::Helpers::AuthenticationHelpers app.helpers Padrino::Admin::Helpers::ViewHelpers app.before { login_required } @@ -147,4 +146,4 @@ def path(prefix=nil) end # ProjectModule end # AccessControl end # Admin -end # Padrino \ No newline at end of file +end # Padrino diff --git a/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt b/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt index 02dae4c13..d53b2273e 100644 --- a/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt +++ b/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt @@ -18,7 +18,10 @@ class Admin < Padrino::Application # disable :flash # Disables rack-flash (enabled by default if Rack::Flash is defined) # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application) # + set :login_page, "/admin/sessions/new" + + enable :sessions disable :store_location access_control.roles_for :any do |role| @@ -28,4 +31,4 @@ class Admin < Padrino::Application access_control.roles_for :admin do |role| end -end \ No newline at end of file +end diff --git a/padrino-admin/test/test_admin_application.rb b/padrino-admin/test/test_admin_application.rb index 8ba450a57..2bf065ab8 100644 --- a/padrino-admin/test/test_admin_application.rb +++ b/padrino-admin/test/test_admin_application.rb @@ -9,6 +9,7 @@ def setup should 'require correctly login' do mock_app do register Padrino::Admin::AccessControl + enable :sessions # Do a simple mapping access_control.roles_for :any do |role| @@ -37,6 +38,7 @@ def setup set :app_name, :basic_app register Padrino::Admin::AccessControl enable :store_location + enable :sessions set :login_page, "/login" access_control.roles_for :any do |role| @@ -70,6 +72,7 @@ def setup should 'set advanced roles with store location and login page' do mock_app do register Padrino::Admin::AccessControl + enable :sessions access_control.roles_for :any do |role| role.protect "/" @@ -146,6 +149,7 @@ def setup should 'emulate an ecommerce app' do mock_app do register Padrino::Admin::AccessControl + enable :sessions access_control.roles_for :any do |role| role.protect "/cart" @@ -196,6 +200,7 @@ def setup should 'check access control helper' do mock_app do register Padrino::Admin::AccessControl + enable :sessions access_control.roles_for :any do |role| role.project_module :foo, "/foo" @@ -243,4 +248,4 @@ def setup get "/modules" assert_equal "admin => /admin", body end -end \ No newline at end of file +end