strongbolt 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +33 -0
  3. data/.gitignore +18 -0
  4. data/.rspec +1 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +130 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +182 -0
  11. data/Rakefile +1 -0
  12. data/app/assets/javascripts/strongbolt.js +1 -0
  13. data/app/assets/javascripts/strongbolt/role-capabilities.js +80 -0
  14. data/app/controllers/strongbolt/capabilities_controller.rb +77 -0
  15. data/app/controllers/strongbolt/roles_controller.rb +92 -0
  16. data/app/controllers/strongbolt/security_controller.rb +8 -0
  17. data/app/controllers/strongbolt/user_groups_controller.rb +76 -0
  18. data/app/controllers/strongbolt/user_groups_users_controller.rb +35 -0
  19. data/app/controllers/strongbolt_controller.rb +2 -0
  20. data/app/views/strongbolt/_menu.html.erb +13 -0
  21. data/app/views/strongbolt/capabilities/index.html.erb +53 -0
  22. data/app/views/strongbolt/capabilities/show.html.erb +53 -0
  23. data/app/views/strongbolt/roles/_capabilities.html.erb +47 -0
  24. data/app/views/strongbolt/roles/_capability.html.erb +21 -0
  25. data/app/views/strongbolt/roles/_form.html.erb +12 -0
  26. data/app/views/strongbolt/roles/edit.html.erb +14 -0
  27. data/app/views/strongbolt/roles/index.html.erb +54 -0
  28. data/app/views/strongbolt/roles/new.html.erb +11 -0
  29. data/app/views/strongbolt/roles/show.html.erb +52 -0
  30. data/app/views/strongbolt/user_groups/_form.html.erb +12 -0
  31. data/app/views/strongbolt/user_groups/edit.html.erb +14 -0
  32. data/app/views/strongbolt/user_groups/index.html.erb +46 -0
  33. data/app/views/strongbolt/user_groups/new.html.erb +13 -0
  34. data/app/views/strongbolt/user_groups/show.html.erb +88 -0
  35. data/lib/generators/strongbolt/fix_generator.rb +23 -0
  36. data/lib/generators/strongbolt/indexes_generator.rb +19 -0
  37. data/lib/generators/strongbolt/install_generator.rb +29 -0
  38. data/lib/generators/strongbolt/templates/fix.rb +5 -0
  39. data/lib/generators/strongbolt/templates/indexes.rb +21 -0
  40. data/lib/generators/strongbolt/templates/migration.rb +73 -0
  41. data/lib/generators/strongbolt/templates/strongbolt.rb +45 -0
  42. data/lib/generators/strongbolt/views_generator.rb +26 -0
  43. data/lib/strongbolt.rb +219 -0
  44. data/lib/strongbolt/base.rb +7 -0
  45. data/lib/strongbolt/bolted.rb +125 -0
  46. data/lib/strongbolt/bolted_controller.rb +297 -0
  47. data/lib/strongbolt/capabilities_role.rb +15 -0
  48. data/lib/strongbolt/capability.rb +165 -0
  49. data/lib/strongbolt/configuration.rb +111 -0
  50. data/lib/strongbolt/controllers/url_helpers.rb +37 -0
  51. data/lib/strongbolt/engine.rb +44 -0
  52. data/lib/strongbolt/errors.rb +38 -0
  53. data/lib/strongbolt/generators/migration.rb +35 -0
  54. data/lib/strongbolt/helpers.rb +18 -0
  55. data/lib/strongbolt/rails/routes.rb +20 -0
  56. data/lib/strongbolt/role.rb +46 -0
  57. data/lib/strongbolt/roles_user_group.rb +15 -0
  58. data/lib/strongbolt/rspec.rb +29 -0
  59. data/lib/strongbolt/rspec/user.rb +90 -0
  60. data/lib/strongbolt/tenantable.rb +304 -0
  61. data/lib/strongbolt/user_abilities.rb +292 -0
  62. data/lib/strongbolt/user_group.rb +24 -0
  63. data/lib/strongbolt/user_groups_user.rb +16 -0
  64. data/lib/strongbolt/users_tenant.rb +12 -0
  65. data/lib/strongbolt/version.rb +3 -0
  66. data/lib/tasks/strongbolt_tasks.rake +29 -0
  67. data/spec/controllers/strongbolt/capabilities_controller_spec.rb +254 -0
  68. data/spec/controllers/strongbolt/roles_controller_spec.rb +228 -0
  69. data/spec/controllers/strongbolt/user_groups_controller_spec.rb +216 -0
  70. data/spec/controllers/strongbolt/user_groups_users_controller_spec.rb +69 -0
  71. data/spec/controllers/without_authorization_controller_spec.rb +20 -0
  72. data/spec/dummy/.rspec +2 -0
  73. data/spec/dummy/README.rdoc +28 -0
  74. data/spec/dummy/Rakefile +6 -0
  75. data/spec/dummy/app/assets/images/.keep +0 -0
  76. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  77. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  78. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  79. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  80. data/spec/dummy/app/controllers/posts_controller.rb +18 -0
  81. data/spec/dummy/app/controllers/test_controller.rb +3 -0
  82. data/spec/dummy/app/controllers/without_authorization_controller.rb +5 -0
  83. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  84. data/spec/dummy/app/mailers/.keep +0 -0
  85. data/spec/dummy/app/models/.keep +0 -0
  86. data/spec/dummy/app/models/concerns/.keep +0 -0
  87. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  88. data/spec/dummy/bin/bundle +3 -0
  89. data/spec/dummy/bin/rails +4 -0
  90. data/spec/dummy/bin/rake +4 -0
  91. data/spec/dummy/config.ru +4 -0
  92. data/spec/dummy/config/application.rb +29 -0
  93. data/spec/dummy/config/boot.rb +5 -0
  94. data/spec/dummy/config/database.yml +25 -0
  95. data/spec/dummy/config/environment.rb +5 -0
  96. data/spec/dummy/config/environments/development.rb +37 -0
  97. data/spec/dummy/config/environments/production.rb +78 -0
  98. data/spec/dummy/config/environments/test.rb +39 -0
  99. data/spec/dummy/config/initializers/assets.rb +8 -0
  100. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  101. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  102. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  103. data/spec/dummy/config/initializers/inflections.rb +16 -0
  104. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  105. data/spec/dummy/config/initializers/session_store.rb +3 -0
  106. data/spec/dummy/config/initializers/strongbolt.rb +32 -0
  107. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  108. data/spec/dummy/config/locales/en.yml +23 -0
  109. data/spec/dummy/config/routes.rb +12 -0
  110. data/spec/dummy/config/secrets.yml +22 -0
  111. data/spec/dummy/db/development.sqlite3 +0 -0
  112. data/spec/dummy/db/migrate/20150630212236_create_strongbolt_tables.rb +54 -0
  113. data/spec/dummy/db/migrate/20150630212251_create_strongbolt_tables_indexes.rb +21 -0
  114. data/spec/dummy/db/schema.rb +84 -0
  115. data/spec/dummy/db/test.sqlite3 +0 -0
  116. data/spec/dummy/lib/assets/.keep +0 -0
  117. data/spec/dummy/public/404.html +67 -0
  118. data/spec/dummy/public/422.html +67 -0
  119. data/spec/dummy/public/500.html +66 -0
  120. data/spec/dummy/public/favicon.ico +0 -0
  121. data/spec/fabricators/capability_fabricator.rb +4 -0
  122. data/spec/fabricators/role_fabricator.rb +9 -0
  123. data/spec/fabricators/user_fabricator.rb +3 -0
  124. data/spec/fabricators/user_group_fabricator.rb +9 -0
  125. data/spec/fixtures/application.rb +28 -0
  126. data/spec/fixtures/controllers.rb +5 -0
  127. data/spec/spec_helper.rb +89 -0
  128. data/spec/strongbolt/bolted_controller_spec.rb +706 -0
  129. data/spec/strongbolt/bolted_spec.rb +136 -0
  130. data/spec/strongbolt/capability_spec.rb +251 -0
  131. data/spec/strongbolt/configuration_spec.rb +119 -0
  132. data/spec/strongbolt/controllers/url_helpers_spec.rb +34 -0
  133. data/spec/strongbolt/helpers_spec.rb +43 -0
  134. data/spec/strongbolt/role_spec.rb +90 -0
  135. data/spec/strongbolt/tenantable_spec.rb +281 -0
  136. data/spec/strongbolt/user_abilities_spec.rb +509 -0
  137. data/spec/strongbolt/user_group_spec.rb +37 -0
  138. data/spec/strongbolt/users_tenant_spec.rb +36 -0
  139. data/spec/strongbolt_spec.rb +274 -0
  140. data/spec/support/controller_macros.rb +11 -0
  141. data/spec/support/db_setup.rb +134 -0
  142. data/spec/support/helpers.rb +62 -0
  143. data/spec/support/transactional_specs.rb +17 -0
  144. data/strongbolt.gemspec +32 -0
  145. metadata +407 -0
