may_may 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,7 +19,6 @@ Simplify your views. Show/hide view elements based on intended action instead of
19
19
  <%= link_to 'only visible if user may edit people', edit_people_path %>
20
20
  <% end %>
21
21
 
22
- ###
23
22
  ### Create a model named "may":
24
23
 
25
24
  # in app/models/may.rb
@@ -38,7 +37,7 @@ Simplify your views. Show/hide view elements based on intended action instead of
38
37
  end
39
38
  end
40
39
 
41
- ### Add a current_roles method to your ApplicationController:
40
+ ### Add a role_names method to your User object
42
41
 
43
42
  Here is a simple example setup:
44
43
 
@@ -59,13 +58,22 @@ Here is a simple example setup:
59
58
  class User
60
59
  has_many :user_roles
61
60
  has_many :roles, through: :user_roles
61
+
62
+ def role_names
63
+ roles.map {|role| role.name.to_sym }
64
+ end
62
65
  end
63
66
 
64
67
  # in app/controllers/application_controller.rb
65
68
 
66
69
  class ApplicationController < ActionController::Base
67
- def current_roles
68
- current_user.roles.map {|role| role.name.to_sym }
70
+ def current_user
71
+ @current_user ||= User.find(session[:user_id]) rescue nil
72
+ end
73
+
74
+ def current_user=(value)
75
+ value ? session[:user_id] = value.id : session.delete(:id)
76
+ @current_user = value
69
77
  end
70
78
  end
71
79
 
@@ -80,6 +88,36 @@ You could instead define permissions within the controller itself:
80
88
  may :show, method: [:may_show?]
81
89
  end
82
90
 
91
+ ## In more depth
92
+
93
+ MayMay adds a few methods to ActionController::Base:
94
+
95
+ *** `may` (class method)
96
+
97
+ Define permissions in your controller instead of May model. Shortcut for `May.may(self, ...)`
98
+
99
+ Usage:
100
+
101
+ class SomeController < ApplicationController
102
+ may :index, except: [:this_role]
103
+ end
104
+
105
+ *** `current_roles`
106
+
107
+ Returns `current_user.role_names` or empty array if `current_user` returns nil or is missing
108
+
109
+ *** `has_role?`
110
+
111
+ Check `current_roles` for a specific role.
112
+
113
+ Usage: if `has_role? :some_role`
114
+
115
+ *** may? (helper method)
116
+
117
+ Check for permission to perform an action.
118
+
119
+ Usage: if `may? :action_name, :controller_name`
120
+
83
121
  ## Licence
84
122
 
85
123
  MIT-LICENSE
@@ -65,7 +65,31 @@ module MayMay
65
65
 
66
66
  def access_denied
67
67
  response.status = 403
68
- render :text => 'Access Denied'
68
+ if Rails.env == 'development'
69
+ render_text = "Permission denied to action :#{params[:action]} on controller :#{params[:controller]}"
70
+ if May.respond_to? get_permission_method
71
+ render text: render_text
72
+ else
73
+ render_text = '<h1>' + render_text + '</h1>' + %{
74
+ <p>Controller action permission needs to be specified in your May model. Example:</p>
75
+
76
+ <pre>
77
+ # in app/models/may.rb:
78
+
79
+ class May
80
+ controller: :#{params[:controller]} do
81
+ may :#{params[:action]}, only: [:role_1, :role_2]
82
+ end
83
+ end
84
+ </pre>
85
+
86
+ <p>For more detailed information, view the <a href="https://github.com/without/may_may/blob/master/README.md">MayMay gem's README.md</a></p>
87
+ }
88
+ render layout: false, inline: render_text
89
+ end
90
+ else
91
+ render text: "Access Denied."
92
+ end
69
93
  end
70
94
 
71
95
  def current_roles
@@ -83,9 +107,13 @@ module MayMay
83
107
 
84
108
  private
85
109
 
110
+ def get_permission_method
111
+ May.get_permission_method params[:action], params[:controller].to_s.pluralize.to_sym
112
+ end
113
+
86
114
  def may_may_setup
87
- May.permissions_setup
88
- access_denied unless May.permission_to? params[:action], params[:controller].to_s.pluralize.to_sym, self
115
+ method = get_permission_method
116
+ access_denied unless May.respond_to?(method) && May.send(get_permission_method, self)
89
117
  end
