Merge pull request #14 from cmrd-senya/relayable-entity-2
Introduce the "Relayable" entity
This commit is contained in:
commit
1b929a6bbf
23 changed files with 81 additions and 122 deletions
|
|
@ -8,6 +8,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "diaspora_federation/entities/relayable"
|
||||||
require "diaspora_federation/entities/profile"
|
require "diaspora_federation/entities/profile"
|
||||||
require "diaspora_federation/entities/person"
|
require "diaspora_federation/entities/person"
|
||||||
require "diaspora_federation/entities/location"
|
require "diaspora_federation/entities/location"
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ module DiasporaFederation
|
||||||
module Entities
|
module Entities
|
||||||
class Comment < Entity
|
class Comment < Entity
|
||||||
property :guid
|
property :guid
|
||||||
property :parent_guid
|
include Relayable
|
||||||
property :parent_author_signature
|
|
||||||
property :author_signature
|
|
||||||
property :text
|
property :text
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ module DiasporaFederation
|
||||||
property :positive
|
property :positive
|
||||||
property :guid
|
property :guid
|
||||||
property :target_type
|
property :target_type
|
||||||
property :parent_guid
|
include Relayable
|
||||||
property :parent_author_signature
|
|
||||||
property :author_signature
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ module DiasporaFederation
|
||||||
module Entities
|
module Entities
|
||||||
class Message < Entity
|
class Message < Entity
|
||||||
property :guid
|
property :guid
|
||||||
property :parent_guid
|
include Relayable
|
||||||
property :parent_author_signature
|
|
||||||
property :author_signature
|
|
||||||
property :text
|
property :text
|
||||||
property :created_at, default: -> { Time.now.utc }
|
property :created_at, default: -> { Time.now.utc }
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,7 @@ module DiasporaFederation
|
||||||
class Participation < Entity
|
class Participation < Entity
|
||||||
property :guid
|
property :guid
|
||||||
property :target_type
|
property :target_type
|
||||||
property :parent_guid
|
include Relayable
|
||||||
property :parent_author_signature
|
|
||||||
property :author_signature
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ module DiasporaFederation
|
||||||
module Entities
|
module Entities
|
||||||
class PollParticipation < Entity
|
class PollParticipation < Entity
|
||||||
property :guid
|
property :guid
|
||||||
property :parent_guid
|
include Relayable
|
||||||
property :parent_author_signature
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
property :poll_answer_guid
|
property :poll_answer_guid
|
||||||
end
|
end
|
||||||
|
|
|
||||||
13
lib/diaspora_federation/entities/relayable.rb
Normal file
13
lib/diaspora_federation/entities/relayable.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
module Relayable
|
||||||
|
def self.included(model)
|
||||||
|
model.class_eval do
|
||||||
|
property :parent_guid
|
||||||
|
property :parent_author_signature
|
||||||
|
property :author_signature
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -34,6 +34,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "diaspora_federation/validators/relayable_validator"
|
||||||
require "diaspora_federation/validators/h_card_validator"
|
require "diaspora_federation/validators/h_card_validator"
|
||||||
require "diaspora_federation/validators/person_validator"
|
require "diaspora_federation/validators/person_validator"
|
||||||
require "diaspora_federation/validators/profile_validator"
|
require "diaspora_federation/validators/profile_validator"
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :parent_guid, :guid
|
include RelayableValidator
|
||||||
|
|
||||||
rule :parent_author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :text, [:not_empty,
|
rule :text, [:not_empty,
|
||||||
length: {maximum: 65_535}]
|
length: {maximum: 65_535}]
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :parent_guid, :guid
|
include RelayableValidator
|
||||||
|
|
||||||
rule :parent_author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :parent_guid, :guid
|
include RelayableValidator
|
||||||
|
|
||||||
rule :parent_author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :target_type, :not_empty
|
rule :target_type, :not_empty
|
||||||
|
|
||||||
rule :parent_guid, :guid
|
include RelayableValidator
|
||||||
|
|
||||||
rule :parent_author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :parent_guid, :guid
|
include RelayableValidator
|
||||||
|
|
||||||
rule :parent_author_signature, :not_empty
|
|
||||||
|
|
||||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||||
|
|
||||||
|
|
|
||||||
11
lib/diaspora_federation/validators/relayable_validator.rb
Normal file
11
lib/diaspora_federation/validators/relayable_validator.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Validators
|
||||||
|
module RelayableValidator
|
||||||
|
def self.included(model)
|
||||||
|
model.class_eval do
|
||||||
|
rule :parent_guid, :guid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -93,15 +93,18 @@ FactoryGirl.define do
|
||||||
width 800
|
width 800
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :participation_entity, class: DiasporaFederation::Entities::Participation do
|
factory :relayable_entity, class: DiasporaFederation::Entities::Relayable do
|
||||||
guid
|
|
||||||
target_type "StatusMessage"
|
|
||||||
parent_guid { generate(:guid) }
|
parent_guid { generate(:guid) }
|
||||||
diaspora_id
|
|
||||||
parent_author_signature { generate(:signature) }
|
parent_author_signature { generate(:signature) }
|
||||||
author_signature { generate(:signature) }
|
author_signature { generate(:signature) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :participation_entity, class: DiasporaFederation::Entities::Participation, parent: :relayable_entity do
|
||||||
|
guid
|
||||||
|
target_type "StatusMessage"
|
||||||
|
diaspora_id
|
||||||
|
end
|
||||||
|
|
||||||
factory :status_message_entity, class: DiasporaFederation::Entities::StatusMessage do
|
factory :status_message_entity, class: DiasporaFederation::Entities::StatusMessage do
|
||||||
raw_message "i am a very interesting status update"
|
raw_message "i am a very interesting status update"
|
||||||
guid
|
guid
|
||||||
|
|
@ -115,22 +118,16 @@ FactoryGirl.define do
|
||||||
recipient_id { generate(:diaspora_id) }
|
recipient_id { generate(:diaspora_id) }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :comment_entity, class: DiasporaFederation::Entities::Comment do
|
factory :comment_entity, class: DiasporaFederation::Entities::Comment, parent: :relayable_entity do
|
||||||
guid
|
guid
|
||||||
parent_guid { generate(:guid) }
|
|
||||||
parent_author_signature { generate(:signature) }
|
|
||||||
author_signature { generate(:signature) }
|
|
||||||
text "this is a very informative comment"
|
text "this is a very informative comment"
|
||||||
diaspora_id
|
diaspora_id
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :like_entity, class: DiasporaFederation::Entities::Like do
|
factory :like_entity, class: DiasporaFederation::Entities::Like, parent: :relayable_entity do
|
||||||
positive 1
|
positive 1
|
||||||
guid
|
guid
|
||||||
target_type "StatusMessage"
|
target_type "StatusMessage"
|
||||||
parent_guid { generate(:guid) }
|
|
||||||
parent_author_signature { generate(:signature) }
|
|
||||||
author_signature { generate(:signature) }
|
|
||||||
diaspora_id
|
diaspora_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -147,11 +144,8 @@ FactoryGirl.define do
|
||||||
participant_ids { 3.times.map { generate(:diaspora_id) }.join(";") }
|
participant_ids { 3.times.map { generate(:diaspora_id) }.join(";") }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :message_entity, class: DiasporaFederation::Entities::Message do
|
factory :message_entity, class: DiasporaFederation::Entities::Message, parent: :relayable_entity do
|
||||||
guid
|
guid
|
||||||
parent_guid { generate(:guid) }
|
|
||||||
parent_author_signature { generate(:signature) }
|
|
||||||
author_signature { generate(:signature) }
|
|
||||||
text "this is a very informative text"
|
text "this is a very informative text"
|
||||||
created_at { DateTime.now.utc }
|
created_at { DateTime.now.utc }
|
||||||
diaspora_id
|
diaspora_id
|
||||||
|
|
@ -200,11 +194,11 @@ FactoryGirl.define do
|
||||||
poll_answers { 3.times.map { FactoryGirl.build(:poll_answer_entity) } }
|
poll_answers { 3.times.map { FactoryGirl.build(:poll_answer_entity) } }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :poll_participation_entity, class: DiasporaFederation::Entities::PollParticipation do
|
factory :poll_participation_entity,
|
||||||
|
class: DiasporaFederation::Entities::PollParticipation,
|
||||||
|
parent: :relayable_entity do
|
||||||
guid
|
guid
|
||||||
parent_guid { generate(:guid) }
|
|
||||||
diaspora_id
|
diaspora_id
|
||||||
parent_author_signature { generate(:signature) }
|
|
||||||
poll_answer_guid { generate(:guid) }
|
poll_answer_guid { generate(:guid) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,26 +15,7 @@ module DiasporaFederation
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<subject>#{data[:subject]}</subject>
|
<subject>#{data[:subject]}</subject>
|
||||||
<created_at>#{data[:created_at]}</created_at>
|
<created_at>#{data[:created_at]}</created_at>
|
||||||
<message>
|
#{data[:messages].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
|
||||||
<guid>#{msg1.guid}</guid>
|
|
||||||
<parent_guid>#{msg1.parent_guid}</parent_guid>
|
|
||||||
<parent_author_signature>#{msg1.parent_author_signature}</parent_author_signature>
|
|
||||||
<author_signature>#{msg1.author_signature}</author_signature>
|
|
||||||
<text>#{msg1.text}</text>
|
|
||||||
<created_at>#{msg1.created_at}</created_at>
|
|
||||||
<diaspora_handle>#{msg1.diaspora_id}</diaspora_handle>
|
|
||||||
<conversation_guid>#{msg1.conversation_guid}</conversation_guid>
|
|
||||||
</message>
|
|
||||||
<message>
|
|
||||||
<guid>#{msg2.guid}</guid>
|
|
||||||
<parent_guid>#{msg2.parent_guid}</parent_guid>
|
|
||||||
<parent_author_signature>#{msg2.parent_author_signature}</parent_author_signature>
|
|
||||||
<author_signature>#{msg2.author_signature}</author_signature>
|
|
||||||
<text>#{msg2.text}</text>
|
|
||||||
<created_at>#{msg2.created_at}</created_at>
|
|
||||||
<diaspora_handle>#{msg2.diaspora_id}</diaspora_handle>
|
|
||||||
<conversation_guid>#{msg2.conversation_guid}</conversation_guid>
|
|
||||||
</message>
|
|
||||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
<participant_handles>#{data[:participant_ids]}</participant_handles>
|
<participant_handles>#{data[:participant_ids]}</participant_handles>
|
||||||
</conversation>
|
</conversation>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ module DiasporaFederation
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
<poll_answer_guid>#{data[:poll_answer_guid]}</poll_answer_guid>
|
<poll_answer_guid>#{data[:poll_answer_guid]}</poll_answer_guid>
|
||||||
</poll_participation>
|
</poll_participation>
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,16 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a common validator"
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
it_behaves_like "a relayable validator"
|
||||||
|
|
||||||
it_behaves_like "a diaspora id validator" do
|
it_behaves_like "a diaspora id validator" do
|
||||||
let(:property) { :diaspora_id }
|
let(:property) { :diaspora_id }
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(guid parent_guid).each do |prop|
|
describe "#guid" do
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
let(:property) { prop }
|
let(:property) { :guid }
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%i(author_signature parent_author_signature).each do |prop|
|
|
||||||
describe "##{prop}" do
|
|
||||||
it_behaves_like "a property that mustn't be empty" do
|
|
||||||
let(:property) { prop }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@ module DiasporaFederation
|
||||||
let(:entity) { :like_entity }
|
let(:entity) { :like_entity }
|
||||||
it_behaves_like "a common validator"
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
%i(guid parent_guid).each do |prop|
|
it_behaves_like "a relayable validator"
|
||||||
it_behaves_like "a guid validator" do
|
|
||||||
let(:property) { prop }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%i(author_signature parent_author_signature).each do |prop|
|
describe "#guid" do
|
||||||
describe "##{prop}" do
|
it_behaves_like "a guid validator" do
|
||||||
it_behaves_like "a property that mustn't be empty" do
|
let(:property) { :guid }
|
||||||
let(:property) { prop }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,19 @@ module DiasporaFederation
|
||||||
let(:entity) { :message_entity }
|
let(:entity) { :message_entity }
|
||||||
it_behaves_like "a common validator"
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
it_behaves_like "a relayable validator"
|
||||||
|
|
||||||
it_behaves_like "a diaspora id validator" do
|
it_behaves_like "a diaspora id validator" do
|
||||||
let(:property) { :diaspora_id }
|
let(:property) { :diaspora_id }
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(guid parent_guid conversation_guid).each do |prop|
|
%i(guid conversation_guid).each do |prop|
|
||||||
describe "##{prop}" do
|
describe "##{prop}" do
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
let(:property) { prop }
|
let(:property) { prop }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(author_signature parent_author_signature).each do |prop|
|
|
||||||
describe "##{prop}" do
|
|
||||||
it_behaves_like "a property that mustn't be empty" do
|
|
||||||
let(:property) { prop }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,24 +4,22 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a common validator"
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
it_behaves_like "a relayable validator"
|
||||||
|
|
||||||
it_behaves_like "a diaspora id validator" do
|
it_behaves_like "a diaspora id validator" do
|
||||||
let(:property) { :diaspora_id }
|
let(:property) { :diaspora_id }
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(guid parent_guid).each do |prop|
|
describe "#guid" do
|
||||||
describe "##{prop}" do
|
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
let(:property) { prop }
|
let(:property) { :guid }
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(target_type author_signature parent_author_signature).each do |prop|
|
describe "#target_type" do
|
||||||
describe "##{prop}" do
|
|
||||||
it_behaves_like "a property that mustn't be empty" do
|
it_behaves_like "a property that mustn't be empty" do
|
||||||
let(:property) { prop }
|
let(:property) { :target_type }
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,23 +4,19 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a common validator"
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
it_behaves_like "a relayable validator"
|
||||||
|
|
||||||
it_behaves_like "a diaspora id validator" do
|
it_behaves_like "a diaspora id validator" do
|
||||||
let(:property) { :diaspora_id }
|
let(:property) { :diaspora_id }
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(guid parent_guid poll_answer_guid).each do |prop|
|
%i(guid poll_answer_guid).each do |prop|
|
||||||
describe "##{prop}" do
|
describe "##{prop}" do
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
let(:property) { prop }
|
let(:property) { prop }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#parent_author_signature" do
|
|
||||||
it_behaves_like "a property that mustn't be empty" do
|
|
||||||
let(:property) { :parent_author_signature }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,14 @@ shared_examples "a common validator" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples "a relayable validator" do
|
||||||
|
describe "#parent_guid" do
|
||||||
|
it_behaves_like "a guid validator" do
|
||||||
|
let(:property) { :parent_guid }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
shared_examples "a property with a value validation/restriction" do
|
shared_examples "a property with a value validation/restriction" do
|
||||||
it "fails if a wrong value is supplied" do
|
it "fails if a wrong value is supplied" do
|
||||||
wrong_values.each do |val|
|
wrong_values.each do |val|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue