Add StatusMessage related entities from the @Raven24's gem.

This makes the testbed pass with this gem.
This commit is contained in:
cmrd Senya 2015-10-23 14:12:45 +03:00
parent 0848ada216
commit 1801de3b52
9 changed files with 173 additions and 0 deletions

View file

@ -1,3 +1,5 @@
require "base64"
require "diaspora_federation/logging"
require "diaspora_federation/callbacks"

View file

@ -10,3 +10,6 @@ end
require "diaspora_federation/entities/profile"
require "diaspora_federation/entities/person"
require "diaspora_federation/entities/location"
require "diaspora_federation/entities/photo"
require "diaspora_federation/entities/status_message"

View file

@ -0,0 +1,9 @@
module DiasporaFederation
module Entities
class Location < Entity
property :address
property :lat
property :lng
end
end
end

View file

@ -0,0 +1,16 @@
module DiasporaFederation
module Entities
class Photo < Entity
property :guid
property :diaspora_id, xml_name: :diaspora_handle
property :public, default: false
property :created_at, default: -> { Time.now.utc }
property :remote_photo_path
property :remote_photo_name
property :text, default: nil
property :status_message_guid
property :height
property :width
end
end
end

View file

@ -0,0 +1,14 @@
module DiasporaFederation
module Entities
class StatusMessage < Entity
property :raw_message
entity :photos, [Entities::Photo], default: []
entity :location, Entities::Location, default: nil
property :guid
property :diaspora_id, xml_name: :diaspora_handle
property :public, default: false
property :created_at, default: -> { Time.now.utc }
property :provider_display_name, default: nil
end
end
end

View file

@ -68,4 +68,23 @@ FactoryGirl.define do
nsfw false
tag_string "#i #love #tags"
end
factory :location_entity, class: DiasporaFederation::Entities::Location do
address "Vienna, Austria"
lat 48.208174.to_s
lng 16.373819.to_s
end
factory :photo_entity, class: DiasporaFederation::Entities::Photo do
guid
diaspora_id
public(true)
created_at { Time.zone.now }
remote_photo_path "https://diaspora.example.tld/uploads/images/"
remote_photo_name "f2a41e9d2db4d9a199c8.jpg"
text "what you see here..."
status_message_guid { guid }
height 480
width 800
end
end

View file

@ -0,0 +1,19 @@
module DiasporaFederation
describe Entities::Location do
let(:data) { FactoryGirl.attributes_for(:location_entity) }
let(:xml) {
<<-XML
<location>
<address>#{data[:address]}</address>
<lat>#{data[:lat]}</lat>
<lng>#{data[:lng]}</lng>
</location>
XML
}
it_behaves_like "an Entity subclass" do
let(:klass) { Entities::Location }
end
end
end

View file

@ -0,0 +1,26 @@
module DiasporaFederation
describe Entities::Photo do
let(:data) { FactoryGirl.attributes_for(:photo_entity) }
let(:xml) {
<<-XML
<photo>
<guid>#{data[:guid]}</guid>
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
<public>#{data[:public]}</public>
<created_at>#{data[:created_at]}</created_at>
<remote_photo_path>#{data[:remote_photo_path]}</remote_photo_path>
<remote_photo_name>#{data[:remote_photo_name]}</remote_photo_name>
<text>#{data[:text]}</text>
<status_message_guid>#{data[:status_message_guid]}</status_message_guid>
<height>#{data[:height]}</height>
<width>#{data[:width]}</width>
</photo>
XML
}
it_behaves_like "an Entity subclass" do
let(:klass) { Entities::Photo }
end
end
end

View file

@ -0,0 +1,65 @@
module DiasporaFederation
describe Entities::StatusMessage do
let(:photo1) { Entities::Photo.new(FactoryGirl.attributes_for(:photo_entity)) }
let(:photo2) { Entities::Photo.new(FactoryGirl.attributes_for(:photo_entity)) }
let(:location) { Entities::Location.new(FactoryGirl.attributes_for(:location_entity)) }
let(:data) {
{
raw_message: "this is such an interesting text",
photos: [photo1, photo2],
location: location,
guid: FactoryGirl.generate(:guid),
diaspora_id: FactoryGirl.generate(:diaspora_id),
public: true,
created_at: Time.zone.now,
provider_display_name: "something"
}
}
let(:xml) {
<<-XML
<status_message>
<raw_message>#{data[:raw_message]}</raw_message>
<photo>
<guid>#{photo1.guid}</guid>
<diaspora_handle>#{photo1.diaspora_id}</diaspora_handle>
<public>#{photo1.public}</public>
<created_at>#{photo1.created_at}</created_at>
<remote_photo_path>#{photo1.remote_photo_path}</remote_photo_path>
<remote_photo_name>#{photo1.remote_photo_name}</remote_photo_name>
<text>#{photo1.text}</text>
<status_message_guid>#{photo1.status_message_guid}</status_message_guid>
<height>#{photo1.height}</height>
<width>#{photo1.width}</width>
</photo>
<photo>
<guid>#{photo2.guid}</guid>
<diaspora_handle>#{photo2.diaspora_id}</diaspora_handle>
<public>#{photo2.public}</public>
<created_at>#{photo2.created_at}</created_at>
<remote_photo_path>#{photo2.remote_photo_path}</remote_photo_path>
<remote_photo_name>#{photo2.remote_photo_name}</remote_photo_name>
<text>#{photo2.text}</text>
<status_message_guid>#{photo2.status_message_guid}</status_message_guid>
<height>#{photo2.height}</height>
<width>#{photo2.width}</width>
</photo>
<location>
<address>#{location.address}</address>
<lat>#{location.lat}</lat>
<lng>#{location.lng}</lng>
</location>
<guid>#{data[:guid]}</guid>
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
<public>#{data[:public]}</public>
<created_at>#{data[:created_at]}</created_at>
<provider_display_name>#{data[:provider_display_name]}</provider_display_name>
</status_message>
XML
}
it_behaves_like "an Entity subclass" do
let(:klass) { Entities::StatusMessage }
end
end
end