From 24f8b33f2f37b680d60ade77d7ea90992b6e94aa Mon Sep 17 00:00:00 2001 From: ilya <ilya@laptop.(none)> Date: Thu, 22 Jul 2010 11:36:32 -0700 Subject: [PATCH] Tests all pass! --- app/models/album.rb | 3 +++ app/models/photo.rb | 8 +++++++- app/uploaders/image_uploader.rb | 2 +- spec/models/album_spec.rb | 17 +++++++---------- spec/models/photo_spec.rb | 26 ++++++++++++++------------ 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/app/models/album.rb b/app/models/album.rb index 3f993a9bfe..1a0a50de32 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 bfb7c912fa..5a5dd1c901 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 5009aa9d2a..460d96abdc 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 58dbb0927f..df37e02a12 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 439e40ce6c..208fd1d962 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 -- GitLab