Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
@aspect = @user.aspect(:name => "losers")
@album = @user.post :album, :name => "foo", :to => @aspect.id
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
@fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml')
@photo = Photo.new(:person => @user.person, :album => @album)
photo = Photo.instantiate(
:person => @user.person, :album => @album, :user_file => image)
begin
binary = @photo.image.read.force_encoding('BINARY')
fixture_binary = File.open(@fixture_name).read.force_encoding('BINARY')
rescue NoMethodError # Ruby 1.8 doesn't have force_encoding
binary = @photo.image.read
fixture_binary = File.open(@fixture_name).read
end
danielvincent
a validé
it 'must have an album' do
photo.save
photo.valid?.should be false
photo.album = Album.create(:name => "foo", :person => @user.person)
photo.save
Photo.first.album.name.should == 'foo'
end
it 'should have a caption' do
@photo.image.store! File.open(@fixture_name)
@photo.caption = "cool story, bro"
danielvincent
a validé
it 'should remove its reference in user profile if it is referred' do
@photo.image.store! File.open(@fixture_name)
@photo.save
@user.profile.image_url = @photo.image.url(:thumb_medium)
@user.save
danielvincent
a validé
@user.profile.image_url.should == @photo.image.url(:thumb_medium)
danielvincent
a validé
@photo.destroy
danielvincent
a validé
end
it 'should not use the imported filename as the url' do
@photo.image.store! File.open(@fixture_name)
@photo.image.url.include?(@fixture_filename).should be false
@photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false
describe 'non-image files' do
it 'should not store' do
file = File.open(@fail_fixture_name)
@photo.image.should_receive(:check_whitelist!)
lambda {
@photo.image.store! file
}.should raise_error
end
xml.include?(@photo.image.url).should be true
danielvincent
a validé
it 'should have an album id on serialization' do
@photo.image.store! File.open(@fixture_name)
xml.include?(@photo.album_id.to_s).should be true
it 'should set the remote_photo on marshalling' do
maxwell
a validé
pending "did the socket get unstubbed?"
@photo.image.store! File.open(@fixture_name)
maxwell
a validé
#security hax
user2 = Factory.create(:user)
aspect2 = user2.aspect(:name => "foobars")
friend_users(@user, @aspect, user2, aspect2)
@photo.person = user2.person
maxwell
a validé
#@photo.reload
url = @photo.url
thumb_url = @photo.url :thumb_medium
xml = @photo.to_diaspora_xml
id = @photo.id
@photo.destroy
new_photo = Photo.first(:id => id)
new_photo.url.nil?.should be false
new_photo.url.include?(url).should be true
new_photo.url(:thumb_medium).include?(thumb_url).should be true