rolify 3.3.0.rc2 → 3.3.0.rc4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +18 -11
  3. data/CHANGELOG.rdoc +18 -0
  4. data/Gemfile +16 -3
  5. data/README.md +17 -17
  6. data/Rakefile +23 -1
  7. data/UPGRADE.rdoc +22 -0
  8. data/gemfiles/Gemfile.rails-3.2 +17 -0
  9. data/gemfiles/Gemfile.rails-4.0 +26 -0
  10. data/lib/generators/active_record/rolify_generator.rb +50 -0
  11. data/lib/generators/active_record/templates/migration.rb +19 -0
  12. data/lib/generators/mongoid/rolify_generator.rb +51 -0
  13. data/lib/generators/rolify/rolify_generator.rb +35 -0
  14. data/lib/generators/rolify/{role/templates → templates}/initializer.rb +2 -2
  15. data/lib/generators/rolify/templates/role-active_record.rb +11 -0
  16. data/lib/generators/rolify/user_generator.rb +39 -0
  17. data/lib/rolify/adapters/active_record/resource_adapter.rb +7 -7
  18. data/lib/rolify/adapters/active_record/role_adapter.rb +8 -8
  19. data/lib/rolify/configure.rb +1 -1
  20. data/lib/rolify/version.rb +1 -1
  21. data/lib/rolify.rb +1 -1
  22. data/rolify.gemspec +5 -12
  23. data/spec/README.rdoc +24 -0
  24. data/spec/generators/rolify/{role/role_generator_spec.rb → rolify_generator_spec.rb} +115 -13
  25. data/spec/generators_helper.rb +14 -0
  26. data/spec/rolify/custom_spec.rb +9 -16
  27. data/spec/rolify/namespace_spec.rb +9 -16
  28. data/spec/rolify/resource_spec.rb +13 -2
  29. data/spec/rolify/resourcifed_and_rolifed_spec.rb +5 -1
  30. data/spec/rolify/role_spec.rb +9 -16
  31. data/spec/rolify/shared_contexts.rb +9 -3
  32. data/spec/rolify/shared_examples/shared_examples_for_add_role.rb +2 -2
  33. data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +1 -1
  34. data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +3 -3
  35. data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +3 -3
  36. data/spec/rolify/shared_examples/shared_examples_for_roles.rb +1 -1
  37. data/spec/rolify/shared_examples/shared_examples_for_scopes.rb +10 -10
  38. data/spec/spec_helper.rb +1 -1
  39. data/spec/support/adapters/active_record.rb +7 -0
  40. data/spec/support/adapters/mongoid.rb +8 -4
  41. data/spec/support/data.rb +3 -0
  42. data/spec/support/schema.rb +5 -0
  43. metadata +38 -77
  44. data/lib/generators/rolify/role/role_generator.rb +0 -52
  45. data/lib/generators/rolify/role/templates/migration.rb +0 -19
  46. data/lib/generators/rolify/role/templates/role-active_record.rb +0 -6
  47. /data/lib/generators/{rolify/role/templates/README-active_record → active_record/templates/README} +0 -0
  48. /data/lib/generators/{rolify/role → mongoid}/templates/README-mongoid +0 -0
  49. /data/lib/generators/rolify/{role/templates → templates}/README +0 -0
  50. /data/lib/generators/rolify/{role/templates → templates}/role-mongoid.rb +0 -0
data/spec/README.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ = Rolify Specs
2
+
3
+ == Running the specs
4
+
5
+ To run the specs first run the +bundle+ command to install the necessary gems and the +rake+ command to run the specs.
6
+
7
+ bundle
8
+ rake
9
+
10
+ == Model Adapters
11
+
12
+ Rolify currently supports 2 different ORMs: ActiveRecord and Mongoid. By default it will use Active Record but you can change this by setting the +ADAPTER+ environment variable before running the specs. You can run the +bundle+ command with this as well to ensure you have all the required gems.
13
+
14
+ ADAPTER=mongoid bundle
15
+ ADAPTER=mongoid rake
16
+
17
+ The different model adapters you can specify are:
18
+
19
+ * active_record (default)
20
+ * mongoid
21
+
22
+ You can also run the +spec_all+ rake task to run specs for each adapter.
23
+
24
+ rake spec_all
@@ -1,11 +1,11 @@
1
- require 'spec_helper'
1
+ require 'generators_helper'
2
2
 
3
3
  # Generators are not automatically loaded by Rails
4
- require 'generators/rolify/role/role_generator'
4
+ require 'generators/rolify/rolify_generator'
5
5
 
6
- describe Rolify::Generators::RoleGenerator do
6
+ describe Rolify::Generators::RolifyGenerator do
7
7
  # Tell the generator where to put its output (what it thinks of as Rails.root)
8
- destination File.expand_path("../../../../../tmp", __FILE__)
8
+ destination File.expand_path("../../../../tmp", __FILE__)
9
9
  teardown :cleanup_destination_root
10
10
 
11
11
  before {
@@ -16,15 +16,19 @@ describe Rolify::Generators::RoleGenerator do
16
16
  FileUtils.rm_rf destination_root
17
17
  end
18
18
 
19
- describe 'no arguments' do
20
- before(:all) { arguments [] }
19
+ describe 'specifying only Role class name' do
20
+ before(:all) { arguments %w(Role) }
21
21
 
22
22
  before {
23
23
  capture(:stdout) {
24
24
  generator.create_file "app/models/user.rb" do
25
- "class User < ActiveRecord::Base\nend"
25
+ <<-RUBY
26
+ class User < ActiveRecord::Base
27
+ end
28
+ RUBY
26
29
  end
27
30
  }
31
+ require File.join(destination_root, "app/models/user.rb")
28
32
  run_generator
29
33
  }
30
34
 
@@ -58,7 +62,7 @@ describe Rolify::Generators::RoleGenerator do
58
62
  end
59
63
  end
60
64
 
61
- describe 'specifying user and role names' do
65
+ describe 'specifying User and Role class names' do
62
66
  before(:all) { arguments %w(AdminRole AdminUser) }
63
67
 
64
68
  before {
@@ -67,6 +71,7 @@ describe Rolify::Generators::RoleGenerator do
67
71
  "class AdminUser < ActiveRecord::Base\nend"
68
72
  end
69
73
  }
74
+ require File.join(destination_root, "app/models/admin_user.rb")
70
75
  run_generator
71
76
  }
72
77
 
@@ -79,7 +84,7 @@ describe Rolify::Generators::RoleGenerator do
79
84
  it { should contain "# config.use_mongoid" }
80
85
  end
81
86
 
82
- describe 'app/models/rank.rb' do
87
+ describe 'app/models/admin_role.rb' do
83
88
  subject { file('app/models/admin_role.rb') }
84
89
 
85
90
  it { should exist }
@@ -103,21 +108,74 @@ describe Rolify::Generators::RoleGenerator do
103
108
  end
104
109
  end
105
110
 
