cream 0.5.6
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.
- data/.document +5 -0
- data/.gitignore +39 -0
- data/.rspec +1 -0
- data/Changelog.txt +8 -0
- data/Gemfile +27 -0
- data/LICENSE +20 -0
- data/README.markdown +196 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/app/views/auth_assist/menu/_admin_login_items.html.erb +11 -0
- data/app/views/auth_assist/menu/_login_items.html.erb +11 -0
- data/app/views/auth_assist/menu/_registration_items.html.erb +10 -0
- data/config/locales/en.yml +14 -0
- data/cream.gemspec +169 -0
- data/features/FEATURE_NOTES.txt +6 -0
- data/features/permission/adds_permission.feature +0 -0
- data/features/role_strategy/adds_role_strategy.feature +0 -0
- data/features/role_strategy/clears_role_strategy.feature +0 -0
- data/init.rb +1 -0
- data/lib/cream.rb +21 -0
- data/lib/cream/configure.rb +3 -0
- data/lib/cream/configure/after_init/role_config.rb +29 -0
- data/lib/cream/configure/rails.rb +23 -0
- data/lib/cream/controller/ability.rb +7 -0
- data/lib/cream/helper/authlabels.rb +21 -0
- data/lib/cream/helper/host.rb +11 -0
- data/lib/cream/helper/role.rb +48 -0
- data/lib/cream/namespaces.rb +5 -0
- data/lib/cream/role.rb +7 -0
- data/lib/cream/view/host_area.rb +12 -0
- data/lib/cream/view/role_area.rb +38 -0
- data/lib/cream/view/user_action_menu.rb +21 -0
- data/lib/generators/cream/config/DESIGN NOTES.markdown +61 -0
- data/lib/generators/cream/config/config_generator.rb +72 -0
- data/lib/generators/cream/config/modules/cancan_config.rb +22 -0
- data/lib/generators/cream/config/modules/cream_config.rb +23 -0
- data/lib/generators/cream/config/modules/devise_config.rb +108 -0
- data/lib/generators/cream/config/modules/helper.rb +57 -0
- data/lib/generators/cream/config/modules/permits_config.rb +15 -0
- data/lib/generators/cream/config/modules/roles_config.rb +15 -0
- data/lib/generators/cream/views/haml_util.rb +44 -0
- data/lib/generators/cream/views/views_generator.rb +34 -0
- data/lib/generators/cream_refactor.rb +82 -0
- data/log/development.log +0 -0
- data/sandbox/test.rb +40 -0
- data/spec/cream/configure/rails_spec.rb +51 -0
- data/spec/cream/helper/host_spec.rb +68 -0
- data/spec/cream/helper/role_spec.rb +187 -0
- data/spec/cream/view/host_area_spec.rb +61 -0
- data/spec/cream/view/role_area_spec.rb +124 -0
- data/spec/cream/view/role_ext_spec.rb +36 -0
- data/spec/generator_spec_helper.rb +26 -0
- data/spec/generators/cream/config/devise/existing_devise_users.rb +61 -0
- data/spec/generators/cream/config/empty_app/default_args_spec.rb +51 -0
- data/spec/generators/cream/config/permits/existing_permits_spec.rb +0 -0
- data/spec/generators/cream/config/permits/no_permits_spec.rb +0 -0
- data/spec/generators/cream/config/roles/default_roles.rb +51 -0
- data/spec/generators/cream/config/roles/roles_spec.rb +60 -0
- data/spec/generators/cream/shared_examples.rb +18 -0
- data/spec/generators/cream/views_generator_spec.rb +30 -0
- data/spec/spec_helper.rb +18 -0
- data/wiki/CONFIG_GENERATOR.txt +21 -0
- data/wiki/DESIGN.txt +21 -0
- data/wiki/INSTALLATION.txt +6 -0
- data/wiki/PERMITS.txt +32 -0
- data/wiki/ROLE_STRATEGIES.txt +40 -0
- data/wiki/SPEC_NOTES.txt +6 -0
- data/wiki/VIEWS_GENERATOR.txt +35 -0
- data/wiki/VIEW_HELPERS.txt +162 -0
- metadata +374 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'require_all'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'cream/helper/host'
|
5
|
+
|
6
|
+
describe Cream::Helper::Host do
|
7
|
+
extend_view_with Cream::Helper::Host
|
8
|
+
|
9
|
+
describe '#localhost?' do
|
10
|
+
it "should return true if request.host is 'localhost'" do
|
11
|
+
request = stub()
|
12
|
+
request.stubs(:host).returns 'localhost'
|
13
|
+
|
14
|
+
with_engine do |e, view|
|
15
|
+
view.stubs(:request).returns request
|
16
|
+
|
17
|
+
res = e.run_template do
|
18
|
+
%{<%= localhost? %> }
|
19
|
+
end
|
20
|
+
res.should match /true/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return true if request.host is '127.0.0.1'" do
|
25
|
+
request = stub()
|
26
|
+
request.stubs(:host).returns '127.0.0.1'
|
27
|
+
|
28
|
+
with_engine do |e, view|
|
29
|
+
view.stubs(:request).returns request
|
30
|
+
|
31
|
+
res = e.run_template do
|
32
|
+
%{<%= localhost? %> }
|
33
|
+
end
|
34
|
+
res.should match /true/
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#publichost?' do
|
40
|
+
it "should return false if request.host is 'localhost'" do
|
41
|
+
request = stub()
|
42
|
+
request.stubs(:host).returns 'localhost'
|
43
|
+
|
44
|
+
with_engine do |e, view|
|
45
|
+
view.stubs(:request).returns request
|
46
|
+
|
47
|
+
res = e.run_template do
|
48
|
+
%{<%= publichost? %> }
|
49
|
+
end
|
50
|
+
res.should match /false/
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return true if request.host is '214.353.343.222'" do
|
55
|
+
request = stub()
|
56
|
+
request.stubs(:host).returns '214.353.343.222'
|
57
|
+
|
58
|
+
with_engine do |e, view|
|
59
|
+
view.stubs(:request).returns request
|
60
|
+
|
61
|
+
res = e.run_template do
|
62
|
+
%{<%= publichost? %> }
|
63
|
+
end
|
64
|
+
res.should match /true/
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cream/helper/role'
|
3
|
+
|
4
|
+
describe Cream::Helper::Role do
|
5
|
+
|
6
|
+
extend_view_with Cream::Helper::Role
|
7
|
+
|
8
|
+
context 'method auto-generated when Rails initialize based on registered roles' do
|
9
|
+
describe '#guest_area' do
|
10
|
+
|
11
|
+
it "should execute an Admin guarded block for :admin" do
|
12
|
+
with_engine do |e, view|
|
13
|
+
view.stubs(:has_role?).with([:admin]).returns true
|
14
|
+
|
15
|
+
res = e.run_template do
|
16
|
+
%{<%= for_admin { 'hello' } %>}
|
17
|
+
end
|
18
|
+
res.should match /hello/
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not execute an Admin guarded block for user not :admin" do
|
23
|
+
with_engine do |e, view|
|
24
|
+
view.stubs(:has_role?).with([:admin]).returns false
|
25
|
+
|
26
|
+
res = e.run_template do
|
27
|
+
%{<%= for_admin { 'hello' } %>}
|
28
|
+
end
|
29
|
+
res.should be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end # desc
|
33
|
+
end # context
|
34
|
+
|
35
|
+
context 'admin user' do
|
36
|
+
describe '#for_roles' do
|
37
|
+
it "display an :admin only block" do
|
38
|
+
with_engine do |e, view|
|
39
|
+
view.stubs(:has_role?).with([:admin]).returns true
|
40
|
+
|
41
|
+
res = e.run_template do
|
42
|
+
%{<%= for_roles(:admin) { 'hello' } %>}
|
43
|
+
end
|
44
|
+
res.should match /hello/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not display a :guest only block" do
|
49
|
+
with_engine do |e, view|
|
50
|
+
view.stubs(:has_role?).with([:guest]).returns false
|
51
|
+
|
52
|
+
res = e.run_template do
|
53
|
+
%{<%= for_roles(:guest) { 'hello' } %>}
|
54
|
+
end
|
55
|
+
res.should be_empty
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end # desc
|
59
|
+
|
60
|
+
describe '#not_for_roles' do
|
61
|
+
it "should not display a block not for :admin" do
|
62
|
+
with_engine do |e, view|
|
63
|
+
view.stubs(:has_role?).with([:admin]).returns true
|
64
|
+
|
65
|
+
res = e.run_template do
|
66
|
+
%{<%= not_for_roles(:admin) { 'hello' } %>}
|
67
|
+
end
|
68
|
+
res.should be_empty
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should display a div block not for :guest" do
|
73
|
+
with_engine do |e, view|
|
74
|
+
view.stubs(:has_role?).with([:guest]).returns false
|
75
|
+
|
76
|
+
res = e.run_template do
|
77
|
+
%{<%= not_for_roles(:guest) { 'hello' } %>}
|
78
|
+
end
|
79
|
+
res.should match /hello/
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end # desc
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#has_role?' do
|
86
|
+
context 'user has role :admin' do
|
87
|
+
it "should make has_role? :admin be true" do
|
88
|
+
user = stub()
|
89
|
+
user.stubs(:has_role?).with([:admin]).returns true
|
90
|
+
|
91
|
+
with_engine do |e, view|
|
92
|
+
view.stubs(:current_user).returns user
|
93
|
+
|
94
|
+
res = e.run_template do
|
95
|
+
%{<%= has_role?(:admin) %> }
|
96
|
+
end
|
97
|
+
res.should match /true/
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should make has_role? :guest be false" do
|
102
|
+
user = stub()
|
103
|
+
user.stubs(:has_role?).with([:guest]).returns false
|
104
|
+
|
105
|
+
with_engine do |e, view|
|
106
|
+
view.stubs(:current_user).returns user
|
107
|
+
res = e.run_template do
|
108
|
+
%{<%= has_role?(:guest) %> }
|
109
|
+
end
|
110
|
+
res.should match /false/
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end # ctx
|
114
|
+
end # dec
|
115
|
+
|
116
|
+
describe '#has_roles?' do
|
117
|
+
context 'user has roles :admin and :guest' do
|
118
|
+
it "should make has_roles? :admin, :guest be true" do
|
119
|
+
user = stub()
|
120
|
+
user.stubs(:has_roles?).with([:admin, :guest]).returns true
|
121
|
+
|
122
|
+
with_engine do |e, view|
|
123
|
+
view.stubs(:current_user).returns user
|
124
|
+
res = e.run_template do
|
125
|
+
%{<%= has_roles?(:admin, :guest) %> }
|
126
|
+
end
|
127
|
+
res.should match /true/
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should make has_role? :unknown, :guest be false" do
|
132
|
+
user = stub()
|
133
|
+
user.stubs(:has_roles?).with([:unknown, :guest]).returns false
|
134
|
+
|
135
|
+
with_engine do |e, view|
|
136
|
+
view.stubs(:current_user).returns user
|
137
|
+
res = e.run_template do
|
138
|
+
%{<%= has_roles?(:unknown, :guest) %> }
|
139
|
+
end
|
140
|
+
res.should match /false/
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end # ctx
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#owner?' do
|
147
|
+
it "should return false, since the user is NOT the owner of the post, but an other user" do
|
148
|
+
user = stub()
|
149
|
+
other_user = stub()
|
150
|
+
with_engine do |e, view|
|
151
|
+
view.stubs(:current_user).returns user
|
152
|
+
@post.stubs(:owner).returns other_user
|
153
|
+
|
154
|
+
res = e.run_template_locals :post => @post do
|
155
|
+
%{<%= owner?(post) %> }
|
156
|
+
end
|
157
|
+
res.should match /false/
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should return true, since the user is the owner of the post (default :owner relation)" do
|
162
|
+
user = stub()
|
163
|
+
with_engine do |e, view|
|
164
|
+
view.stubs(:current_user).returns user
|
165
|
+
@post.stubs(:owner).returns user
|
166
|
+
|
167
|
+
res = e.run_template_locals :post => @post do
|
168
|
+
%{<%= owner?(post) %> }
|
169
|
+
end
|
170
|
+
res.should match /true/
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should return true, since the user is the owner of the post using custom ownership relation :maker" do
|
175
|
+
user = stub()
|
176
|
+
with_engine do |e, view|
|
177
|
+
view.stubs(:current_user).returns user
|
178
|
+
@post.stubs(:maker).returns user
|
179
|
+
|
180
|
+
res = e.run_template_locals :post => @post do
|
181
|
+
%{<%= owner?(post, :maker) %> }
|
182
|
+
end
|
183
|
+
res.should match /true/
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end # desc
|
187
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cream/view/host_area'
|
3
|
+
|
4
|
+
describe Cream::View::Host do
|
5
|
+
extend_view_with Cream::View::Host
|
6
|
+
|
7
|
+
before do
|
8
|
+
@post = stub(:title => 'my post', :id => 1, :author => 'kristian' )
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#for_localhost' do
|
12
|
+
it "should display localhost guarded content for localhost browser agent" do
|
13
|
+
with_engine do |e, view|
|
14
|
+
view.stubs(:localhost?).returns true
|
15
|
+
|
16
|
+
res = e.run_template do
|
17
|
+
%{<%= for_localhost do %>
|
18
|
+
hello
|
19
|
+
<% end %>
|
20
|
+
}
|
21
|
+
end
|
22
|
+
res.should match /hello/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should NOT display localhost guarded content for NON-localhost browser agent" do
|
27
|
+
with_engine do |e, view|
|
28
|
+
view.stubs(:localhost?).returns false
|
29
|
+
|
30
|
+
res = e.run_template do
|
31
|
+
%{<%= for_localhost { 'hello' } %>}
|
32
|
+
end
|
33
|
+
res.should be_empty
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#for_public' do
|
39
|
+
it "should display public content for public browser agent" do
|
40
|
+
with_engine do |e, view|
|
41
|
+
view.stubs(:publichost?).returns true
|
42
|
+
|
43
|
+
res = e.run_template do
|
44
|
+
%{<%= for_public { 'hello' } %>}
|
45
|
+
end
|
46
|
+
res.should match /hello/
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should display public content for public browser agent" do
|
51
|
+
with_engine do |e, view|
|
52
|
+
view.stubs(:publichost?).returns false
|
53
|
+
|
54
|
+
res = e.run_template do
|
55
|
+
%{<%= for_public { 'hello' } %>}
|
56
|
+
end
|
57
|
+
res.should be_empty
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'rspec-action_view'
|
2
|
+
require 'require_all'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require 'cream/namespaces'
|
6
|
+
require 'cream/view/role_area'
|
7
|
+
require 'cream/view/host_area'
|
8
|
+
|
9
|
+
describe Cream::View::Role do
|
10
|
+
extend_view_with Cream::View, :role, :host
|
11
|
+
|
12
|
+
describe '#area' do
|
13
|
+
it "should display the div with hello" do
|
14
|
+
with_engine do |e, view|
|
15
|
+
|
16
|
+
res = e.run_template do
|
17
|
+
%{<%= area :class => 'red' do %>
|
18
|
+
hello
|
19
|
+
<% end %>}
|
20
|
+
end
|
21
|
+
res.should match /<div class="red">/
|
22
|
+
res.should match /hello/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should display the div with hello when localhost block nested inside" do
|
27
|
+
with_engine do |e, view|
|
28
|
+
view.stubs(:localhost?).returns true
|
29
|
+
|
30
|
+
res = e.run_template do
|
31
|
+
%{<%= area :class => 'red' do %>
|
32
|
+
<%= for_localhost { 'hello' } %>
|
33
|
+
<% end %>}
|
34
|
+
end
|
35
|
+
res.should match /<div class="red">/
|
36
|
+
res.should match /hello/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should display the div with hello when nested within localhost block" do
|
41
|
+
with_engine do |e, view|
|
42
|
+
view.stubs(:localhost?).returns true
|
43
|
+
|
44
|
+
res = e.run_template do
|
45
|
+
%{<%= for_localhost do %>
|
46
|
+
<%= area :class => 'red' do %>
|
47
|
+
hello
|
48
|
+
<% end %>
|
49
|
+
<% end %>
|
50
|
+
}
|
51
|
+
end
|
52
|
+
res.should match /<div class="red">/
|
53
|
+
res.should match /hello/
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#area_for_roles' do
|
59
|
+
it "should display an area for :admin" do
|
60
|
+
with_engine do |e, view|
|
61
|
+
view.stubs(:has_role?).with([:admin]).returns true
|
62
|
+
|
63
|
+
res = e.run_template do
|
64
|
+
%{<%= area_for_roles(:admin) { 'hello' } %>}
|
65
|
+
end
|
66
|
+
res.should match /hello/
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not display an area for user not :admin" do
|
71
|
+
with_engine do |e, view|
|
72
|
+
view.stubs(:has_role?).with([:admin]).returns false
|
73
|
+
|
74
|
+
res = e.run_template do
|
75
|
+
%{<%= area_for_roles(:admin) { 'hello' } %>}
|
76
|
+
end
|
77
|
+
res.should be_empty
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end # desc
|
81
|
+
|
82
|
+
describe '#area_not_for_roles' do
|
83
|
+
it "should not display an area for user :admin" do
|
84
|
+
with_action_view do |view|
|
85
|
+
view.stubs(:has_role?).with([:admin]).returns true
|
86
|
+
view.area_not_for_roles(:admin) { 'hello' }.should be_nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should display an area for user not :admin" do
|
91
|
+
with_action_view do |view|
|
92
|
+
# he is not admin
|
93
|
+
view.stubs(:has_role?).with([:admin]).returns false
|
94
|
+
view.area_not_for_roles(:admin) { 'hello' }.should match /hello/
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end # desc
|
98
|
+
|
99
|
+
context 'method auto-generated when Rails initialize based on registered roles'
|
100
|
+
describe '#guest_area' do
|
101
|
+
it "should display an Admin area for :admin" do
|
102
|
+
with_engine do |e, view|
|
103
|
+
view.stubs(:has_role?).with([:admin]).returns true
|
104
|
+
|
105
|
+
res = e.run_template do
|
106
|
+
%{<%= admin_area { 'hello' } %>}
|
107
|
+
end
|
108
|
+
res.should match /hello/
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should not display a Admin area for user not :admin" do
|
113
|
+
with_engine do |e, view|
|
114
|
+
view.stubs(:has_role?).with([:admin]).returns false
|
115
|
+
|
116
|
+
res = e.run_template do
|
117
|
+
%{<%= admin_area { 'hello' } %>}
|
118
|
+
end
|
119
|
+
res.should be_empty
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end # desc
|
123
|
+
end # context
|
124
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'action_controller'
|
5
|
+
require 'action_view'
|
6
|
+
# require 'active_record'
|
7
|
+
# require 'action_mailer'
|
8
|
+
require 'active_support/railtie'
|
9
|
+
# require 'rails/all'
|
10
|
+
|
11
|
+
module Minimal
|
12
|
+
class Application < Rails::Application
|
13
|
+
config.active_support.deprecation = :log
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Rails.application = Minimal::Application
|
18
|
+
|
19
|
+
class User
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "View extensions" do
|
23
|
+
describe 'Role area functionality' do
|
24
|
+
|
25
|
+
it "should extend Action View with various Roles helper methods" do
|
26
|
+
after_init :view do
|
27
|
+
:view.should be_extended_with AuthAssistant::View, :roles
|
28
|
+
:view.should be_extended_with AuthAssistant::Helper, :role
|
29
|
+
end
|
30
|
+
|
31
|
+
User.stubs(:roles).returns [:admin, :guest]
|
32
|
+
|
33
|
+
init_app_railties :minimal, :view
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|