3 # This spec was generated by rspec-rails when you ran the scaffold generator.
4 # It demonstrates how one might use RSpec to specify the controller code that
5 # was generated by the Rails when you ran the scaffold generator.
7 describe GoonsController do
9 def mock_goon(stubs={})
10 @mock_goon ||= mock_model(Goon, stubs).as_null_object
13 describe "GET index" do
14 it "assigns all goons as @goons" do
15 Goon.stub(:all) { [mock_goon] }
17 assigns(:goons).should eq([mock_goon])
21 describe "GET show" do
22 it "assigns the requested goon as @goon" do
23 Goon.stub(:find).with("37") { mock_goon }
24 get :show, :id => "37"
25 assigns(:goon).should be(mock_goon)
30 it "assigns a new goon as @goon" do
31 Goon.stub(:new) { mock_goon }
33 assigns(:goon).should be(mock_goon)
37 describe "GET edit" do
38 it "assigns the requested goon as @goon" do
39 Goon.stub(:find).with("37") { mock_goon }
40 get :edit, :id => "37"
41 assigns(:goon).should be(mock_goon)
45 describe "POST create" do
46 describe "with valid params" do
47 it "assigns a newly created goon as @goon" do
48 Goon.stub(:new).with({'these' => 'params'}) { mock_goon(:save => true) }
49 post :create, :goon => {'these' => 'params'}
50 assigns(:goon).should be(mock_goon)
53 it "redirects to the created goon" do
54 Goon.stub(:new) { mock_goon(:save => true) }
55 post :create, :goon => {}
56 response.should redirect_to(goon_url(mock_goon))
60 describe "with invalid params" do
61 it "assigns a newly created but unsaved goon as @goon" do
62 Goon.stub(:new).with({'these' => 'params'}) { mock_goon(:save => false) }
63 post :create, :goon => {'these' => 'params'}
64 assigns(:goon).should be(mock_goon)
67 it "re-renders the 'new' template" do
68 Goon.stub(:new) { mock_goon(:save => false) }
69 post :create, :goon => {}
70 response.should render_template("new")
75 describe "PUT update" do
76 describe "with valid params" do
77 it "updates the requested goon" do
78 Goon.stub(:find).with("37") { mock_goon }
79 mock_goon.should_receive(:update_attributes).with({'these' => 'params'})
80 put :update, :id => "37", :goon => {'these' => 'params'}
83 it "assigns the requested goon as @goon" do
84 Goon.stub(:find) { mock_goon(:update_attributes => true) }
85 put :update, :id => "1"
86 assigns(:goon).should be(mock_goon)
89 it "redirects to the goon" do
90 Goon.stub(:find) { mock_goon(:update_attributes => true) }
91 put :update, :id => "1"
92 response.should redirect_to(goon_url(mock_goon))
96 describe "with invalid params" do
97 it "assigns the goon as @goon" do
98 Goon.stub(:find) { mock_goon(:update_attributes => false) }
99 put :update, :id => "1"
100 assigns(:goon).should be(mock_goon)
103 it "re-renders the 'edit' template" do
104 Goon.stub(:find) { mock_goon(:update_attributes => false) }
105 put :update, :id => "1"
106 response.should render_template("edit")
111 describe "DELETE destroy" do
112 it "destroys the requested goon" do
113 Goon.stub(:find).with("37") { mock_goon }
114 mock_goon.should_receive(:destroy)
115 delete :destroy, :id => "37"
118 it "redirects to the goons list" do
119 Goon.stub(:find) { mock_goon }
120 delete :destroy, :id => "1"
121 response.should redirect_to(goons_url)