public
Description: A Haml Scaffolding Generator for RSpec
Homepage: http://blog.citrusbyte.com/2008/3/11/what-s-that-rspec-haml-scaffolds-yes-it-is
Clone URL: git://github.com/dfischer/rspec-haml-scaffold-generator.git
Search Repo:
initial commit of files
Daniel Fischer (author)
Mon Mar 10 15:27:18 -0700 2008
commit  5ef8fb6f10af312059fb5c6f87596260ae9811be
tree    913bbef3e767364255aa706f3ba48c7d14ff1caf
0
...
 
0
...
1
2
0
@@ -0,0 +1 @@
0
+blhal balhsljaslbas
0
\ No newline at end of file
...
 
0
...
1
2
0
@@ -0,0 +1 @@
0
+blah blah rspec test haml
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
0
@@ -0,0 +1,224 @@
1
+class RspecHamlScaffoldGenerator < Rails::Generator::NamedBase
0
+ default_options :skip_migration => false
0
+ # include Rails::Generator::Commands::Base
0
+
0
+ attr_reader :controller_name,
0
+ :controller_class_path,
0
+ :controller_file_path,
0
+ :controller_class_nesting,
0
+ :controller_class_nesting_depth,
0
+ :controller_class_name,
0
+ :controller_singular_name,
0
+ :controller_plural_name,
0
+ :resource_edit_path,
0
+ :default_file_extension
0
+ alias_method :controller_file_name, :controller_singular_name
0
+ alias_method :controller_table_name, :controller_plural_name
0
+
0
+ def initialize(runtime_args, runtime_options = {})
0
+ super
0
+
0
+ @controller_name = @name.pluralize
0
+
0
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
0
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
0
+
0
+ if @controller_class_nesting.empty?
0
+ @controller_class_name = @controller_class_name_without_nesting
0
+ else
0
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
0
+ end
0
+
0
+ # ActionView::Base::DEFAULT_TEMPLATE_HANDLER_PREFERENCE.unshift(:haml)
0
+ #
0
+ # if ActionView::Base.const_defined?('DEFAULT_TEMPLATE_HANDLER_PREFERENCE') &&
0
+ # ActionView::Base::DEFAULT_TEMPLATE_HANDLER_PREFERENCE.include?(:haml) then
0
+ @resource_generator = "rspec_haml_scaffold"
0
+ @default_file_extension = "haml"
0
+ @resource_edit_path = "/edit"
0
+ # else
0
+ # @resource_generator = "scaffold_resource"
0
+ # @default_file_extension = "rhtml"
0
+ # @resource_edit_path = ";edit"
0
+ # end
0
+
0
+
0
+ end
0
+
0
+ def manifest
0
+ record do |m|
0
+ #just so you can see what the variables are
0
+ # => "yoda/bob"
0
+ #p @name # yoda/bob
0
+ #p @controller_name # yoda/bobs
0
+ #p @controller_class_name_without_nesting # Bobs
0
+ #p @controller_class_nesting # yoda
0
+ #p @controller_plural_name #bobs
0
+ #p @controller_singular_name #bobs
0
+ #p @controller_file_path #yoda/bobs
0
+ #p @controller_class_path # ["yoda"]
0
+
0
+ # Check for class naming collisions.
0
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
0
+ m.class_collisions(class_path, "#{class_name}")
0
+
0
+ # Controller, helper, views, and spec directories.
0
+ m.directory(File.join('app/models'))
0
+ m.directory(File.join('app/controllers', controller_class_path))
0
+ m.directory(File.join('app/helpers', controller_class_path))
0
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
0
+ m.directory(File.join('spec/controllers', controller_class_path))
0
+ m.directory(File.join('spec/models'))
0
+ m.directory(File.join('spec/helpers', class_path))
0
+ m.directory File.join('spec/fixtures')
0
+ m.directory File.join('spec/views', controller_class_path, controller_file_name)
0
+
0
+ # Controller spec, class, and helper.
0
+ m.template 'rspec_haml_scaffold:controller_spec.rb',
0
+ File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
0
+
0
+ m.template "rspec_haml_scaffold:controller.rb",
0
+ File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
0
+
0
+ m.template 'rspec_haml_scaffold:helper_spec.rb',
0
+ File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
0
+
0
+ m.template "#{@resource_generator}:helper.rb",
0
+ File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")
0
+
0
+ for action in scaffold_views
0
+ m.template(
0
+ "rspec_haml_scaffold:view_#{action}_haml.erb",
0
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
0
+ )
0
+ end
0
+
0
+ # Model class, unit test, and fixtures.
0
+ m.template 'rspec_haml_scaffold:model.rb', File.join('app/models', "#{@controller_singular_name.singularize}.rb")
0
+ m.template 'model:fixtures.yml', File.join('spec/fixtures', "#{@controller_singular_name}.yml")
0
+ m.template 'rspec_haml_scaffold:model_spec.rb', File.join('spec/models', "#{@controller_singular_name}_spec.rb")
0
+
0
+ # View specs
0
+ m.template "rspec_haml_scaffold:edit_haml_spec.rb",
0
+ File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb")
0
+ m.template "rspec_haml_scaffold:index_haml_spec.rb",
0
+ File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb")
0
+ m.template "rspec_haml_scaffold:new_haml_spec.rb",
0
+ File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb")
0
+ m.template "rspec_haml_scaffold:show_haml_spec.rb",
0
+ File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb")
0
+
0
+ unless options[:skip_migration]
0
+ m.migration_template(
0
+ 'rspec_haml_scaffold:migration.rb', 'db/migrate',
0
+ :assigns => {
0
+ :migration_name => "Create#{singular_name.pluralize.capitalize}",
0
+ :attributes => attributes
0
+ },
0
+ :migration_file_name => "create_#{controller_singular_name.gsub(/\//, '_').pluralize}"
0
+ )
0
+ end
0
+
0
+ #m.route_resources controller_file_name
0
+ route_resources name
0
+
0
+ end
0
+ end
0
+
0
+ protected
0
+ def form_link_for(table_name, singular_name)
0
+ if !@controller_name.split("/")[1].nil?
0
+ return "[:#{@controller_class_nesting.downcase}, @#{singular_name.singularize}]"
0
+ else
0
+ return "@#{singular_name.singularize}"
0
+ end
0
+ end
0
+
0
+ def path_for(singular, plural, txt)
0
+ case txt
0
+ when "show"
0
+ return "#{table_name.singularize}_path(@#{singular_name.singularize})"
0
+ when "edit"
0
+ return "edit_#{table_name.singularize}_path(@#{singular_name.singularize})"
0
+ when "destroy"
0
+ return "#{table_name.singularize}_path(@#{singular_name.singularize}), :confirm => 'Are you sure?', :method => :delete"
0
+ when "index"
0
+ return "#{table_name}_path"
0
+ end
0
+ end
0
+
0
+ # Override with your own usage banner.
0
+ def banner
0
+ "Usage: #{$0} rspec_haml_scaffold ModelName [field:type field:type]"
0
+ end
0
+
0
+ def add_options!(opt)
0
+ opt.separator ''
0
+ opt.separator 'Options:'
0
+ opt.on("--skip-migration",
0
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
0
+ end
0
+
0
+ def scaffold_views
0
+ %w[ index show new edit ]
0
+ end
0
+
0
+ def model_name
0
+ class_name.demodulize
0
+ end
0
+
0
+ def route_resources(resource)
0
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
0
+ logger.route "map.resources #{resource}"
0
+ unless options[:pretend]
0
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
0
+
0
+ if !resource.split('/')[1].nil?
0
+ one = resource.split('/')[0]
0
+ two = resource.split('/')[1]
0
+ "#{match}\n map.namespace(:#{one}) do |#{one}|\n #{one}.resources :#{two.pluralize}\n end"
0
+ else
0
+ "#{match}\n map.resources :#{resource.pluralize}\n"
0
+ end
0
+
0
+ end
0
+ end
0
+ end
0
+
0
+
0
+ def gsub_file(relative_destination, regexp, *args, &block)
0
+ path = destination_path(relative_destination)
0
+ content = File.read(path).gsub(regexp, *args, &block)
0
+ File.open(path, 'wb') { |file| file.write(content) }
0
+ end
0
+
0
+end
0
+
0
+module Rails
0
+ module Generator
0
+ class GeneratedAttribute
0
+ def default_value
0
+ @default_value ||= case type
0
+ when :int, :integer then "\"1\""
0
+ when :float then "\"1.5\""
0
+ when :decimal then "\"9.99\""
0
+ when :datetime, :timestamp, :time then "Time.now"
0
+ when :date then "Date.today"
0
+ when :string then "\"MyString\""
0
+ when :text then "\"MyText\""
0
+ when :boolean then "false"
0
+ else
0
+ ""
0
+ end
0
+ end
0
+
0
+ def input_type
0
+ @input_type ||= case type
0
+ when :text then "textarea"
0
+ else
0
+ "input"
0
+ end
0
+ end
0
+ end
0
+ end
0
+end
...
 
0
...
1
2
0
@@ -0,0 +1 @@
0
+test blah blah
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
0
@@ -0,0 +1,85 @@
0
+class <%= controller_class_name %>Controller < ApplicationController
0
+ # GET /<%= name %>
0
+ # GET /<%= name %>.xml
0
+ def index
0
+ @<%= plural_name %> = <%= singular_name.capitalize %>.find(:all)
0
+
0
+ respond_to do |format|
0
+ format.html # index.haml
0
+ format.xml { render :xml => @<%= plural_name %> }
0
+ end
0
+ end
0
+
0
+ # GET /<%= name %>/1
0
+ # GET /<%= name %>/1.xml
0
+ def show
0
+ @<%= singular_name %> = <%= singular_name.capitalize %>.find(params[:id])
0
+
0
+ respond_to do |format|
0
+ format.html # show.haml
0
+ format.xml { render :xml => @<%= singular_name %> }
0
+ end
0
+ end
0
+
0
+ # GET /<%= name %>/new
0
+ # GET /<%= name %>/new.xml
0
+ def new
0
+ @<%= singular_name %> = <%= singular_name.capitalize %>.new
0
+
0
+ respond_to do |format|
0
+ format.html # new.haml
0
+ format.xml { render :xml => @<%= singular_name %> }
0
+ end
0
+ end
0
+
0
+ # GET /<%= name %>/1/edit
0
+ def edit
0
+ @<%= singular_name %> = <%= singular_name.capitalize %>.find(params[:id])
0
+ end
0
+
0
+ # POST /<%= name %>
0
+ # POST /<%= name %>.xml
0
+ def create
0
+ @<%= file_name %> = <%= singular_name.capitalize %>.new(params[:<%= singular_name %>])
0
+
0
+ respond_to do |format|
0
+ if @<%= file_name %>.save
0
+ flash[:notice] = '<%= singular_name.capitalize %> was successfully created.'
0
+ format.html { redirect_to(<%= table_name.singularize %>_path(@<%= file_name %>)) }
0
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
0
+ else
0
+ format.html { render :action => "new" }
0
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
0
+ end
0
+ end
0
+ end
0
+
0
+ # PUT /<%= name %>/1
0
+ # PUT /<%= name %>/1.xml
0
+ def update
0
+ @<%= file_name %> = <%= singular_name.capitalize %>.find(params[:id])
0
+
0
+ respond_to do |format|
0
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
0
+ flash[:notice] = '<%= singular_name.capitalize %> was successfully updated.'
0
+ format.html { redirect_to(<%= table_name.singularize %>_path(@<%= file_name %>)) }
0
+ format.xml { head :ok }
0
+ else
0
+ format.html { render :action => "edit" }
0
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
0
+ end
0
+ end
0
+ end
0
+
0
+ # DELETE /<%= name %>/1
0
+ # DELETE /<%= name %>/1.xml
0
+ def destroy
0
+ @<%= file_name %> = <%= singular_name.capitalize %>.find(params[:id])
0
+ @<%= file_name %>.destroy
0
+
0
+ respond_to do |format|
0
+ format.html { redirect_to(<%= table_name %>_url) }
0
+ format.xml { head :ok }
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
0
@@ -0,0 +1,323 @@
0
+require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
0
+
0
+describe <%= controller_class_name %>Controller, "#route_for" do
0
+
0
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'index' } to /<%= name.pluralize %>" do
0
+ route_for(:controller => "<%= name.pluralize %>", :action => "index").should == "/<%= name.pluralize %>"
0
+ end
0
+
0
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'new' } to /<%= name.pluralize %>/new" do
0
+ route_for(:controller => "<%= name.pluralize %>", :action => "new").should == "/<%= name.pluralize %>/new"
0
+ end
0
+
0
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'show', :id => 1 } to /<%= name.pluralize %>/1" do
0
+ route_for(:controller => "<%= name.pluralize %>", :action => "show", :id => 1).should == "/<%= name.pluralize %>/1"
0
+ end
0
+
0
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'edit', :id => 1 } to /<%= name.pluralize %>/1<%= resource_edit_path %>" do
0
+ route_for(:controller => "<%= name.pluralize %>", :action => "edit", :id => 1).should == "/<%= name.pluralize %>/1<%= resource_edit_path %>"
0
+ end
0
+
0
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'update', :id => 1} to /<%= name.pluralize %>/1" do
0
+ route_for(:controller => "<%= name.pluralize %>", :action => "update", :id => 1).should == "/<%= name.pluralize %>/1"
0
+ end
0
+
0
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'destroy', :id => 1} to /<%= name.pluralize %>/1" do
0
+ route_for(:controller => "<%= name.pluralize %>", :action => "destroy", :id => 1).should == "/<%= name.pluralize %>/1"
0
+ end
0
+
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
0
+ <%= singular_name.capitalize %>.stub!(:find).and_return([@<%= file_name %>])
0
+ end
0
+
0
+ def do_get
0
+ get :index
0
+ end
0
+
0
+ it "should be successful" do
0
+ do_get
0
+ response.should be_success
0
+ end
0
+
0
+ it "should render index template" do
0
+ do_get
0
+ response.should render_template('index')
0
+ end
0
+
0
+ it "should find all <%= name.pluralize %>" do
0
+ <%= singular_name.capitalize %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
0
+ do_get
0
+ end
0
+
0
+ it "should assign the found <%= name.pluralize %> for the view" do
0
+ do_get
0
+ assigns[:<%= singular_name.pluralize %>].should == [@<%= file_name %>]
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>.xml" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_xml => "XML")
0
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def do_get
0
+ @request.env["HTTP_ACCEPT"] = "application/xml"
0
+ get :index
0
+ end
0
+
0
+ it "should be successful" do
0
+ do_get
0
+ response.should be_success
0
+ end
0
+
0
+ it "should find all <%= name.pluralize %>" do
0
+ <%= singular_name.capitalize %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
0
+ do_get
0
+ end
0
+
0
+ it "should render the found <%= name %> as xml" do
0
+ @<%= file_name %>.should_receive(:to_xml).and_return("XML")
0
+ do_get
0
+ response.body.should == "XML"
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/1" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
0
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def do_get
0
+ get :show, :id => "1"
0
+ end
0
+
0
+ it "should be successful" do
0
+ do_get
0
+ response.should be_success
0
+ end
0
+
0
+ it "should render show template" do
0
+ do_get
0
+ response.should render_template('show')
0
+ end
0
+
0
+ it "should find the <%= file_name %> requested" do
0
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
0
+ do_get
0
+ end
0
+
0
+ it "should assign the found <%= file_name %> for the view" do
0
+ do_get
0
+ assigns[:<%= file_name %>].should equal(@<%= file_name %>)
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/1.xml" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_xml => "XML")
0
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def do_get
0
+ @request.env["HTTP_ACCEPT"] = "application/xml"
0
+ get :show, :id => "1"
0
+ end
0
+
0
+ it "should be successful" do
0
+ do_get
0
+ response.should be_success
0
+ end
0
+
0
+ it "should find the <%= file_name %> requested" do
0
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
0
+ do_get
0
+ end
0
+
0
+ it "should render the found <%= file_name %> as xml" do
0
+ @<%= singular_name %>.should_receive(:to_xml).and_return("XML")
0
+ do_get
0
+ response.body.should == "XML"
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/new" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
0
+ <%= singular_name.capitalize %>.stub!(:new).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def do_get
0
+ get :new
0
+ end
0
+
0
+ it "should be successful" do
0
+ do_get
0
+ response.should be_success
0
+ end
0
+
0
+ it "should render new template" do
0
+ do_get
0
+ response.should render_template('new')
0
+ end
0
+
0
+ it "should create an new <%= file_name %>" do
0
+ <%= singular_name.capitalize %>.should_receive(:new).and_return(@<%= file_name %>)
0
+ do_get
0
+ end
0
+
0
+ it "should not save the new <%= file_name %>" do
0
+ @<%= file_name %>.should_not_receive(:save)
0
+ do_get
0
+ end
0
+
0
+ it "should assign the new <%= file_name %> for the view" do
0
+ do_get
0
+ assigns[:<%= file_name %>].should equal(@<%= file_name %>)
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/1/edit" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
0
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def do_get
0
+ get :edit, :id => "1"
0
+ end
0
+
0
+ it "should be successful" do
0
+ do_get
0
+ response.should be_success
0
+ end
0
+
0
+ it "should render edit template" do
0
+ do_get
0
+ response.should render_template('edit')
0
+ end
0
+
0
+ it "should find the <%= file_name %> requested" do
0
+ <%= singular_name.capitalize %>.should_receive(:find).and_return(@<%= file_name %>)
0
+ do_get
0
+ end
0
+
0
+ it "should assign the found <%= file_name %> for the view" do
0
+ do_get
0
+ assigns[:<%= file_name %>].should equal(@<%= file_name %>)
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling POST /<%= name.pluralize %>" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_param => "1")
0
+ <%= singular_name.capitalize %>.stub!(:new).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def post_with_successful_save
0
+ @<%= file_name %>.should_receive(:save).and_return(true)
0
+ post :create, :<%= file_name %> => {}
0
+ end
0
+
0
+ def post_with_failed_save
0
+ @<%= file_name %>.should_receive(:save).and_return(false)
0
+ post :create, :<%= file_name %> => {}
0
+ end
0
+
0
+ it "should create a new <%= file_name %>" do
0
+ <%= singular_name.capitalize %>.should_receive(:new).with({}).and_return(@<%= file_name %>)
0
+ post_with_successful_save
0
+ end
0
+
0
+ it "should redirect to the new <%= file_name %> on successful save" do
0
+ post_with_successful_save
0
+ response.should redirect_to(<%= table_name.singularize %>_url("1"))
0
+ end
0
+
0
+ it "should re-render 'new' on failed save" do
0
+ post_with_failed_save
0
+ response.should render_template('new')
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling PUT /<%= name.pluralize %>/1" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_param => "1")
0
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def put_with_successful_update
0
+ @<%= file_name %>.should_receive(:update_attributes).and_return(true)
0
+ put :update, :id => "1"
0
+ end
0
+
0
+ def put_with_failed_update
0
+ @<%= file_name %>.should_receive(:update_attributes).and_return(false)
0
+ put :update, :id => "1"
0
+ end
0
+
0
+ it "should find the <%= file_name %> requested" do
0
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
0
+ put_with_successful_update
0
+ end
0
+
0
+ it "should update the found <%= file_name %>" do
0
+ put_with_successful_update
0
+ assigns(:<%= file_name %>).should equal(@<%= file_name %>)
0
+ end
0
+
0
+ it "should assign the found <%= file_name %> for the view" do
0
+ put_with_successful_update
0
+ assigns(:<%= file_name %>).should equal(@<%= file_name %>)
0
+ end
0
+
0
+ it "should redirect to the <%= file_name %> on successful update" do
0
+ put_with_successful_update
0
+ response.should redirect_to(<%= table_name.singularize %>_url("1"))
0
+ end
0
+
0
+ it "should re-render 'edit' on failed update" do
0
+ put_with_failed_update
0
+ response.should render_template('edit')
0
+ end
0
+end
0
+
0
+describe <%= controller_class_name %>Controller, "handling DELETE /<%= name %>/1" do
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :destroy => true)
0
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
0
+ end
0
+
0
+ def do_delete
0
+ delete :destroy, :id => "1"
0
+ end
0
+
0
+ it "should find the <%= file_name %> requested" do
0
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
0
+ do_delete
0
+ end
0
+
0
+ it "should call destroy on the found <%= file_name %>" do
0
+ @<%= file_name %>.should_receive(:destroy)
0
+ do_delete
0
+ end
0
+
0
+ it "should redirect to the <%= name.pluralize %> list" do
0
+ do_delete
0
+ response.should redirect_to(<%= table_name.pluralize %>_url)
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -0,0 +1,23 @@
0
+require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
0
+
0
+describe "/<%= name %>/edit.<%= default_file_extension %>" do
0
+ include <%= controller_class_name %>Helper
0
+
0
+ before do
0
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
0
+<% for attribute in attributes -%>
0
+ @<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
0
+<% end -%>
0
+ assigns[:<%= file_name %>] = @<%= file_name %>
0
+ end
0
+
0
+ it "should render edit form" do
0
+ render "/<%= name.pluralize %>/edit.<%= default_file_extension %>"
0
+
0
+ response.should have_tag("form[actio