diff --git a/app/models/album.rb b/app/models/album.rb index 3f993a9bfe58ed1ed5a7fcb9ae244bcc7e919c97..1a0a50de322a2b29ede24e34dbae2040a76cebc6 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -36,4 +36,7 @@ class Album photos.each{|p| p.destroy} end + def propagate_retraction + Retraction.for(self).notify_people + end end diff --git a/app/models/photo.rb b/app/models/photo.rb index bfb7c912fa4d5d2fb8e579f84edd64b99d618279..5a5dd1c9010c6540636d38d48bd6761c3578a521 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -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 diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 5009aa9d2a893eebbb76b69a6e80b7b0d359f4f7..460d96abdcbf2d76712fd21c525dd238389fbd0a 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -10,7 +10,7 @@ class ImageUploader < CarrierWave::Uploader::Base def extension_white_list %w(jpg jpeg gif png) end - + version :thumb_small do process :resize_to_fill => [30,30] end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 58dbb0927f01162935257db6763426f632b0d124..df37e02a12497eed7ef60fbbc2f5b0a9a0c168ea 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -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 diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 439e40ce6cea00fa7d3ce67f95d38b2ca2b058db..208fd1d9622353d4e47fdbd75cb1983c7d1bc870 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -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