RS, IZ; Photos might push urls to friends

This commit is contained in:
ilya 2010-07-21 18:02:04 -07:00
parent 5c77ab048e
commit 606fa3353c
4 changed files with 59 additions and 0 deletions

View file

@ -1,6 +1,13 @@
class Album
require 'lib/common'
include MongoMapper::Document
include ROXML
include Diaspora::Webhooks
include Encryptable
xml_reader :name
xml_reader :person, :as => Person
xml_reader :_id
key :name, String
belongs_to :person, :class_name => 'Person'

View file

@ -2,10 +2,21 @@ class Photo < Post
require 'carrierwave/orm/mongomapper'
include MongoMapper::Document
mount_uploader :image, ImageUploader
xml_reader :remote_photo
xml_reader :album_id
key :album_id, ObjectId
belongs_to :album, :class_name => 'Album'
timestamps!
validates_presence_of :album
def remote_photo
image.path
end
def remote_photo= remote_path
image.store! open(remote_path)
end
end

View file

@ -71,6 +71,26 @@ describe Album do
end
end
describe 'serialization' do
before 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
end
it 'should have a name' do
@xml.include?(@album.name).should be true
end
it 'should have an id' do
@xml.include?(@album.id.to_s).should be true
end
end
end

View file

@ -59,4 +59,25 @@ describe Photo do
end
end
describe 'remote photos' do
it 'should write the url on serialization' do
@photo.image = File.open(@fixture_name)
xml = @photo.to_xml.to_s
xml.include?(@photo.image.path).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