diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 1563550..32f677b 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -13,7 +13,7 @@ describe ProjectsController do describe 'create' do - context 'with a valid fields' do + context 'with valid fields' do before :each do @subject = FactoryGirl.build(:project) @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers @@ -92,4 +92,51 @@ describe ProjectsController do end end -end + describe 'update' do + + context 'with valid fields' do + before :each do + @subject = FactoryGirl.build(:project) + @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers + + Project.expects(:find).with(@subject.id.to_s).returns(@subject) + Project.any_instance.expects(:update).with(@subject_params).returns(true) + end + + context 'rendering the show' do + before :each do + Project.expects(:exists?).returns(true) + + post :update, :id => @subject.id, :project => @subject_params + end + + it 'should redirect to the show view' do + response.should redirect_to project_path(@subject) + end + end + + context 'without rendering the show view' do + before :each do + post :update, :id => @subject.id, :project => @subject_params + end + + it { should respond_with(:redirect) } + end + end + + context 'with an invalid field' do + before :each do + @subject = FactoryGirl.build(:project) + @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers + + Project.expects(:find).with(@subject.id.to_s).returns(@subject) + Project.any_instance.expects(:update).with(@subject_params).returns(false) + + post :update, :id => @subject.id, :project => @subject_params + end + + it { should render_template(:edit) } + end + end + +end \ No newline at end of file diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1a95be3..0d7f507 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -31,5 +31,32 @@ describe Project do end end end + + describe 'update' do + before :each do + @qt = FactoryGirl.build(:project) + @qt_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers + end + + context 'with valid attributes' do + before :each do + @qt.expects(:save).returns(true) + end + + it 'should return true' do + @qt.update(@qt_params).should eq(true) + end + end + + context 'with invalid attributes' do + before :each do + @qt.expects(:save).returns(false) + end + + it 'should return false' do + @qt.update(@qt_params).should eq(false) + end + end + end end end -- libgit2 0.21.2