Add code for event entities
This commit is contained in:
parent
d347c74306
commit
1097130988
9 changed files with 203 additions and 0 deletions
|
|
@ -28,6 +28,10 @@ require "diaspora_federation/entities/poll"
|
||||||
require "diaspora_federation/entities/poll_participation"
|
require "diaspora_federation/entities/poll_participation"
|
||||||
|
|
||||||
require "diaspora_federation/entities/location"
|
require "diaspora_federation/entities/location"
|
||||||
|
|
||||||
|
require "diaspora_federation/entities/event"
|
||||||
|
require "diaspora_federation/entities/event_participation"
|
||||||
|
|
||||||
require "diaspora_federation/entities/photo"
|
require "diaspora_federation/entities/photo"
|
||||||
require "diaspora_federation/entities/status_message"
|
require "diaspora_federation/entities/status_message"
|
||||||
require "diaspora_federation/entities/reshare"
|
require "diaspora_federation/entities/reshare"
|
||||||
|
|
|
||||||
55
lib/diaspora_federation/entities/event.rb
Normal file
55
lib/diaspora_federation/entities/event.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
# This entity represents an event and it is federated as a part of a status message.
|
||||||
|
#
|
||||||
|
# @see Validators::EventValidator
|
||||||
|
class Event < Entity
|
||||||
|
# @!attribute [r] author
|
||||||
|
# The diaspora* ID of the person who created the event
|
||||||
|
# @see Person#author
|
||||||
|
# @return [String] author diaspora* ID
|
||||||
|
property :author, :string
|
||||||
|
|
||||||
|
# @!attribute [r] guid
|
||||||
|
# A random string of at least 16 chars
|
||||||
|
# @see Validation::Rule::Guid
|
||||||
|
# @return [String] guid
|
||||||
|
property :guid, :string
|
||||||
|
|
||||||
|
# @!attribute [r] summary
|
||||||
|
# The summary of the event
|
||||||
|
# @return [String] event summary
|
||||||
|
property :summary, :string
|
||||||
|
|
||||||
|
# @!attribute [r] description
|
||||||
|
# Description of the event
|
||||||
|
# @return [String] event description
|
||||||
|
property :description, :string, default: nil
|
||||||
|
|
||||||
|
# @!attribute [r] start
|
||||||
|
# The start time of the event
|
||||||
|
# @return [String] event start
|
||||||
|
property :start, :timestamp
|
||||||
|
|
||||||
|
# @!attribute [r] end
|
||||||
|
# The end time of the event
|
||||||
|
# @return [String] event end
|
||||||
|
property :end, :timestamp, default: nil
|
||||||
|
|
||||||
|
# @!attribute [r] all_day
|
||||||
|
# Points if the event is an all day event
|
||||||
|
# @return [Boolean] is it an all day event
|
||||||
|
property :all_day, :boolean, default: false
|
||||||
|
|
||||||
|
# @!attribute [r] timezone
|
||||||
|
# Timezone to which the event is fixed to
|
||||||
|
# @return [String] timezone
|
||||||
|
property :timezone, :string, default: nil
|
||||||
|
|
||||||
|
# @!attribute [r] location
|
||||||
|
# Location of the event
|
||||||
|
# @return [Entities::Location] location
|
||||||
|
entity :location, Entities::Location, default: nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
27
lib/diaspora_federation/entities/event_participation.rb
Normal file
27
lib/diaspora_federation/entities/event_participation.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
# This entity represents a participation in an event, i.e. it is issued when a user responds to en event.
|
||||||
|
#
|
||||||
|
# @see Validators::EventParticipationValidator
|
||||||
|
class EventParticipation < Entity
|
||||||
|
# Old signature order
|
||||||
|
# @deprecated
|
||||||
|
LEGACY_SIGNATURE_ORDER = %i(author guid parent_guid status).freeze
|
||||||
|
|
||||||
|
# The {EventParticipation} parent is an {Event}
|
||||||
|
PARENT_TYPE = "Event".freeze
|
||||||
|
|
||||||
|
include Relayable
|
||||||
|
|
||||||
|
# Redefine the author property without +diaspora_handle+ +xml_name+
|
||||||
|
# @deprecated Can be removed after XMLs are generated with new names
|
||||||
|
property :author, :string
|
||||||
|
|
||||||
|
# @!attribute [r] status
|
||||||
|
# The participation status of the user
|
||||||
|
# "accepted", "declined" or "tentative"
|
||||||
|
# @return [String] event participation status
|
||||||
|
property :status, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -26,6 +26,11 @@ module DiasporaFederation
|
||||||
# @return [Entities::Poll] poll
|
# @return [Entities::Poll] poll
|
||||||
entity :poll, Entities::Poll, default: nil
|
entity :poll, Entities::Poll, default: nil
|
||||||
|
|
||||||
|
# @!attribute [r] event
|
||||||
|
# Optional event attached to the status message
|
||||||
|
# @return [Entities::Event] event
|
||||||
|
entity :event, Entities::Event, default: nil
|
||||||
|
|
||||||
# @!attribute [r] public
|
# @!attribute [r] public
|
||||||
# Shows whether the status message is visible to everyone or only to some aspects
|
# Shows whether the status message is visible to everyone or only to some aspects
|
||||||
# @return [Boolean] is it public
|
# @return [Boolean] is it public
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,24 @@ module DiasporaFederation
|
||||||
poll_answer_guid { generate(:guid) }
|
poll_answer_guid { generate(:guid) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :event_entity, class: DiasporaFederation::Entities::Event do
|
||||||
|
author { generate(:diaspora_id) }
|
||||||
|
guid
|
||||||
|
summary "Cool event"
|
||||||
|
description "You need to see this!"
|
||||||
|
start { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) - 1.hour }
|
||||||
|
add_attribute(:end) { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) + 1.hour }
|
||||||
|
all_day false
|
||||||
|
timezone "Europe/Berlin"
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :event_participation_entity,
|
||||||
|
class: DiasporaFederation::Entities::EventParticipation, parent: :relayable_entity do
|
||||||
|
author { generate(:diaspora_id) }
|
||||||
|
guid
|
||||||
|
status "accepted"
|
||||||
|
end
|
||||||
|
|
||||||
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do
|
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do
|
||||||
author { generate(:diaspora_id) }
|
author { generate(:diaspora_id) }
|
||||||
local true
|
local true
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,12 @@ FactoryGirl.define do
|
||||||
after(:create, &:save)
|
after(:create, &:save)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :event, class: Entity do
|
||||||
|
entity_type "Event"
|
||||||
|
author { FactoryGirl.build(:person) }
|
||||||
|
after(:create, &:save)
|
||||||
|
end
|
||||||
|
|
||||||
factory :conversation, class: Entity do
|
factory :conversation, class: Entity do
|
||||||
entity_type "Conversation"
|
entity_type "Conversation"
|
||||||
author { FactoryGirl.build(:person) }
|
author { FactoryGirl.build(:person) }
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::EventParticipation do
|
||||||
|
let(:parent) { FactoryGirl.create(:event, author: bob) }
|
||||||
|
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
||||||
|
let(:data) {
|
||||||
|
add_signatures(
|
||||||
|
FactoryGirl.build(
|
||||||
|
:event_participation_entity,
|
||||||
|
author: alice.diaspora_id,
|
||||||
|
parent_guid: parent.guid,
|
||||||
|
parent: parent_entity
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:xml) { <<-XML }
|
||||||
|
<event_participation>
|
||||||
|
<author>#{data[:author]}</author>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<parent_guid>#{parent.guid}</parent_guid>
|
||||||
|
<status>#{data[:status]}</status>
|
||||||
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
|
</event_participation>
|
||||||
|
XML
|
||||||
|
|
||||||
|
let(:string) { "EventParticipation:#{data[:guid]}:#{parent.guid}" }
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
it_behaves_like "an XML Entity"
|
||||||
|
|
||||||
|
it_behaves_like "a relayable Entity"
|
||||||
|
end
|
||||||
|
end
|
||||||
52
spec/lib/diaspora_federation/entities/event_spec.rb
Normal file
52
spec/lib/diaspora_federation/entities/event_spec.rb
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::Event do
|
||||||
|
let(:location) { FactoryGirl.build(:location_entity) }
|
||||||
|
let(:data) {
|
||||||
|
FactoryGirl.attributes_for(:event_entity).merge(author: alice.diaspora_id, location: location)
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:xml) { <<-XML }
|
||||||
|
<event>
|
||||||
|
<author>#{data[:author]}</author>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<summary>#{data[:summary]}</summary>
|
||||||
|
<description>#{data[:description]}</description>
|
||||||
|
<start>#{data[:start].utc.iso8601}</start>
|
||||||
|
<end>#{data[:end].utc.iso8601}</end>
|
||||||
|
<all_day>#{data[:all_day]}</all_day>
|
||||||
|
<timezone>#{data[:timezone]}</timezone>
|
||||||
|
<location>
|
||||||
|
<address>#{location.address}</address>
|
||||||
|
<lat>#{location.lat}</lat>
|
||||||
|
<lng>#{location.lng}</lng>
|
||||||
|
</location>
|
||||||
|
</event>
|
||||||
|
XML
|
||||||
|
|
||||||
|
let(:string) { "Event:#{data[:guid]}" }
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
it_behaves_like "an XML Entity"
|
||||||
|
|
||||||
|
context "default values" do
|
||||||
|
it "uses default values" do
|
||||||
|
minimal_xml = <<-XML
|
||||||
|
<event>
|
||||||
|
<author>#{data[:author]}</author>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<summary>#{data[:summary]}</summary>
|
||||||
|
<start>#{data[:start].utc.iso8601}</start>
|
||||||
|
</event>
|
||||||
|
XML
|
||||||
|
|
||||||
|
parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML::Document.parse(minimal_xml).root)
|
||||||
|
expect(parsed_instance.end).to be_nil
|
||||||
|
expect(parsed_instance.all_day).to be_falsey
|
||||||
|
expect(parsed_instance.timezone).to be_nil
|
||||||
|
expect(parsed_instance.description).to be_nil
|
||||||
|
expect(parsed_instance.location).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -9,6 +9,7 @@ module DiasporaFederation
|
||||||
photos: [photo1, photo2],
|
photos: [photo1, photo2],
|
||||||
location: location,
|
location: location,
|
||||||
poll: nil,
|
poll: nil,
|
||||||
|
event: nil,
|
||||||
provider_display_name: "something"
|
provider_display_name: "something"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue