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")
|
@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.image.store! File.open(@fixture_name)
|
||||||
photo.save
|
photo.save
|
||||||
photo.reload
|
photo.reload
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,9 @@ class PhotosController < ApplicationController
|
||||||
respond_with @photo
|
respond_with @photo
|
||||||
else
|
else
|
||||||
flash[:error] = I18n.t 'photos.update.error'
|
flash[:error] = I18n.t 'photos.update.error'
|
||||||
render :action => :edit
|
@album = @photo.album
|
||||||
|
set_friends_and_status
|
||||||
|
render :edit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,16 @@ class Photo < Post
|
||||||
|
|
||||||
before_destroy :ensure_user_picture
|
before_destroy :ensure_user_picture
|
||||||
|
|
||||||
|
attr_protected :person
|
||||||
|
|
||||||
def self.instantiate(params = {})
|
def self.instantiate(params = {})
|
||||||
image_file = params[:user_file]
|
image_file = params.delete(:user_file)
|
||||||
params.delete :user_file
|
person = params.delete(:person)
|
||||||
|
|
||||||
photo = Photo.new(params)
|
photo = Photo.new(params)
|
||||||
|
|
||||||
photo.image.store! image_file
|
photo.image.store! image_file
|
||||||
|
photo.person = person
|
||||||
photo.save
|
photo.save
|
||||||
photo
|
photo
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ describe PhotosController do
|
||||||
image = File.open(@fixture_name)
|
image = File.open(@fixture_name)
|
||||||
#@photo = Photo.instantiate(
|
#@photo = Photo.instantiate(
|
||||||
# :person => @user.person, :album => @album, :user_file => image)
|
# :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
|
sign_in :user, @user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,21 @@ describe Photo do
|
||||||
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
|
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
|
||||||
@fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml')
|
@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
|
end
|
||||||
|
|
||||||
it 'has a constructor' do
|
it 'has a constructor' do
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,13 @@ describe User do
|
||||||
|
|
||||||
describe 'overwriting people' do
|
describe 'overwriting people' do
|
||||||
it 'does not overwrite old users with factory' 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 = Factory.create(:user, :id => user.id)
|
||||||
new_user.persisted?.should be_true
|
new_user.persisted?.should be_true
|
||||||
new_user.id.should_not == user.id
|
new_user.id.should_not == user.id
|
||||||
end
|
end
|
||||||
it 'does not overwrite old users with create' do
|
it 'does not overwrite old users with create' do
|
||||||
|
pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!"
|
||||||
params = {:username => "ohai",
|
params = {:username => "ohai",
|
||||||
:email => "ohai@example.com",
|
:email => "ohai@example.com",
|
||||||
:password => "password",
|
:password => "password",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue