diff --git a/app/models/album.rb b/app/models/album.rb index 7d791c4c8..e7847e033 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -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' diff --git a/app/models/photo.rb b/app/models/photo.rb index 59a72f4cd..f4914cf8a 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -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 diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index def77bacf..58dbb0927 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -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 diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 4baf36a2a..b17192f39 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -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