the_role 2.5.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +178 -526
- data/gem_version.rb +3 -0
- data/lib/the_role/version.rb +1 -3
- data/lib/the_role.rb +3 -41
- data/the_role.gemspec +5 -5
- metadata +20 -231
- data/.ruby-gemset.example +0 -1
- data/.ruby-version.example +0 -1
- data/.rvmrc.example +0 -1
- data/.travis.yml +0 -5
- data/Bye_bye_CanCan_I_got_the_Role.png +0 -0
- data/app/controllers/admin/role_sections_controller.rb +0 -90
- data/app/controllers/admin/roles_controller.rb +0 -74
- data/app/controllers/concerns/controller.rb +0 -23
- data/app/models/_templates_/role.rb +0 -3
- data/app/models/concerns/base.rb +0 -37
- data/app/models/concerns/role.rb +0 -156
- data/app/models/concerns/user.rb +0 -57
- data/config/locales/en.yml +0 -44
- data/config/locales/es.yml +0 -42
- data/config/locales/nl.yml +0 -44
- data/config/locales/pl.yml +0 -43
- data/config/locales/pt_BR.yml +0 -43
- data/config/locales/ru.yml +0 -43
- data/config/locales/zh_CN.yml +0 -42
- data/config/routes.rb +0 -23
- data/db/migrate/20111025025129_create_roles.rb +0 -23
- data/docs/2.1.1.png +0 -0
- data/lib/generators/the_role/USAGE +0 -32
- data/lib/generators/the_role/templates/the_role.rb +0 -11
- data/lib/generators/the_role/the_role_generator.rb +0 -64
- data/lib/tasks/roles.rake +0 -137
- data/lib/the_role/activerecord.rb +0 -11
- data/lib/the_role/config.rb +0 -30
- data/lib/the_role/hash.rb +0 -58
- data/lib/the_role/the_class_exists.rb +0 -8
- data/pic.png +0 -0
- data/spec/dummy_app/.gitignore +0 -18
- data/spec/dummy_app/.rspec +0 -1
- data/spec/dummy_app/Gemfile +0 -43
- data/spec/dummy_app/README.md +0 -39
- data/spec/dummy_app/Rakefile +0 -6
- data/spec/dummy_app/app/assets/images/.keep +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +0 -17
- data/spec/dummy_app/app/assets/stylesheets/app/style.css.scss +0 -23
- data/spec/dummy_app/app/assets/stylesheets/application.css +0 -3
- data/spec/dummy_app/app/controllers/application_controller.rb +0 -38
- data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
- data/spec/dummy_app/app/controllers/pages_controller.rb +0 -75
- data/spec/dummy_app/app/controllers/users_controller.rb +0 -32
- data/spec/dummy_app/app/controllers/welcome_controller.rb +0 -13
- data/spec/dummy_app/app/helpers/application_helper.rb +0 -2
- data/spec/dummy_app/app/mailers/.keep +0 -0
- data/spec/dummy_app/app/models/.keep +0 -0
- data/spec/dummy_app/app/models/concerns/.keep +0 -0
- data/spec/dummy_app/app/models/page.rb +0 -24
- data/spec/dummy_app/app/models/role.rb +0 -4
- data/spec/dummy_app/app/models/user.rb +0 -21
- data/spec/dummy_app/app/views/layouts/_current_user_info.html.haml +0 -17
- data/spec/dummy_app/app/views/layouts/application.html.haml +0 -68
- data/spec/dummy_app/app/views/pages/_form.html.haml +0 -19
- data/spec/dummy_app/app/views/pages/edit.html.haml +0 -7
- data/spec/dummy_app/app/views/pages/index.html.haml +0 -27
- data/spec/dummy_app/app/views/pages/manage.html.haml +0 -23
- data/spec/dummy_app/app/views/pages/my.html.haml +0 -10
- data/spec/dummy_app/app/views/pages/new.html.haml +0 -5
- data/spec/dummy_app/app/views/pages/show.html.haml +0 -15
- data/spec/dummy_app/app/views/users/edit.html.haml +0 -34
- data/spec/dummy_app/app/views/welcome/index.html.haml +0 -38
- data/spec/dummy_app/app/views/welcome/profile.html.haml +0 -2
- data/spec/dummy_app/bin/bundle +0 -3
- data/spec/dummy_app/bin/rails +0 -4
- data/spec/dummy_app/bin/rake +0 -4
- data/spec/dummy_app/config/application.rb +0 -25
- data/spec/dummy_app/config/boot.rb +0 -4
- data/spec/dummy_app/config/database.yml +0 -17
- data/spec/dummy_app/config/environment.rb +0 -5
- data/spec/dummy_app/config/environments/development.rb +0 -29
- data/spec/dummy_app/config/environments/production.rb +0 -80
- data/spec/dummy_app/config/environments/test.rb +0 -36
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy_app/config/initializers/devise.rb +0 -227
- data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy_app/config/initializers/inflections.rb +0 -16
- data/spec/dummy_app/config/initializers/mime_types.rb +0 -5
- data/spec/dummy_app/config/initializers/secret_token.rb +0 -12
- data/spec/dummy_app/config/initializers/session_store.rb +0 -3
- data/spec/dummy_app/config/initializers/the_role.rb +0 -6
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy_app/config/locales/devise.en.yml +0 -57
- data/spec/dummy_app/config/locales/en.yml +0 -7
- data/spec/dummy_app/config/locales/ru.yml +0 -4
- data/spec/dummy_app/config/routes.rb +0 -26
- data/spec/dummy_app/config.ru +0 -4
- data/spec/dummy_app/db/migrate/20120212061952_devise_create_users.rb +0 -63
- data/spec/dummy_app/db/migrate/20120212063249_create_roles.rb +0 -18
- data/spec/dummy_app/db/migrate/20120314061307_create_pages.rb +0 -14
- data/spec/dummy_app/db/schema.rb +0 -59
- data/spec/dummy_app/db/seeds.rb +0 -85
- data/spec/dummy_app/lib/assets/.keep +0 -0
- data/spec/dummy_app/lib/tasks/.keep +0 -0
- data/spec/dummy_app/lib/tasks/assets.rake +0 -15
- data/spec/dummy_app/lib/tasks/db_bootstrap.rake +0 -16
- data/spec/dummy_app/log/.keep +0 -0
- data/spec/dummy_app/public/404.html +0 -58
- data/spec/dummy_app/public/422.html +0 -58
- data/spec/dummy_app/public/500.html +0 -57
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/robots.txt +0 -5
- data/spec/dummy_app/spec/controllers/admin_roles_controller_spec.rb +0 -52
- data/spec/dummy_app/spec/controllers/pages_controller_spec.rb +0 -141
- data/spec/dummy_app/spec/controllers/welcome_controller_spec.rb +0 -66
- data/spec/dummy_app/spec/factories/page.rb +0 -6
- data/spec/dummy_app/spec/factories/role.rb +0 -55
- data/spec/dummy_app/spec/factories/user.rb +0 -11
- data/spec/dummy_app/spec/models/hash_spec.rb +0 -272
- data/spec/dummy_app/spec/models/param_process_spec.rb +0 -39
- data/spec/dummy_app/spec/models/role_spec.rb +0 -218
- data/spec/dummy_app/spec/models/user_spec.rb +0 -164
- data/spec/dummy_app/spec/routing/admin_roles_routing_spec.rb +0 -41
- data/spec/dummy_app/spec/routing/pages_routing_spec.rb +0 -35
- data/spec/dummy_app/spec/spec_helper.rb +0 -68
- data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
- data/the_role.yml.teamocil.example +0 -11
@@ -1,272 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hash do
|
4
|
-
context "METHODS" do
|
5
|
-
it "underscorify_keys" do
|
6
|
-
Hash.new.respond_to?(:underscorify_keys).should eq true
|
7
|
-
end
|
8
|
-
|
9
|
-
it "underscorify_keys!" do
|
10
|
-
Hash.new.respond_to?(:underscorify_keys!).should eq true
|
11
|
-
end
|
12
|
-
|
13
|
-
it "deep_reset" do
|
14
|
-
Hash.new.respond_to?(:deep_reset).should eq true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "deep_reset!" do
|
18
|
-
Hash.new.respond_to?(:deep_reset!).should eq true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "deep_merge" do
|
22
|
-
Hash.new.respond_to?(:deep_merge).should eq true
|
23
|
-
end
|
24
|
-
|
25
|
-
it "deep_merge!" do
|
26
|
-
Hash.new.respond_to?(:deep_merge!).should eq true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "deep HASH.underscorify_keys" do
|
31
|
-
it "UNDERSCORIFY hash keys" do
|
32
|
-
hash = {
|
33
|
-
'a b' => 1,
|
34
|
-
"x y" => {
|
35
|
-
:hello => 1,
|
36
|
-
:'hello-world' => 1,
|
37
|
-
'good MorninG mom!' => 1
|
38
|
-
}
|
39
|
-
}
|
40
|
-
result = {
|
41
|
-
'a_b' => 1,
|
42
|
-
'x_y' => {
|
43
|
-
'hello' => 1,
|
44
|
-
'hello_world' => 1,
|
45
|
-
'good_morning_mom' => 1
|
46
|
-
}
|
47
|
-
}
|
48
|
-
hash.underscorify_keys.should eq result
|
49
|
-
hash.should_not eq result
|
50
|
-
end
|
51
|
-
|
52
|
-
it "UNDERSCORIFY! hash keys" do
|
53
|
-
hash = {
|
54
|
-
'a b' => 1,
|
55
|
-
"x y" => {
|
56
|
-
'hello' => 1
|
57
|
-
}
|
58
|
-
}
|
59
|
-
result = {
|
60
|
-
'a_b' => 1,
|
61
|
-
'x_y' => {
|
62
|
-
'hello' => 1
|
63
|
-
}
|
64
|
-
}
|
65
|
-
hash.underscorify_keys!.should eq result
|
66
|
-
hash.should eq result
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "HASH.deep_reset" do
|
71
|
-
before(:each) do
|
72
|
-
@hash = {
|
73
|
-
:pages => {
|
74
|
-
:index => true,
|
75
|
-
:show => true,
|
76
|
-
:new => false,
|
77
|
-
:edit => false,
|
78
|
-
:update => false,
|
79
|
-
:destroy => false
|
80
|
-
},
|
81
|
-
:articles => {
|
82
|
-
:index => true,
|
83
|
-
:show => true
|
84
|
-
}
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
it "DEEP RESET hash values to nil" do
|
89
|
-
result = {
|
90
|
-
:pages => {
|
91
|
-
:index => nil,
|
92
|
-
:show => nil,
|
93
|
-
:new => nil,
|
94
|
-
:edit => nil,
|
95
|
-
:update => nil,
|
96
|
-
:destroy => nil
|
97
|
-
},
|
98
|
-
:articles => {
|
99
|
-
:index => nil,
|
100
|
-
:show => nil
|
101
|
-
}
|
102
|
-
}
|
103
|
-
hash = @hash.deep_reset
|
104
|
-
hash.should eq result
|
105
|
-
end
|
106
|
-
|
107
|
-
it "DEEP RESET hash values to nil :test" do
|
108
|
-
result = {
|
109
|
-
:pages => {
|
110
|
-
:index => :test,
|
111
|
-
:show => :test,
|
112
|
-
:new => :test,
|
113
|
-
:edit => :test,
|
114
|
-
:update => :test,
|
115
|
-
:destroy => :test
|
116
|
-
},
|
117
|
-
:articles => {
|
118
|
-
:index => :test,
|
119
|
-
:show => :test
|
120
|
-
}
|
121
|
-
}
|
122
|
-
hash = @hash.deep_reset(:test)
|
123
|
-
hash.should eq result
|
124
|
-
end
|
125
|
-
|
126
|
-
it "DEEP RESET! hash values to nil" do
|
127
|
-
result = {
|
128
|
-
:pages => {
|
129
|
-
:index => :test,
|
130
|
-
:show => :test,
|
131
|
-
:new => :test,
|
132
|
-
:edit => :test,
|
133
|
-
:update => :test,
|
134
|
-
:destroy => :test
|
135
|
-
},
|
136
|
-
:articles => {
|
137
|
-
:index => :test,
|
138
|
-
:show => :test
|
139
|
-
}
|
140
|
-
}
|
141
|
-
hash = @hash.deep_reset(:test)
|
142
|
-
hash.should eq result
|
143
|
-
@hash.should_not eq result
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "DEEP RESET! with different keys types" do
|
148
|
-
it "work fine" do
|
149
|
-
hash = {
|
150
|
-
'pages' => {
|
151
|
-
:index => true,
|
152
|
-
'edit' => true
|
153
|
-
}
|
154
|
-
}
|
155
|
-
result = {
|
156
|
-
'pages' => {
|
157
|
-
:index => nil,
|
158
|
-
'edit' => nil
|
159
|
-
}
|
160
|
-
}
|
161
|
-
hash.deep_reset!(nil).should eq result
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "DEEP MERGE" do
|
166
|
-
it " => hashes" do
|
167
|
-
first_hash = {
|
168
|
-
'pages' => {
|
169
|
-
'index' => false,
|
170
|
-
'edit' => false
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
second_hash = {
|
175
|
-
'pages' => {
|
176
|
-
'index' => true,
|
177
|
-
'edit' => false,
|
178
|
-
'destroy' => true
|
179
|
-
}
|
180
|
-
}
|
181
|
-
|
182
|
-
result = {
|
183
|
-
'pages' => {
|
184
|
-
'index' => true,
|
185
|
-
'edit' => false,
|
186
|
-
'destroy' => true
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
first_hash.deep_merge!(second_hash).should eq result
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should merge 2 hash (1st 3-lavels, 2nd - 2 levels => 2 level)" do
|
194
|
-
first_hash = {
|
195
|
-
'pages' => {
|
196
|
-
'index' => false,
|
197
|
-
'edit' => {
|
198
|
-
'one' => 1,
|
199
|
-
'two' => 2
|
200
|
-
}
|
201
|
-
}
|
202
|
-
}
|
203
|
-
|
204
|
-
second_hash = {
|
205
|
-
'pages' => {
|
206
|
-
'index' => true,
|
207
|
-
'edit' => false,
|
208
|
-
'destroy' => true
|
209
|
-
}
|
210
|
-
}
|
211
|
-
|
212
|
-
result = {
|
213
|
-
'pages' => {
|
214
|
-
'index' => true,
|
215
|
-
'edit' => false,
|
216
|
-
'destroy' => true
|
217
|
-
}
|
218
|
-
}
|
219
|
-
|
220
|
-
first_hash.deep_merge!(second_hash).should eq result
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "DEEP MERGE!" do
|
225
|
-
before(:each) do
|
226
|
-
@incoming_hash = {
|
227
|
-
'pages' => {
|
228
|
-
'edit' => true,
|
229
|
-
'manage' => true,
|
230
|
-
'destroy' => true
|
231
|
-
}
|
232
|
-
}
|
233
|
-
@base_hash = {
|
234
|
-
'pages' => {
|
235
|
-
'index' => true,
|
236
|
-
'edit' => false,
|
237
|
-
'destroy' => false,
|
238
|
-
'banners' => false
|
239
|
-
}
|
240
|
-
}
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'should reset base hash to false' do
|
244
|
-
result = {
|
245
|
-
'pages' => {
|
246
|
-
'index' => nil,
|
247
|
-
'edit' => nil,
|
248
|
-
'destroy' => nil,
|
249
|
-
'banners' => nil
|
250
|
-
}
|
251
|
-
}
|
252
|
-
@base_hash.deep_reset!
|
253
|
-
@base_hash.should == result
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'should merge 2 hashes' do
|
257
|
-
result = {
|
258
|
-
'pages' => {
|
259
|
-
'index' => false,
|
260
|
-
'edit' => true,
|
261
|
-
'manage' => true,
|
262
|
-
'destroy' => true,
|
263
|
-
'banners' => false
|
264
|
-
}
|
265
|
-
}
|
266
|
-
|
267
|
-
@base_hash.deep_reset!(false)
|
268
|
-
@base_hash.deep_merge! @incoming_hash
|
269
|
-
@base_hash.should == result
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "String to slug" do
|
6
|
-
it 'string process 1' do
|
7
|
-
'hello world!'.to_slug_param(sep: '_').should eq 'hello_world'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'string process 2' do
|
11
|
-
:hello_world!.to_slug_param(sep: '_').should eq 'hello_world'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'string process 3' do
|
15
|
-
"hello ! world".to_slug_param(sep: '_').should eq 'hello_world'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'string process 4' do
|
19
|
-
"HELLO $!= WorlD".to_slug_param(sep: '_').should eq 'hello_world'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'string process 5' do
|
23
|
-
"HELLO---WorlD".to_slug_param(sep: '_').should eq 'hello_world'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should work with Controller Name" do
|
27
|
-
ctrl = PagesController.new
|
28
|
-
ctrl.controller_path
|
29
|
-
ctrl.controller_path.to_slug_param(sep: '_').should eq 'pages'
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should work with Nested Controller Name" do
|
33
|
-
class Admin::PagesController < ApplicationController; end
|
34
|
-
ctrl = Admin::PagesController.new
|
35
|
-
ctrl.controller_path
|
36
|
-
|
37
|
-
ctrl.controller_path.to_slug_param(sep: '_').should eq 'admin_pages'
|
38
|
-
end
|
39
|
-
end
|
@@ -1,218 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Role do
|
4
|
-
context "Role *Create* methods" do
|
5
|
-
it "New/Create invalid" do
|
6
|
-
role = Role.new
|
7
|
-
role.save.should be_false
|
8
|
-
|
9
|
-
role.should have(1).error_on(:name)
|
10
|
-
role.should have(1).error_on(:title)
|
11
|
-
role.should have(1).error_on(:description)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "New/Create valid, without Role hash" do
|
15
|
-
role = Role.new
|
16
|
-
|
17
|
-
role.name = :user
|
18
|
-
role.title = :user_title
|
19
|
-
role.description = :role_description
|
20
|
-
|
21
|
-
role.save.should be_true
|
22
|
-
end
|
23
|
-
|
24
|
-
it "New/Create valid, without Role hash (2)" do
|
25
|
-
Role.new(
|
26
|
-
name: :user,
|
27
|
-
title: :user_title,
|
28
|
-
description: :role_description
|
29
|
-
).save.should be_true
|
30
|
-
end
|
31
|
-
|
32
|
-
it "New/Create, without Role hash, default Role hash value" do
|
33
|
-
role = FactoryGirl.create :role_without_rules
|
34
|
-
role.the_role.should == "{}"
|
35
|
-
role.to_hash.should == {}
|
36
|
-
end
|
37
|
-
|
38
|
-
it "New/Create, role methods result types" do
|
39
|
-
role = FactoryGirl.create :role_without_rules
|
40
|
-
role.the_role.should be_an_instance_of String
|
41
|
-
role.to_hash.should be_an_instance_of Hash
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "Role *Section/Rule create* methods" do
|
46
|
-
before(:each) do
|
47
|
-
@role = FactoryGirl.create :role_without_rules
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should have empty Role hash" do
|
51
|
-
@role.to_hash.should == {}
|
52
|
-
end
|
53
|
-
|
54
|
-
it "Create section" do
|
55
|
-
@role.create_section(:articles)
|
56
|
-
@role.to_hash.should == { "articles" => {} }
|
57
|
-
end
|
58
|
-
|
59
|
-
it "Create rule (with section)" do
|
60
|
-
@role.create_section(:articles)
|
61
|
-
@role.create_rule(:articles, :index)
|
62
|
-
@role.to_hash.should == { "articles" => { "index" => false } }
|
63
|
-
end
|
64
|
-
|
65
|
-
it "Create rule (without section)" do
|
66
|
-
@role.create_rule(:articles, :index)
|
67
|
-
@role.to_hash.should == { "articles" => { "index" => false } }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "*has?* is aliace of *has_role?*" do
|
72
|
-
before(:each) do
|
73
|
-
@role = FactoryGirl.create :role_user
|
74
|
-
end
|
75
|
-
|
76
|
-
it "aliace methods" do
|
77
|
-
@role.has?(:pages, :index).should be_true
|
78
|
-
@role.has_role?(:pages, :index).should be_true
|
79
|
-
|
80
|
-
@role.has?(:pages, :secret).should be_false
|
81
|
-
@role.has_role?(:pages, :secret).should be_false
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "Rule *On/Off* methods" do
|
86
|
-
before(:each) do
|
87
|
-
@role = FactoryGirl.create :role_user
|
88
|
-
end
|
89
|
-
|
90
|
-
it "has access to pages/index" do
|
91
|
-
@role.has_role?(:pages, :index).should be_true
|
92
|
-
end
|
93
|
-
|
94
|
-
it "set pages/index on false" do
|
95
|
-
@role.rule_off(:pages, :index)
|
96
|
-
@role.has_role?(:pages, :index).should be_false
|
97
|
-
end
|
98
|
-
|
99
|
-
it "has no access to pages/secret" do
|
100
|
-
@role.has_role?(:pages, :secret).should be_false
|
101
|
-
end
|
102
|
-
|
103
|
-
it "set pages/secret on true" do
|
104
|
-
@role.rule_on(:pages, :secret)
|
105
|
-
@role.has_role?(:pages, :secret).should be_true
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "Class Methods" do
|
110
|
-
before(:each) do
|
111
|
-
@role = FactoryGirl.create :role_user
|
112
|
-
end
|
113
|
-
|
114
|
-
it "Role.with_name(:name) method" do
|
115
|
-
Role.with_name(:user).should be_an_instance_of Role
|
116
|
-
Role.with_name('user').should be_an_instance_of Role
|
117
|
-
|
118
|
-
Role.with_name(:moderator).should be_nil
|
119
|
-
Role.with_name('moderator').should be_nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context "*Delete* methods" do
|
124
|
-
before(:each) do
|
125
|
-
@role = FactoryGirl.create :role_user
|
126
|
-
end
|
127
|
-
|
128
|
-
it "*has_section?* method" do
|
129
|
-
@role.has_section?(:pages).should be_true
|
130
|
-
@role.has_section?(:articles).should be_false
|
131
|
-
end
|
132
|
-
|
133
|
-
it "has pages section" do
|
134
|
-
@role.to_hash['pages'].should be_an_instance_of Hash
|
135
|
-
end
|
136
|
-
|
137
|
-
it "has pages/index value" do
|
138
|
-
@role.to_hash['pages']['index'].should be_true
|
139
|
-
end
|
140
|
-
|
141
|
-
it "delete rule pages/index" do
|
142
|
-
@role.delete_rule(:pages, :index)
|
143
|
-
@role.to_hash['pages']['index'].should be_nil
|
144
|
-
end
|
145
|
-
|
146
|
-
it "delete section pages" do
|
147
|
-
@role.delete_section(:pages)
|
148
|
-
@role.to_hash['pages'].should be_nil
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "*helper* methods" do
|
153
|
-
before(:each) do
|
154
|
-
@role = FactoryGirl.create :role_without_rules
|
155
|
-
end
|
156
|
-
|
157
|
-
it "to_hash on empty rules set" do
|
158
|
-
@role.to_hash.should == {}
|
159
|
-
end
|
160
|
-
|
161
|
-
it "to_json on empty rules set" do
|
162
|
-
@role.to_json.should == "{}"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context "Update method" do
|
167
|
-
before(:each) do
|
168
|
-
@role = FactoryGirl.create :role_user
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should has true rules" do
|
172
|
-
@role.has?(:pages, :index).should be_true
|
173
|
-
@role.has?(:pages, :edit).should be_true
|
174
|
-
@role.has?(:pages, :update).should be_true
|
175
|
-
@role.has?(:pages, :secret).should be_false
|
176
|
-
|
177
|
-
@role.has?(:articles, :index).should be_false
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should has true rules" do
|
181
|
-
@role.update_role({ articles: { index: true } })
|
182
|
-
|
183
|
-
@role.has?(:pages, :index).should be_false
|
184
|
-
@role.has?(:pages, :edit).should be_false
|
185
|
-
@role.has?(:pages, :update).should be_false
|
186
|
-
@role.has?(:pages, :secret).should be_false
|
187
|
-
|
188
|
-
@role.has?(:articles, :index).should be_true
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should has any rules 1" do
|
192
|
-
@role.has?(:pages, :index).should be_true
|
193
|
-
@role.has?(:pages, :update).should be_true
|
194
|
-
|
195
|
-
@role.any?({ pages: :index }).should be_true
|
196
|
-
@role.any?({ pages: :update }).should be_true
|
197
|
-
@role.any?({ pages: :index, pages: :update}).should be_true
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should has any rules 2" do
|
201
|
-
@role.has?(:pages, :index).should be_true
|
202
|
-
@role.has?(:articles, :index).should be_false
|
203
|
-
|
204
|
-
@role.any?({ pages: :index }).should be_true
|
205
|
-
@role.any?({ articles: :index }).should be_false
|
206
|
-
|
207
|
-
@role.any?({ articles: :index }).should be_false
|
208
|
-
@role.any?({ pages: :index, articles: :index}).should be_true
|
209
|
-
@role.any?({ pages: :index, pages: :update}).should be_true
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should has any rules 3, easy syntaxis" do
|
213
|
-
@role.any?(articles: :index).should be_false
|
214
|
-
@role.any?(pages: :index, articles: :index).should be_true
|
215
|
-
@role.any?(pages: :index, pages: :update).should be_true
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe User do
|
6
|
-
describe "Owner check for User and object" do
|
7
|
-
context "Regular user" do
|
8
|
-
before(:each) do
|
9
|
-
@user_1 = FactoryGirl.create(:user)
|
10
|
-
@user_2 = FactoryGirl.create(:user)
|
11
|
-
|
12
|
-
@user_1_page = FactoryGirl.create(:page, user: @user_1)
|
13
|
-
@user_2_page = FactoryGirl.create(:page, user: @user_2)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should have test varaibles' do
|
17
|
-
@user_1.should be_instance_of User
|
18
|
-
@user_2.should be_instance_of User
|
19
|
-
|
20
|
-
@user_1_page.should be_instance_of Page
|
21
|
-
@user_2_page.should be_instance_of Page
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should be owner of page' do
|
25
|
-
@user_1.owner?(@user_1_page).should be_true
|
26
|
-
@user_2.owner?(@user_2_page).should be_true
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should not be owner of page' do
|
30
|
-
@user_1.owner?(@user_2_page).should be_false
|
31
|
-
@user_2.owner?(@user_1_page).should be_false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "Moderator" do
|
36
|
-
before(:each) do
|
37
|
-
mrole = FactoryGirl.create(:role_moderator)
|
38
|
-
|
39
|
-
@moderator = FactoryGirl.create(:user, role: mrole)
|
40
|
-
@user = FactoryGirl.create(:user)
|
41
|
-
|
42
|
-
@moderator_page = FactoryGirl.create(:page, user: @moderator)
|
43
|
-
@user_page = FactoryGirl.create(:page, user: @user)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'Moderator is owner of any Page' do
|
47
|
-
@moderator.owner?(@moderator_page).should be_true
|
48
|
-
@moderator.owner?(@user_page).should be_true
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'User is owner of his Pages' do
|
52
|
-
@user.owner?(@user_page).should be_true
|
53
|
-
@user.owner?(@moderator_page).should be_false
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "Admin" do
|
58
|
-
# not important. to implement later
|
59
|
-
end
|
60
|
-
|
61
|
-
# context "Custom Page relation to User" do
|
62
|
-
# before(:each) do
|
63
|
-
# Page.class_eval do
|
64
|
-
# belongs_to :user, class_name: User, foreign_key: 'person_id'
|
65
|
-
# end
|
66
|
-
|
67
|
-
# @user = FactoryGirl.create(:user)
|
68
|
-
# @page = FactoryGirl.create(:page, user: @user)
|
69
|
-
# end
|
70
|
-
|
71
|
-
# it 'relation via person_id' do
|
72
|
-
# @page.user_id.should eq @user.id
|
73
|
-
# @page.person_id.should eq @user.id
|
74
|
-
# end
|
75
|
-
# end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "Create user without any Role" do
|
79
|
-
before(:each) do
|
80
|
-
FactoryGirl.create(:user)
|
81
|
-
@user = User.first
|
82
|
-
end
|
83
|
-
|
84
|
-
it "Create test user" do
|
85
|
-
User.count.should be 1
|
86
|
-
end
|
87
|
-
|
88
|
-
it "User have not any role" do
|
89
|
-
@user.role.should be_nil
|
90
|
-
end
|
91
|
-
|
92
|
-
it "User should gives false on any request" do
|
93
|
-
@user.has_role?(:pages, :index).should be_false
|
94
|
-
@user.has_role?(:moderator, :pages).should be_false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "Create user with default Role" do
|
99
|
-
before(:each) do
|
100
|
-
TheRole.config.default_user_role = :user
|
101
|
-
FactoryGirl.create(:role_user)
|
102
|
-
FactoryGirl.create(:user)
|
103
|
-
@user = User.first
|
104
|
-
end
|
105
|
-
|
106
|
-
it "User and Role should exists" do
|
107
|
-
Role.count.should be 1
|
108
|
-
User.count.should be 1
|
109
|
-
end
|
110
|
-
|
111
|
-
it "Role should nave name :user" do
|
112
|
-
Role.first.name.should eq 'user'
|
113
|
-
end
|
114
|
-
|
115
|
-
it "User should have default Role" do
|
116
|
-
@user.role.should_not be_nil
|
117
|
-
end
|
118
|
-
|
119
|
-
it "User has Role for Pages" do
|
120
|
-
@user.has_role?(:pages, :index).should be_true
|
121
|
-
@user.has_role?(:pages, :destroy).should be_true
|
122
|
-
end
|
123
|
-
|
124
|
-
it "User has disabled rule" do
|
125
|
-
@user.has_role?(:pages, :secret).should be_false
|
126
|
-
end
|
127
|
-
|
128
|
-
it "User try to have access to undefined rule" do
|
129
|
-
@user.has_role?(:pages, :wrong_name).should be_false
|
130
|
-
end
|
131
|
-
|
132
|
-
it "User has not Role for Atricles" do
|
133
|
-
@user.has_role?(:articles, :index).should be_false
|
134
|
-
end
|
135
|
-
|
136
|
-
# Any
|
137
|
-
it "should has any rules 1" do
|
138
|
-
@user.has_role?(:pages, :index).should be_true
|
139
|
-
@user.has_role?(:pages, :update).should be_true
|
140
|
-
|
141
|
-
@user.any_role?({ pages: :index }).should be_true
|
142
|
-
@user.any_role?({ pages: :update }).should be_true
|
143
|
-
@user.any_role?({ pages: :index, pages: :update}).should be_true
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should has any rules 2" do
|
147
|
-
@user.has_role?(:pages, :index).should be_true
|
148
|
-
@user.has_role?(:articles, :index).should be_false
|
149
|
-
|
150
|
-
@user.any_role?({ pages: :index }).should be_true
|
151
|
-
@user.any_role?({ articles: :index }).should be_false
|
152
|
-
|
153
|
-
@user.any_role?({ articles: :index }).should be_false
|
154
|
-
@user.any_role?({ pages: :index, articles: :index}).should be_true
|
155
|
-
@user.any_role?({ pages: :index, pages: :update}).should be_true
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should has any rules 3, easy syntaxis" do
|
159
|
-
@user.any_role?(articles: :index).should be_false
|
160
|
-
@user.any_role?(pages: :index, articles: :index).should be_true
|
161
|
-
@user.any_role?(pages: :index, pages: :update).should be_true
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|