Commit 3436fcef
Changed files (1)
spec
controllers
spec/controllers/creations_controller_spec.rb
@@ -6,16 +6,12 @@ describe CreationsController do
let(:user){ Factory.create(:user) }
let(:creation){ Factory.create(:creation) }
- def mock_user(stubs={})
- @mock_user ||= mock_model(User, stubs).as_null_object
- end
-
def mock_creation(stubs={})
@mock_creation ||= mock_model(Creation, stubs).as_null_object
end
before (:each) do
- request.env['warden'] = mock(Warden, :authenticate => mock_user, :authenticate! => mock_user)
+ request.env['warden'] = mock(Warden, :authenticate => user, :authenticate! => user)
end
describe "GET index" do
@@ -45,8 +41,7 @@ describe CreationsController do
describe "GET edit" do
it "assigns the requested creation as @creation" do
- # Creation.stub(:find).with("37") { mock_creation }
- mock_user.stub(:creations){ mock_creation }
+ user.stub(:creations){ mock_creation }
get :edit, :id => "37"
assigns(:creation).should be(mock_creation)
end
@@ -55,15 +50,13 @@ describe CreationsController do
describe "POST create" do
describe "with valid params" do
it "assigns a newly created creation as @creation" do
- # Creation.stub(:new).with({'these' => 'params'}) { mock_creation(:save => true) }
- mock_user.stub(:creations){ mock_creation(:save => true) }
+ user.stub(:creations){ mock_creation(:save => true) }
post :create, :creation => {'these' => 'params'}
assigns(:creation).should be(mock_creation)
end
it "redirects to the created creation" do
- # Creation.stub(:new) { mock_creation(:save => true) }
- mock_user.stub(:creations){ mock_creation(:save => true) }
+ user.stub(:creations){ mock_creation(:save => true) }
post :create, :creation => {}
response.should redirect_to(creation_url(mock_creation))
end
@@ -71,15 +64,13 @@ describe CreationsController do
describe "with invalid params" do
it "assigns a newly created but unsaved creation as @creation" do
- # Creation.stub(:new).with({'these' => 'params'}) { mock_creation(:save => false) }
- mock_user.stub(:creations){ mock_creation(:save => false) }
+ user.stub(:creations){ mock_creation(:save => false) }
post :create, :creation => {'these' => 'params'}
assigns(:creation).should be(mock_creation)
end
it "re-renders the 'new' template" do
- # Creation.stub(:new) { mock_creation(:save => false) }
- mock_user.stub(:creations){ mock_creation(:save => false) }
+ user.stub(:creations){ mock_creation(:save => false) }
post :create, :creation => {}
response.should render_template("new")
end
@@ -89,23 +80,20 @@ describe CreationsController do
describe "PUT update" do
describe "with valid params" do
it "updates the requested creation" do
- # Creation.stub(:find).with("37") { mock_creation }
- mock_user.stub(:creations){ mock_creation }
+ user.stub(:creations){ mock_creation }
mock_creation.should_receive(:update_attributes).with({'these' => 'params', 'category_ids' => []})
put :update, :id => "37", :creation => {'these' => 'params'}
end
it "assigns the requested creation as @creation" do
- # Creation.stub(:find) { mock_creation(:update_attributes => true) }
creation = mock_creation(:update_attributes => true, :category_ids => [])
- mock_user.stub(:creations){ creation }
+ user.stub(:creations){ creation }
put :update, :id => "1", :creation => { :category_ids => [] }
assigns(:creation).should be(creation)
end
it "redirects to the creation" do
- # Creation.stub(:find) { mock_creation(:update_attributes => true) }
- mock_user.stub(:creations){ mock_creation(:update_attributes => true) }
+ user.stub(:creations){ mock_creation(:update_attributes => true) }
put :update, :id => "1", :creation => { :category_ids => [] }
response.should redirect_to(creation_url(mock_creation))
end
@@ -113,15 +101,13 @@ describe CreationsController do
describe "with invalid params" do
it "assigns the creation as @creation" do
- mock_user.stub(:creations){ mock_creation(:update_attributes => false) }
- # Creation.stub(:find) { mock_creation(:update_attributes => false) }
+ user.stub(:creations){ mock_creation(:update_attributes => false) }
put :update, :id => "1", :creation => { :category_ids => [] }
assigns(:creation).should be(mock_creation)
end
it "re-renders the 'edit' template" do
- mock_user.stub(:creations){ mock_creation(:update_attributes => false) }
- # Creation.stub(:find) { mock_creation(:update_attributes => false) }
+ user.stub(:creations){ mock_creation(:update_attributes => false) }
put :update, :id => "1", :creation => { :category_ids => [] }
response.should render_template("edit")
end
@@ -130,14 +116,13 @@ describe CreationsController do
describe "DELETE destroy" do
it "destroys the requested creation" do
-# Creation.stub(:find).with("37") { mock_creation }
- mock_user.stub(:creations){ mock_creation }
+ user.stub(:creations){ mock_creation }
mock_creation.should_receive(:destroy)
delete :destroy, :id => "37"
end
it "redirects to the creations list" do
- Creation.stub(:find) { mock_creation }
+ user.stub(:creations){ mock_creation }
delete :destroy, :id => "1"
response.should redirect_to(creations_url)
end