@@ -0,0 +1,509 @@
1
+ require "spec_helper"
2
+
3
+ describe Strongbolt::UserAbilities do
4
+
5
+ before(:all) do
6
+ #
7
+ # This is a very basic schema that allows having a model,
8
+ # ChildModel, being tenanted by Model
9
+ #
10
+ define_model "TenantModel" do
11
+ self.table_name = "models"
12
+
13
+ has_many :owned_models, foreign_key: :parent_id
14
+ belongs_to :unowned_model, foreign_key: :parent_id
15
+ end
16
+
17
+ define_model "OwnedModel" do
18
+ self.table_name = "child_models"
19
+
20
+ belongs_to :user, foreign_key: :model_id
21
+ belongs_to :tenant_model, foreign_key: :parent_id
22
+
23
+ has_many :child_models, foreign_key: :parent_id
24
+
25
+ validates :tenant_model, presence: true
26
+ end
27
+
28
+ define_model "ChildModel" do
29
+ self.table_name = "model_models"
30
+
31
+ belongs_to :owned_model, foreign_key: :parent_id
32
+ end
33
+
34
+ define_model "UnownedModel" do
35
+ self.table_name = "unowned_models"
36
+
37
+ has_many :tenant_models, foreign_key: :parent_id
38
+ end
39
+
40
+ define_model "OtherModel" do
41
+ self.table_name = "models"
42
+
43
+ authorize_as "UnownedModel"
44
+ end
45
+
46
+ Strongbolt::Configuration.add_tenant TenantModel
47
+ end
48
+ after(:all) do
49
+ undefine_model TenantModel
50
+ Strongbolt::Configuration.tenants = []
51
+ end
52
+
53
+ let(:user) { User.create! }
54
+
55
+ subject { user }
56
+
57
+ it { is_expected.to have_many(:user_groups_users).class_name("Strongbolt::UserGroupsUser")
58
+ .dependent :delete_all }
59
+ it { is_expected.to have_many(:user_groups).through :user_groups_users }
60
+ it { is_expected.to have_many(:roles).through :user_groups }
61
+ it { is_expected.to respond_to(:capabilities) }
62
+ it { is_expected.to have_many(:tenant_models) }
63
+
64
+ it "should let user find itself" do
65
+ expect(user.can? :find, user).to eq true
66
+ end
67
+
68
+
69
+ #
70
+ # Creates some fixtures for the tests here
71
+ #
72
+ def create_fixtures
73
+ # An unown model linked to a tenant
74
+ @linked_to_tenant = UnownedModel.create!
75
+ @tenant_model = TenantModel.create! unowned_model: @linked_to_tenant
76
+ @other_tenant_model = TenantModel.create!
77
+ # Add to the user
78
+ user.add_tenant @tenant_model
79
+
80
+ # Another user
81
+ @other_user = User.create!
82
+ # A owned model, owned
83
+ @owned_model = OwnedModel.create! user: user,
84
+ tenant_model: @tenant_model
85
+ # An model not owned
86
+ @unowned_model = OwnedModel.create! user: @other_user,
87
+ tenant_model: @tenant_model
88
+ # Other tenant model
89
+ @unmanaged_model = OwnedModel.create! tenant_model: @other_tenant_model
90
+ # An unownable model
91
+ @model = UnownedModel.create!
92
+
93
+ # Child
94
+ @child_model = @owned_model.child_models.create!
95
+
96
+ # The user belong to a group
97
+ @group = Strongbolt::UserGroup.create! name: "Normal"
98
+ @group.users << user
99
+
100
+ # That has a role
101
+ @guest_role = Strongbolt::Role.create! name: "Guest"
102
+ @parent_role = Strongbolt::Role.create! name: "Basic", parent_id: @guest_role.id
103
+ @other_role = Strongbolt::Role.create! name: "Admin"
104
+ @role = @group.roles.create! name: "Normal", parent_id: @parent_role.id
105
+
106
+ # Which has capabilities
107
+
108
+ # User can update self
109
+ @parent_role.capabilities.create! model: "User", action: "update", require_ownership: true
110
+
111
+ # User can read all owned models
112
+ @parent_role.capabilities.create! model: "OwnedModel", action: "find"
113
+
114
+ # And create some
115
+ @role.capabilities.create! model: "OwnedModel", action: "create", require_ownership: true
116
+
117
+ # But can delete only owned models
118
+ @role.capabilities.create! model: "OwnedModel", action: "destroy", require_ownership: true
119
+
120
+ # User can read any unowned models
121
+ @guest_role.capabilities.create! model: "UnownedModel", action: "find"
122
+
123
+ # But can create setting only the attribute name
124
+ @role.capabilities.create! model: "UnownedModel", action: "create", attr: "name",
125
+ :require_tenant_access => false
126
+
127
+ # Admin can do whatever
128
+ @other_role.capabilities.create! model: "UnownedModel", action: "create"
129
+ end
130
+
131
+
132
+
133
+
134
+ #
135
+ # Adding a tenant to the user
136
+ #
137
+ describe "add_tenant" do
138
+
139
+ context 'when instance is from a tenant' do
140
+ let(:model) { TenantModel.create! }
141
+
142
+ it "should create an association" do
143
+ expect do
144
+ user.add_tenant model
145
+ end.to change(Strongbolt::UsersTenant, :count).by 1
146
+ end
147
+
148
+ it "should add the tenant to users's list" do
149
+ user.add_tenant model
150
+ expect(user.tenant_models).to include model
151
+ end
152
+ end
153
+
154
+ context "when instance is not from a tenant" do
155
+ let(:model) { Model.create! }
156
+
157
+ it "should raise an error" do
158
+ expect do
159
+ user.add_tenant model
160
+ end.to raise_error
161
+ end
162
+ end
163
+
164
+ end
165
+
166
+
167
+
168
+ #
169
+ # Has access to tenants?
170
+ #
171
+ describe "has_access_to_tenants?" do
172
+ before { create_fixtures }
173
+
174
+ context "when same tenant" do
175
+
176
+ it "should be true when model is tenant" do
177
+ expect(user.has_access_to_tenants? @tenant_model).to eq true
178
+ end
179
+
180
+ it "should be true when model is first child" do
181
+ expect(user.has_access_to_tenants? @unowned_model).to eq true
182
+ end
183
+
184
+ it "should be true when grand child" do
185
+ expect(user.has_access_to_tenants? @child_model).to eq true
186
+ end
187
+
188
+ it "should be true for a user defined association" do
189
+ expect(user.has_access_to_tenants? @linked_to_tenant).to eq true
190
+ end
191
+
192
+ end
193
+
194
+ context "when different tenant" do
195
+ it "should be false when model is tenant" do
196
+ expect(user.has_access_to_tenants? @other_tenant_model).to eq false
197
+ end
198
+
199
+ it "should be false when model is first child" do
200
+ expect(user.has_access_to_tenants? @unmanaged_model).to eq false
201
+ end
202
+ end
203
+
204
+ context "when model doesn't have link to tenant" do
205
+ it "should return true" do
206
+ expect(user.has_access_to_tenants? @model).to eq true
207
+ end
208
+ end
209
+ end
210
+
211
+
212
+
213
+ #
214
+ # All Capabilities
215
+ #
216
+ describe 'capabilities' do
217
+
218
+ before { create_fixtures }
219
+
220
+ let(:capabilities) { user.capabilities }
221
+
222
+ subject { capabilities }
223
+
224
+ it "should have 6 capabilities" do
225
+ expect(capabilities.size).to eq 6
226
+ end
227
+
228
+ end
229
+
230
+
231
+ #
232
+ # CAN?
233
+ #
234
+
235
+ describe "can?" do
236
+
237
+ before { create_fixtures }
238
+
239
+ describe "creating an owned model" do
240
+
241
+ context "when authorized" do
242
+ let(:tenant_model) { TenantModel.create! }
243
+
244
+ before { user.tenant_models << tenant_model }
245
+
246
+ context "when same tenant" do
247
+ let(:instance) { OwnedModel.new tenant_model: tenant_model }
248
+
249
+ it "should return true when passing instance" do
250
+ expect(user.can? :create, instance).to eq true
251
+ end
252
+ end
253
+
254
+ context "when not same tenant" do
255
+
256
+ let(:instance) { OwnedModel.new tenant_model: TenantModel.create! }
257
+
258
+ it "should return false when passing instance" do
259
+ expect(user.can? :create, instance).to eq false
260
+ end
261
+ end
262
+
263
+ it "should return true when passing class" do
264
+ expect(user.can? :create, OwnedModel).to eq true
265
+ end
266
+ end
267
+
268
+ context "when not authorized" do
269
+ it "should return true when passing instance" do
270
+ expect(user.can? :create, User.new).to eq false
271
+ end
272
+
273
+ it "should return true when passing class" do
274
+ expect(user.can? :create, User).to eq false
275
+ end
276
+ end
277
+
278
+ context "when default set of permissions" do
279
+ before do
280
+ Strongbolt.setup do |config|
281
+ config.default_capabilities = [
282
+ {:model => "OwnedModel", :require_ownership => true, :actions => :update},
283
+ {:model => "TenantModel", :require_tenant_access => false, :require_ownership => false, :actions => "find"}
284
+ ]
285
+ end
286
+ end
287
+ after do
288
+ Strongbolt.setup do |config|
289
+ config.default_capabilities = []
290
+ end
291
+ end
292
+
293
+ let(:other_user) { User.create! }
294
+ let(:owned_model) { OwnedModel.create! :user => user, :tenant_model => TenantModel.create! }
295
+ let(:unowned_model) { OwnedModel.create! :user => other_user, :tenant_model => TenantModel.create! }
296
+
297
+ it "should let the user update an owned model" do
298
+ expect(user.can? :update, owned_model).to eq true
299
+ end
300
+
301
+ it "should not let the user update an owned model from another user" do
302
+ expect(user.can? :update, unowned_model).to eq false
303
+ end
304
+ end
305
+
306
+ end # Creating an owned model
307
+
308
+ describe "updating an owned model" do
309
+ context "when owning model" do
310
+ it "should return true" do
311
+ expect(user.can? :update, user).to eq true
312
+ end
313
+ end
314
+
315
+ context "when not owning model" do
316
+ it "should return false" do
317
+ expect(user.can? :update, @other_user).to eq false
318
+ end
319
+ end
320
+ end # Updating an owned model
321
+
322
+ describe "creating a model with attribute restriction" do
323
+
324
+ context "when requiring all attributes" do
325
+ it "should return false" do
326
+ expect(user.can? :create, UnownedModel, :all).to eq false
327
+ end
328
+
329
+ it "should return false for other model authorized as it" do
330
+ expect(user.can? :create, OtherModel, :all).to eq false
331
+ end
332
+ end
333
+
334
+ context "when requiring any attribute" do
335
+ it "should return true" do
336
+ expect(user.can? :create, UnownedModel, :any).to eq true
337
+ end
338
+
339
+ it "should return true for other model authorized as it" do
340
+ expect(user.can? :create, OtherModel, :any).to eq true
341
+ end
342
+ end
343
+
344
+ end # Creating a model with restricted attributes
345
+
346
+ describe "creating a non tenanted model" do
347
+ let(:instance) { UnownedModel.new }
348
+
349
+ context "when user has the right" do
350
+ it "should return true" do
351
+ expect(user.can? :create, instance).to eq true
352
+ end
353
+ end
354
+ end
355
+
356
+ describe 'destroying an owned model' do
357
+ context "when owning" do
358
+ it "should be true" do
359
+ expect(user.can? :destroy, @owned_model).to eq true
360
+ end
361
+ end
362
+
363
+ context "when not owning" do
364
+ it "should be false" do
365
+ expect(user.can? :destroy, @unowned_model).to eq false
366
+ end
367
+ end
368
+ end
369
+
370
+ describe "finding model" do
371
+ context "when same tenant" do
372
+ it "should be true" do
373
+ expect(user.can? :find, @unowned_model).to eq true
374
+ end
375
+ end
376
+
377
+ context "when not same tenant" do
378
+ it "should be false" do
379
+ expect(user.can? :find, @unmanaged_model).to eq false
380
+ end
381
+ end
382
+ end
383
+
384
+ end # End can?
385
+
386
+
387
+
388
+
389
+
390
+ #
391
+ # Populate Capabilities Cache
392
+ #
393
+
394
+ describe "Populate Capabilities Cache" do
395
+
396
+ #
397
+ # We create some fixtures for the population of cache to be tested
398
+ #
399
+ before { create_fixtures }
400
+
401
+ let(:cache) { user.populate_capabilities_cache }
402
+
403
+ subject { cache }
404
+
405
+ it "should have the right number of capabilities" do
406
+ expect(cache.size).to eq 4 * 6 + 2
407
+ end
408
+
409
+ [
410
+ "updateUserall-any", "updateUserany-any", # "updateUserall-#{User.first.id}", "updateUserany-#{User.first.id}",
411
+ "findOwnedModelall-any", "findOwnedModelany-any", "findOwnedModelall-tenanted", "findOwnedModelany-tenanted",
412
+ "createOwnedModelall-any", "createOwnedModelany-any", "createOwnedModelall-owned", "createOwnedModelany-owned",
413
+ "destroyOwnedModelall-any", "destroyOwnedModelany-any", "destroyOwnedModelall-owned", "destroyOwnedModelany-owned",
414
+ "findUnownedModelall-any", "findUnownedModelany-any", "findUnownedModelall-tenanted", "findUnownedModelany-tenanted",
415
+ "createUnownedModelname-any", "createUnownedModelany-any", "createUnownedModelname-all", "createUnownedModelany-all"
416
+ ].each do |key|
417
+ it "should have set true to #{key}" do
418
+ expect(cache[key]).to eq true
419
+ end
420
+ end
421
+
422
+ end
423
+
424
+
425
+
426
+
427
+
428
+
429
+ #
430
+ # OWNS?
431
+ #
432
+ describe "owns?" do
433
+
434
+ #
435
+ # Another user
436
+ #
437
+ context "when testing against a user" do
438
+
439
+ context 'when other user' do
440
+
441
+ let(:other_user) { User.create! }
442
+
443
+ it "should not own it" do
444
+ expect(user.owns? other_user).to eq false
445
+ end
446
+
447
+ end
448
+
449
+ context "when same user" do
450
+ it "should own it" do
451
+ expect(user.owns? user).to eq true
452
+ end
453
+ end
454
+
455
+ end # End owning user
456
+
457
+
458
+ #
459
+ # Another object
460
+ #
461
+ context "when testing against another model having user_id" do
462
+
463
+ context "when owning it" do
464
+ let(:model) { Model.create! user_id: user.id }
465
+
466
+ it "should own it" do
467
+ expect(user.owns? model).to eq true
468
+ end
469
+ end
470
+
471
+ context "when not owning it" do
472
+ let(:model) { Model.create! user_id: 0 }
473
+
474
+ it "should own it" do
475
+ expect(user.owns? model).to eq false
476
+ end
477
+ end
478
+
479
+ end # End testing against model having user id
480
+
481
+ end
482
+
483
+
484
+ #
485
+ # Another object unowned
486
+ #
487
+ context "when testing against a model not having user id" do
488
+
489
+ let(:model) { UnownedModel.create! }
490
+
491
+ it "should not own it" do
492
+ expect(user.owns? model).to eq false
493
+ end
494
+
495
+ end
496
+
497
+
498
+ #
499
+ # Wrong arguments
500
+ #
501
+ context "when given something else than an object" do
502
+ it "should raise error" do
503
+ expect do
504
+ user.owns? Model
505
+ end.to raise_error ArgumentError
506
+ end
507
+ end
508
+
509
+ end