Module: RoleRequirementTestHelper
- Defined in:
- lib/role_requirement_test_helper.rb
Overview
Include this is test_helper.rb to enable test-case helper support for RoleRequirement via:
include RoleRequirementTestHelper
RoleRequirementTestHelper uses the power of ruby to temporarily “hijack” your target action. (don’t worry, it puts things back the way it was after it runs) This means that the only thing that will be tested is whether or not the action can be accessed with a given circumstances. Any authentication you implement inside of your action will be ignored.
Instance Method Summary collapse
-
#assert_user_can_access(user, actions, params = {}) ⇒ Object
Makes sure a user can access the given action.
-
#assert_user_cant_access(user, actions, params = {}) ⇒ Object
(also: #assert_user_cannot_access)
Makes sure a user cant access the given action.
-
#assert_users_access(users_access_list, actions, params = {}) ⇒ Object
Check a list of users against a set of actions with parameters.
Instance Method Details
#assert_user_can_access(user, actions, params = {}) ⇒ Object
Makes sure a user can access the given action
Example:
assert_user_can_access(:quentin, "index")
16 17 18 |
# File 'lib/role_requirement_test_helper.rb', line 16 def assert_user_can_access(user, actions, params = {}) assert_user_access_check(true, user, actions, params) end |
#assert_user_cant_access(user, actions, params = {}) ⇒ Object Also known as: assert_user_cannot_access
Makes sure a user cant access the given action
Example:
assert_user_cant_access(:quentin, "destroy", :listing_id => 1)
26 27 28 |
# File 'lib/role_requirement_test_helper.rb', line 26 def assert_user_cant_access(user, actions, params = {}) assert_user_access_check(false, user, actions, params) end |
#assert_users_access(users_access_list, actions, params = {}) ⇒ Object
Check a list of users against a set of actions with parameters.
Parameters:
users_access_list - a hash where the key is the label for a fixture, and the value is a boolean.
actions - a list of actions to test against
params - a hash containing the parameters to pass to each test call to the controller.
Example:
assert_user_access(
{:admin => true, :quentin => false },
[:show, :edit],
{:listing_id => 1})
42 43 44 45 46 |
# File 'lib/role_requirement_test_helper.rb', line 42 def assert_users_access(users_access_list, actions, params = {}) users_access_list.each_pair {|user, access| assert_user_access_check(access, user, actions, params) } end |