roles_mongoid 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+ use_roles_strategy :role_strings
3
+
4
+ class User
5
+ include Mongoid::Document
6
+ include Roles::Mongoid
7
+
8
+ strategy :role_strings, :default
9
+
10
+ valid_roles_are :admin, :guest
11
+
12
+ field :name, :type => String
13
+ end
14
+
15
+ describe "Roles for Mongoid" do
16
+
17
+ after :each do
18
+ Database.teardown
19
+ end
20
+
21
+ context "default setup" do
22
+
23
+ before do
24
+ @user = User.create(:name => 'Kristian')
25
+ @user.role = :guest
26
+ @user.save
27
+
28
+ @admin_user = User.create(:name => 'Admin user')
29
+ @admin_user.roles = :admin
30
+ @admin_user.save
31
+ end
32
+
33
+ describe '#in_role' do
34
+ it "should return first user matching role" do
35
+ User.in_role(:guest).first.name.should == 'Kristian'
36
+ User.in_role(:admin).first.name.should == 'Admin user'
37
+ end
38
+ end
39
+
40
+ describe "Role API" do
41
+ it "should have admin user role to :admin" do
42
+ @admin_user.roles_list.first.should == :admin
43
+ @admin_user.admin?.should be_true
44
+
45
+ @admin_user.has_role?(:guest).should be_false
46
+
47
+ @admin_user.has_role?(:admin).should be_true
48
+ @admin_user.is?(:admin).should be_true
49
+ @admin_user.has_roles?(:admin).should be_true
50
+ @admin_user.has?(:admin).should be_true
51
+ end
52
+
53
+ it "should have user role to :guest" do
54
+ @user.roles_list.first.should == :guest
55
+ @user.admin?.should be_false
56
+
57
+ @user.has_role?(:guest).should be_true
58
+ @user.has_role?(:admin).should be_false
59
+ @user.is?(:admin).should be_false
60
+
61
+ @user.has_roles?(:admin).should be_false
62
+ @user.has?(:admin).should be_false
63
+ end
64
+
65
+ it "should set user role to :admin using roles=" do
66
+ @user.roles = :admin
67
+ @user.roles_list.first.should == :admin
68
+ @user.has_role?(:admin).should be_true
69
+ end
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+ use_roles_strategy :roles_mask
3
+
4
+ class User
5
+ include Mongoid::Document
6
+ include Roles::Mongoid
7
+
8
+ strategy :roles_mask, :default
9
+
10
+ valid_roles_are :admin, :guest
11
+
12
+ field :name, :type => String
13
+ end
14
+
15
+ describe "Roles for Mongoid" do
16
+
17
+ after :each do
18
+ Database.teardown
19
+ end
20
+
21
+ context "default setup" do
22
+
23
+ before do
24
+ @user = User.create(:name => 'Kristian')
25
+ @user.role = :guest
26
+ @user.save
27
+
28
+ @admin_user = User.create(:name => 'Admin user')
29
+ @admin_user.roles = :admin
30
+ @admin_user.save
31
+ end
32
+
33
+ describe '#in_role' do
34
+ it "should return first user matching role" do
35
+ User.in_role(:guest).first.name.should == 'Kristian'
36
+ User.in_role(:admin).first.name.should == 'Admin user'
37
+ end
38
+ end
39
+
40
+ describe "Role API" do
41
+ it "should have admin user role to :admin" do
42
+ @admin_user.roles_list.first.should == :admin
43
+ @admin_user.admin?.should be_true
44
+
45
+ @admin_user.has_role?(:guest).should be_false
46
+
47
+ @admin_user.has_role?(:admin).should be_true
48
+ @admin_user.is?(:admin).should be_true
49
+ @admin_user.has_roles?(:admin).should be_true
50
+ @admin_user.has?(:admin).should be_true
51
+ end
52
+
53
+ it "should have user role to :guest" do
54
+ @user.roles_list.first.should == :guest
55
+ @user.admin?.should be_false
56
+
57
+ @user.has_role?(:guest).should be_true
58
+ @user.has_role?(:admin).should be_false
59
+ @user.is?(:admin).should be_false
60
+
61
+ @user.has_roles?(:admin).should be_false
62
+ @user.has?(:admin).should be_false
63
+ end
64
+
65
+ it "should set user role to :admin using roles=" do
66
+ @user.roles = :admin
67
+ @user.roles_list.first.should == :admin
68
+ @user.has_role?(:admin).should be_true
69
+ end
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,28 @@
1
+ require 'rspec/core'
2
+ require 'mongoid'
3
+ require 'roles_mongoid'
4
+
5
+ Mongoid.configure.master = Mongo::Connection.new.db('roles_mongoid')
6
+
7
+ module Database
8
+ def self.teardown
9
+ # Mongoid.database.collections.each do |coll|
10
+ # coll.remove
11
+ # end
12
+ end
13
+ end
14
+
15
+ Mongoid.database.collections.each do |coll|
16
+ coll.remove
17
+ end
18
+
19
+ RSpec.configure do |config|
20
+ config.mock_with :mocha
21
+ # config.before do
22
+ # Mongoid.database.collections.each do |coll|
23
+ # coll.remove
24
+ # end
25
+ # end
26
+ end
27
+
28
+
@@ -0,0 +1,8 @@
1
+ class User
2
+ include Mongoid::Document
3
+ include Roles::Mongoid
4
+ strategy :admin_flag
5
+
6
+ valid_roles_are :admin, :guest, :user
7
+
8
+ end
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roles_mongoid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 4
9
+ version: 0.2.4
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-06 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ - 22
34
+ version: 2.0.0.beta.22
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: mongoid
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 2
47
+ - 0
48
+ - 0
49
+ - beta
50
+ - 18
51
+ version: 2.0.0.beta.18
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: bson
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 7
66
+ version: 1.0.7
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 3
79
+ - 0
80
+ - 0
81
+ version: 3.0.0
82
+ type: :runtime
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: require_all
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ~>
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 1
94
+ - 2
95
+ - 0
96
+ version: 1.2.0
97
+ type: :runtime
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: sugar-high
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ - 2
110
+ - 11
111
+ version: 0.2.11
112
+ type: :runtime
113
+ version_requirements: *id006
114
+ - !ruby/object:Gem::Dependency
115
+ name: roles_generic
116
+ prerelease: false
117
+ requirement: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ - 2
125
+ - 7
126
+ version: 0.2.7
127
+ type: :runtime
128
+ version_requirements: *id007
129
+ description: Makes it easy to set a role strategy on your User model in Mongoid
130
+ email: kmandrup@gmail.com
131
+ executables: []
132
+
133
+ extensions: []
134
+
135
+ extra_rdoc_files:
136
+ - LICENSE
137
+ - README.markdown
138
+ files:
139
+ - .bundle/config
140
+ - .document
141
+ - .gitignore
142
+ - .rspec
143
+ - Gemfile
144
+ - LICENSE
145
+ - README.markdown
146
+ - Rakefile
147
+ - VERSION
148
+ - lib/generators/mongoid/roles/roles_generator.rb
149
+ - lib/roles_mongoid.rb
150
+ - lib/roles_mongoid/base.rb
151
+ - lib/roles_mongoid/namespaces.rb
152
+ - lib/roles_mongoid/role.rb
153
+ - lib/roles_mongoid/strategy.rb
154
+ - lib/roles_mongoid/strategy/multi/many_roles.rb
155
+ - lib/roles_mongoid/strategy/multi/role_strings.rb
156
+ - lib/roles_mongoid/strategy/multi/roles_mask.rb
157
+ - lib/roles_mongoid/strategy/single/admin_flag.rb
158
+ - lib/roles_mongoid/strategy/single/one_role.rb
159
+ - lib/roles_mongoid/strategy/single/role_string.rb
160
+ - roles_mongoid.gemspec
161
+ - sandbox/roles_assign.rb
162
+ - sandbox/single_role.rb
163
+ - sandbox/test.rb
164
+ - spec/generator_spec_helper.rb
165
+ - spec/generators/roles_generator_spec.rb
166
+ - spec/roles_mongoid/admin_flag_spec.rb
167
+ - spec/roles_mongoid/many_roles_spec.rb
168
+ - spec/roles_mongoid/one_role_spec.rb
169
+ - spec/roles_mongoid/role_string_spec.rb
170
+ - spec/roles_mongoid/role_strings_spec.rb
171
+ - spec/roles_mongoid/roles_mask_spec.rb
172
+ - spec/spec_helper.rb
173
+ - tmp/rails/app/models/user.rb
174
+ - tmp/rails/config/routes.rb
175
+ has_rdoc: true
176
+ homepage: http://github.com/kristianmandrup/roles_mongoid
177
+ licenses: []
178
+
179
+ post_install_message:
180
+ rdoc_options:
181
+ - --charset=UTF-8
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ segments:
190
+ - 0
191
+ version: "0"
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ segments:
198
+ - 0
199
+ version: "0"
200
+ requirements: []
201
+
202
+ rubyforge_project:
203
+ rubygems_version: 1.3.7
204
+ signing_key:
205
+ specification_version: 3
206
+ summary: Implementation of Roles generic API for Mongoid
207
+ test_files:
208
+ - spec/generator_spec_helper.rb
209
+ - spec/generators/roles_generator_spec.rb
210
+ - spec/roles_mongoid/admin_flag_spec.rb
211
+ - spec/roles_mongoid/many_roles_spec.rb
212
+ - spec/roles_mongoid/one_role_spec.rb
213
+ - spec/roles_mongoid/role_string_spec.rb
214
+ - spec/roles_mongoid/role_strings_spec.rb
215
+ - spec/roles_mongoid/roles_mask_spec.rb
216
+ - spec/spec_helper.rb