106
- describe 'specifying orm adapter' do
107
- before(:all) { arguments [ "Role", "User", "mongoid" ] }
111
+ describe 'specifying namespaced User and Role class names' do
112
+ before(:all) { arguments %w(Admin::Role Admin::User) }
113
+
114
+ before {
115
+ capture(:stdout) {
116
+ generator.create_file "app/models/admin/user.rb" do
117
+ <<-RUBY
118
+ module Admin
119
+ class User < ActiveRecord::Base
120
+ self.table_name_prefix = 'admin_'
121
+ end
122
+ end
123
+ RUBY
124
+ end
125
+ }
126
+ require File.join(destination_root, "app/models/admin/user.rb")
127
+ run_generator
128
+ }
129
+
130
+ describe 'config/initializers/rolify.rb' do
131
+ subject { file('config/initializers/rolify.rb') }
132
+
133
+ it { should exist }
134
+ it { should contain "Rolify.configure(\"Admin::Role\") do |config|"}
135
+ it { should contain "# config.use_dynamic_shortcuts" }
136
+ it { should contain "# config.use_mongoid" }
137
+ end
138
+
139
+ describe 'app/models/admin/role.rb' do
140
+ subject { file('app/models/admin/role.rb') }
141
+
142
+ it { should exist }
143
+ it { should contain "class Admin::Role < ActiveRecord::Base" }
144
+ it { should contain "has_and_belongs_to_many :admin_users, :join_table => :admin_users_admin_roles" }
145
+ it { should contain "belongs_to :resource, :polymorphic => true" }
146
+ end
147
+
148
+ describe 'app/models/admin/user.rb' do
149
+ subject { file('app/models/admin/user.rb') }
150
+
151
+ it { should contain /class User < ActiveRecord::Base\n rolify :role_cname => 'Admin::Role'\n/ }
152
+ end
153
+
154
+ describe 'migration file' do
155
+ subject { migration_file('db/migrate/rolify_create_admin_roles.rb') }
156
+
157
+ it { should be_a_migration }
158
+ it { should contain "create_table(:admin_roles)" }
159
+ it { should contain "create_table(:admin_users_admin_roles, :id => false) do" }
160
+ end
161
+ end
162
+
163
+ describe 'specifying ORM adapter' do
164
+ before(:all) { arguments [ "Role", "User", "--orm=mongoid" ] }
108
165
 
109
166
  before {
110
167
  capture(:stdout) {
111
168
  generator.create_file "app/models/user.rb" do
112
- <<-CLASS
169
+ <<-RUBY
113
170
  class User
114
171
  include Mongoid::Document
115
172
 
116
173
  field :login, :type => String
117
174
  end
118
- CLASS
175
+ RUBY
119
176
  end
120
177
  }
178
+ require File.join(destination_root, "app/models/user.rb")
121
179
  run_generator
122
180
  }
123
181
 
@@ -149,4 +207,48 @@ CLASS
149
207
  it { should contain /class User\n include Mongoid::Document\n rolify\n/ }
150
208
  end
151
209
  end
210
+
211
+ describe 'specifying namespaced User and Role class names and ORM adapter' do
212
+ before(:all) { arguments %w(Admin::Role Admin::User --orm=mongoid) }
213
+
214
+ before {
215
+ capture(:stdout) {
216
+ generator.create_file "app/models/admin/user.rb" do
217
+ <<-RUBY
218
+ module Admin
219
+ class User
220
+ include Mongoid::Document
221
+ end
222
+ end
223
+ RUBY
224
+ end
225
+ }
226
+ require File.join(destination_root, "app/models/admin/user.rb")
227
+ run_generator
228
+ }
229
+
230
+ describe 'config/initializers/rolify.rb' do
231
+ subject { file('config/initializers/rolify.rb') }
232
+
233
+ it { should exist }
234
+ it { should contain "Rolify.configure(\"Admin::Role\") do |config|"}
235
+ it { should contain "# config.use_dynamic_shortcuts" }
236
+ it { should_not contain "# config.use_mongoid" }
237
+ end
238
+
239
+ describe 'app/models/admin/role.rb' do
240
+ subject { file('app/models/admin/role.rb') }
241
+
242
+ it { should exist }
243
+ it { should contain "class Admin::Role" }
244
+ it { should contain "has_and_belongs_to_many :admin_users" }
245
+ it { should contain "belongs_to :resource, :polymorphic => true" }
246
+ end
247
+
248
+ describe 'app/models/admin/user.rb' do
249
+ subject { file('app/models/admin/user.rb') }
250
+
251
+ it { should contain /class User\n include Mongoid::Document\n rolify :role_cname => 'Admin::Role'\n/ }
252
+ end
253
+ end
152
254
  end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require "bundler/setup"
3
+
4
+ require 'rolify'
5
+ require 'rolify/matchers'
6
+ require 'rails/all'
7
+
8
+ module TestApp
9
+ class Application < ::Rails::Application
10
+ config.root = File.dirname(__FILE__)
11
+ end
12
+ end
13
+
14
+ require 'ammeter/init'
@@ -5,23 +5,16 @@ require "rolify/shared_examples/shared_examples_for_scopes"
5
5
  require "rolify/shared_examples/shared_examples_for_callbacks"
6
6
 
