Module: MuckEngine::Controllers::Matchers
- Defined in:
- lib/muck-engine/test/controllers/matchers.rb,
lib/muck-engine/test/controllers/matchers/role_matcher.rb,
lib/muck-engine/test/controllers/matchers/login_matcher.rb
Overview
Matchers for common controller methods:
describe UsersController, "on GET to show with a valid id" do
it { should require_login :index, :get }
it { should require_role('admin', :index, :get) }
end
Defined Under Namespace
Classes: RequireLoginMatcher, RequireRoleMatcher
Instance Method Summary collapse
-
#require_login(action, verb, login_url = '/login') ⇒ Object
Ensure a login is required for the given action Parameters: action - Name of the action in the control that should require a login ie “index” verb - Method to use to call the action ie :post, :get login_url - Optional url the user should be redirected to if they aren’t logged in.
-
#require_role(role, action, verb, flash_message = /permission/i, role_url = '/login') ⇒ Object
Ensure a role is required for the given action Parameters: role - Role require to access the url.
Instance Method Details
#require_login(action, verb, login_url = '/login') ⇒ Object
Ensure a login is required for the given action Parameters:
action - Name of the action in the control that should require a login ie "index"
verb - Method to use to call the action ie :post, :get
login_url - Optional url the user should be redirected to if they aren't logged in. Defaults to '/login'
Example:
it { should require_login 'index', :get, '/signup' }
13 14 15 |
# File 'lib/muck-engine/test/controllers/matchers/login_matcher.rb', line 13 def require_login(action, verb, login_url = '/login') RequireLoginMatcher.new(action, verb, login_url, self) end |
#require_role(role, action, verb, flash_message = /permission/i, role_url = '/login') ⇒ Object
Ensure a role is required for the given action Parameters:
role - Role require to access the url.
action - Name of the action in the control that should require a role ie "index"
verb - Method to use to call the action ie :post, :get
flash_message - Flash message indicating that the user was denied access
role_url - Optional url the user should be redirected to if they aren't logged in. Defaults to '/role'
Example:
it { should require_role 'index', :get, /access denied/i, '/signup' }
15 16 17 |
# File 'lib/muck-engine/test/controllers/matchers/role_matcher.rb', line 15 def require_role(role, action, verb, = /permission/i, role_url = '/login') RequireRoleMatcher.new(role, action, verb, role_url, , self) end |