Commit 779bfbf0662cc73824277de63f50948d0373e108
1 parent
0df7a7c6
Exists in
colab
and in
4 other branches
Project image form field adjusted and unit tests mocked correctly
Showing
3 changed files
with
6 additions
and
8 deletions
Show diff stats
app/controllers/projects_controller.rb
... | ... | @@ -20,7 +20,7 @@ class ProjectsController < ApplicationController |
20 | 20 | # POST /projects |
21 | 21 | # POST /projects.json |
22 | 22 | def create |
23 | - image_url = project_params.delete(:url) | |
23 | + image_url = project_params.delete(:image_url) | |
24 | 24 | @project = Project.new(project_params) |
25 | 25 | respond_to do |format| |
26 | 26 | create_and_redir(format) |
... | ... | @@ -43,7 +43,7 @@ class ProjectsController < ApplicationController |
43 | 43 | |
44 | 44 | def update |
45 | 45 | set_project |
46 | - image_url = project_params.delete(:url) | |
46 | + image_url = project_params.delete(:image_url) | |
47 | 47 | if @project.update(project_params) && @project_image.update(url: image_url) |
48 | 48 | redirect_to(project_path(@project.id)) |
49 | 49 | else | ... | ... |
app/views/projects/_form.html.erb
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | <div class="form-row"> |
18 | 18 | <div class="field-container"> |
19 | 19 | <%= f.label "Image url", class: 'control-label' %><br> |
20 | - <%= f.text_field :url, class: 'text-area', value: @project_image.nil? ? '#' : @project_image.url %> | |
20 | + <%= f.text_field :image_url, class: 'text-area', value: @project_image.nil? ? '#' : @project_image.url %> | |
21 | 21 | </div> |
22 | 22 | </div> |
23 | 23 | </div> | ... | ... |
spec/controllers/projects_controller_spec.rb
... | ... | @@ -195,10 +195,9 @@ describe ProjectsController, :type => :controller do |
195 | 195 | |
196 | 196 | describe 'update' do |
197 | 197 | before do |
198 | - @project_image = FactoryGirl.create(:project_image) | |
199 | - @subject = FactoryGirl.create(:project) | |
198 | + @project_image = FactoryGirl.build(:project_image) | |
199 | + @subject = FactoryGirl.build(:project) | |
200 | 200 | @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] |
201 | - | |
202 | 201 | end |
203 | 202 | |
204 | 203 | context 'when the user is logged in' do |
... | ... | @@ -213,7 +212,6 @@ describe ProjectsController, :type => :controller do |
213 | 212 | @ownerships.expects(:find_by_project_id).with("#{@subject.id}").returns(@ownership) |
214 | 213 | User.any_instance.expects(:project_ownerships).at_least_once.returns(@ownerships) |
215 | 214 | ProjectImage.expects(:find_by_project_id).with(@subject.id).returns(@project_image) |
216 | - | |
217 | 215 | end |
218 | 216 | |
219 | 217 | context 'with valid fields' do |
... | ... | @@ -244,7 +242,7 @@ describe ProjectsController, :type => :controller do |
244 | 242 | |
245 | 243 | context 'with an invalid field' do |
246 | 244 | before :each do |
247 | - #Project.expects(:find).with(@subject.id.to_s).returns(@subject) | |
245 | + Project.expects(:find).with(@subject.id.to_s).returns(@subject) | |
248 | 246 | Project.any_instance.expects(:update).with(@subject_params).returns(false) |
249 | 247 | |
250 | 248 | post :update, :id => @subject.id, :project => @subject_params | ... | ... |