authorized_rails_scaffolds 0.0.14 → 0.0.15

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