90
118
  end
91
119
 
@@ -1,3 +1,3 @@
1
1
  module MayMay
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5026,3 +5026,320 @@ Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
5026
5026
   (0.0ms) rollback transaction
5027
5027
   (0.0ms) begin transaction
5028
5028
   (0.0ms) rollback transaction
5029
+ Connecting to database specified by database.yml
5030
+ Connecting to database specified by database.yml
5031
+  (0.4ms) begin transaction
5032
+  (0.0ms) rollback transaction
5033
+  (0.0ms) begin transaction
5034
+  (0.0ms) rollback transaction
5035
+  (0.0ms) begin transaction
5036
+  (0.0ms) rollback transaction
5037
+  (0.0ms) begin transaction
5038
+  (0.0ms) rollback transaction
5039
+  (0.0ms) begin transaction
5040
+  (0.0ms) rollback transaction
5041
+  (0.0ms) begin transaction
5042
+  (0.0ms) rollback transaction
5043
+  (0.0ms) begin transaction
5044
+  (0.0ms) rollback transaction
5045
+  (0.0ms) begin transaction
5046
+  (0.0ms) rollback transaction
5047
+  (0.0ms) begin transaction
5048
+  (0.0ms) rollback transaction
5049
+  (0.0ms) begin transaction
5050
+  (0.0ms) rollback transaction
5051
+  (0.4ms) begin transaction
5052
+ Processing by MayMaysController#create as HTML
5053
+ Parameters: {"user"=>"admin"}
5054
+ Rendered text template (0.0ms)
5055
+ Completed 200 OK in 375ms (Views: 72.0ms | ActiveRecord: 7.1ms)
5056
+  (0.1ms) rollback transaction
5057
+  (0.0ms) begin transaction
5058
+ Processing by MayMaysController#destroy as HTML
5059
+ Parameters: {"user"=>"admin", "id"=>"1"}
5060
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5061
+  (0.0ms) rollback transaction
5062
+  (0.0ms) begin transaction
5063
+ Processing by MayMaysController#show as HTML
5064
+ Parameters: {"user"=>"admin", "id"=>"1"}
5065
+ Filter chain halted as :may_may_setup rendered or redirected
5066
+ Completed 403 Forbidden in 2ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5067
+  (0.0ms) rollback transaction
5068
+  (0.0ms) begin transaction
5069
+ Processing by MayMaysController#index as HTML
5070
+ Parameters: {"user"=>"guest"}
5071
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5072
+  (0.0ms) rollback transaction
5073
+  (0.0ms) begin transaction
5074
+ Processing by MayMaysController#create as HTML
5075
+ Parameters: {"user"=>"guest"}
5076
+ Filter chain halted as :may_may_setup rendered or redirected
5077
+ Completed 403 Forbidden in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
5078
+  (0.0ms) rollback transaction
5079
+  (0.0ms) begin transaction
5080
+ Processing by MayMaysController#show as HTML
5081
+ Parameters: {"user"=>"guest", "id"=>"1"}
5082
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5083
+  (0.0ms) rollback transaction
5084
+  (0.0ms) begin transaction
5085
+ Processing by MayMaysController#new as HTML
5086
+ Parameters: {"user"=>"admin"}
5087
+ Completed 200 OK in 18ms (Views: 17.2ms | ActiveRecord: 0.0ms)
5088
+  (0.1ms) rollback transaction
5089
+  (0.0ms) begin transaction
5090
+ Processing by MayMaysController#destroy as HTML
5091
+ Parameters: {"user"=>"standard", "id"=>"1"}
5092
+ Filter chain halted as :may_may_setup rendered or redirected
5093
+ Completed 403 Forbidden in 3ms (Views: 0.5ms | ActiveRecord: 0.0ms)
5094
+  (0.1ms) rollback transaction
5095
+  (0.0ms) begin transaction
5096
+ Processing by MayMaysController#new as HTML
5097
+ Parameters: {"user"=>"standard"}
5098
+ Completed 200 OK in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms)
5099
+  (0.1ms) rollback transaction
5100
+  (0.0ms) begin transaction
5101
+ Processing by MayMaysController#show as HTML
5102
+ Parameters: {"user"=>"standard", "id"=>"1"}
5103
+ Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
5104
+  (0.0ms) rollback transaction
5105
+  (0.0ms) begin transaction
5106
+  (0.0ms) rollback transaction
5107
+  (0.0ms) begin transaction
5108
+  (0.0ms) rollback transaction
5109
+ Connecting to database specified by database.yml
5110
+  (0.4ms) begin transaction
5111
+  (0.0ms) rollback transaction
5112
+  (0.0ms) begin transaction
5113
+  (0.0ms) rollback transaction
5114
+  (0.0ms) begin transaction
5115
+  (0.0ms) rollback transaction
5116
+  (0.0ms) begin transaction
5117
+  (0.0ms) rollback transaction
5118
+  (0.0ms) begin transaction
5119
+  (0.0ms) rollback transaction
5120
+  (0.0ms) begin transaction
5121
+  (0.0ms) rollback transaction
5122
+  (0.0ms) begin transaction
5123
+  (0.0ms) rollback transaction
5124
+  (0.0ms) begin transaction
5125
+  (0.0ms) rollback transaction
5126
+  (0.0ms) begin transaction
5127
+  (0.0ms) rollback transaction
5128
+  (0.0ms) begin transaction
5129
+  (0.0ms) rollback transaction
5130
+  (0.0ms) begin transaction
5131
+ Processing by MayMaysController#create as HTML
5132
+ Parameters: {"user"=>"admin"}
5133
+ Rendered text template (0.0ms)
5134
+ Completed 200 OK in 191ms (Views: 60.5ms | ActiveRecord: 5.7ms)
5135
+  (0.1ms) rollback transaction
5136
+  (0.0ms) begin transaction
5137
+ Processing by MayMaysController#destroy as HTML
5138
+ Parameters: {"user"=>"admin", "id"=>"1"}
5139
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5140
+  (0.1ms) rollback transaction
5141
+  (0.0ms) begin transaction
5142
+ Processing by MayMaysController#show as HTML
5143
+ Parameters: {"user"=>"admin", "id"=>"1"}
5144
+ Filter chain halted as :may_may_setup rendered or redirected
5145
+ Completed 403 Forbidden in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5146
+  (0.0ms) rollback transaction
5147
+  (0.0ms) begin transaction
5148
+ Processing by MayMaysController#index as HTML
5149
+ Parameters: {"user"=>"guest"}
5150
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5151
+  (0.0ms) rollback transaction
5152
+  (0.0ms) begin transaction
5153
+ Processing by MayMaysController#create as HTML
5154
+ Parameters: {"user"=>"guest"}
5155
+ Filter chain halted as :may_may_setup rendered or redirected
5156
+ Completed 403 Forbidden in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
5157
+  (0.0ms) rollback transaction
5158
+  (0.0ms) begin transaction
5159
+ Processing by MayMaysController#show as HTML
5160
+ Parameters: {"user"=>"guest", "id"=>"1"}
5161
+ Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
5162
+  (0.0ms) rollback transaction
5163
+  (0.0ms) begin transaction
5164
+ Processing by MayMaysController#new as HTML
5165
+ Parameters: {"user"=>"admin"}
5166
+ Completed 200 OK in 19ms (Views: 17.6ms | ActiveRecord: 0.0ms)
5167
+  (0.1ms) rollback transaction
5168
+  (0.0ms) begin transaction
5169
+ Processing by MayMaysController#destroy as HTML
5170
+ Parameters: {"user"=>"standard", "id"=>"1"}
5171
+ Filter chain halted as :may_may_setup rendered or redirected
5172
+ Completed 403 Forbidden in 2ms (Views: 0.4ms | ActiveRecord: 0.0ms)
5173
+  (0.1ms) rollback transaction
5174
+  (0.0ms) begin transaction
5175
+ Processing by MayMaysController#new as HTML
5176
+ Parameters: {"user"=>"standard"}
5177
+ Completed 200 OK in 2ms (Views: 0.4ms | ActiveRecord: 0.0ms)
5178
+  (0.1ms) rollback transaction
5179
+  (0.0ms) begin transaction
5180
+ Processing by MayMaysController#show as HTML
5181
+ Parameters: {"user"=>"standard", "id"=>"1"}
5182
+ Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
5183
+  (0.0ms) rollback transaction
5184
+  (0.0ms) begin transaction
5185
+  (0.0ms) rollback transaction
5186
+  (0.0ms) begin transaction
5187
+  (0.0ms) rollback transaction
5188
+ Connecting to database specified by database.yml
5189
+  (0.4ms) begin transaction
5190
+  (0.0ms) rollback transaction
5191
+  (0.0ms) begin transaction
5192
+  (0.0ms) rollback transaction
5193
+  (0.0ms) begin transaction
5194
+  (0.0ms) rollback transaction
5195
+  (0.0ms) begin transaction
5196
+  (0.0ms) rollback transaction
5197
+  (0.0ms) begin transaction
5198
+  (0.0ms) rollback transaction
5199
+  (0.0ms) begin transaction
5200
+  (0.0ms) rollback transaction
5201
+  (0.0ms) begin transaction
5202
+  (0.0ms) rollback transaction
5203
+  (0.0ms) begin transaction
5204
+  (0.0ms) rollback transaction
5205
+  (0.0ms) begin transaction
5206
+  (0.0ms) rollback transaction
5207
+  (0.0ms) begin transaction
5208
+  (0.0ms) rollback transaction
5209
+  (0.0ms) begin transaction
5210
+ Processing by MayMaysController#create as HTML
5211
+ Parameters: {"user"=>"admin"}
5212
+ Rendered text template (0.0ms)
5213
+ Completed 200 OK in 206ms (Views: 34.5ms | ActiveRecord: 6.5ms)
5214
+  (0.1ms) rollback transaction
5215
+  (0.0ms) begin transaction
5216
+ Processing by MayMaysController#destroy as HTML
5217
+ Parameters: {"user"=>"admin", "id"=>"1"}
5218
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5219
+  (0.1ms) rollback transaction
5220
+  (0.0ms) begin transaction
5221
+ Processing by MayMaysController#show as HTML
5222
+ Parameters: {"user"=>"admin", "id"=>"1"}
5223
+ Filter chain halted as :may_may_setup rendered or redirected
5224
+ Completed 403 Forbidden in 2ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5225
+  (0.0ms) rollback transaction
5226
+  (0.0ms) begin transaction
5227
+ Processing by MayMaysController#index as HTML
5228
+ Parameters: {"user"=>"guest"}
5229
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5230
+  (0.0ms) rollback transaction
5231
+  (0.0ms) begin transaction
5232
+ Processing by MayMaysController#create as HTML
5233
+ Parameters: {"user"=>"guest"}
5234
+ Filter chain halted as :may_may_setup rendered or redirected
5235
+ Completed 403 Forbidden in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
5236
+  (0.0ms) rollback transaction
5237
+  (0.0ms) begin transaction
5238
+ Processing by MayMaysController#show as HTML
5239
+ Parameters: {"user"=>"guest", "id"=>"1"}
5240
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5241
+  (0.1ms) rollback transaction
5242
+  (0.0ms) begin transaction
5243
+ Processing by MayMaysController#new as HTML
5244
+ Parameters: {"user"=>"admin"}
5245
+ Completed 200 OK in 13ms (Views: 11.4ms | ActiveRecord: 0.0ms)
5246
+  (0.1ms) rollback transaction
5247
+  (0.0ms) begin transaction
5248
+ Processing by MayMaysController#destroy as HTML
5249
+ Parameters: {"user"=>"standard", "id"=>"1"}
5250
+ Filter chain halted as :may_may_setup rendered or redirected
5251
+ Completed 403 Forbidden in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5252
+  (0.1ms) rollback transaction
5253
+  (0.0ms) begin transaction
5254
+ Processing by MayMaysController#new as HTML
5255
+ Parameters: {"user"=>"standard"}
5256
+ Completed 200 OK in 2ms (Views: 0.9ms | ActiveRecord: 0.0ms)
5257
+  (0.0ms) rollback transaction
5258
+  (0.0ms) begin transaction
5259
+ Processing by MayMaysController#show as HTML
5260
+ Parameters: {"user"=>"standard", "id"=>"1"}
5261
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5262
+  (0.0ms) rollback transaction
5263
+  (0.0ms) begin transaction
5264
+  (0.0ms) rollback transaction
5265
+  (0.1ms) begin transaction
5266
+  (0.1ms) rollback transaction
5267
+ Connecting to database specified by database.yml
5268
+  (0.4ms) begin transaction
5269
+  (0.0ms) rollback transaction
5270
+  (0.0ms) begin transaction
5271
+  (0.0ms) rollback transaction
5272
+  (0.0ms) begin transaction
5273
+  (0.0ms) rollback transaction
5274
+  (0.0ms) begin transaction
5275
+  (0.0ms) rollback transaction
5276
+  (0.0ms) begin transaction
5277
+  (0.0ms) rollback transaction
5278
+  (0.0ms) begin transaction
5279
+  (0.0ms) rollback transaction
5280
+  (0.0ms) begin transaction
5281
+  (0.0ms) rollback transaction
5282
+  (0.0ms) begin transaction
5283
+  (0.0ms) rollback transaction
5284
+  (0.0ms) begin transaction
5285
+  (0.0ms) rollback transaction
5286
+  (0.0ms) begin transaction
5287
+  (0.0ms) rollback transaction
5288
+  (0.0ms) begin transaction
5289
+ Processing by MayMaysController#create as HTML
5290
+ Parameters: {"user"=>"admin"}
5291
+ Rendered text template (0.0ms)
5292
+ Completed 200 OK in 229ms (Views: 93.5ms | ActiveRecord: 5.5ms)
5293
+  (0.1ms) rollback transaction
5294
+  (0.0ms) begin transaction
5295
+ Processing by MayMaysController#destroy as HTML
5296
+ Parameters: {"user"=>"admin", "id"=>"1"}
5297
+ Completed 200 OK in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5298
+  (0.0ms) rollback transaction
5299
+  (0.0ms) begin transaction
5300
+ Processing by MayMaysController#show as HTML
5301
+ Parameters: {"user"=>"admin", "id"=>"1"}
5302
+ Filter chain halted as :may_may_setup rendered or redirected
5303
+ Completed 403 Forbidden in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5304
+  (0.1ms) rollback transaction
5305
+  (0.0ms) begin transaction
5306
+ Processing by MayMaysController#index as HTML
5307
+ Parameters: {"user"=>"guest"}
5308
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5309
+  (0.0ms) rollback transaction
5310
+  (0.0ms) begin transaction
5311
+ Processing by MayMaysController#create as HTML
5312
+ Parameters: {"user"=>"guest"}
5313
+ Filter chain halted as :may_may_setup rendered or redirected
5314
+ Completed 403 Forbidden in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5315
+  (0.0ms) rollback transaction
5316
+  (0.0ms) begin transaction
5317
+ Processing by MayMaysController#show as HTML
5318
+ Parameters: {"user"=>"guest", "id"=>"1"}
5319
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5320
+  (0.0ms) rollback transaction
5321
+  (0.0ms) begin transaction
5322
+ Processing by MayMaysController#new as HTML
5323
+ Parameters: {"user"=>"admin"}
5324
+ Completed 200 OK in 13ms (Views: 11.4ms | ActiveRecord: 0.0ms)
5325
+  (0.1ms) rollback transaction
5326
+  (0.0ms) begin transaction
5327
+ Processing by MayMaysController#destroy as HTML
5328
+ Parameters: {"user"=>"standard", "id"=>"1"}
5329
+ Filter chain halted as :may_may_setup rendered or redirected
5330
+ Completed 403 Forbidden in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5331
+  (0.1ms) rollback transaction
5332
+  (0.0ms) begin transaction
5333
+ Processing by MayMaysController#new as HTML
5334
+ Parameters: {"user"=>"standard"}
5335
+ Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
5336
+  (0.0ms) rollback transaction
5337
+  (0.0ms) begin transaction
5338
+ Processing by MayMaysController#show as HTML
5339
+ Parameters: {"user"=>"standard", "id"=>"1"}
5340
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
5341
+  (0.0ms) rollback transaction
5342
+  (0.1ms) begin transaction
5343
+  (0.0ms) rollback transaction
5344
+  (0.0ms) begin transaction
5345
+  (0.0ms) rollback transaction
@@ -20,24 +20,23 @@ end
20
20
 
