Skip to content
Extraits de code Groupes Projets
Valider ac45960b rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Fixed album spec, condensed traversing tests to halve the time of the spec (It...

Fixed album spec, condensed traversing tests to halve the time of the spec (It was reading the photos from disk on every spec)
parent 86582763
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper' ...@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Album do describe Album do
before do before do
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
@user = Factory.create(:user) @user = Factory.create(:user)
@album = Album.new(:name => "test collection", :person => @user) @album = Album.new(:name => "test collection", :person => @user)
end end
...@@ -33,11 +34,13 @@ describe Album do ...@@ -33,11 +34,13 @@ describe Album do
end end
it 'should remove all photos on album delete' do it 'should remove all photos on album delete' do
photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now) photos = []
photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-1) 1.upto 3 do
photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-2) photo = Photo.new(:person => @user, :album => @album, :created_at => Time.now)
photo.image.store! File.open @fixture_name
@album.photos += [photo_one, photo_two, photo_three] photos << photo
end
@album.photos += photos
Photo.all.count.should == 3 Photo.all.count.should == 3
@album.destroy @album.destroy
...@@ -46,29 +49,28 @@ describe Album do ...@@ -46,29 +49,28 @@ describe Album do
describe 'traversing' do describe 'traversing' do
before do before do
@photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now) @photos = []
@photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+1) 1.upto 3 do |n|
@photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+2) photo = Photo.new(:person => @user, :album => @album, :created_at => Time.now + n)
photo.image.store! File.open @fixture_name
@album.photos += [@photo_one, @photo_two, @photo_three] @photos << photo
end
it 'should retrieve the next photo relative to a given photo' do
@album.next_photo(@photo_two).id.should == @photo_three.id
end
it 'should retrieve the previous photo relative to a given photo' do
@album.prev_photo(@photo_two).id.should == @photo_one.id
end
describe 'wrapping' do
it 'does next photo of last to first' do
@album.next_photo(@photo_three).id.should == @photo_one.id
end
it 'does previous photo of first to last' do
@album.prev_photo(@photo_one).id.should == @photo_three.id
end end
@album.photos += @photos
end
it 'should traverse the album correctly' do
#should retrieve the next photo relative to a given photo
@album.next_photo(@photos[1]).id.should == @photos[2].id
#should retrieve the previous photo relative to a given photo
@album.prev_photo(@photos[1]).id.should == @photos[0].id
#wrapping
#does next photo of last to first
@album.next_photo(@photos[2]).id.should == @photos[0].id
#does previous photo of first to last
@album.prev_photo(@photos[0]).id.should == @photos[2].id
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