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, "handling GET /<%= table_name %>" do
34 @<%= file_name %> = mock_model(<%= class_name %>)
35 <%= class_name %>.stub!(:find).and_return([@<%= file_name %>])
42 it "should be successful" do
44 response.should be_success
47 it "should render index template" do
49 response.should render_template('index')
52 it "should find all <%= table_name %>" do
53 <%= class_name %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
57 it "should assign the found <%= table_name %> for the view" do
59 assigns[:<%= table_name %>].should == [@<%= file_name %>]
63 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>.xml" do
66 @<%= file_name %> = mock_model(<%= class_name %>, :to_xml => "XML")
67 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
71 @request.env["HTTP_ACCEPT"] = "application/xml"
75 it "should be successful" do
77 response.should be_success
80 it "should find all <%= table_name %>" do
81 <%= class_name %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
85 it "should render the found <%= table_name %> as xml" do
86 @<%= file_name %>.should_receive(:to_xml).and_return("XML")
88 response.body.should == "XML"
92 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/1" do
95 @<%= file_name %> = mock_model(<%= class_name %>)
96 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
100 get :show, :id => "1"
103 it "should be successful" do
105 response.should be_success
108 it "should render show template" do
110 response.should render_template('show')
113 it "should find the <%= file_name %> requested" do
114 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
118 it "should assign the found <%= file_name %> for the view" do
120 assigns[:<%= file_name %>].should equal(@<%= file_name %>)
124 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/1.xml" do
127 @<%= file_name %> = mock_model(<%= class_name %>, :to_xml => "XML")
128 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
132 @request.env["HTTP_ACCEPT"] = "application/xml"
133 get :show, :id => "1"
136 it "should be successful" do
138 response.should be_success
141 it "should find the <%= file_name %> requested" do
142 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
146 it "should render the found <%= file_name %> as xml" do
147 @<%= file_name %>.should_receive(:to_xml).and_return("XML")
149 response.body.should == "XML"
153 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/new" do
156 @<%= file_name %> = mock_model(<%= class_name %>)
157 <%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
164 it "should be successful" do
166 response.should be_success
169 it "should render new template" do
171 response.should render_template('new')
174 it "should create an new <%= file_name %>" do
175 <%= class_name %>.should_receive(:new).and_return(@<%= file_name %>)
179 it "should not save the new <%= file_name %>" do
180 @<%= file_name %>.should_not_receive(:save)
184 it "should assign the new <%= file_name %> for the view" do
186 assigns[:<%= file_name %>].should equal(@<%= file_name %>)
190 describe <%= controller_class_name %>Controller, "handling GET /<%= table_name %>/1/edit" do
193 @<%= file_name %> = mock_model(<%= class_name %>)
194 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
198 get :edit, :id => "1"
201 it "should be successful" do
203 response.should be_success
206 it "should render edit template" do
208 response.should render_template('edit')
211 it "should find the <%= file_name %> requested" do
212 <%= class_name %>.should_receive(:find).and_return(@<%= file_name %>)
216 it "should assign the found <%= class_name %> for the view" do
218 assigns[:<%= file_name %>].should equal(@<%= file_name %>)
222 describe <%= controller_class_name %>Controller, "handling POST /<%= table_name %>" do
225 @<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1", :save => true)
226 <%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
231 post :create, :<%= file_name %> => @params
234 it "should create a new <%= file_name %>" do
235 <%= class_name %>.should_receive(:new).with(@params).and_return(@<%= file_name %>)
239 it "should redirect to the new <%= file_name %>" do
241 response.should redirect_to(<%= table_name.singularize %>_url("1"))
245 describe <%= controller_class_name %>Controller, "handling PUT /<%= table_name %>/1" do
248 @<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1", :update_attributes => true)
249 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
253 put :update, :id => "1"
256 it "should find the <%= file_name %> requested" do
257 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
261 it "should update the found <%= file_name %>" do
262 @<%= file_name %>.should_receive(:update_attributes)
264 assigns(:<%= file_name %>).should equal(@<%= file_name %>)
267 it "should assign the found <%= file_name %> for the view" do
269 assigns(:<%= file_name %>).should equal(@<%= file_name %>)
272 it "should redirect to the <%= file_name %>" do
274 response.should redirect_to(<%= table_name.singularize %>_url("1"))
278 describe <%= controller_class_name %>Controller, "handling DELETE /<%= table_name %>/1" do
281 @<%= file_name %> = mock_model(<%= class_name %>, :destroy => true)
282 <%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
286 delete :destroy, :id => "1"
289 it "should find the <%= file_name %> requested" do
290 <%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
294 it "should call destroy on the found <%= file_name %>" do
295 @<%= file_name %>.should_receive(:destroy)
299 it "should redirect to the <%= table_name %> list" do
301 response.should redirect_to(<%= table_name %>_url)