1 require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
3 describe <%= controller_class_name %>Controller, "#route_for" do
5 it "should map { :controller => '<%= table_name %>', :action => 'index' } to /<%= table_name %>" do
6 route_for(:controller => "<%= table_name %>", :action => "index").should == "/<%= table_name %>"
9 it "should map { :controller => '<%= table_name %>', :action => 'new' } to /<%= table_name %>/new" do
10 route_for(:controller => "<%= table_name %>", :action => "new").should == "/<%= table_name %>/new"
13 it "should map { :controller => '<%= table_name %>', :action => 'show', :id => 1 } to /<%= table_name %>/1" do
14 route_for(:controller => "<%= table_name %>", :action => "show", :id => 1).should == "/<%= table_name %>/1"
17 it "should map { :controller => '<%= table_name %>', :action => 'edit', :id => 1 } to /<%= table_name %>/1<%= resource_edit_path %>" do
18 route_for(:controller => "<%= table_name %>", :action => "edit", :id => 1).should == "/<%= table_name %>/1<%= resource_edit_path %>"
21 it "should map { :controller => '<%= table_name %>', :action => 'update', :id => 1} to /<%= table_name %>/1" do
22 route_for(:controller => "<%= table_name %>", :action => "update", :id => 1).should == "/<%= table_name %>/1"
25 it "should map { :controller => '<%= table_name %>', :action => 'destroy', :id => 1} to /<%= table_name %>/1" do
26 route_for(:controller => "<%= table_name %>", :action => "destroy", :id => 1).should == "/<%= table_name %>/1"
31 describe <%= controller_class_name %>Controller, "#params_from" do
33 it "should generate params { :controller => '<%= table_name %>', action => 'index' } from GET /<%= table_name %>" do
34 params_from(:get, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "index"}
37 it "should generate params { :controller => '<%= table_name %>', action => 'new' } from GET /<%= table_name %>/new" do
38 params_from(:get, "/<%= table_name %>/new").should == {:controller => "<%= table_name %>", :action => "new"}
41 it "should generate params { :controller => '<%= table_name %>', action => 'create' } from POST /<%= table_name %>" do
42 params_from(:post, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "create"}
45 it "should generate params { :controller => '<%= table_name %>', action => 'show', id => '1' } from GET /<%= table_name %>/1" do
46 params_from(:get, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "show", :id => "1"}
49 it "should generate params { :controller => '<%= table_name %>', action => 'edit', id => '1' } from GET /<%= table_name %>/1;edit" do
50 params_from(:get, "/<%= table_name %>/1<%= resource_edit_path %>").should == {:controller => "<%= table_name %>", :action => "edit", :id => "1"}
53 it "should generate params { :controller => '<%= table_name %>', action => 'update', id => '1' } from PUT /<%= table_name %>/1" do
54 params_from(:put, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "update", :id => "1"}
57 it "should generate params { :controller => '<%= table_name %>', action => 'destroy', id => '1' } from DELETE /<%= table_name %>/1" do
58 params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
63 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>" do
66 @<%= file_name %> = mock_model(<%= class_name %>)
67 <%= class_name %>.stub!(:find).and_return([@<%= file_name %>])
74 it "should be successful" do
76 response.should be_success
79 it "should render index template" do
81 response.should render_template('index')
84 it "should find all <%= table_name %>" do
85 <%= class_name %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
89 it "should assign the found <%= table_name %> for the view" do
91 assigns[:<%= table_name %>].should == [@<%= file_name %>]
95 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>.xml" do
98 @<%= file_name %> = mock_model(<%= class_name %>, :to_xml => "XML")
99 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
103 @request.env["HTTP_ACCEPT"] = "application/xml"
107 it "should be successful" do
109 response.should be_success
112 it "should find all <%= table_name %>" do
113 <%= class_name %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
117 it "should render the found <%= table_name %> as xml" do
118 @<%= file_name %>.should_receive(:to_xml).and_return("XML")
120 response.body.should == "XML"
124 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/1" do
127 @<%= file_name %> = mock_model(<%= class_name %>)
128 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
132 get :show, :id => "1"
135 it "should be successful" do
137 response.should be_success
140 it "should render show template" do
142 response.should render_template('show')
145 it "should find the <%= file_name %> requested" do
146 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
150 it "should assign the found <%= file_name %> for the view" do
152 assigns[:<%= file_name %>].should equal(@<%= file_name %>)
156 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/1.xml" do
159 @<%= file_name %> = mock_model(<%= class_name %>, :to_xml => "XML")
160 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
164 @request.env["HTTP_ACCEPT"] = "application/xml"
165 get :show, :id => "1"
168 it "should be successful" do
170 response.should be_success
173 it "should find the <%= file_name %> requested" do
174 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
178 it "should render the found <%= file_name %> as xml" do
179 @<%= file_name %>.should_receive(:to_xml).and_return("XML")
181 response.body.should == "XML"
185 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/new" do
188 @<%= file_name %> = mock_model(<%= class_name %>)
189 <%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
196 it "should be successful" do
198 response.should be_success
201 it "should render new template" do
203 response.should render_template('new')
206 it "should create an new <%= file_name %>" do
207 <%= class_name %>.should_receive(:new).and_return(@<%= file_name %>)
211 it "should not save the new <%= file_name %>" do
212 @<%= file_name %>.should_not_receive(:save)
216 it "should assign the new <%= file_name %> for the view" do
218 assigns[:<%= file_name %>].should equal(@<%= file_name %>)
222 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/1/edit" do
225 @<%= file_name %> = mock_model(<%= class_name %>)
226 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
230 get :edit, :id => "1"
233 it "should be successful" do
235 response.should be_success
238 it "should render edit template" do
240 response.should render_template('edit')
243 it "should find the <%= file_name %> requested" do
244 <%= class_name %>.should_receive(:find).and_return(@<%= file_name %>)
248 it "should assign the found <%= class_name %> for the view" do
250 assigns[:<%= file_name %>].should equal(@<%= file_name %>)
254 describe <%= controller_class_name %>Controller, "handling POST /<%= table_name %>" do
257 @<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1")
258 <%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
261 def post_with_successful_save
262 @<%= file_name %>.should_receive(:save).and_return(true)
263 post :create, :<%= file_name %> => {}
266 def post_with_failed_save
267 @<%= file_name %>.should_receive(:save).and_return(false)
268 post :create, :<%= file_name %> => {}
271 it "should create a new <%= file_name %>" do
272 <%= class_name %>.should_receive(:new).with({}).and_return(@<%= file_name %>)
273 post_with_successful_save
276 it "should redirect to the new <%= file_name %> on successful save" do
277 post_with_successful_save
278 response.should redirect_to(<%= table_name.singularize %>_url("1"))
281 it "should re-render 'new' on failed save" do
282 post_with_failed_save
283 response.should render_template('new')
287 describe <%= controller_class_name %>Controller, "handling PUT /<%= table_name %>/1" do
290 @<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1")
291 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
294 def put_with_successful_update
295 @<%= file_name %>.should_receive(:update_attributes).and_return(true)
296 put :update, :id => "1"
299 def put_with_failed_update
300 @<%= file_name %>.should_receive(:update_attributes).and_return(false)
301 put :update, :id => "1"
304 it "should find the <%= file_name %> requested" do
305 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
306 put_with_successful_update
309 it "should update the found <%= file_name %>" do
310 put_with_successful_update
311 assigns(:<%= file_name %>).should equal(@<%= file_name %>)
314 it "should assign the found <%= file_name %> for the view" do
315 put_with_successful_update
316 assigns(:<%= file_name %>).should equal(@<%= file_name %>)
319 it "should redirect to the <%= file_name %> on successful update" do
320 put_with_successful_update
321 response.should redirect_to(<%= table_name.singularize %>_url("1"))
324 it "should re-render 'edit' on failed update" do
325 put_with_failed_update
326 response.should render_template('edit')
330 describe <%= controller_class_name %>Controller, "handling DELETE /<%= table_name %>/1" do
333 @<%= file_name %> = mock_model(<%= class_name %>, :destroy => true)
334 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
338 delete :destroy, :id => "1"
341 it "should find the <%= file_name %> requested" do
342 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
346 it "should call destroy on the found <%= file_name %>" do
347 @<%= file_name %>.should_receive(:destroy)
351 it "should redirect to the <%= table_name %> list" do
353 response.should redirect_to(<%= table_name %>_url)