Skip to content
Browse files

Fixed create when save fails zen-9

  • Loading branch information...
1 parent 8ad121c commit 5a3f9b5ee5b6e8d815ad56c07a16a6c7a2c5f05e @amirci committed Apr 9, 2012
Showing with 19 additions and 17 deletions.
  1. +19 −17 spec/controllers/projects_controller_spec.rb
View
36 spec/controllers/projects_controller_spec.rb
@@ -22,34 +22,38 @@
end
describe '#create' do
- let(:attrib) {{name: 'Super project', description: 'Really super!'}}
- let(:new_project) {stub_model(Project, attrib)}
+ let(:attrib) { Fabricate.attributes_for(:project) }
+ let!(:new_project) { stub_model(Project, attrib) }
let(:create_attrib) {{"name"=>"Super project", "description"=>"Really super!"}}
- # before { Project.stub(:new).and_return(new_project) }
-
context "When create succeeds" do
before do
- # given_saving_new_project(:succeeds)
+ Project.stub(:new).and_return(new_project)
+ given_saving_new_project(:succeeds)
post :create, :format => :json, :project => attrib
end
it { should respond_with(:created) }
it { should respond_with_json({project: new_project}.to_json(except: exceptions)) }
end
- # context "When create fails" do
- # before do
- # # given_saving_new_project(:fails)
- # post :create, :format => :json, :project => attrib
- # end
- #
- # it { should respond_with(:error) }
- # # it { should respond_with_json({project: new_project}.to_json(except: exceptions)) }
- # end
+ context "When create fails" do
+ let(:errors) { {saving: 'Saving failed!'} }
+
+ before do
+ Project.stub(:new).and_return(new_project)
+ given_saving_new_project(:fails)
+ post :create, :format => :json, :project => attrib
+ end
+
+ it { should respond_with(:unprocessable_entity) }
+ it { should respond_with_json({errors: errors}.to_json) }
+ end
def given_saving_new_project(succeeds)
- new_project.should_receive(:save).and_return(succeeds == :succeeds)
+ new_project.stub(:save).and_return(succeeds == :succeeds)
+ new_project.stub(:errors).and_return(errors) if succeeds == :fails
+ new_project.stub(:has_errors?).and_return(succeeds == :succeeds)
end
end
@@ -69,8 +73,6 @@ def given_saving_new_project(succeeds)
end
context "when project does not exist" do
- # before { given_project_is(:not_found) }
-
before { delete :destroy, :format => :json, :id => project.id }
it { should respond_with(:not_found) }

0 comments on commit 5a3f9b5

Please sign in to comment.
Something went wrong with that request. Please try again.