7
7
  describe "Using Rolify with custom User and Role class names" do
8
- it_behaves_like Rolify::Role do
9
- let(:user_class) { Customer }
10
- let(:role_class) { Privilege }
8
+ def user_class
9
+ Customer
11
10
  end
12
11
 
13
- it_behaves_like "Role.scopes" do
14
- let(:user_class) { Customer }
15
- let(:role_class) { Privilege }
16
- end
17
-
18
- it_behaves_like Rolify::Dynamic do
19
- let(:user_class) { Customer }
20
- let(:role_class) { Privilege }
21
- end
22
-
23
- it_behaves_like "Rolify.callbacks" do
24
- let(:user_class) { Customer }
25
- let(:role_class) { Privilege }
12
+ def role_class
13
+ Privilege
26
14
  end
15
+
16
+ it_behaves_like Rolify::Role
17
+ it_behaves_like "Role.scopes"
18
+ it_behaves_like Rolify::Dynamic
19
+ it_behaves_like "Rolify.callbacks"
27
20
  end
@@ -5,23 +5,16 @@ require "rolify/shared_examples/shared_examples_for_scopes"
5
5
  require "rolify/shared_examples/shared_examples_for_callbacks"
6
6
 
7
7
  describe "Rolify.namespace" do
8
- it_behaves_like Rolify::Role do
9
- let(:user_class) { Admin::Moderator }
10
- let(:role_class) { Admin::Right }
8
+ def user_class
9
+ Admin::Moderator
11
10
  end
12
11
 
13
- it_behaves_like "Role.scopes" do
14
- let(:user_class) { Admin::Moderator }
15
- let(:role_class) { Admin::Right }
16
- end
17
-
18
- it_behaves_like Rolify::Dynamic do
19
- let(:user_class) { Admin::Moderator }
20
- let(:role_class) { Admin::Right }
21
- end
22
-
23
- it_behaves_like "Rolify.callbacks" do
24
- let(:user_class) { Admin::Moderator }
25
- let(:role_class) { Admin::Right }
12
+ def role_class
13
+ Admin::Right
26
14
  end
15
+
16
+ it_behaves_like Rolify::Role
17
+ it_behaves_like "Role.scopes"
18
+ it_behaves_like Rolify::Dynamic
19
+ it_behaves_like "Rolify.callbacks"
27
20
  end
@@ -6,12 +6,14 @@ describe Rolify::Resource do
6
6
  User.rolify
7
7
  Forum.resourcify
8
8
  Group.resourcify
9
+ Team.resourcify
9
10
  Role.destroy_all
10
11
  end
11
12
 
12
13
  # Users
13
14
  let(:admin) { User.first }
14
15
  let(:tourist) { User.last }
16
+ let(:captain) { User.where(:login => "god").first }
15
17
 
16
18
  # roles
17
19
  let!(:forum_role) { admin.add_role(:forum, Forum.first) }
@@ -20,6 +22,8 @@ describe Rolify::Resource do
20
22
  let!(:grouper_role) { admin.add_role(:grouper, Group.first) }
21
23
  let!(:tourist_role) { tourist.add_role(:forum, Forum.last) }
22
24
  let!(:sneaky_role) { tourist.add_role(:group, Forum.first) }
25
+ let!(:captain_role) { captain.add_role(:captain, Team.first) }
26
+ let!(:player_role) { captain.add_role(:player, Team.last) }
23
27
 
24
28
  describe ".with_roles" do
25
29
  subject { Group }
@@ -127,7 +131,14 @@ describe Rolify::Resource do
127
131
 
128
132
  end
129
133
  end
130
-
134
+
135
+ context "with a model not having ID column" do
136
+ subject { Team }
137
+
138
+ it "should find Team instance using team_code column" do
139
+ subject.with_roles([:captain, :player], captain).should =~ [ Team.first, Team.last ]
140
+ end
141
+ end
131
142
  end
132
143
 
133
144
  describe ".find_role" do
@@ -327,7 +338,7 @@ describe Rolify::Resource do
327
338
 
328
339
  context "on a Forum instance" do
