Tests all pass!

This commit is contained in:
ilya 2010-07-22 11:36:32 -07:00
parent 07767e62fe
commit 24f8b33f2f
5 changed files with 32 additions and 24 deletions

View file

@ -36,4 +36,7 @@ class Album
photos.each{|p| p.destroy}
end
def propagate_retraction
Retraction.for(self).notify_people
end
end

View file

@ -14,9 +14,15 @@ class Photo < Post
validates_presence_of :album
def self.instantiate params = {}
image_file = params[:image]
params.delete :image
photo = Photo.new(params)
photo.image.store! image_file
photo
end
def remote_photo
puts image.url
User.owner.url.chop + image.url
end

View file

@ -24,16 +24,16 @@ describe Album do
it 'should contain photos' do
album = Album.create(:name => "test collection")
photo = Photo.new(:person => @user)
photo = Factory.build(:photo, :person => @user)
album.photos << photo
album.photos.count.should == 1
end
it 'should remove all photos on album delete' do
photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now)
photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now-1)
photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now-2)
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_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-2)
@album.photos += [photo_one, photo_two, photo_three]
@ -45,9 +45,9 @@ describe Album do
describe 'traversing' do
before do
@album = Album.create(:name => "test collection")
@photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now)
@photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now+1)
@photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now+2)
@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_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+2)
@album.photos += [@photo_one, @photo_two, @photo_three]
end
@ -76,9 +76,6 @@ describe Album do
@album.person = @user
@album.save
@xml = @album.to_xml.to_s
@photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now)
@photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now+1)
@photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now+2)
end
it 'should have a person' do
@xml.include?(@album.person.id.to_s).should be true

View file

@ -5,8 +5,16 @@ describe Photo do
@user = Factory.create(:user)
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml'
@photo = Photo.new(:person => @user, :album => Album.create(:name => "foo", :person => @user))
@album = Album.create(:name => "foo", :person => @user)
@photo = Photo.new(:person => @user, :album => @album)
end
it 'should have a constructor' do
photo = Photo.instantiate(:person => @user, :album => @album, :image => File.open(@fixture_name))
photo.save.should be true
photo.image.read.nil?.should be false
end
it 'should save a @photo to GridFS' do
file = File.open(@fixture_name)
@photo.image = file
@ -60,9 +68,9 @@ describe Photo do
end
it 'should save a signed @photo to GridFS' do
@photo.image = File.open(@fixture_name)
@photo.save.should == true
@photo.verify_creator_signature.should be true
photo = Photo.instantiate(:person => @user, :album => @album, :image => File.open(@fixture_name))
photo.save.should == true
photo.verify_creator_signature.should be true
end
end
@ -70,21 +78,15 @@ describe Photo do
describe 'remote photos' do
it 'should write the url on serialization' do
@photo.image = File.open(@fixture_name)
@photo.image.store!
@photo.save
xml = @photo.to_xml.to_s
xml.include?(@photo.image.url).should be true
remote_photo = Photo.from_xml xml
@photo.destroy
remote_photo.image.read.nil?.should be false
end
it 'should have an album id on serialization' do
@photo.image = File.open(@fixture_name)
xml = @photo.to_xml.to_s
xml.include?(@photo.album.id.to_s).should be true
remote_photo = Photo.from_xml xml
@photo.destroy
remote_photo.save.should be true
remote_photo.album.nil?.should be false
end
end
end