authorized_rails_scaffolds 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +13 -26
  3. data/lib/authorized_rails_scaffolds.rb +11 -2
  4. data/lib/authorized_rails_scaffolds/controller_macros.rb +22 -0
  5. data/lib/authorized_rails_scaffolds/factory_macros.rb +65 -0
  6. data/lib/authorized_rails_scaffolds/helper.rb +38 -115
  7. data/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper.rb +40 -0
  8. data/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper.rb +20 -0
  9. data/lib/authorized_rails_scaffolds/resource_macros.rb +81 -0
  10. data/lib/authorized_rails_scaffolds/route_example_macros.rb +43 -0
  11. data/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper.rb +17 -0
  12. data/lib/authorized_rails_scaffolds/rspec_scaffold_helper.rb +26 -0
  13. data/lib/authorized_rails_scaffolds/rspec_scaffold_routing_helper.rb +12 -0
  14. data/lib/authorized_rails_scaffolds/{rspec_scaffold_generator_view_helper.rb → rspec_scaffold_view_helper.rb} +3 -2
  15. data/lib/authorized_rails_scaffolds/test_var_macros.rb +40 -0
  16. data/lib/authorized_rails_scaffolds/version.rb +1 -1
  17. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/_form.html.erb +4 -6
  18. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/controller.rb +50 -34
  19. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/edit.html.erb +2 -4
  20. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/index.html.erb +17 -18
  21. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/new.html.erb +2 -4
  22. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/scaffold/show.html.erb +15 -17
  23. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/controller_spec.rb +126 -101
  24. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/edit_spec.rb +44 -39
  25. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/index_spec.rb +73 -65
  26. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/model_spec.rb +9 -8
  27. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/new_spec.rb +38 -35
  28. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/routing_spec.rb +21 -10
  29. data/lib/generators/authorized_rails_scaffolds/install_templates/templates/spec/show_spec.rb +37 -20
  30. data/spec/lib/authorized_rails_scaffolds/rails_erb_scaffold_helper_spec.rb +59 -0
  31. data/spec/lib/authorized_rails_scaffolds/rails_scaffold_controller_helper_spec.rb +89 -0
  32. data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_controller_helper_spec.rb +155 -0
  33. data/spec/lib/authorized_rails_scaffolds/{rspec_scaffold_generator_helper_spec.rb → rspec_scaffold_routing_helper_spec.rb} +57 -50
  34. data/spec/lib/authorized_rails_scaffolds/rspec_scaffold_view_helper_spec.rb +86 -0
  35. data/spec/spec_helper.rb +5 -2
  36. data/spec/support/rails_erb_scaffold_helper_macros.rb +15 -0
  37. data/spec/support/rails_scaffold_controller_helper_macros.rb +15 -0
  38. data/spec/support/{rspec_scaffold_generator_helper_macros.rb → rspec_scaffold_controller_helper_macros.rb} +2 -2
  39. data/spec/support/rspec_scaffold_routing_helper_macros.rb +15 -0
  40. data/spec/support/rspec_scaffold_view_helper_macros.rb +15 -0
  41. metadata +66 -28
  42. data/lib/authorized_rails_scaffolds/rspec_scaffold_generator_helper.rb +0 -82
@@ -1,15 +1,13 @@
1
1
  <%-
2
2
 
