diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index a3a815f69133d92504f46af691f8d4c3d0556b53..1d4faa310864d71aedaf059ba3916de9f4d86664 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -37,9 +37,7 @@ class PhotosController < ApplicationController params[:user_file] = file - data = clean_hash(params) - - @photo = current_user.post(:photo, data) + @photo = current_user.post(:photo, params) respond_to do |format| format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} @@ -94,9 +92,7 @@ class PhotosController < ApplicationController def update @photo = current_user.find_visible_post_by_id params[:id] - data = clean_hash(params) - - if current_user.update_post( @photo, data[:photo] ) + if current_user.update_post( @photo, params[:photo] ) flash[:notice] = I18n.t 'photos.update.notice' respond_with @photo else @@ -104,21 +100,4 @@ class PhotosController < ApplicationController render :action => :edit end end - - private - def clean_hash(params) - if params[:photo] - return { - :photo => { - :caption => params[:photo][:caption], - } - } - else - return{ - :album_id => params[:album_id], - :user_file => params[:user_file] - } - end - end - end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 90bc9c183ea6fe43a01e0f9967fd8398bdc43822..0afd2ad9e1147f6958cfa46fa484f052db11e504 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' describe PhotosController do - render_views + render_views before do @user = Factory.create(:user) @aspect = @user.aspect(:name => "lame-os") @@ -31,7 +31,7 @@ describe PhotosController do it "doesn't overwrite random attributes" do new_user = Factory.create :user params = { :caption => "now with lasers!", :person_id => new_user.id} - put('update', :id => @photo.id, :photo => params) + put :update, :id => @photo.id, :photo => params @photo.reload.person_id.should == @user.person.id end end