Class: DeclarativeAuthorization::Test::Helpers::PrivilegeTestGenerator
- Inherits:
-
Object
- Object
- DeclarativeAuthorization::Test::Helpers::PrivilegeTestGenerator
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/declarative_authorization/test/helpers.rb
Instance Method Summary collapse
- #allowed(options) ⇒ Object
- #denied(options) ⇒ Object
-
#initialize(test_class, role, privileges) ⇒ PrivilegeTestGenerator
constructor
A new instance of PrivilegeTestGenerator.
Constructor Details
#initialize(test_class, role, privileges) ⇒ PrivilegeTestGenerator
Returns a new instance of PrivilegeTestGenerator.
19 20 21 22 23 |
# File 'lib/declarative_authorization/test/helpers.rb', line 19 def initialize(test_class, role, privileges) @test_class = test_class @role = role @privileges = [privileges].flatten end |
Instance Method Details
#allowed(options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/declarative_authorization/test/helpers.rb', line 25 def allowed() role, privileges, actions, params_name = () actions.each do |action| privileges.each do |privilege| @test_class.send(:define_method, "test_#{action}__access_allowed__#{role}_role__#{privilege ? "#{privilege}_permissions__" : ""}with_#{params_name || 'no_params'}") do priv_param = (privilege == :hidden ? nil : privilege) if forbidden_with_role_and_privilege?(action, role, priv_param, params_name, ) flunk "The '#{action}' action #{params_name ? "with '#{params_name}' parameters " : ''}should be accessible for users with #{privilege ? "'#{privilege}' permissions for " : ""}the '#{role}' role." end end end end end |
#denied(options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/declarative_authorization/test/helpers.rb', line 40 def denied() role, privileges, actions, params_name = () actions.each do |action| privileges.each do |privilege| @test_class.send(:define_method, "test_#{action}__access_denied__#{role}_role__#{privilege ? "#{privilege}_permissions__" : ""}with_#{params_name || 'no_params'}") do priv_param = (privilege == :hidden ? nil : privilege) unless forbidden_with_role_and_privilege?(action, role, priv_param, params_name, ) flunk "The '#{action}' action #{params_name ? "with '#{params_name}' parameters " : ''}should NOT be accessible for users with #{privilege ? "'#{privilege}' permissions for " : ""}the '#{role}' role." end end end end end |