21
21
  class MayMayTest < ActiveSupport::TestCase
22
22
  test "access_denied if not specifically permitted" do
23
- May.permissions_setup {}
24
23
  assert !May.permission_to?(:test_1_action, :people, Roles.new)
25
24
  end
26
25
 
27
26
  test "access allowed for anyone if named but no roles specified" do
28
- May.permissions_setup { controller(:people) { may :test_2_action } }
27
+ May.controller(:people) { May.may :test_2_action }
29
28
  assert May.permission_to?(:test_2_action, :people, Roles.new)
30
29
  end
31
30
 
32
31
  test "access allowed for specified role only" do
33
- May.permissions_setup { controller(:people) { may :test_3_action, :only => :a_role } }
32
+ May.controller(:people) { May.may :test_3_action, :only => :a_role }
34
33
  with_correct_role = May.permission_to?(:test_3_action, :people, Roles.new(:a_role))
35
34
  without_correct_role = May.permission_to?(:test_3_action, :people, Roles.new(:b_role))
36
35
  assert_equal [true, false], [with_correct_role, without_correct_role]
37
36
  end
38
37
 
39
38
  test "access allowed for specified roles" do
40
- May.permissions_setup { controller(:people) { may :test_4_action, :only => [:a_role1, :a_role2] } }
39
+ May.controller(:people) { May.may :test_4_action, :only => [:a_role1, :a_role2] }
41
40
  with_first_role = May.permission_to?(:test_4_action, :people, Roles.new(:a_role1))
42
41
  with_second_role = May.permission_to?(:test_4_action, :people, Roles.new(:a_role2))
43
42
  with_both_roles = May.permission_to?(:test_4_action, :people, Roles.new([:a_role1, :a_role2]))
@@ -46,7 +45,7 @@ class MayMayTest < ActiveSupport::TestCase
46
45
  end
47
46
 
48
47
  test "access denied for specified roles" do
49
- May.permissions_setup { controller(:people) { may :test_5_action, :except => [:a_role1, :a_role2] } }
48
+ May.controller(:people) { May.may :test_5_action, :except => [:a_role1, :a_role2] }
50
49
  with_first_role = May.permission_to?(:test_5_action, :people, Roles.new(:a_role1))
51
50
  with_second_role = May.permission_to?(:test_5_action, :people, Roles.new(:a_role2))
52
51
  with_both_roles = May.permission_to?(:test_5_action, :people, Roles.new([:a_role1, :a_role2]))
@@ -55,24 +54,24 @@ class MayMayTest < ActiveSupport::TestCase
55
54
  end
56
55
 
57
56
  test "access denied by block" do
58
- May.permissions_setup { controller(:people) { may(:test_6_action) {|controller| false } } }
57
+ May.controller(:people) { May.may(:test_6_action) {|controller| false } }
59
58
  assert !May.permission_to?(:test_6_action, :people, Roles.new)
60
59
  end
61
60
 
62
61
  test "access allowed by block" do
63
- May.permissions_setup { controller(:people) { may(:test_7_action) {|controller| true } } }
62
+ May.controller(:people) { May.may(:test_7_action) {|controller| true } }
64
63
  assert May.permission_to?(:test_7_action, :people, Roles.new)
65
64
  end
66
65
 
67
66
  test "controller may method works" do
68
- May.permissions_setup { controller(:people) { may(:test_8_action, :only => [:a_role]) } }
67
+ May.controller(:people) { May.may(:test_8_action, :only => [:a_role]) }
69
68
  with_role = Roles.new(:a_role).may?(:test_8_action, :people)
70
69
  without_role = Roles.new.may?(:test_8_action, :people)
71
70
  assert_equal [true, false], [with_role, without_role]
72
71
  end
73
72
 
74
73
  test "controller may method with block" do
75
- May.permissions_setup { controller(:people) { may(:test_9_action, :only => [:a_role]) } }
74
+ May.controller(:people) { May.may(:test_9_action, :only => [:a_role]) }
76
75
  with_role = false
77
76
  Roles.new(:a_role).may?(:test_9_action, :people) { with_role = 'allowed!' }
78
77
  without_role = Roles.new.may?(:test_9_action, :people) { without_role = 'not allowed!' }
@@ -81,7 +80,7 @@ class MayMayTest < ActiveSupport::TestCase
81
80
 
82
81
  test "controller may with permission block" do
83
82
  can = true
84
- May.permissions_setup {controller(:people) { may(:test_10_action) { can } } }
83
+ May.controller(:people) { May.may(:test_10_action) { can } }
85
84
  should = false
86
85
  Roles.new.may?(:test_10_action, :people) { should = 'allowed!' }
87
86
  can = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: may_may
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: