From 14fedf536996c77c9a66bc52eeb3d09b2eae3b43 Mon Sep 17 00:00:00 2001 From: Sarah Mei <sarahmei@gmail.com> Date: Fri, 29 Oct 2010 00:59:26 -0700 Subject: [PATCH] GAHHH STOP EMAILING ME (specs pass) Also, added attr_protected to Photo#person and Photo#person_id. --- app/controllers/dev_utilities_controller.rb | 3 ++- app/controllers/photos_controller.rb | 4 +++- app/models/photo.rb | 8 ++++++-- spec/controllers/photos_controller_spec.rb | 2 +- spec/models/photo_spec.rb | 16 +++++++++++++++- spec/models/user_spec.rb | 2 ++ 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/controllers/dev_utilities_controller.rb b/app/controllers/dev_utilities_controller.rb index 549b25b00f..6318dfb78a 100644 --- a/app/controllers/dev_utilities_controller.rb +++ b/app/controllers/dev_utilities_controller.rb @@ -48,7 +48,8 @@ class DevUtilitiesController < ApplicationController @fixture_name = File.join(File.dirname(__FILE__), "..", "..", "public", "images", "user", "#{username}.jpg") - photo = Photo.new(:person => current_user.person, :album => album) + photo = Photo.new(:album => album) + photo.person = current_user.person photo.image.store! File.open(@fixture_name) photo.save photo.reload diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 1d4faa3108..c0c5851486 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -97,7 +97,9 @@ class PhotosController < ApplicationController respond_with @photo else flash[:error] = I18n.t 'photos.update.error' - render :action => :edit + @album = @photo.album + set_friends_and_status + render :edit end end end diff --git a/app/models/photo.rb b/app/models/photo.rb index 94985e2bf7..afc3fa5838 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -32,12 +32,16 @@ class Photo < Post before_destroy :ensure_user_picture + attr_protected :person + def self.instantiate(params = {}) - image_file = params[:user_file] - params.delete :user_file + image_file = params.delete(:user_file) + person = params.delete(:person) photo = Photo.new(params) + photo.image.store! image_file + photo.person = person photo.save photo end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 0afd2ad9e1..86d8d448c5 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -15,7 +15,7 @@ describe PhotosController do image = File.open(@fixture_name) #@photo = Photo.instantiate( # :person => @user.person, :album => @album, :user_file => image) - @photo = @user.post(:photo, :album_id => @album.id, :user_file => image, :to => @aspect.id) + @photo = @user.post(:photo, :album_id => @album.id, :user_file => image, :to => @aspect.id) sign_in :user, @user end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 1cf1340d40..edc3aecf68 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -14,7 +14,21 @@ describe Photo do @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) @fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml') - @photo = Photo.new(:person => @user.person, :album => @album) + @photo = Photo.new(:album => @album) + @photo.person = @user.person + end + + describe "protected attributes" do + it "doesn't allow mass assignment of person" do + @photo.save! + @photo.update_attributes(:person => Factory(:person)) + @photo.reload.person.should == @user.person + end + it "doesn't allow mass assignment of person_id" do + @photo.save! + @photo.update_attributes(:person_id => Factory(:person).id) + @photo.reload.person.should == @user.person + end end it 'has a constructor' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a9530093f5..17a52afff7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -16,11 +16,13 @@ describe User do describe 'overwriting people' do it 'does not overwrite old users with factory' do + pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!" new_user = Factory.create(:user, :id => user.id) new_user.persisted?.should be_true new_user.id.should_not == user.id end it 'does not overwrite old users with create' do + pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!" params = {:username => "ohai", :email => "ohai@example.com", :password => "password", -- GitLab