Commit a48fe5f383cb6712d739f7bce562874415f7dbb8
Committed by
Rafael Manzo
1 parent
fc4da177
Exists in
colab
and in
4 other branches
project model update method Unit tests
Showing
2 changed files
with
76 additions
and
2 deletions
Show diff stats
spec/controllers/projects_controller_spec.rb
| ... | ... | @@ -13,7 +13,7 @@ describe ProjectsController do |
| 13 | 13 | |
| 14 | 14 | describe 'create' do |
| 15 | 15 | |
| 16 | - context 'with a valid fields' do | |
| 16 | + context 'with valid fields' do | |
| 17 | 17 | before :each do |
| 18 | 18 | @subject = FactoryGirl.build(:project) |
| 19 | 19 | @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 |
| 92 | 92 | end |
| 93 | 93 | end |
| 94 | 94 | |
| 95 | -end | |
| 95 | + describe 'update' do | |
| 96 | + | |
| 97 | + context 'with valid fields' do | |
| 98 | + before :each do | |
| 99 | + @subject = FactoryGirl.build(:project) | |
| 100 | + @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 | |
| 101 | + | |
| 102 | + Project.expects(:find).with(@subject.id.to_s).returns(@subject) | |
| 103 | + Project.any_instance.expects(:update).with(@subject_params).returns(true) | |
| 104 | + end | |
| 105 | + | |
| 106 | + context 'rendering the show' do | |
| 107 | + before :each do | |
| 108 | + Project.expects(:exists?).returns(true) | |
| 109 | + | |
| 110 | + post :update, :id => @subject.id, :project => @subject_params | |
| 111 | + end | |
| 112 | + | |
| 113 | + it 'should redirect to the show view' do | |
| 114 | + response.should redirect_to project_path(@subject) | |
| 115 | + end | |
| 116 | + end | |
| 117 | + | |
| 118 | + context 'without rendering the show view' do | |
| 119 | + before :each do | |
| 120 | + post :update, :id => @subject.id, :project => @subject_params | |
| 121 | + end | |
| 122 | + | |
| 123 | + it { should respond_with(:redirect) } | |
| 124 | + end | |
| 125 | + end | |
| 126 | + | |
| 127 | + context 'with an invalid field' do | |
| 128 | + before :each do | |
| 129 | + @subject = FactoryGirl.build(:project) | |
| 130 | + @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 | |
| 131 | + | |
| 132 | + Project.expects(:find).with(@subject.id.to_s).returns(@subject) | |
| 133 | + Project.any_instance.expects(:update).with(@subject_params).returns(false) | |
| 134 | + | |
| 135 | + post :update, :id => @subject.id, :project => @subject_params | |
| 136 | + end | |
| 137 | + | |
| 138 | + it { should render_template(:edit) } | |
| 139 | + end | |
| 140 | + end | |
| 141 | + | |
| 142 | +end | |
| 96 | 143 | \ No newline at end of file | ... | ... |
spec/models/project_spec.rb
| ... | ... | @@ -31,5 +31,32 @@ describe Project do |
| 31 | 31 | end |
| 32 | 32 | end |
| 33 | 33 | end |
| 34 | + | |
| 35 | + describe 'update' do | |
| 36 | + before :each do | |
| 37 | + @qt = FactoryGirl.build(:project) | |
| 38 | + @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 | |
| 39 | + end | |
| 40 | + | |
| 41 | + context 'with valid attributes' do | |
| 42 | + before :each do | |
| 43 | + @qt.expects(:save).returns(true) | |
| 44 | + end | |
| 45 | + | |
| 46 | + it 'should return true' do | |
| 47 | + @qt.update(@qt_params).should eq(true) | |
| 48 | + end | |
| 49 | + end | |
| 50 | + | |
| 51 | + context 'with invalid attributes' do | |
| 52 | + before :each do | |
| 53 | + @qt.expects(:save).returns(false) | |
| 54 | + end | |
| 55 | + | |
| 56 | + it 'should return false' do | |
| 57 | + @qt.update(@qt_params).should eq(false) | |
| 58 | + end | |
| 59 | + end | |
| 60 | + end | |
| 34 | 61 | end |
| 35 | 62 | end | ... | ... |