329
340
  its(:roles) { should eq([ forum_role, sneaky_role ]) }
330
- its(:roles) { subject.should_not include(group_role, godfather_role, tourist_role) }
341
+ its(:roles) { should_not include(group_role, godfather_role, tourist_role) }
331
342
  end
332
343
 
333
344
  context "on a Group instance" do
@@ -8,7 +8,11 @@ describe "Resourcify and rolify on the same model" do
8
8
  HumanResource.delete_all
9
9
  end
10
10
 
11
- let!(:user) { user = HumanResource.new login: 'Samer'; user.save; user }
11
+ let!(:user) do
12
+ user = HumanResource.new login: 'Samer'
13
+ user.save
14
+ user
15
+ end
12
16
 
13
17
  it "should add the role to the user" do
14
18
  expect { user.add_role :admin }.to change { user.roles.count }.by(1)
@@ -5,23 +5,16 @@ require "rolify/shared_examples/shared_examples_for_scopes"
5
5
  require "rolify/shared_examples/shared_examples_for_callbacks"
6
6
 
7
7
  describe Rolify do
8
- it_behaves_like Rolify::Role do
9
- let(:user_class) { User }
10
- let(:role_class) { Role }
8
+ def user_class
9
+ User
11
10
  end
12
11
 
13
- it_behaves_like "Role.scopes" do
14
- let(:user_class) { User }
15
- let(:role_class) { Role }
16
- end
17
-
18
- it_behaves_like Rolify::Dynamic do
19
- let(:user_class) { User }
20
- let(:role_class) { Role }
21
- end
22
-
23
- it_behaves_like "Rolify.callbacks" do
24
- let(:user_class) { User }
25
- let(:role_class) { Role }
12
+ def role_class
13
+ Role
26
14
  end
15
+
16
+ it_behaves_like Rolify::Role
17
+ it_behaves_like "Role.scopes"
18
+ it_behaves_like Rolify::Dynamic
19
+ it_behaves_like "Rolify.callbacks"
27
20
  end
@@ -1,7 +1,9 @@
1
1
  shared_context "global role", :scope => :global do
2
2
  subject { admin }
3
3
 
4
- let(:admin) { user_class.first }
4
+ def admin
5
+ user_class.first
6
+ end
5
7
 
6
8
  before(:all) do
7
9
  load_roles
@@ -29,7 +31,9 @@ shared_context "class scoped role", :scope => :class do
29
31
  create_other_roles
30
32
  end
31
33
 
32
- let(:manager) { user_class.where(:login => "moderator").first }
34
+ def manager
35
+ user_class.where(:login => "moderator").first
36
+ end
33
37
 
34
38
  def load_roles
35
39
  role_class.destroy_all
@@ -51,7 +55,9 @@ shared_context "instance scoped role", :scope => :instance do
51
55
  create_other_roles
52
56
  end
53
57
 
54
- let(:moderator) { user_class.where(:login => "god").first }
58
+ def moderator
59
+ user_class.where(:login => "god").first
60
+ end
55
61
 
56
62
  def load_roles
57
63
  role_class.destroy_all
@@ -50,7 +50,7 @@ shared_examples_for "#add_role_examples" do |param_name, param_method|
50
50
  context "should not create another role" do
51
51
  it "if the role was already assigned to the user" do
52
52
  subject.add_role "warrior".send(param_method), Forum
53
- expect { subject.add_role "warrior".send(param_method), Forum }.not_to change { subject.roles.size }
53
+ expect { subject.add_role "warrior".send(param_method), Forum }.not_to change { subject.roles.count }
54
54
  end
55
55
 
56
56
  it "if already existing in the database" do
@@ -62,7 +62,7 @@ shared_examples_for "#add_role_examples" do |param_name, param_method|
62
62
 
63
63
  context "with an instance scoped role", :scope => :instance do
64
64
  it "should add the role to the user" do
65
- expect { subject.add_role "visitor".send(param_method), Forum.last }.to change { subject.roles.size }.by(1)
65
+ expect { subject.add_role "visitor".send(param_method), Forum.last }.to change { subject.roles.count }.by(1)
66
66
  end