3
- t_helper = AuthorizedRailsScaffolds::Helper.new(
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 = <%= local_class_name %> -%>
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>
@@ -1,17 +1,15 @@
1
1
  <%-
2
2
 
3
- t_helper = AuthorizedRailsScaffolds::Helper.new(
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
- 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 = <%= local_class_name %> -%>
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 @<%= var_name %>.<%= attribute.name %>.present? && can?(:read, @<%= var_name %>.<%= attribute.name %>) %>
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 @<%= var_name %>.<%= attribute.name %>, <%= t_helper.references_show_route attribute.name %> %></dd>
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 @<%= var_name %>.<%= attribute.name %>.nil? %>
26
+ <%% unless <%= resource_var %>.<%= attribute.name %>.nil? %>
29
27
  <dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
30
- <dd><%%=l @<%= var_name %>.<%= attribute.name %><% if attribute.type == :datetime %>, :format => :long<% end %><% if attribute.type == :time %>, :format => :short<% end %> %></dd>
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 @<%= var_name %>.<%= attribute.name %>.blank? %>
31
+ <%% unless <%= resource_var %>.<%= attribute.name %>.blank? %>
34
32
  <dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
35
- <dd><%%= @<%= var_name %>.<%= attribute.name %> %></dd>
33
+ <dd><%%= <%= resource_var %>.<%= attribute.name %> %></dd>
36
34
  <%% end %>
37
35
  <%- else -%>
38
- <%% unless @<%= var_name %>.<%= attribute.name %>.nil? %>
36
+ <%% unless <%= resource_var %>.<%= attribute.name %>.nil? %>
39
37
  <dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
40
- <dd><%%= @<%= var_name %>.<%= attribute.name %> %></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, @<%= var_name %> %>
47
+ <%% if can? :update, <%= resource_var %> %>
50
48
  <%%= link_to t('.edit', :default => t("helpers.links.edit")),
51
- edit_<%= t_helper.controller_show_route "@#{var_name}" %>,
49
+ edit_<%= t_helper.controller_show_route resource_var %>,
52
50
  :class => 'btn'
53
51
  %>
54
52
  <%% end %>
55
- <%% if can? :destroy, @<%= var_name %> %>
53
+ <%% if can? :destroy, <%= resource_var %> %>
56
54
  <%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
57
- <%= t_helper.controller_show_route "@#{var_name}" %>,
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'
@@ -21,54 +21,65 @@ require 'spec_helper'
21
21
  <% module_namespacing do -%>
22
22
  <%-
23
23
 
24
- t_helper = AuthorizedRailsScaffolds::RSpecScaffoldGeneratorHelper.new(
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
- local_class_name = t_helper.local_class_name # Non-Namespaced class name
32
- var_name = t_helper.var_name # Non-namespaced variable name
33
- plural_var_name = t_helper.plural_var_name # Pluralized non-namespaced variable name
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 %>Controller do
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
- # <%= local_class_name %>.
54
+ # <%= resource_class %>.
42
55
  def valid_create_attributes
43
- FactoryGirl.attributes_for(:<%= var_name %>)
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
- # <%= local_class_name %>.
60
+ # <%= resource_class %>.
48
61
  def valid_update_attributes
49
- FactoryGirl.attributes_for(:<%= var_name %>)
62
+ FactoryGirl.attributes_for(<%= resource_symbol %>)
50
63
  end
51
64
 
52
65
  <%- if parent_model_tables.any? -%>
53
- before(:each) do
54
- <%- parent_model_tables.each do |parent_model| -%>
55
- @<%= parent_model %> = <%= t_helper.create_parent_model parent_model %>
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
- <%- parent_model_tables.each do |parent_model| -%>
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
71
- get :index, {<%= t_helper.index_action_params_prefix %>}
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
82
- get :index, {<%= t_helper.index_action_params_prefix %>}
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, <%= local_class_name %>
101
+ login_user_with_ability :read, <%= resource_class %>
102
+
90
103
  describe 'with valid request' do
91
104
  before(:each) do
92
- @<%= var_name %> = <%= t_helper.create_factory_model %>
93
- get :index, {<%= t_helper.index_action_params_prefix %>}
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 <%= plural_var_name %> as @<%= plural_var_name %>" do
99
- assigns(:<%= plural_var_name %>).should eq([@<%= var_name %>])
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
117
- get :show, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
128
- get :show, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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, <%= local_class_name %>
149
+ login_user_with_ability :read, <%= resource_class %>
150
+
136
151
  describe 'with valid request' do
137
152
  before(:each) do
138
- @<%= var_name %> = <%= t_helper.create_factory_model %>
139
- get :show, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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 <%= var_name %> as @<%= var_name %>" do
145
- assigns(:<%= var_name %>).should eq(@<%= var_name %>)
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.index_action_params_prefix %>}
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.index_action_params_prefix %>}
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, <%= local_class_name %>
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.index_action_params_prefix %>}
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 <%= var_name %> as @<%= var_name %>" do
187
- assigns(:<%= var_name %>).should be_a_new(<%= local_class_name %>)
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
204
- get :edit, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
215
- get :edit, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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, <%= local_class_name %>
240
+ login_user_with_ability :update, <%= resource_class %>
241
+
223
242
  describe 'with valid request' do
224
243
  before(:each) do
