dry_scaffold 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +55 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +473 -0
- data/Rakefile +54 -0
- data/TODO.textile +36 -0
- data/bin/dmodel +3 -0
- data/bin/dry_model +3 -0
- data/bin/dry_scaffold +3 -0
- data/bin/dscaffold +3 -0
- data/config/scaffold.yml +33 -0
- data/generators/dmodel/dmodel_generator.rb +15 -0
- data/generators/dry_model/USAGE +9 -0
- data/generators/dry_model/dry_model_generator.rb +134 -0
- data/generators/dry_model/prototypes/active_record_migration.rb +17 -0
- data/generators/dry_model/prototypes/active_record_model.rb +9 -0
- data/generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml +3 -0
- data/generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb +4 -0
- data/generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb +8 -0
- data/generators/dry_model/prototypes/tests/rspec/unit_test.rb +9 -0
- data/generators/dry_model/prototypes/tests/shoulda/unit_test.rb +20 -0
- data/generators/dry_model/prototypes/tests/test_unit/unit_test.rb +15 -0
- data/generators/dry_model/templates/models/active_record_migration.rb +23 -0
- data/generators/dry_model/templates/models/active_record_model.rb +15 -0
- data/generators/dry_model/templates/models/fixture_data/active_record_fixtures.yml +6 -0
- data/generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb +5 -0
- data/generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb +9 -0
- data/generators/dry_model/templates/models/tests/rspec/unit_test.rb +11 -0
- data/generators/dry_model/templates/models/tests/shoulda/unit_test.rb +23 -0
- data/generators/dry_model/templates/models/tests/test_unit/unit_test.rb +17 -0
- data/generators/dry_scaffold/USAGE +11 -0
- data/generators/dry_scaffold/dry_scaffold_generator.rb +410 -0
- data/generators/dry_scaffold/prototypes/controllers/action_controller.rb +135 -0
- data/generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb +25 -0
- data/generators/dry_scaffold/prototypes/controllers/tests/rspec/functional_test.rb +57 -0
- data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +99 -0
- data/generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb +70 -0
- data/generators/dry_scaffold/prototypes/helpers/helper.rb +3 -0
- data/generators/dry_scaffold/prototypes/helpers/tests/rspec/unit_test.rb +9 -0
- data/generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb +9 -0
- data/generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb +9 -0
- data/generators/dry_scaffold/prototypes/views/builder/index.atom.builder +20 -0
- data/generators/dry_scaffold/prototypes/views/builder/index.rss.builder +21 -0
- data/generators/dry_scaffold/prototypes/views/haml/_form.html.haml +3 -0
- data/generators/dry_scaffold/prototypes/views/haml/_item.html.haml +9 -0
- data/generators/dry_scaffold/prototypes/views/haml/edit.html.haml +10 -0
- data/generators/dry_scaffold/prototypes/views/haml/index.html.haml +17 -0
- data/generators/dry_scaffold/prototypes/views/haml/layout.html.haml +18 -0
- data/generators/dry_scaffold/prototypes/views/haml/new.html.haml +10 -0
- data/generators/dry_scaffold/prototypes/views/haml/show.html.haml +13 -0
- data/generators/dry_scaffold/templates/controllers/action_controller.rb +250 -0
- data/generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb +26 -0
- data/generators/dry_scaffold/templates/controllers/tests/rspec/functional_test.rb +85 -0
- data/generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb +90 -0
- data/generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb +87 -0
- data/generators/dry_scaffold/templates/helpers/helper.rb +3 -0
- data/generators/dry_scaffold/templates/helpers/tests/rspec/unit_test.rb +9 -0
- data/generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb +9 -0
- data/generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb +9 -0
- data/generators/dry_scaffold/templates/views/builder/index.atom.builder +20 -0
- data/generators/dry_scaffold/templates/views/builder/index.rss.builder +21 -0
- data/generators/dry_scaffold/templates/views/haml/_form.html.haml +13 -0
- data/generators/dry_scaffold/templates/views/haml/_item.html.haml +10 -0
- data/generators/dry_scaffold/templates/views/haml/edit.html.haml +18 -0
- data/generators/dry_scaffold/templates/views/haml/index.html.haml +20 -0
- data/generators/dry_scaffold/templates/views/haml/layout.html.haml +19 -0
- data/generators/dry_scaffold/templates/views/haml/new.html.haml +18 -0
- data/generators/dry_scaffold/templates/views/haml/show.html.haml +13 -0
- data/generators/dscaffold/dscaffold_generator.rb +15 -0
- data/lib/dry_generator.rb +197 -0
- data/lib/dry_scaffold/tasks.rb +5 -0
- data/lib/setup_helper.rb +36 -0
- data/tasks/dry_scaffold.rake +95 -0
- metadata +140 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
xml.instruct! :xml, :version => '1.0'
|
2
|
+
xml.rss(:version => '2.0') do
|
3
|
+
xml.channel do
|
4
|
+
xml.title 'Ducks'
|
5
|
+
xml.description 'Index of all ducks.'
|
6
|
+
xml.link ducks_url(:rss)
|
7
|
+
xml.lastBuildDate (@ducks.first.created_at rescue Time.now.utc).to_s(:rfc822)
|
8
|
+
xml.language I18n.locale
|
9
|
+
|
10
|
+
@ducks.each do |duck|
|
11
|
+
xml.item do
|
12
|
+
xml.title 'title'
|
13
|
+
xml.description 'summary'
|
14
|
+
xml.pubDate duck.try(:created_at).to_s(:rfc822)
|
15
|
+
xml.link duck_url(duck, :rss)
|
16
|
+
|
17
|
+
xml.author 'author_name'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
- content_tag_for(:tr, duck) do
|
2
|
+
%td.title= h duck.try(:title)
|
3
|
+
%td.description= h duck.try(:description)
|
4
|
+
%td.actions
|
5
|
+
= link_to 'Show', duck_url(duck)
|
6
|
+
|
|
7
|
+
= link_to 'Edit', edit_duck_url(duck)
|
8
|
+
|
|
9
|
+
= link_to 'Destroy', duck_url(duck), :confirm => 'Are you sure?', :method => :delete
|
@@ -0,0 +1,17 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= 'Ducks'
|
3
|
+
|
4
|
+
%p.actions
|
5
|
+
= link_to 'New duck', new_duck_url
|
6
|
+
|
7
|
+
%table
|
8
|
+
%thead.header
|
9
|
+
%tr
|
10
|
+
%th.title= 'Title'
|
11
|
+
%th.description= 'Description'
|
12
|
+
%th.actions= 'Actions'
|
13
|
+
%tbody.items.resources
|
14
|
+
- @ducks.each do |duck|
|
15
|
+
= render 'item', :duck => duck
|
16
|
+
|
17
|
+
= will_paginate(@ducks)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
%html{html_attrs(I18n.locale).update(:lang => nil)}
|
3
|
+
%head
|
4
|
+
%title= "#{controller_class_name}: #{controller.action_name}"
|
5
|
+
|
6
|
+
= stylesheet_link_tag 'screen', :media => 'screen, projection'
|
7
|
+
= stylesheet_link_tag 'print', :media => 'print'
|
8
|
+
/[if IE]
|
9
|
+
= stylesheet_link_tag 'ie', :media => 'screen, projection'
|
10
|
+
= stylesheet_link_tag 'scaffold'
|
11
|
+
|
12
|
+
= javascript_link_tag :defaults
|
13
|
+
|
14
|
+
%body{:id => "#{controller.controller_name}_#{controller.action_name}", :class => "#{controller.controller_name}_controller #{controller.action_name}_action"}
|
15
|
+
|
16
|
+
%p.flash{:style => 'color: green'}= flash[:notice]
|
17
|
+
|
18
|
+
= yield
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= "Duck %s" % @duck.id
|
3
|
+
|
4
|
+
- content_tag_for(:dl, @duck) do
|
5
|
+
%dt.label= 'Title'
|
6
|
+
%dd.title= h @duck.try(:title)
|
7
|
+
%dt.label= 'Description'
|
8
|
+
%dd.description= h @duck.try(:description)
|
9
|
+
|
10
|
+
%p.actions
|
11
|
+
= link_to 'Edit', edit_duck_url(@duck)
|
12
|
+
|
|
13
|
+
= link_to 'Index', ducks_url
|
@@ -0,0 +1,250 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
|
3
|
+
<% if actions -%>
|
4
|
+
before_filter :load_resource, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_MEMBER_AUTOLOAD_ACTIONS) %>]
|
5
|
+
<% end -%>
|
6
|
+
<% if actions -%>
|
7
|
+
before_filter :load_and_paginate_resources, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_COLLECTION_AUTOLOAD_ACTIONS) %>]
|
8
|
+
|
9
|
+
<% end -%>
|
10
|
+
<% if actions.include?(:index) -%>
|
11
|
+
<% formats.each do |_format| -%>
|
12
|
+
# GET /<%= plural_name %><%= ".#{_format}" unless _format == :html %>
|
13
|
+
<% end -%>
|
14
|
+
def index
|
15
|
+
respond_to do |format|
|
16
|
+
<% formats.each do |_format| -%>
|
17
|
+
<% case _format when :html then -%>
|
18
|
+
format.html # index.html.haml
|
19
|
+
<% when :js then -%>
|
20
|
+
format.js # index.js.rjs
|
21
|
+
<% when :xml, :json then -%>
|
22
|
+
format.<%= _format %> { render :<%= _format %> => @<%= plural_name %> }
|
23
|
+
<% when :yml, :yaml then -%>
|
24
|
+
format.yaml { render :text => @<%= plural_name %>.to_yaml, :content_type => :'text/yaml' }
|
25
|
+
<% when :txt, :text then -%>
|
26
|
+
format.txt { render :text => @<%= plural_name %>.to_s, :content_type => :text }
|
27
|
+
<% when :atom, :rss then -%>
|
28
|
+
<% unless options[:skip_builders] -%>
|
29
|
+
format.<%= _format %> # index.<%= _format %>.builder
|
30
|
+
<% else -%>
|
31
|
+
format.<%= _format %> { }
|
32
|
+
<% end -%>
|
33
|
+
<% else -%>
|
34
|
+
format.<%= _format %> { }
|
35
|
+
<% end -%>
|
36
|
+
<% end -%>
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
<% end -%>
|
41
|
+
<% if actions.include?(:show) -%>
|
42
|
+
<% formats.each do |_format| -%>
|
43
|
+
# GET /<%= plural_name %>/:id<%= ".#{_format}" unless _format == :html %>
|
44
|
+
<% end -%>
|
45
|
+
def show
|
46
|
+
respond_to do |format|
|
47
|
+
<% formats.each do |_format| -%>
|
48
|
+
<% case _format when :html then -%>
|
49
|
+
format.html # show.html.haml
|
50
|
+
<% when :js then -%>
|
51
|
+
format.js # show.js.rjs
|
52
|
+
<% when :xml, :json then -%>
|
53
|
+
format.<%= _format %> { render :<%= _format %> => @<%= plural_name %> }
|
54
|
+
<% when :yml, :yaml then -%>
|
55
|
+
format.yaml { render :text => @<%= plural_name %>.to_yaml, :content_type => :'text/yaml' }
|
56
|
+
<% when :txt, :text then -%>
|
57
|
+
format.txt { render :text => @<%= plural_name %>.to_s, :content_type => :text }
|
58
|
+
<% else -%>
|
59
|
+
format.<%= _format %> { }
|
60
|
+
<% end -%>
|
61
|
+
<% end -%>
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
<% end -%>
|
66
|
+
<% if actions.include?(:new) -%>
|
67
|
+
<% formats.each do |_format| -%>
|
68
|
+
# GET /<%= plural_name %>/new<%= ".#{_format}" unless _format == :html %>
|
69
|
+
<% end -%>
|
70
|
+
def new
|
71
|
+
<%= resource_instance %> = <%= class_name %>.new
|
72
|
+
|
73
|
+
respond_to do |format|
|
74
|
+
<% formats.each do |_format| -%>
|
75
|
+
<% case _format when :html then -%>
|
76
|
+
format.html # new.html.haml
|
77
|
+
<% when :js then -%>
|
78
|
+
format.js # new.js.rjs
|
79
|
+
<% when :xml, :json then -%>
|
80
|
+
format.<%= _format %> { render :<%= _format %> => <%= resource_instance %> }
|
81
|
+
<% when :yml, :yaml then -%>
|
82
|
+
format.yaml { render :text => <%= resource_instance %>.to_yaml, :content_type => :'text/yaml' }
|
83
|
+
<% when :txt, :text then -%>
|
84
|
+
format.txt { render :text => <%= resource_instance %>.to_s, :content_type => :text }
|
85
|
+
<% else -%>
|
86
|
+
format.<%= _format %> { }
|
87
|
+
<% end -%>
|
88
|
+
<% end -%>
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
<% end -%>
|
93
|
+
<% if actions.include?(:edit) -%>
|
94
|
+
# GET /<%= plural_name %>/:id/edit
|
95
|
+
def edit
|
96
|
+
end
|
97
|
+
|
98
|
+
<% end -%>
|
99
|
+
<% if actions.include?(:create) -%>
|
100
|
+
<% formats.each do |_format| -%>
|
101
|
+
# POST /<%= plural_name %><%= ".#{_format}" unless _format == :html %>
|
102
|
+
<% end -%>
|
103
|
+
def create
|
104
|
+
<%= resource_instance %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
105
|
+
|
106
|
+
respond_to do |format|
|
107
|
+
if <%= resource_instance %>.save
|
108
|
+
flash[:notice] = "<%= singular_name.humanize %> was successfully created."
|
109
|
+
<% formats.each do |_format| -%>
|
110
|
+
<% case _format when :html then -%>
|
111
|
+
format.html { redirect_to(<%= resource_instance %>) }
|
112
|
+
<% when :js then -%>
|
113
|
+
format.js # create.js.rjs
|
114
|
+
<% when :xml, :json then -%>
|
115
|
+
format.<%= _format %> { render :<%= _format %> => <%= resource_instance %>, :status => :created, :location => <%= resource_instance %> }
|
116
|
+
<% when :yml, :yaml then -%>
|
117
|
+
format.yaml { render :text => <%= resource_instance %>.to_yaml, :content_type => :'text/yaml', :status => :created, :location => <%= resource_instance %> }
|
118
|
+
<% when :txt, :text then -%>
|
119
|
+
format.txt { render :text => <%= resource_instance %>.to_s, :content_type => :text, :status => :created, :location => <%= resource_instance %> }
|
120
|
+
<% else -%>
|
121
|
+
format.<%= _format %> { }
|
122
|
+
<% end -%>
|
123
|
+
<% end -%>
|
124
|
+
else
|
125
|
+
flash[:error] = "<%= singular_name.humanize %> could not be created."
|
126
|
+
<% formats.each do |_format| -%>
|
127
|
+
<% case _format when :html then -%>
|
128
|
+
format.html { render 'new' }
|
129
|
+
<% when :js then -%>
|
130
|
+
format.js # create.js.rjs
|
131
|
+
<% when :xml, :json then -%>
|
132
|
+
format.<%= _format %> { render :<%= _format %> => <%= resource_instance %>.errors, :status => :unprocessable_entity }
|
133
|
+
<% when :yml, :yaml then -%>
|
134
|
+
format.yaml { render :text => <%= resource_instance %>.errors.to_yaml, :content_type => :'text/yaml', :status => :unprocessable_entity }
|
135
|
+
<% when :txt, :text then -%>
|
136
|
+
format.txt { render :text => <%= resource_instance %>.errors.to_s, :content_type => :text, :status => :unprocessable_entity }
|
137
|
+
<% else -%>
|
138
|
+
format.<%= _format %> { }
|
139
|
+
<% end -%>
|
140
|
+
<% end -%>
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
<% end -%>
|
146
|
+
<% if actions.include?(:update) -%>
|
147
|
+
<% formats.each do |_format| -%>
|
148
|
+
# PUT /<%= plural_name %>/:id<%= ".#{_format}" unless _format == :html %>
|
149
|
+
<% end -%>
|
150
|
+
def update
|
151
|
+
respond_to do |format|
|
152
|
+
if <%= resource_instance %>.update_attributes(params[:<%= singular_name %>])
|
153
|
+
flash[:notice] = "<%= singular_name.humanize %> was successfully updated."
|
154
|
+
<% formats.each do |_format| -%>
|
155
|
+
<% case _format when :html then -%>
|
156
|
+
format.html { redirect_to(<%= resource_instance %>) }
|
157
|
+
<% when :js then -%>
|
158
|
+
format.js # update.js.rjs
|
159
|
+
<% when :xml, :json, :yml, :yaml, :txt, :text then -%>
|
160
|
+
format.<%= _format %> { head :ok }
|
161
|
+
<% else -%>
|
162
|
+
format.<%= _format %> { head :ok }
|
163
|
+
<% end -%>
|
164
|
+
<% end -%>
|
165
|
+
else
|
166
|
+
flash[:error] = "<%= singular_name.humanize %> could not be updated."
|
167
|
+
<% formats.each do |_format| -%>
|
168
|
+
<% case _format when :html then -%>
|
169
|
+
format.html { render 'edit' }
|
170
|
+
<% when :js then -%>
|
171
|
+
format.js # update.js.rjs
|
172
|
+
<% when :xml, :json then -%>
|
173
|
+
format.<%= _format %> { render :<%= _format %> => <%= resource_instance %>.errors, :status => :unprocessable_entity }
|
174
|
+
<% when :yml, :yaml then -%>
|
175
|
+
format.yaml { render :text => <%= resource_instance %>.errors.to_yaml, :status => :unprocessable_entity }
|
176
|
+
<% when :txt, :text then -%>
|
177
|
+
format.txt { render :text => <%= resource_instance %>.errors.to_s, :status => :unprocessable_entity }
|
178
|
+
<% else -%>
|
179
|
+
format.<%= _format %> { head :unprocessable_entity }
|
180
|
+
<% end -%>
|
181
|
+
<% end -%>
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
<% end -%>
|
187
|
+
<% if actions.include?(:destroy) -%>
|
188
|
+
<% formats.each do |_format| -%>
|
189
|
+
# DELETE /<%= plural_name %>/:id<%= ".#{_format}" unless _format == :html %>
|
190
|
+
<% end -%>
|
191
|
+
def destroy
|
192
|
+
respond_to do |format|
|
193
|
+
if <%= resource_instance %>.destroy
|
194
|
+
flash[:notice] = "<%= singular_name.humanize %> was successfully destroyed."
|
195
|
+
<% formats.each do |_format| -%>
|
196
|
+
<% case _format when :html then -%>
|
197
|
+
format.html { redirect_to(<%= plural_name %>_url) }
|
198
|
+
<% when :js then -%>
|
199
|
+
format.js # destroy.js.rjs
|
200
|
+
<% when :xml, :json, :yml, :yaml, :txt, :text then -%>
|
201
|
+
format.<%= _format %> { head :ok }
|
202
|
+
<% else -%>
|
203
|
+
format.<%= _format %> { head :ok }
|
204
|
+
<% end -%>
|
205
|
+
<% end -%>
|
206
|
+
else
|
207
|
+
flash[:error] = "<%= singular_name.humanize %> could not be destroyed."
|
208
|
+
<% formats.each do |_format| -%>
|
209
|
+
<% case _format when :html then -%>
|
210
|
+
format.html { redirect_to(<%= singular_name %>_url(<%= resource_instance %>)) }
|
211
|
+
<% when :js then -%>
|
212
|
+
format.js # destroy.js.rjs
|
213
|
+
<% when :xml, :json, :yml, :yaml, :txt, :text then -%>
|
214
|
+
format.<%= _format %> { head :unprocessable_entity }
|
215
|
+
<% else -%>
|
216
|
+
format.<%= _format %> { head :unprocessable_entity }
|
217
|
+
<% end -%>
|
218
|
+
<% end -%>
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
<% end -%>
|
224
|
+
<% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
|
225
|
+
# GET /<%= plural_name %>/<%= action.to_s %>
|
226
|
+
def <%= action.to_s %>
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
<% end -%>
|
231
|
+
protected
|
232
|
+
|
233
|
+
def collection
|
234
|
+
<% if options[:pagination] -%>
|
235
|
+
paginate_options ||= {}
|
236
|
+
paginate_options[:page] ||= (params[:page] || 1)
|
237
|
+
paginate_options[:per_page] ||= (params[:per_page] || 20)
|
238
|
+
@collection = @<%= plural_name %> ||= <%= class_name %>.paginate(paginate_options)
|
239
|
+
<% else -%>
|
240
|
+
@collection = @<%= plural_name %> ||= <%= class_name %>.all
|
241
|
+
<% end -%>
|
242
|
+
end
|
243
|
+
alias :load_and_paginate_resources :collection
|
244
|
+
|
245
|
+
def resource
|
246
|
+
@resource = <%= resource_instance %> ||= <%= class_name %>.find(params[:id])
|
247
|
+
end
|
248
|
+
alias :load_resource :resource
|
249
|
+
|
250
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < InheritedResources::Base
|
2
|
+
|
3
|
+
<% if actions -%>
|
4
|
+
actions <%= symbol_array_to_expression(actions) %>
|
5
|
+
<% end -%>
|
6
|
+
<% if formats -%>
|
7
|
+
respond_to <%= symbol_array_to_expression(formats) %>
|
8
|
+
|
9
|
+
<% end -%>
|
10
|
+
<% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
|
11
|
+
# GET /<%= plural_name %>/<%= action.to_s %>
|
12
|
+
def <%= action.to_s %>
|
13
|
+
end
|
14
|
+
|
15
|
+
<% end -%>
|
16
|
+
<% if options[:pagination] -%>
|
17
|
+
protected
|
18
|
+
|
19
|
+
def collection
|
20
|
+
paginate_options ||= {}
|
21
|
+
paginate_options[:page] ||= (params[:page] || 1)
|
22
|
+
paginate_options[:per_page] ||= (params[:per_page] || 20)
|
23
|
+
@<%= model_plural_name %> ||= end_of_association_chain.paginate(paginate_options)
|
24
|
+
end
|
25
|
+
<% end %>
|
26
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe <%= controller_class_name %>Controller do
|
4
|
+
<% if options[:fixtures] -%>
|
5
|
+
fixtures :all
|
6
|
+
<% end -%>
|
7
|
+
integrate_views
|
8
|
+
<% unless options[:factory_framework]==:fixtures %>
|
9
|
+
before(:each) do
|
10
|
+
<%= build_object %>
|
11
|
+
end
|
12
|
+
<% end %>
|
13
|
+
<% if actions.include?(:index) -%>
|
14
|
+
it "index action should render index template" do
|
15
|
+
get :index
|
16
|
+
response.should render_template(:index)
|
17
|
+
end
|
18
|
+
|
19
|
+
<% end %>
|
20
|
+
<% if actions.include?(:show) -%>
|
21
|
+
it "show action should render show template" do
|
22
|
+
get :show, :id => <%= class_name %>.first
|
23
|
+
response.should render_template(:show)
|
24
|
+
end
|
25
|
+
|
26
|
+
<% end %>
|
27
|
+
<% if actions.include?(:new) -%>
|
28
|
+
it "new action should render new template" do
|
29
|
+
get :new
|
30
|
+
response.should render_template(:new)
|
31
|
+
end
|
32
|
+
|
33
|
+
<% end %>
|
34
|
+
<% if actions.include?(:create) -%>
|
35
|
+
it "create action should render new template when model is invalid" do
|
36
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
37
|
+
post :create
|
38
|
+
response.should render_template(:new)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "create action should redirect when model is valid" do
|
42
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
43
|
+
post :create
|
44
|
+
response.should redirect_to(<%= singular_name %>_url(assigns[:<%= singular_name %>]))
|
45
|
+
end
|
46
|
+
|
47
|
+
<% end %>
|
48
|
+
<% if actions.include?(:edit) -%>
|
49
|
+
it "edit action should render edit template" do
|
50
|
+
get :edit, :id => <%= class_name %>.first
|
51
|
+
response.should render_template(:edit)
|
52
|
+
end
|
53
|
+
|
54
|
+
<% end %>
|
55
|
+
<% if actions.include?(:update) -%>
|
56
|
+
it "update action should render edit template when model is invalid" do
|
57
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
58
|
+
put :update, :id => <%= class_name %>.first
|
59
|
+
response.should render_template(:edit)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "update action should redirect when model is valid" do
|
63
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
64
|
+
put :update, :id => <%= class_name %>.first
|
65
|
+
response.should redirect_to(<%= singular_name %>_url(assigns[:<%= singular_name %>]))
|
66
|
+
end
|
67
|
+
|
68
|
+
<% end %>
|
69
|
+
<% if actions.include?(:destroy) -%>
|
70
|
+
it "destroy action should destroy model and redirect to index action" do
|
71
|
+
<%= singular_name %> = <%= class_name %>.first
|
72
|
+
delete :destroy, :id => <%= singular_name %>
|
73
|
+
response.should redirect_to(<%= plural_name %>_url)
|
74
|
+
<%= class_name %>.exists?(<%= singular_name %>.id).should be_false
|
75
|
+
end
|
76
|
+
|
77
|
+
<% end %>
|
78
|
+
<% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
|
79
|
+
it '<%= action.to_s %> action should render <%= action.to_s %> template' do
|
80
|
+
get :<%= action.to_s %>
|
81
|
+
response.should render_template(:<%= action.to_s %>)
|
82
|
+
end
|
83
|
+
|
84
|
+
<% end -%>
|
85
|
+
end
|