Can't upload to other people's album

This commit is contained in:
ilya 2010-07-23 16:26:05 -07:00
parent 1c0d5f6e6b
commit 4eccf63fef
4 changed files with 12 additions and 8 deletions

View file

@ -14,7 +14,7 @@ class Album
timestamps! timestamps!
validates_presence_of :name validates_presence_of :name, :person
before_destroy :destroy_photos before_destroy :destroy_photos
after_save :notify_people after_save :notify_people

View file

@ -22,8 +22,12 @@ class Photo < Post
photo photo
end end
after_save :log_inspection after_save :log_save_inspection
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
def validate_album_person
album.person_id == person_id
end
def remote_photo def remote_photo
@remote_photo ||= User.owner.url.chop + image.url @remote_photo ||= User.owner.url.chop + image.url
end end

View file

@ -1,5 +1,6 @@
%h3= @album.name %h3= @album.name
= render "photos/new_photo", :photo => @photo, :album => @album -if mine? @album
= render "photos/new_photo", :photo => @photo, :album => @album
- for photo in @album_photos - for photo in @album_photos
= link_to (image_tag photo.image.url(:thumb_medium)), object_path(photo) = link_to (image_tag photo.image.url(:thumb_medium)), object_path(photo)

View file

@ -3,10 +3,12 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Album do describe Album do
before do before do
@user = Factory.create(:user) @user = Factory.create(:user)
@album = Album.new(:name => "test collection") @album = Album.new(:name => "test collection", :person => @user)
end end
it 'should belong to a person' do it 'should belong to a person' do
@album.person = nil
@album.valid?.should be false
person = Factory.create(:person) person = Factory.create(:person)
@album.person = person @album.person = person
@album.valid?.should be true @album.valid?.should be true
@ -23,7 +25,7 @@ describe Album do
end end
it 'should contain photos' do it 'should contain photos' do
album = Album.create(:name => "test collection") album = Album.create(:name => "test collection", :person => @user)
photo = Factory.build(:photo, :person => @user) photo = Factory.build(:photo, :person => @user)
album.photos << photo album.photos << photo
@ -44,7 +46,6 @@ describe Album do
describe 'traversing' do describe 'traversing' do
before do before do
@album = Album.create(:name => "test collection")
@photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now) @photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now)
@photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+1) @photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+1)
@photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+2) @photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+2)
@ -73,8 +74,6 @@ describe Album do
describe 'serialization' do describe 'serialization' do
before do before do
@album.person = @user
@album.save
@xml = @album.to_xml.to_s @xml = @album.to_xml.to_s
end end
it 'should have a person' do it 'should have a person' do