225
- @<%= var_name %> = <%= t_helper.create_factory_model %>
226
- get :edit, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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 <%= var_name %> as @<%= var_name %>" do
232
- assigns(:<%= var_name %>).should eq(@<%= var_name %>)
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.action_params_prefix %>:<%= var_name %> => valid_create_attributes}
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.action_params_prefix %>:<%= var_name %> => valid_create_attributes}
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, <%= local_class_name %>
285
+ login_user_with_ability :create, <%= resource_class %>
286
+
266
287
  describe "with valid params" do
267
- it "creates a new <%= local_class_name %>" do
288
+ it "creates a new <%= resource_class %>" do
268
289
  expect {
269
- post :create, {<%= t_helper.action_params_prefix %>:<%= var_name %> => valid_create_attributes}
270
- }.to change(<%= local_class_name %>, :count).by(1)
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.action_params_prefix %>:<%= var_name %> => valid_create_attributes}
296
+ post :create, {<%= t_helper.build_example_request_params "#{resource_symbol} => valid_update_attributes" %>}
276
297
  end
277
- it "assigns a newly created <%= var_name %> as @<%= var_name %>" do
278
- assigns(:<%= var_name %>).should be_a(<%= local_class_name %>)
279
- assigns(:<%= var_name %>).should be_persisted
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 <%= parent_model_tables[-1].classify %> to <%= var_name %>" do
283
- assigns(:<%= var_name %>).<%= parent_model_tables[-1] %>.should eq(@<%= parent_model_tables[-1] %>)
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 <%= var_name %>" do
287
- response.should redirect_to(<%= t_helper.controller_show_route "#{local_class_name}.last" %>)
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
- <%= local_class_name %>.any_instance.stub(:save).and_return(false)
294
- post :create, {<%= t_helper.action_params_prefix %>:<%= var_name %> => <%= formatted_hash(example_invalid_attributes) %>}
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 <%= var_name %> as @<%= var_name %>" do
299
- assigns(:<%= var_name %>).should be_a_new(<%= local_class_name %>)
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
316
- put :update, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param, :<%= var_name %> => valid_update_attributes}
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
327
- put :update, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param, :<%= var_name %> => valid_update_attributes}
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, <%= local_class_name %>
356
+ login_user_with_ability :update, <%= resource_class %>
357
+
335
358
  describe "with valid params" do
336
- it "updates the requested <%= var_name %>" do
337
- @<%= var_name %> = <%= t_helper.create_factory_model %>
338
- # Assuming there are no other <%= var_name %> in the database, this
339
- # specifies that the <%= local_class_name %> created on the previous line
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
- <%= local_class_name %>.any_instance.should_receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
366
+ <%= resource_class %>.any_instance.should_receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
344
367
  <%- else -%>
345
- <%= local_class_name %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
368
+ <%= resource_class %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
346
369
  <%- end -%>
347
- put :update, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param, :<%= var_name %> => <%= formatted_hash(example_params_for_update) %>}
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
353
- put :update, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param, :<%= var_name %> => valid_update_attributes}
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 <%= var_name %> as @<%= var_name %>" do
356
- assigns(:<%= var_name %>).should eq(@<%= var_name %>)
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 <%= var_name %>" do
359
- response.should redirect_to(<%= t_helper.controller_show_route "@#{var_name}" %>)
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
387
+ <%= resource_test_var %> = <%= t_helper.create_resource_from_factory %>
365
388
  # Trigger the behavior that occurs when invalid params are submitted
366
- <%= local_class_name %>.any_instance.stub(:save).and_return(false)
367
- put :update, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param, :<%= var_name %> => <%= formatted_hash(example_invalid_attributes) %>}
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 <%= var_name %> as @<%= var_name %>" do
372
- assigns(:<%= var_name %>).should eq(@<%= var_name %>)
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
389
- delete :destroy, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
400
- delete :destroy, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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, <%= local_class_name %>
408
- it "destroys the requested <%= var_name %>" do
409
- @<%= var_name %> = <%= t_helper.create_factory_model %>
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.action_params_prefix %>:id => @<%= var_name %>.to_param}
412
- }.to change(<%= local_class_name %>, :count).by(-1)
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
- @<%= var_name %> = <%= t_helper.create_factory_model %>
417
- delete :destroy, {<%= t_helper.action_params_prefix %>:id => @<%= var_name %>.to_param}
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 <%= var_name %> list" do
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