acl9 0.12.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +21 -7
  3. data/.travis.yml +19 -0
  4. data/Appraisals +8 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +88 -32
  8. data/LICENSE +9 -0
  9. data/README.md +156 -0
  10. data/Rakefile +6 -3
  11. data/acl9.gemspec +10 -13
  12. data/gemfiles/rails_4.0.gemfile +8 -0
  13. data/gemfiles/rails_4.1.gemfile +8 -0
  14. data/lib/acl9/model_extensions/for_subject.rb +5 -1
  15. data/lib/acl9/model_extensions.rb +3 -24
  16. data/lib/acl9/version.rb +1 -1
  17. data/lib/acl9.rb +1 -1
  18. data/test/controller_extensions/actions_test.rb +167 -0
  19. data/test/controller_extensions/anon_test.rb +39 -0
  20. data/test/controller_extensions/base.rb +96 -0
  21. data/test/controller_extensions/basics_test.rb +44 -0
  22. data/test/controller_extensions/conditions_test.rb +48 -0
  23. data/test/controller_extensions/method_test.rb +50 -0
  24. data/test/controller_extensions/multi_match_test.rb +142 -0
  25. data/test/controller_extensions/multiple_role_arguments_test.rb +135 -0
  26. data/test/controller_extensions/prepositions_test.rb +99 -0
  27. data/test/controller_extensions/pseudo_role_test.rb +26 -0
  28. data/test/controller_extensions/role_test.rb +75 -0
  29. data/test/controllers/acl_action_override_test.rb +24 -0
  30. data/test/controllers/acl_arguments_test.rb +5 -0
  31. data/test/controllers/acl_block_test.rb +5 -0
  32. data/test/controllers/acl_boolean_method_test.rb +5 -0
  33. data/test/controllers/acl_helper_method_test.rb +26 -0
  34. data/test/controllers/acl_ivars_test.rb +15 -0
  35. data/test/controllers/acl_method2_test.rb +6 -0
  36. data/test/controllers/acl_method_test.rb +6 -0
  37. data/test/controllers/acl_object_hash_test.rb +18 -0
  38. data/test/controllers/acl_query_method_named_test.rb +9 -0
  39. data/test/controllers/acl_query_method_test.rb +9 -0
  40. data/test/controllers/acl_query_method_with_lambda_test.rb +9 -0
  41. data/test/controllers/acl_query_mixin.rb +51 -0
  42. data/test/controllers/acl_subject_method_test.rb +15 -0
  43. data/test/controllers/arguments_checking_test.rb +43 -0
  44. data/test/dummy/app/controllers/acl_action_override.rb +15 -0
  45. data/test/dummy/app/controllers/acl_arguments.rb +10 -0
  46. data/test/dummy/app/controllers/acl_block.rb +6 -0
  47. data/test/dummy/app/controllers/acl_boolean_method.rb +23 -0
  48. data/test/dummy/app/controllers/acl_helper_method.rb +11 -0
  49. data/test/dummy/app/controllers/acl_ivars.rb +17 -0
  50. data/test/dummy/app/controllers/acl_method.rb +6 -0
  51. data/test/dummy/app/controllers/acl_method2.rb +6 -0
  52. data/test/dummy/app/controllers/acl_objects_hash.rb +10 -0
  53. data/test/dummy/app/controllers/acl_query_method.rb +9 -0
  54. data/test/dummy/app/controllers/acl_query_method_named.rb +13 -0
  55. data/test/dummy/app/controllers/acl_query_method_with_lambda.rb +9 -0
  56. data/test/dummy/app/controllers/acl_subject_method.rb +16 -0
  57. data/test/dummy/app/controllers/application_controller.rb +7 -0
  58. data/test/dummy/app/controllers/empty_controller.rb +5 -0
  59. data/test/dummy/app/helpers/application_helper.rb +2 -0
  60. data/test/dummy/app/helpers/some_helper.rb +8 -0
  61. data/test/dummy/app/models/.keep +0 -0
  62. data/test/dummy/app/models/access.rb +3 -0
  63. data/test/dummy/app/models/account.rb +3 -0
  64. data/test/dummy/app/models/bar.rb +3 -0
  65. data/test/dummy/app/models/concerns/.keep +0 -0
  66. data/test/dummy/app/models/foo.rb +3 -0
  67. data/test/dummy/app/models/foo_bar.rb +3 -0
  68. data/test/dummy/app/models/other/foo.rb +5 -0
  69. data/test/dummy/app/models/other/role.rb +5 -0
  70. data/test/dummy/app/models/other/user.rb +5 -0
  71. data/test/dummy/app/models/role.rb +3 -0
  72. data/test/dummy/app/models/user.rb +3 -0
  73. data/test/dummy/app/models/uuid.rb +4 -0
  74. data/test/dummy/config/application.rb +23 -0
  75. data/test/dummy/config/boot.rb +4 -0
  76. data/test/dummy/config/database.yml +25 -0
  77. data/test/dummy/config/environment.rb +5 -0
  78. data/test/dummy/config/environments/development.rb +37 -0
  79. data/test/dummy/config/environments/production.rb +78 -0
  80. data/test/dummy/config/environments/test.rb +39 -0
  81. data/test/dummy/config/initializers/assets.rb +8 -0
  82. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  83. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  84. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  85. data/test/dummy/config/initializers/inflections.rb +16 -0
  86. data/test/dummy/config/initializers/mime_types.rb +4 -0
  87. data/test/dummy/config/initializers/secrets.rb +1 -0
  88. data/test/dummy/config/initializers/session_store.rb +3 -0
  89. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  90. data/test/dummy/config/locales/en.yml +23 -0
  91. data/test/dummy/config/routes.rb +3 -0
  92. data/test/dummy/config.ru +4 -0
  93. data/test/dummy/db/migrate/20141117132218_create_tables.rb +102 -0
  94. data/test/helpers/helper_test.rb +89 -0
  95. data/test/models/roles_test.rb +251 -0
  96. data/test/models/roles_with_custom_association_names_test.rb +28 -0
  97. data/test/models/roles_with_custom_class_names_test.rb +28 -0
  98. data/test/models/system_roles_test.rb +16 -0
  99. data/test/models/users_roles_and_subjects_with_namespaced_class_names_test.rb +30 -0
  100. data/test/test_helper.rb +76 -23
  101. data/test/version_test.rb +2 -2
  102. metadata +190 -74
  103. data/README.textile +0 -921
  104. data/VERSION.yml +0 -5
  105. data/init.rb +0 -1
  106. data/test/access_control_test.rb +0 -338
  107. data/test/dsl_base_test.rb +0 -795
  108. data/test/helpers_test.rb +0 -133
  109. data/test/roles_test.rb +0 -370
  110. data/test/support/controllers.rb +0 -207
  111. data/test/support/models.rb +0 -59
  112. data/test/support/schema.rb +0 -93
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ class HelperTest < ActionView::TestCase
4
+ setup do
5
+ @helper = Class.new do
6
+ include ActionView::Helpers
7
+ include SomeHelper
8
+
9
+ attr_accessor :current_user
10
+ attr_accessor :action_name
11
+ def controller
12
+ self
13
+ end
14
+
15
+ def set_hamlet
16
+ ( self.current_user = User.create ).has_role! :hamlet
17
+ end
18
+ end.new
19
+
20
+ end
21
+
22
+ test "has :the_question method" do
23
+ assert @helper.respond_to? :the_question
24
+ end
25
+
26
+ test "role :hamlet is allowed to be" do
27
+ assert @helper.set_hamlet
28
+
29
+ assert @helper.action_name = 'be'
30
+ assert @helper.the_question
31
+ end
32
+
33
+ test "role :hamlet is allowed to not_be" do
34
+ assert @helper.set_hamlet
35
+
36
+ assert @helper.action_name = 'not_be'
37
+ assert @helper.the_question
38
+ end
39
+
40
+ test "not logged in is not allowed to be" do
41
+ assert_nil @helper.current_user = nil
42
+
43
+ assert @helper.action_name = 'be'
44
+ refute @helper.the_question
45
+ end
46
+
47
+ test "noone is not allowed to be" do
48
+ assert ( @helper.current_user = User.create )
49
+
50
+ assert @helper.action_name = 'be'
51
+ refute @helper.the_question
52
+ end
53
+
54
+ test "has :show_to method" do
55
+ assert @helper.respond_to? :show_to
56
+ end
57
+
58
+ test "has :show_to hamlet 'hello hamlet' message" do
59
+ assert @helper.set_hamlet
60
+
61
+ assert message = 'hello hamlet'
62
+ assert_equal message, @helper.show_to('hamlet') { message }
63
+ end
64
+
65
+ test "has to show message if user has hamlet role on object" do
66
+ assert foo = Foo.create
67
+ assert ( @helper.current_user = User.create ).has_role! :hamlet, foo
68
+
69
+ assert message = 'hello hamlet'
70
+ assert_equal message, @helper.show_to(:hamlet, :of => foo) { message }
71
+ end
72
+
73
+ test "has not to show message if user has no hamlet role on object" do
74
+ assert @helper.set_hamlet
75
+
76
+ assert foo = Foo.create
77
+ assert @helper.current_user.has_role! :hamlet, foo
78
+
79
+ assert_nil @helper.show_to('hamlet', :of => Foo.new) { 'hello my prince' }
80
+ end
81
+
82
+ test "has :show_to nothing to NotLoggedIn" do
83
+ assert_nil @helper.current_user = nil
84
+
85
+ assert @helper.action_name = 'be'
86
+ assert message = 'hello hamlet'
87
+ assert_nil @helper.show_to(:hamlet) { message }
88
+ end
89
+ end
@@ -0,0 +1,251 @@
1
+ require 'test_helper'
2
+
3
+ class RolesTest < ActiveSupport::TestCase
4
+ setup do
5
+ assert @user = User.create
6
+ assert @user2 = User.create
7
+ assert @foo = Foo.create
8
+ assert @bar = Bar.create
9
+ end
10
+
11
+ test "should not have any roles by default" do
12
+ %w(user manager admin owner).each do |role|
13
+ refute @user.has_role? role
14
+ end
15
+ end
16
+
17
+ test "#has_role! without object (global role)" do
18
+ assert_difference -> { Role.count } do
19
+ assert @user.has_role! :admin
20
+ end
21
+
22
+ assert @user.has_role? :admin
23
+ refute @user2.has_role? :admin
24
+ end
25
+
26
+ test "should not count global role as object role" do
27
+ assert @user.has_role! :admin
28
+
29
+ [@foo, @bar, Foo, Bar, @user].each do |obj|
30
+ refute @user.has_role? :admin, obj
31
+ refute @user.has_roles_for?(obj)
32
+ assert_equal [], @user.roles_for(obj)
33
+ end
34
+
35
+ [@foo, @bar].each do |obj|
36
+ refute obj.accepts_role? :admin, @user
37
+ end
38
+ end
39
+
40
+ test "#has_role! with object (object role)" do
41
+ assert @user.has_role! :manager, @foo
42
+
43
+ assert @user.has_role? :manager, @foo
44
+ assert @user.has_roles_for? @foo
45
+ assert @user.has_role_for? @foo
46
+
47
+ assert roles = @user.roles_for( @foo )
48
+ assert_equal roles, @foo.accepted_roles_by(@user)
49
+ assert_equal 1, roles.size
50
+ assert_equal 'manager', roles.first.name
51
+
52
+ refute @user.has_role? :manager, @bar
53
+ refute @user2.has_role? :manager, @foo
54
+
55
+ assert @foo.accepts_role? :manager, @user
56
+ assert @foo.accepts_role_by? @user
57
+ assert @foo.accepts_roles_by? @user
58
+ end
59
+
60
+ test "should count object role also as global role when :protect_global_roles == false" do
61
+ Acl9.config[:protect_global_roles] = false
62
+
63
+ assert @user.has_role! :manager, @foo
64
+ assert @user.has_role? :manager
65
+
66
+ Acl9.config[:protect_global_roles] = true
67
+ end
68
+
69
+ test "should not count object role as object class role" do
70
+ assert @user.has_role! :manager, @foo
71
+ refute @user.has_role? :manager, Foo
72
+ end
73
+
74
+ test "don't count object role as global" do
75
+ assert @user.has_role! :manager, @foo
76
+ refute @user.has_role? :manager
77
+ end
78
+
79
+ test "#has_role! with class" do
80
+ assert @user.has_role! :user, Bar
81
+
82
+ assert @user.has_role? :user, Bar
83
+ assert @user.has_roles_for? Bar
84
+ assert @user.has_role_for? Bar
85
+
86
+ assert roles = @user.roles_for( Bar)
87
+ assert_equal 1, roles.size
88
+ assert_equal "user", roles.first.name
89
+
90
+ refute @user.has_role? :user, Foo
91
+ refute @user2.has_role? :user, Bar
92
+ end
93
+
94
+ test "should not count class role as object role" do
95
+ assert @user.has_role! :manager, Foo
96
+ refute @user.has_role? :manager, @foo
97
+ end
98
+
99
+ test "should be able to have several roles on the same object" do
100
+ assert @user.has_role! :manager, @foo
101
+ assert @user.has_role! :user, @foo
102
+ assert @user.has_role! :admin, @foo
103
+
104
+ assert @user.has_role! :owner, @bar
105
+
106
+ assert_equal_elements %w(admin manager user), @user.roles_for(@foo).map(&:name)
107
+ assert_equal_elements %w(admin manager user), @foo.accepted_roles_by(@user).map(&:name)
108
+ end
109
+
110
+ test "should reuse existing roles" do
111
+ @user.has_role! :owner, @bar
112
+ @user2.has_role! :owner, @bar
113
+
114
+ assert_equal @user2.role_objects, @user.role_objects
115
+ end
116
+
117
+ test "#has_no_role! should unassign a global role from user" do
118
+ set_some_roles
119
+
120
+ assert_difference -> { @user.role_objects.count }, -1 do
121
+ assert @user.has_no_role! '3133t'
122
+ end
123
+
124
+ refute @user.has_role? '3133t'
125
+ end
126
+
127
+ test "#has_no_role! should unassign an object role from user" do
128
+ set_some_roles
129
+
130
+ assert_difference -> { @user.role_objects.count }, -1 do
131
+ assert @user.has_no_role! :manager, @foo
132
+ end
133
+
134
+ refute @user.has_role? :manager, @foo
135
+ assert @user.has_role? :user, @foo # another role on the same object
136
+ end
137
+
138
+ test "#has_no_role! should unassign a class role from user" do
139
+ set_some_roles
140
+
141
+ assert_difference -> { @user.role_objects.count }, -1 do
142
+ assert @user.has_no_role! :admin, Foo
143
+ end
144
+
145
+ refute @user.has_role? :admin, Foo
146
+ assert @user.has_role? :admin # global role
147
+ end
148
+
149
+ test "#has_no_roles_for! should unassign global and class roles with nil object" do
150
+ set_some_roles
151
+
152
+ assert_difference -> { @user.role_objects.count }, -4 do
153
+ assert @user.has_no_roles_for!
154
+ end
155
+
156
+ refute @user.has_role? :admin
157
+ refute @user.has_role? '3133t'
158
+ refute @user.has_role? :admin, Foo
159
+ refute @user.has_role? :manager, Foo
160
+ end
161
+
162
+ test "#has_no_roles_for! should unassign object roles" do
163
+ set_some_roles
164
+
165
+ assert_difference -> { @user.role_objects.count }, -2 do
166
+ assert @user.has_no_roles_for! @foo
167
+ end
168
+
169
+ refute @user.has_role? :user, @foo
170
+ refute @user.has_role? :manager, @foo
171
+ end
172
+
173
+ test "#has_no_roles_for! should unassign both class roles and object roles for objects of that class" do
174
+ set_some_roles
175
+
176
+ assert_difference -> { @user.role_objects.count }, -4 do
177
+ assert @user.has_no_roles_for! Foo
178
+ end
179
+
180
+ refute @user.has_role? :admin, Foo
181
+ refute @user.has_role? :manager, Foo
182
+ refute @user.has_role? :user, @foo
183
+ refute @user.has_role? :manager, @foo
184
+ end
185
+
186
+ test "#has_no_roles! should unassign all roles" do
187
+ set_some_roles
188
+
189
+ @user.has_no_roles!
190
+ assert_equal 0, @user.role_objects.count
191
+ end
192
+
193
+ test "should delete unused roles from table" do
194
+ assert @user.has_role! :owner, @bar
195
+ assert @user2.has_role! :owner, @bar
196
+
197
+ assert_equal 1, Role.count
198
+
199
+ @bar.accepts_no_role! :owner, @user2
200
+ assert_equal 1, Role.count
201
+
202
+ @bar.accepts_no_role! :owner, @user
203
+
204
+ assert_equal 0, Role.count
205
+ end
206
+
207
+ test "should be able to get users that have a role on a authorized object" do
208
+ assert @user.has_role! :owner, @bar
209
+ assert @user2.has_role! :owner, @bar
210
+
211
+ assert_equal 2, @bar.users.count
212
+ end
213
+
214
+ test "should be able to get users that have a role on a authorized object with text primary key" do
215
+ assert uuid = Uuid.create( id: "C41642EE-2780-0001-189F-17F3101B26E0" )
216
+
217
+ assert @user.has_role! :owner, uuid
218
+ assert @user2.has_role! :owner, uuid
219
+
220
+ assert_equal 2, uuid.users.count
221
+ end
222
+
223
+ test "should accept :symbols as role names" do
224
+ assert @user.has_role! :admin
225
+ assert @user.has_role! :_3133t
226
+
227
+ assert @user.has_role! :admin, Foo
228
+ assert @user.has_role! :manager, Foo
229
+ assert @user.has_role! :user, @foo
230
+ assert @foo.accepts_role! :manager, @user
231
+ assert @bar.accepts_role! :owner, @user
232
+
233
+ assert @user.has_role?(:admin)
234
+ assert @user.has_role?(:_3133t)
235
+ assert @user.has_role?(:admin, Foo)
236
+ assert @user.has_role?(:manager, @foo)
237
+ end
238
+
239
+ private
240
+
241
+ def set_some_roles
242
+ assert @user.has_role! :admin
243
+ assert @user.has_role! '3133t'
244
+
245
+ assert @user.has_role! :admin, Foo
246
+ assert @user.has_role! :manager, Foo
247
+ assert @user.has_role! :user, @foo
248
+ assert @foo.accepts_role! :manager, @user
249
+ assert @bar.accepts_role! :owner, @user
250
+ end
251
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class RolesWithCustomAssociationNamesTest < ActiveSupport::TestCase
4
+ setup do
5
+ Access.destroy_all
6
+ [Account, FooBar].each { |model| model.delete_all }
7
+
8
+ assert @subj = Account.create!
9
+ assert @subj2 = Account.create!
10
+ assert @foobar = FooBar.create!
11
+ end
12
+
13
+ test "should basically work" do
14
+ assert_difference -> { Access.count }, 2 do
15
+ assert @subj.has_role! :admin
16
+ assert @subj.has_role! :user, @foobar
17
+ end
18
+
19
+ assert @subj.has_role? :admin
20
+ refute @subj2.has_role? :admin
21
+
22
+ assert @subj.has_role? :user, @foobar
23
+ refute @subj2.has_role? :user, @foobar
24
+
25
+ @subj.has_no_roles!
26
+ @subj2.has_no_roles!
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class RolesWithCustomClassNamesTest < ActiveSupport::TestCase
4
+ setup do
5
+ Access.destroy_all
6
+ [Account, FooBar].each { |model| model.delete_all }
7
+
8
+ @subj = Account.create!
9
+ @subj2 = Account.create!
10
+ @foobar = FooBar.create!
11
+ end
12
+
13
+ test "should basically work" do
14
+ assert_difference -> { Access.count }, 2 do
15
+ assert @subj.has_role! :admin
16
+ assert @subj.has_role! :user, @foobar
17
+ end
18
+
19
+ assert @subj.has_role? :admin
20
+ refute @subj2.has_role? :admin
21
+
22
+ assert @subj.has_role? :user, @foobar
23
+ refute @subj2.has_role? :user, @foobar
24
+
25
+ assert @subj.has_no_roles!
26
+ assert @subj2.has_no_roles!
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class SystemRolesTest < ActiveSupport::TestCase
4
+ test "should not delete a system role" do
5
+ assert role = Role.create( :name => "admin", :system => true)
6
+ assert role.system
7
+ assert_equal 1, Role.count
8
+
9
+ assert user = User.create
10
+ assert user.has_role! :admin
11
+ assert_equal 1, Role.count
12
+
13
+ refute user.has_no_role! :admin
14
+ assert_equal 1, Role.count
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class UsersRolesAndSubjectsWithNamespacedClassNamesTest < ActiveSupport::TestCase
4
+ setup do
5
+ assert Other::Role.destroy_all
6
+ [Other::User, Other::Foo].each { |model| model.delete_all }
7
+
8
+ assert @user = Other::User.create!
9
+ assert @user2 = Other::User.create!
10
+ assert @foobar = Other::Foo.create!
11
+ end
12
+
13
+ test "should basically work" do
14
+ assert_difference -> { Other::Role.count }, 2 do
15
+ assert @user.has_role! :admin
16
+ assert @user.has_role! :user, @foobar
17
+ end
18
+
19
+ assert @user.has_role?('admin')
20
+ refute @user2.has_role?('admin')
21
+
22
+ assert @user.has_role?(:user, @foobar)
23
+ refute @user2.has_role?(:user, @foobar)
24
+
25
+ assert_equal 1, @foobar.accepted_roles.count
26
+
27
+ @user.has_no_roles!
28
+ @user2.has_no_roles!
29
+ end
30
+ end
data/test/test_helper.rb CHANGED
@@ -1,30 +1,83 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'test/unit'
4
- require 'context'
5
- require 'matchy'
6
- require 'active_support'
7
- require 'active_record'
8
- require 'action_controller'
9
- require 'action_controller/test_process'
10
- require 'turn'
11
-
12
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'test.sqlite3')
13
-
14
- class Test::Unit::TestCase
15
- custom_matcher :be_false do |receiver, matcher, args|
16
- !receiver
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ ENV["RAILS_ENV"] = "test"
5
+
6
+ require 'minitest/autorun'
7
+
8
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
9
+ require "rails/test_help"
10
+
11
+ Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
12
+
13
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
14
+
15
+ class ActionController::TestCase
16
+ class << self
17
+ def test_allowed method, action, params=nil, cookies=nil
18
+ test "allowed #{action} #{method}" do
19
+ if block_given?
20
+ yield user = User.create
21
+ ( params ||= {} ).merge! :user_id => user.id
22
+ end
23
+ assert send( method, action, params, cookies )
24
+ assert_response :ok
25
+ end
26
+ end
27
+
28
+ def test_denied method, action, params=nil, cookies=nil
29
+ test "denied #{action} #{method}" do
30
+ assert_raises Acl9::AccessDenied do
31
+ if block_given?
32
+ yield user = User.create
33
+ ( params ||= {} ).merge! :user_id => user.id
34
+ end
35
+ assert send( method, action, params, cookies )
36
+ end
37
+ end
38
+ end
17
39
  end
40
+ end
18
41
 
19
- custom_matcher :be_true do |receiver, matcher, args|
20
- !!receiver
42
+ class ActiveSupport::TestCase
43
+ def assert_equal_elements expected, test, message=nil
44
+ assert_equal [], expected - test, message
21
45
  end
22
46
  end
23
47
 
24
- ActionController::Routing::Routes.draw do |map|
25
- map.connect ":controller/:action/:id"
48
+ module BaseTests
49
+ def self.included(klass)
50
+ klass.class_eval do
51
+ test_allowed :get, :index
52
+ test_allowed :get, :show, :id => 1
53
+ test_denied :get, :new
54
+ test_denied :get, :edit, :id => 1
55
+ test_denied :post, :create
56
+ test_denied :put, :update, :id => 1
57
+ test_denied :patch, :update, :id => 1
58
+ test_denied :delete, :destroy, :id => 1
59
+
60
+ admin = -> (user) { user.has_role! :admin }
61
+ test_allowed :get, :new, &admin
62
+ test_allowed :get, :edit, :id => 1, &admin
63
+ test_allowed :post, :create, &admin
64
+ test_allowed :put, :update, :id => 1, &admin
65
+ test_allowed :patch, :update, :id => 1, &admin
66
+ test_allowed :delete, :destroy, :id => 1, &admin
67
+ end
68
+ end
26
69
  end
27
70
 
28
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
29
- ActionController::Base.logger = ActiveRecord::Base.logger
30
- ActiveRecord::Base.silence { ActiveRecord::Migration.verbose = false }
71
+ module ShouldRespondToAcl
72
+ def self.included(klass)
73
+ klass.class_eval do
74
+ test "#{klass} has :acl method" do
75
+ assert @controller.respond_to? :acl
76
+ end
77
+
78
+ test "#{klass} has no :acl? method" do
79
+ refute @controller.respond_to? :acl?
80
+ end
81
+ end
82
+ end
83
+ end
data/test/version_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
- class VersionTest < Test::Unit::TestCase
4
- it "Should have a version" do
3
+ class VersionTest < ActiveSupport::TestCase
4
+ test "has a version" do
5
5
  assert defined? Acl9::VERSION
6
6
  end
7
7
  end