authorized_rails_scaffolds 0.0.10 → 0.0.11
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.
- checksums.yaml +7 -0
- data/README.md +13 -26
- data/lib/authorized_rails_scaffolds.rb +11 -2
- data/lib/authorized_rails_scaffolds/controller_macros.rb +22 -0
- data/lib/authorized_rails_scaffolds/factory_macros.rb +65 -0
- data/lib/authorized_rails_scaffolds/helper.rb +38 -115
- data/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper.rb +40 -0
- data/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper.rb +20 -0
- data/lib/authorized_rails_scaffolds/resource_macros.rb +81 -0
- data/lib/authorized_rails_scaffolds/route_example_macros.rb +43 -0
- data/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper.rb +17 -0
- data/lib/authorized_rails_scaffolds/rspec_scaffold_helper.rb +26 -0
- data/lib/authorized_rails_scaffolds/rspec_scaffold_routing_helper.rb +12 -0
- data/lib/authorized_rails_scaffolds/{rspec_scaffold_generator_view_helper.rb → rspec_scaffold_view_helper.rb} +3 -2
- data/lib/authorized_rails_scaffolds/test_var_macros.rb +40 -0
- data/lib/authorized_rails_scaffolds/version.rb +1 -1
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/_form.html.erb +4 -6
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/controller.rb +50 -34
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/edit.html.erb +2 -4
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/index.html.erb +17 -18
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/new.html.erb +2 -4
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/show.html.erb +15 -17
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/controller_spec.rb +126 -101
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/edit_spec.rb +44 -39
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/index_spec.rb +73 -65
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/model_spec.rb +9 -8
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/new_spec.rb +38 -35
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/routing_spec.rb +21 -10
- data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/show_spec.rb +37 -20
- data/spec/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper_spec.rb +59 -0
- data/spec/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper_spec.rb +89 -0
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper_spec.rb +155 -0
- data/spec/lib/authorized_rails_scaffolds/{rspec_scaffold_generator_helper_spec.rb → rspec_scaffold_routing_helper_spec.rb} +57 -50
- data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper_spec.rb +86 -0
- data/spec/spec_helper.rb +5 -2
- data/spec/support/rails_erb_scaffold_helper_macros.rb +15 -0
- data/spec/support/rails_scaffold_controller_helper_macros.rb +15 -0
- data/spec/support/{rspec_scaffold_generator_helper_macros.rb → rspec_scaffold_controller_helper_macros.rb} +2 -2
- data/spec/support/rspec_scaffold_routing_helper_macros.rb +15 -0
- data/spec/support/rspec_scaffold_view_helper_macros.rb +15 -0
- metadata +66 -28
- data/lib/authorized_rails_scaffolds/rspec_scaffold_generator_helper.rb +0 -82
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/new.html.erb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
<%-
|
2
2
|
|
3
|
-
t_helper = AuthorizedRailsScaffolds::
|
3
|
+
t_helper = AuthorizedRailsScaffolds::RailsErbScaffoldHelper.new(
|
4
4
|
:class_name => class_name,
|
5
5
|
:singular_table_name => singular_table_name,
|
6
6
|
:file_name => file_name
|
7
7
|
)
|
8
8
|
|
9
|
-
local_class_name = t_helper.local_class_name # Non-Namespaced class name
|
10
|
-
|
11
9
|
-%>
|
12
|
-
<%%- model_class = <%=
|
10
|
+
<%%- model_class = <%= t_helper.resource_class %> -%>
|
13
11
|
<div class="page-header">
|
14
12
|
<h1><%%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human %></h1>
|
15
13
|
</div>
|
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/show.html.erb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
<%-
|
2
2
|
|
3
|
-
t_helper = AuthorizedRailsScaffolds::
|
3
|
+
t_helper = AuthorizedRailsScaffolds::RailsErbScaffoldHelper.new(
|
4
4
|
:class_name => class_name,
|
5
5
|
:singular_table_name => singular_table_name,
|
6
6
|
:file_name => file_name
|
7
7
|
)
|
8
8
|
|
9
|
-
|
10
|
-
var_name = t_helper.var_name # Non-namespaced variable name
|
11
|
-
plural_var_name = t_helper.plural_var_name # Pluralized non-namespaced variable name
|
9
|
+
resource_var = t_helper.resource_var
|
12
10
|
|
13
11
|
-%>
|
14
|
-
<%%- model_class = <%=
|
12
|
+
<%%- model_class = <%= t_helper.resource_class %> -%>
|
15
13
|
<div class="page-header">
|
16
14
|
<h1><%%=t '.title', :default => model_class.model_name.human %></h1>
|
17
15
|
</div>
|
@@ -20,24 +18,24 @@ plural_var_name = t_helper.plural_var_name # Pluralized non-namespaced variable
|
|
20
18
|
<%- attributes.each do |attribute| -%>
|
21
19
|
<%- attribute_label = "model_class.human_attribute_name(:#{attribute.name})" -%>
|
22
20
|
<%- if attribute.type == :references -%>
|
23
|
-
<%% if
|
21
|
+
<%% if <%= resource_var %>.<%= attribute.name %>.present? && can?(:read, <%= resource_var %>.<%= attribute.name %>) %>
|
24
22
|
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
25
|
-
<dd><%%= link_to
|
23
|
+
<dd><%%= link_to <%= resource_var %>.<%= attribute.name %>, <%= t_helper.references_show_route attribute.name %> %></dd>
|
26
24
|
<%% end %>
|
27
25
|
<%- elsif [:datetime, :timestamp, :time, :date].include? attribute.type -%>
|
28
|
-
<%% unless
|
26
|
+
<%% unless <%= resource_var %>.<%= attribute.name %>.nil? %>
|
29
27
|
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
30
|
-
<dd><%%=l
|
28
|
+
<dd><%%=l <%= resource_var %>.<%= attribute.name %><% if attribute.type == :datetime %>, :format => :long<% end %><% if attribute.type == :time %>, :format => :short<% end %> %></dd>
|
31
29
|
<%% end %>
|
32
30
|
<%- elsif attribute.type == :string -%>
|
33
|
-
<%% unless
|
31
|
+
<%% unless <%= resource_var %>.<%= attribute.name %>.blank? %>
|
34
32
|
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
35
|
-
<dd><%%=
|
33
|
+
<dd><%%= <%= resource_var %>.<%= attribute.name %> %></dd>
|
36
34
|
<%% end %>
|
37
35
|
<%- else -%>
|
38
|
-
<%% unless
|
36
|
+
<%% unless <%= resource_var %>.<%= attribute.name %>.nil? %>
|
39
37
|
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
40
|
-
<dd><%%=
|
38
|
+
<dd><%%= <%= resource_var %>.<%= attribute.name %> %></dd>
|
41
39
|
<%% end %>
|
42
40
|
<%- end -%>
|
43
41
|
<%- end -%>
|
@@ -46,15 +44,15 @@ plural_var_name = t_helper.plural_var_name # Pluralized non-namespaced variable
|
|
46
44
|
<div class="form-actions">
|
47
45
|
<%%= link_to t('.back', :default => t("helpers.links.back")),
|
48
46
|
<%= t_helper.controller_index_path %>, :class => 'btn' %>
|
49
|
-
<%% if can? :update,
|
47
|
+
<%% if can? :update, <%= resource_var %> %>
|
50
48
|
<%%= link_to t('.edit', :default => t("helpers.links.edit")),
|
51
|
-
edit_<%= t_helper.controller_show_route
|
49
|
+
edit_<%= t_helper.controller_show_route resource_var %>,
|
52
50
|
:class => 'btn'
|
53
51
|
%>
|
54
52
|
<%% end %>
|
55
|
-
<%% if can? :destroy,
|
53
|
+
<%% if can? :destroy, <%= resource_var %> %>
|
56
54
|
<%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
|
57
|
-
<%= t_helper.controller_show_route
|
55
|
+
<%= t_helper.controller_show_route resource_var %>,
|
58
56
|
:method => 'delete',
|
59
57
|
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
|
60
58
|
:class => 'act act-danger pull-right'
|
data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/controller_spec.rb
CHANGED
@@ -21,54 +21,65 @@ require 'spec_helper'
|
|
21
21
|
<% module_namespacing do -%>
|
22
22
|
<%-
|
23
23
|
|
24
|
-
|
24
|
+
#
|
25
|
+
# Available properties:
|
26
|
+
#
|
27
|
+
# class_name
|
28
|
+
# controller_class_name
|
29
|
+
# singular_table_name
|
30
|
+
# file_name
|
31
|
+
# attributes
|
32
|
+
#
|
33
|
+
|
34
|
+
t_helper = AuthorizedRailsScaffolds::RSpecScaffoldControllerHelper.new(
|
25
35
|
:class_name => class_name,
|
36
|
+
:controller_class_name => controller_class_name,
|
26
37
|
:singular_table_name => singular_table_name,
|
27
38
|
:file_name => file_name,
|
28
39
|
:attributes => attributes
|
29
40
|
)
|
30
41
|
|
31
|
-
|
32
|
-
|
33
|
-
|
42
|
+
resource_class = t_helper.resource_class
|
43
|
+
resource_var = t_helper.resource_var
|
44
|
+
resource_symbol = t_helper.resource_symbol
|
45
|
+
resource_test_var = t_helper.resource_test_var
|
46
|
+
resource_table_name = t_helper.resource_table_name
|
34
47
|
|
35
48
|
parent_model_tables = t_helper.parent_model_tables
|
36
49
|
|
37
50
|
-%>
|
38
|
-
describe <%= controller_class_name %>
|
51
|
+
describe <%= t_helper.controller_class_name %> do
|
39
52
|
|
40
53
|
# This should return the minimal set of attributes required to create a valid
|
41
|
-
# <%=
|
54
|
+
# <%= resource_class %>.
|
42
55
|
def valid_create_attributes
|
43
|
-
FactoryGirl.attributes_for(
|
56
|
+
FactoryGirl.attributes_for(<%= resource_symbol %>)
|
44
57
|
end
|
45
58
|
|
46
59
|
# This should return the minimal set of attributes required to update a valid
|
47
|
-
# <%=
|
60
|
+
# <%= resource_class %>.
|
48
61
|
def valid_update_attributes
|
49
|
-
FactoryGirl.attributes_for(
|
62
|
+
FactoryGirl.attributes_for(<%= resource_symbol %>)
|
50
63
|
end
|
51
64
|
|
52
65
|
<%- if parent_model_tables.any? -%>
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
<%- end -%>
|
57
|
-
end
|
66
|
+
<%- parent_model_tables.each do |parent_model| -%>
|
67
|
+
let(<%= t_helper.references_test_sym(parent_model) %>) { <%= t_helper.create_parent_resource_from_factory parent_model %> }
|
68
|
+
<%- end -%>
|
58
69
|
|
59
70
|
<%- end -%>
|
60
71
|
<% unless options[:singleton] -%>
|
61
72
|
describe "GET index" do
|
62
73
|
context <% if parent_model_tables.any? %>"within <%= parent_model_tables.join('/') %> nesting"<% end %> do<%- unless parent_model_tables.any? -%> # Within default nesting<% end %>
|
63
|
-
<%-
|
74
|
+
<%- t_helper.parent_models.each do |parent_model| -%>
|
64
75
|
grant_ability :read, <%= parent_model.classify %>
|
65
76
|
<%- end -%>
|
66
77
|
|
67
78
|
context 'without a user session' do
|
68
79
|
describe 'with valid request' do
|
69
80
|
before(:each) do
|
70
|
-
|
71
|
-
get :index, {<%= t_helper.
|
81
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
82
|
+
get :index, {<%= t_helper.build_example_request_params %>}
|
72
83
|
end
|
73
84
|
it { should redirect_to(new_user_session_path) }
|
74
85
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -76,27 +87,29 @@ describe <%= controller_class_name %>Controller do
|
|
76
87
|
end
|
77
88
|
context 'as an unauthorized user' do
|
78
89
|
login_unauthorized_user
|
90
|
+
|
79
91
|
describe 'with valid request' do
|
80
92
|
before(:each) do
|
81
|
-
|
82
|
-
get :index, {<%= t_helper.
|
93
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
94
|
+
get :index, {<%= t_helper.build_example_request_params %>}
|
83
95
|
end
|
84
96
|
it { should redirect_to(root_url) }
|
85
97
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
86
98
|
end
|
87
99
|
end
|
88
100
|
context 'as user with read ability' do
|
89
|
-
login_user_with_ability :read, <%=
|
101
|
+
login_user_with_ability :read, <%= resource_class %>
|
102
|
+
|
90
103
|
describe 'with valid request' do
|
91
104
|
before(:each) do
|
92
|
-
|
93
|
-
get :index, {<%= t_helper.
|
105
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
106
|
+
get :index, {<%= t_helper.build_example_request_params %>}
|
94
107
|
end
|
95
108
|
it { should respond_with(:success) }
|
96
109
|
it { should render_template(:index) }
|
97
110
|
it { should render_with_layout(:application) }
|
98
|
-
it "assigns all <%=
|
99
|
-
assigns(:<%=
|
111
|
+
it "assigns all <%= t_helper.resource_plural_name %> as <%= t_helper.resources_var %>" do
|
112
|
+
assigns(:<%= t_helper.resource_plural_name %>).should eq([<%= resource_test_var %>])
|
100
113
|
end
|
101
114
|
end
|
102
115
|
end
|
@@ -113,8 +126,8 @@ describe <%= controller_class_name %>Controller do
|
|
113
126
|
context 'without a user session' do
|
114
127
|
describe 'with valid request' do
|
115
128
|
before(:each) do
|
116
|
-
|
117
|
-
get :show, {<%= t_helper.
|
129
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
130
|
+
get :show, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
118
131
|
end
|
119
132
|
it { should redirect_to(new_user_session_path) }
|
120
133
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -122,27 +135,29 @@ describe <%= controller_class_name %>Controller do
|
|
122
135
|
end
|
123
136
|
context 'as an unauthorized user' do
|
124
137
|
login_unauthorized_user
|
138
|
+
|
125
139
|
describe 'with valid request' do
|
126
140
|
before(:each) do
|
127
|
-
|
128
|
-
get :show, {<%= t_helper.
|
141
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
142
|
+
get :show, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
129
143
|
end
|
130
144
|
it { should redirect_to(<%= t_helper.controller_index_route %>) }
|
131
145
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
132
146
|
end
|
133
147
|
end
|
134
148
|
context 'as user with read ability' do
|
135
|
-
login_user_with_ability :read, <%=
|
149
|
+
login_user_with_ability :read, <%= resource_class %>
|
150
|
+
|
136
151
|
describe 'with valid request' do
|
137
152
|
before(:each) do
|
138
|
-
|
139
|
-
get :show, {<%= t_helper.
|
153
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
154
|
+
get :show, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
140
155
|
end
|
141
156
|
it { should respond_with(:success) }
|
142
157
|
it { should render_template(:show) }
|
143
158
|
it { should render_with_layout(:application) }
|
144
|
-
it "assigns the requested <%=
|
145
|
-
assigns(
|
159
|
+
it "assigns the requested <%= resource_table_name %> as <%= resource_var %>" do
|
160
|
+
assigns(<%= resource_symbol %>).should eq(<%= resource_test_var %>)
|
146
161
|
end
|
147
162
|
end
|
148
163
|
end
|
@@ -158,7 +173,7 @@ describe <%= controller_class_name %>Controller do
|
|
158
173
|
context 'without a user session' do
|
159
174
|
describe 'with valid request' do
|
160
175
|
before(:each) do
|
161
|
-
get :new, {<%= t_helper.
|
176
|
+
get :new, {<%= t_helper.build_example_request_params %>}
|
162
177
|
end
|
163
178
|
it { should redirect_to(new_user_session_path) }
|
164
179
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -166,25 +181,27 @@ describe <%= controller_class_name %>Controller do
|
|
166
181
|
end
|
167
182
|
context 'as an unauthorized user' do
|
168
183
|
login_unauthorized_user
|
184
|
+
|
169
185
|
describe 'with valid request' do
|
170
186
|
before(:each) do
|
171
|
-
get :new, {<%= t_helper.
|
187
|
+
get :new, {<%= t_helper.build_example_request_params %>}
|
172
188
|
end
|
173
189
|
it { should redirect_to(<%= t_helper.controller_index_route %>) }
|
174
190
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
175
191
|
end
|
176
192
|
end
|
177
193
|
context 'as user with create ability' do
|
178
|
-
login_user_with_ability :create, <%=
|
194
|
+
login_user_with_ability :create, <%= resource_class %>
|
195
|
+
|
179
196
|
describe 'with valid request' do
|
180
197
|
before(:each) do
|
181
|
-
get :new, {<%= t_helper.
|
198
|
+
get :new, {<%= t_helper.build_example_request_params %>}
|
182
199
|
end
|
183
200
|
it { should respond_with(:success) }
|
184
201
|
it { should render_template(:new) }
|
185
202
|
it { should render_with_layout(:application) }
|
186
|
-
it "assigns a new <%=
|
187
|
-
assigns(
|
203
|
+
it "assigns a new <%= resource_table_name %> as <%= resource_var %>" do
|
204
|
+
assigns(<%= resource_symbol %>).should be_a_new(<%= resource_class %>)
|
188
205
|
end
|
189
206
|
end
|
190
207
|
end
|
@@ -200,8 +217,8 @@ describe <%= controller_class_name %>Controller do
|
|
200
217
|
context 'without a user session' do
|
201
218
|
describe 'with valid request' do
|
202
219
|
before(:each) do
|
203
|
-
|
204
|
-
get :edit, {<%= t_helper.
|
220
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
221
|
+
get :edit, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
205
222
|
end
|
206
223
|
it { should redirect_to(new_user_session_path) }
|
207
224
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -209,27 +226,29 @@ describe <%= controller_class_name %>Controller do
|
|
209
226
|
end
|
210
227
|
context 'as an unauthorized user' do
|
211
228
|
login_unauthorized_user
|
229
|
+
|
212
230
|
describe 'with valid request' do
|
213
231
|
before(:each) do
|
214
|
-
|
215
|
-
get :edit, {<%= t_helper.
|
232
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
233
|
+
get :edit, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
216
234
|
end
|
217
235
|
it { should redirect_to(<%= t_helper.controller_index_route %>) }
|
218
236
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
219
237
|
end
|
220
238
|
end
|
221
239
|
context 'as user with update ability' do
|
222
|
-
login_user_with_ability :update, <%=
|
240
|
+
login_user_with_ability :update, <%= resource_class %>
|
241
|
+
|
223
242
|
describe 'with valid request' do
|
224
243
|
before(:each) do
|
225
|
-
|
226
|
-
get :edit, {<%= t_helper.
|
244
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
245
|
+
get :edit, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
227
246
|
end
|
228
247
|
it { should respond_with(:success) }
|
229
248
|
it { should render_template(:edit) }
|
230
249
|
it { should render_with_layout(:application) }
|
231
|
-
it "assigns the requested <%=
|
232
|
-
assigns(
|
250
|
+
it "assigns the requested <%= resource_table_name %> as <%= resource_var %>" do
|
251
|
+
assigns(<%= resource_symbol %>).should eq(<%= resource_test_var %>)
|
233
252
|
end
|
234
253
|
end
|
235
254
|
end
|
@@ -245,7 +264,7 @@ describe <%= controller_class_name %>Controller do
|
|
245
264
|
context 'without a user session' do
|
246
265
|
describe 'with valid params' do
|
247
266
|
before(:each) do
|
248
|
-
post :create, {<%= t_helper.
|
267
|
+
post :create, {<%= t_helper.build_example_request_params "#{resource_symbol} => valid_update_attributes" %>}
|
249
268
|
end
|
250
269
|
it { should redirect_to(new_user_session_path) }
|
251
270
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -253,50 +272,52 @@ describe <%= controller_class_name %>Controller do
|
|
253
272
|
end
|
254
273
|
context 'as an unauthorized user' do
|
255
274
|
login_unauthorized_user
|
275
|
+
|
256
276
|
describe "with valid params" do
|
257
277
|
before(:each) do
|
258
|
-
post :create, {<%= t_helper.
|
278
|
+
post :create, {<%= t_helper.build_example_request_params "#{resource_symbol} => valid_update_attributes" %>}
|
259
279
|
end
|
260
280
|
it { should redirect_to(<%= t_helper.controller_index_route %>) }
|
261
281
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
262
282
|
end
|
263
283
|
end
|
264
284
|
context 'as user with create ability' do
|
265
|
-
login_user_with_ability :create, <%=
|
285
|
+
login_user_with_ability :create, <%= resource_class %>
|
286
|
+
|
266
287
|
describe "with valid params" do
|
267
|
-
it "creates a new <%=
|
288
|
+
it "creates a new <%= resource_class %>" do
|
268
289
|
expect {
|
269
|
-
post :create, {<%= t_helper.
|
270
|
-
}.to change(<%=
|
290
|
+
post :create, {<%= t_helper.build_example_request_params "#{resource_symbol} => valid_update_attributes" %>}
|
291
|
+
}.to change(<%= resource_class %>, :count).by(1)
|
271
292
|
end
|
272
293
|
end
|
273
294
|
describe 'with valid params' do
|
274
295
|
before(:each) do
|
275
|
-
post :create, {<%= t_helper.
|
296
|
+
post :create, {<%= t_helper.build_example_request_params "#{resource_symbol} => valid_update_attributes" %>}
|
276
297
|
end
|
277
|
-
it "assigns a newly created <%=
|
278
|
-
assigns(
|
279
|
-
assigns(
|
298
|
+
it "assigns a newly created <%= resource_table_name %> as <%= resource_var %>" do
|
299
|
+
assigns(<%= resource_symbol %>).should be_a(<%= resource_class %>)
|
300
|
+
assigns(<%= resource_symbol %>).should be_persisted
|
280
301
|
end
|
281
302
|
<% if parent_model_tables.any? -%>
|
282
|
-
it "assigns the parent <%=
|
283
|
-
assigns(
|
303
|
+
it "assigns the parent <%= t_helper.parent_models[-1] %> to <%= resource_table_name %>" do
|
304
|
+
assigns(<%= resource_symbol %>).<%= parent_model_tables[-1] %>.should eq(<%= t_helper.references_test_property(parent_model_tables[-1]) %>)
|
284
305
|
end
|
285
306
|
<% end -%>
|
286
|
-
it "redirects to the created <%=
|
287
|
-
response.should redirect_to(<%= t_helper.controller_show_route "#{
|
307
|
+
it "redirects to the created <%= resource_table_name %>" do
|
308
|
+
response.should redirect_to(<%= t_helper.controller_show_route "#{resource_class}.last" %>)
|
288
309
|
end
|
289
310
|
end
|
290
311
|
describe "with invalid params" do
|
291
312
|
before(:each) do
|
292
313
|
# Trigger the behavior that occurs when invalid params are submitted
|
293
|
-
<%=
|
294
|
-
post :create, {<%= t_helper.
|
314
|
+
<%= resource_class %>.any_instance.stub(:save).and_return(false)
|
315
|
+
post :create, {<%= t_helper.build_example_request_params "#{resource_symbol} => #{formatted_hash(example_invalid_attributes)}" %>}
|
295
316
|
end
|
296
317
|
it { should render_template(:new) }
|
297
318
|
it { should render_with_layout(:application) }
|
298
|
-
it "assigns a newly created but unsaved <%=
|
299
|
-
assigns(
|
319
|
+
it "assigns a newly created but unsaved <%= resource_table_name %> as <%= resource_var %>" do
|
320
|
+
assigns(<%= resource_symbol %>).should be_a_new(<%= resource_class %>)
|
300
321
|
end
|
301
322
|
end
|
302
323
|
end
|
@@ -312,8 +333,8 @@ describe <%= controller_class_name %>Controller do
|
|
312
333
|
context 'without a user session' do
|
313
334
|
describe 'with valid params' do
|
314
335
|
before(:each) do
|
315
|
-
|
316
|
-
put :update, {<%= t_helper.
|
336
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
337
|
+
put :update, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param", "#{resource_symbol} => valid_update_attributes" %>}
|
317
338
|
end
|
318
339
|
it { should redirect_to(new_user_session_path) }
|
319
340
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -321,55 +342,57 @@ describe <%= controller_class_name %>Controller do
|
|
321
342
|
end
|
322
343
|
context 'as an unauthorized user' do
|
323
344
|
login_unauthorized_user
|
345
|
+
|
324
346
|
describe "with valid params" do
|
325
347
|
before(:each) do
|
326
|
-
|
327
|
-
put :update, {<%= t_helper.
|
348
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
349
|
+
put :update, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param", "#{resource_symbol} => valid_update_attributes" %>}
|
328
350
|
end
|
329
351
|
it { should redirect_to(<%= t_helper.controller_index_route %>) }
|
330
352
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
331
353
|
end
|
332
354
|
end
|
333
355
|
context 'as user with update ability' do
|
334
|
-
login_user_with_ability :update, <%=
|
356
|
+
login_user_with_ability :update, <%= resource_class %>
|
357
|
+
|
335
358
|
describe "with valid params" do
|
336
|
-
it "updates the requested <%=
|
337
|
-
|
338
|
-
# Assuming there are no other <%=
|
339
|
-
# specifies that the <%=
|
359
|
+
it "updates the requested <%= resource_table_name %>" do
|
360
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
361
|
+
# Assuming there are no other <%= resource_table_name %> in the database, this
|
362
|
+
# specifies that the <%= resource_class %> created on the previous line
|
340
363
|
# receives the :update_attributes message with whatever params are
|
341
364
|
# submitted in the request.
|
342
365
|
<%- if Rails.version >= '4' -%>
|
343
|
-
<%=
|
366
|
+
<%= resource_class %>.any_instance.should_receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
|
344
367
|
<%- else -%>
|
345
|
-
<%=
|
368
|
+
<%= resource_class %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
|
346
369
|
<%- end -%>
|
347
|
-
put :update, {<%= t_helper.
|
370
|
+
put :update, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param", "#{resource_symbol} => #{formatted_hash(example_params_for_update)}" %>}
|
348
371
|
end
|
349
372
|
end
|
350
373
|
describe "with valid params" do
|
351
374
|
before(:each) do
|
352
|
-
|
353
|
-
put :update, {<%= t_helper.
|
375
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
376
|
+
put :update, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param", "#{resource_symbol} => valid_update_attributes" %>}
|
354
377
|
end
|
355
|
-
it "assigns the requested <%=
|
356
|
-
assigns(
|
378
|
+
it "assigns the requested <%= resource_table_name %> as <%= resource_var %>" do
|
379
|
+
assigns(<%= resource_symbol %>).should eq(<%= resource_test_var %>)
|
357
380
|
end
|
358
|
-
it "redirects to the <%=
|
359
|
-
response.should redirect_to(<%= t_helper.controller_show_route
|
381
|
+
it "redirects to the <%= resource_table_name %>" do
|
382
|
+
response.should redirect_to(<%= t_helper.controller_show_route resource_test_var %>)
|
360
383
|
end
|
361
384
|
end
|
362
385
|
describe "with invalid params" do
|
363
386
|
before(:each) do
|
364
|
-
|
387
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
365
388
|
# Trigger the behavior that occurs when invalid params are submitted
|
366
|
-
<%=
|
367
|
-
put :update, {<%= t_helper.
|
389
|
+
<%= resource_class %>.any_instance.stub(:save).and_return(false)
|
390
|
+
put :update, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param", "#{resource_symbol} => #{formatted_hash(example_invalid_attributes)}" %>}
|
368
391
|
end
|
369
392
|
it { should render_template(:edit) }
|
370
393
|
it { should render_with_layout(:application) }
|
371
|
-
it "assigns the <%=
|
372
|
-
assigns(
|
394
|
+
it "assigns the <%= resource_table_name %> as <%= resource_var %>" do
|
395
|
+
assigns(<%= resource_symbol %>).should eq(<%= resource_test_var %>)
|
373
396
|
end
|
374
397
|
end
|
375
398
|
end
|
@@ -385,8 +408,8 @@ describe <%= controller_class_name %>Controller do
|
|
385
408
|
context 'without a user session' do
|
386
409
|
describe 'with valid request' do
|
387
410
|
before(:each) do
|
388
|
-
|
389
|
-
delete :destroy, {<%= t_helper.
|
411
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
412
|
+
delete :destroy, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
390
413
|
end
|
391
414
|
it { should redirect_to(new_user_session_path) }
|
392
415
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -394,29 +417,31 @@ describe <%= controller_class_name %>Controller do
|
|
394
417
|
end
|
395
418
|
context 'as an unauthorized user' do
|
396
419
|
login_unauthorized_user
|
420
|
+
|
397
421
|
describe "with valid request" do
|
398
422
|
before(:each) do
|
399
|
-
|
400
|
-
delete :destroy, {<%= t_helper.
|
423
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
424
|
+
delete :destroy, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
401
425
|
end
|
402
426
|
it { should redirect_to(<%= t_helper.controller_index_route %>) }
|
403
427
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
404
428
|
end
|
405
429
|
end
|
406
430
|
context 'as user with destroy ability' do
|
407
|
-
login_user_with_ability :destroy, <%=
|
408
|
-
|
409
|
-
|
431
|
+
login_user_with_ability :destroy, <%= resource_class %>
|
432
|
+
|
433
|
+
it "destroys the requested <%= resource_table_name %>" do
|
434
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
410
435
|
expect {
|
411
|
-
delete :destroy, {<%= t_helper.
|
412
|
-
}.to change(<%=
|
436
|
+
delete :destroy, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
437
|
+
}.to change(<%= resource_class %>, :count).by(-1)
|
413
438
|
end
|
414
439
|
describe 'with valid request' do
|
415
440
|
before(:each) do
|
416
|
-
|
417
|
-
delete :destroy, {<%= t_helper.
|
441
|
+
<%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
|
442
|
+
delete :destroy, {<%= t_helper.build_example_request_params ":id => #{resource_test_var}.to_param" %>}
|
418
443
|
end
|
419
|
-
it "redirects to the <%=
|
444
|
+
it "redirects to the <%= resource_table_name %> list" do
|
420
445
|
response.should redirect_to(<%= t_helper.controller_index_route %>)
|
421
446
|
end
|
422
447
|
end
|