Browse files

simplify generated controller spec

  • Loading branch information...
1 parent 2ddd3f2 commit 3dfe273b90311ea35d51400385caf51de90323f2 @dchelimsky dchelimsky committed Apr 4, 2009
Showing with 11 additions and 51 deletions.
  1. +11 −51 generators/rspec_scaffold/templates/controller_spec.rb
View
62 generators/rspec_scaffold/templates/controller_spec.rb
@@ -7,72 +7,41 @@ def mock_<%= file_name %>(stubs={})
end
describe "GET index" do
-
- it "exposes all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
+ it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
<%= class_name %>.should_receive(:find).with(:all).and_return([mock_<%= file_name %>])
get :index
assigns[:<%= table_name %>].should == [mock_<%= file_name %>]
end
-
- describe "with mime type of xml" do
-
- it "renders all <%= table_name.pluralize %> as xml" do
- <%= class_name %>.should_receive(:find).with(:all).and_return(<%= file_name.pluralize %> = mock("Array of <%= class_name.pluralize %>"))
- <%= file_name.pluralize %>.should_receive(:to_xml).and_return("generated XML")
- get :index, :format => 'xml'
- response.body.should == "generated XML"
- end
-
- end
-
end
describe "GET show" do
-
- it "exposes the requested <%= file_name %> as @<%= file_name %>" do
+ it "assigns the requested <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
get :show, :id => "37"
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
end
-
- describe "with mime type of xml" do
-
- it "renders the requested <%= file_name %> as xml" do
- <%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
- mock_<%= file_name %>.should_receive(:to_xml).and_return("generated XML")
- get :show, :id => "37", :format => 'xml'
- response.body.should == "generated XML"
- end
-
- end
-
end
describe "GET new" do
-
- it "exposes a new <%= file_name %> as @<%= file_name %>" do
+ it "assigns a new <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:new).and_return(mock_<%= file_name %>)
get :new
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
end
-
end
describe "GET edit" do
-
- it "exposes the requested <%= file_name %> as @<%= file_name %>" do
+ it "assigns the requested <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
get :edit, :id => "37"
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
end
-
end
describe "POST create" do
-
+
describe "with valid params" do
-
- it "exposes a newly created <%= file_name %> as @<%= file_name %>" do
+ it "assigns a newly created <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
post :create, :<%= file_name %> => {:these => 'params'}
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
@@ -83,12 +52,10 @@ def mock_<%= file_name %>(stubs={})
post :create, :<%= file_name %> => {}
response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
end
-
end
describe "with invalid params" do
-
- it "exposes a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
+ it "assigns a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.stub!(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
post :create, :<%= file_name %> => {:these => 'params'}
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
@@ -99,22 +66,20 @@ def mock_<%= file_name %>(stubs={})
post :create, :<%= file_name %> => {}
response.should render_template('new')
end
-
end
end
describe "PUT udpate" do
-
+
describe "with valid params" do
-
it "updates the requested <%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
end
- it "exposes the requested <%= file_name %> as @<%= file_name %>" do
+ it "assigns the requested <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
put :update, :id => "1"
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
@@ -125,18 +90,16 @@ def mock_<%= file_name %>(stubs={})
put :update, :id => "1"
response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
end
-
end
describe "with invalid params" do
-
it "updates the requested <%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
end
- it "exposes the <%= file_name %> as @<%= file_name %>" do
+ it "assigns the <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
put :update, :id => "1"
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
@@ -147,13 +110,11 @@ def mock_<%= file_name %>(stubs={})
put :update, :id => "1"
response.should render_template('edit')
end
-
end
-
+
end
describe "DELETE destroy" do
-
it "destroys the requested <%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:destroy)
@@ -165,7 +126,6 @@ def mock_<%= file_name %>(stubs={})
delete :destroy, :id => "1"
response.should redirect_to(<%= table_name %>_url)
end
-
end
end

0 comments on commit 3dfe273

Please sign in to comment.