GAHHH STOP EMAILING ME (specs pass)
Also, added attr_protected to Photo#person and Photo#person_id.
This commit is contained in:
parent
f1ae95fac9
commit
14fedf5369
6 changed files with 29 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue