Skip to content
Extraits de code Groupes Projets
Valider 24f8b33f rédigé par ilya's avatar ilya
Parcourir les fichiers

Tests all pass!

parent 07767e62
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -36,4 +36,7 @@ class Album ...@@ -36,4 +36,7 @@ class Album
photos.each{|p| p.destroy} photos.each{|p| p.destroy}
end end
def propagate_retraction
Retraction.for(self).notify_people
end
end end
...@@ -14,9 +14,15 @@ class Photo < Post ...@@ -14,9 +14,15 @@ class Photo < Post
validates_presence_of :album 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 def remote_photo
puts image.url
User.owner.url.chop + image.url User.owner.url.chop + image.url
end end
......
...@@ -10,7 +10,7 @@ class ImageUploader < CarrierWave::Uploader::Base ...@@ -10,7 +10,7 @@ class ImageUploader < CarrierWave::Uploader::Base
def extension_white_list def extension_white_list
%w(jpg jpeg gif png) %w(jpg jpeg gif png)
end end
version :thumb_small do version :thumb_small do
process :resize_to_fill => [30,30] process :resize_to_fill => [30,30]
end end
......
...@@ -24,16 +24,16 @@ describe Album do ...@@ -24,16 +24,16 @@ describe Album do
it 'should contain photos' do it 'should contain photos' do
album = Album.create(:name => "test collection") album = Album.create(:name => "test collection")
photo = Photo.new(:person => @user) photo = Factory.build(:photo, :person => @user)
album.photos << photo album.photos << photo
album.photos.count.should == 1 album.photos.count.should == 1
end end
it 'should remove all photos on album delete' do it 'should remove all photos on album delete' do
photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now) photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now)
photo_two = Photo.create(: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 = Photo.create(:person => @user, :album => @album, :created_at => Time.now-2) photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-2)
@album.photos += [photo_one, photo_two, photo_three] @album.photos += [photo_one, photo_two, photo_three]
...@@ -45,9 +45,9 @@ describe Album do ...@@ -45,9 +45,9 @@ describe Album do
describe 'traversing' do describe 'traversing' do
before do before do
@album = Album.create(:name => "test collection") @album = Album.create(:name => "test collection")
@photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now) @photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now)
@photo_two = Photo.create(: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 = Photo.create(:person => @user, :album => @album, :created_at => Time.now+2) @photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+2)
@album.photos += [@photo_one, @photo_two, @photo_three] @album.photos += [@photo_one, @photo_two, @photo_three]
end end
...@@ -76,9 +76,6 @@ describe Album do ...@@ -76,9 +76,6 @@ describe Album do
@album.person = @user @album.person = @user
@album.save @album.save
@xml = @album.to_xml.to_s @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 end
it 'should have a person' do it 'should have a person' do
@xml.include?(@album.person.id.to_s).should be true @xml.include?(@album.person.id.to_s).should be true
......
...@@ -5,8 +5,16 @@ describe Photo do ...@@ -5,8 +5,16 @@ describe Photo do
@user = Factory.create(:user) @user = Factory.create(:user)
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' @fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml' @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 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 it 'should save a @photo to GridFS' do
file = File.open(@fixture_name) file = File.open(@fixture_name)
@photo.image = file @photo.image = file
...@@ -60,9 +68,9 @@ describe Photo do ...@@ -60,9 +68,9 @@ describe Photo do
end end
it 'should save a signed @photo to GridFS' do it 'should save a signed @photo to GridFS' do
@photo.image = File.open(@fixture_name) photo = Photo.instantiate(:person => @user, :album => @album, :image => File.open(@fixture_name))
@photo.save.should == true photo.save.should == true
@photo.verify_creator_signature.should be true photo.verify_creator_signature.should be true
end end
end end
...@@ -70,21 +78,15 @@ describe Photo do ...@@ -70,21 +78,15 @@ describe Photo do
describe 'remote photos' do describe 'remote photos' do
it 'should write the url on serialization' do it 'should write the url on serialization' do
@photo.image = File.open(@fixture_name) @photo.image = File.open(@fixture_name)
@photo.image.store!
@photo.save
xml = @photo.to_xml.to_s xml = @photo.to_xml.to_s
xml.include?(@photo.image.url).should be true 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 end
it 'should have an album id on serialization' do it 'should have an album id on serialization' do
@photo.image = File.open(@fixture_name) @photo.image = File.open(@fixture_name)
xml = @photo.to_xml.to_s xml = @photo.to_xml.to_s
xml.include?(@photo.album.id.to_s).should be true 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 end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter