module Suit::Controllers::Matchers
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
Public Instance Methods
require_login(action, verb, login_url = '/login')
click to toggle source
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' }
# File lib/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')
click to toggle source
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' }
# File lib/controllers/matchers/role_matcher.rb, line 15 def require_role(role, action, verb, flash_message = /permission/i, role_url = '/login') RequireRoleMatcher.new(role, action, verb, role_url, flash_message, self) end