67
67
 
68
68
  it "should create a role in the roles table" do
@@ -1,4 +1,4 @@
1
- shared_examples_for Rolify::Dynamic do
1
+ shared_examples_for Rolify::Dynamic do
2
2
  before(:all) do
3
3
  Rolify.dynamic_shortcuts = true
4
4
  role_class.destroy_all
@@ -1,7 +1,7 @@
1
1
  shared_examples_for "#has_any_role?_examples" do |param_name, param_method|
2
2
  context "using #{param_name} as parameter" do
3
3
  context "with a global role", :scope => :global do
4
- before(:all) do
4
+ before do
5
5
  subject.add_role "staff".send(param_method)
6
6
  end
7
7
 
@@ -20,7 +20,7 @@ shared_examples_for "#has_any_role?_examples" do |param_name, param_method|
20
20
  end
21
21
 
22
22
  context "with a class scoped role", :scope => :class do
23
- before(:all) do
23
+ before do
24
24
  subject.add_role "player".send(param_method), Forum
25
25
  subject.add_role "superhero".send(param_method)
26
26
  end
@@ -40,7 +40,7 @@ shared_examples_for "#has_any_role?_examples" do |param_name, param_method|
40
40
  end
41
41
 
42
42
  context "with a instance scoped role", :scope => :instance do
43
- before(:all) do
43
+ before do
44
44
  subject.add_role "visitor".send(param_method), Forum.last
45
45
  subject.add_role "leader", Group
46
46
  subject.add_role "warrior"
@@ -36,7 +36,7 @@ shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
36
36
  end
37
37
 
38
38
  context "with multiple roles" do
39
- before(:all) { subject.add_role "multiple_global_roles".send(param_method) }
39
+ before { subject.add_role "multiple_global_roles".send(param_method) }
40
40
 
41
41
  it { subject.only_has_role?("global_role".send(param_method)).should be_false }
42
42
  end
@@ -93,7 +93,7 @@ shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
93
93
  end
94
94
 
95
95
  context "with multiple roles" do
96
- before(:all) { subject.add_role "multiple_class_roles".send(param_method) }
96
+ before { subject.add_role "multiple_class_roles".send(param_method) }
97
97
 
98
98
  it { subject.only_has_role?("class_role".send(param_method), Forum).should be_false }
99
99
  it { subject.only_has_role?("class_role".send(param_method), Forum.first).should be_false }
@@ -164,7 +164,7 @@ shared_examples_for "#only_has_role?_examples" do |param_name, param_method|
164
164
  end
165
165
 
166
166
  context "with multiple roles" do
167
- before(:all) { subject.add_role "multiple_instance_roles".send(param_method), Forum.first }
167
+ before { subject.add_role "multiple_instance_roles".send(param_method), Forum.first }
168
168
 
169
169
  it { subject.only_has_role?("instance_role".send(param_method), Forum.first).should be_false }
170
170
  it { subject.only_has_role?("instance_role".send(param_method), :any).should be_false }
@@ -82,7 +82,7 @@ shared_examples_for Rolify::Role do
82
82
  context "with a new instance" do
83
83
  let(:user) { user_class.new }
84
84
 
85
- before(:all) do
85
+ before do
86
86
  user.add_role :admin
87
87
  user.add_role :moderator, Forum.first
88
88
  end
@@ -1,7 +1,7 @@
1
1
  require "rolify/shared_contexts"
2
2
 
3
- shared_examples_for "Role.scopes" do |param_name, param_method|
4
- before(:all) do
3
+ shared_examples_for "Role.scopes" do
4
+ before do
5
5
  role_class.destroy_all
6
6
  end
7
7
 
@@ -18,9 +18,9 @@ shared_examples_for "Role.scopes" do |param_name, param_method|
18
18
  let!(:manager_role) { subject.add_role :manager, Group }
19
19
  let!(:moderator_role) { subject.add_role :moderator, Forum }
20
20
 
21
- it { subject.roles.class_scoped.should == [ manager_role, moderator_role ] }
22
- it { subject.roles.class_scoped(Group).should == [ manager_role ] }
23
- it { subject.roles.class_scoped(Forum).should == [ moderator_role ] }
21
+ it { subject.roles.class_scoped.should =~ [ manager_role, moderator_role ] }
22
+ it { subject.roles.class_scoped(Group).should =~ [ manager_role ] }
23
+ it { subject.roles.class_scoped(Forum).should =~ [ moderator_role ] }
24
24
  end
25
25
 
26
26
  describe ".instance_scoped" do
@@ -28,11 +28,11 @@ shared_examples_for "Role.scopes" do |param_name, param_method|
28
28
  let!(:zombie_role) { subject.add_role :visitor, Forum.last }
29
29
  let!(:anonymous_role) { subject.add_role :anonymous, Group.last }
30
30
 
31
- it { subject.roles.instance_scoped.should == [ visitor_role, zombie_role, anonymous_role ] }
32
- it { subject.roles.instance_scoped(Forum).should == [ visitor_role, zombie_role ] }
33
- it { subject.roles.instance_scoped(Forum.first).should == [ visitor_role ] }
34
- it { subject.roles.instance_scoped(Forum.last).should == [ zombie_role ] }
35
- it { subject.roles.instance_scoped(Group.last).should == [ anonymous_role ] }
31
+ it { subject.roles.instance_scoped.all.entries.should =~ [ visitor_role, zombie_role, anonymous_role ] }
32
+ it { subject.roles.instance_scoped(Forum).should =~ [ visitor_role, zombie_role ] }
33
+ it { subject.roles.instance_scoped(Forum.first).should =~ [ visitor_role ] }
34
+ it { subject.roles.instance_scoped(Forum.last).should =~ [ zombie_role ] }
35
+ it { subject.roles.instance_scoped(Group.last).should =~ [ anonymous_role ] }
36
36
  it { subject.roles.instance_scoped(Group.first).should be_empty }
37
37
  end
38
38
  end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ require "bundler/setup"
3
3
 
4
4
  require 'rolify'
5
5
  require 'rolify/matchers'
6
- require 'ammeter/init'
6
+ require 'rails/all'
7
7
 
8
8
  ENV['ADAPTER'] ||= 'active_record'
9
9
 
@@ -66,4 +66,11 @@ class Group < ActiveRecord::Base
66
66
  def subgroups
67
67
  Group.where(:parent_id => id)
68
68
  end
69
+ end
70
+
71
+ class Team < ActiveRecord::Base
72
+ #resourcify done during specs setup to be able to use custom user classes
73
+ self.primary_key = "team_code"
74
+
75
+ default_scope order(:team_code)
69
76
  end
@@ -2,10 +2,6 @@ require 'mongoid'
2
2
 
3
3
  Mongoid.load!("spec/support/adapters/mongoid.yml", :test)
4
4
 
5
- RSpec.configure do |config|
6
- config.include Mongoid::Matchers
7
- end
8
-
9
5
  ::Mongoid::Document.module_eval do
10
6
  def self.included(base)
11
7
  base.extend Rolify
@@ -137,3 +133,11 @@ class Group
137
133
  Group.in(:parent_id => _id)
138
134
  end
139
135
  end
136
+
137
+ class Team
138
+ include Mongoid::Document
139
+ #resourcify done during specs setup to be able to use custom user classes
140
+
141
+ field :team_code, :type => Integer
142
+ field :name, :type => String
143
+ end
data/spec/support/data.rb CHANGED
@@ -20,3 +20,6 @@ Forum.create(:name => "forum 3")
20
20
 
21
21
  Group.create(:name => "group 1")
22
22
  Group.create(:name => "group 2")
23
+
24
+ Team.create(:team_code => "1", :name => "PSG")
25
+ Team.create(:team_code => "2", :name => "MU")
@@ -44,4 +44,9 @@ ActiveRecord::Schema.define do
44
44
  t.integer :parent_id
45
45
  t.string :name
46
46
  end
47
+
48
+ create_table(:teams, :id => false) do |t|
49
+ t.primary_key :team_code
50
+ t.string :name
51
+ end
47
52
  end