commit
3e8b1fa7f2
18 changed files with 231 additions and 24 deletions
|
|
@ -12,6 +12,8 @@ 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"
|
||||||
require "diaspora_federation/entities/photo"
|
require "diaspora_federation/entities/photo"
|
||||||
|
require "diaspora_federation/entities/poll_answer"
|
||||||
|
require "diaspora_federation/entities/poll"
|
||||||
require "diaspora_federation/entities/status_message"
|
require "diaspora_federation/entities/status_message"
|
||||||
require "diaspora_federation/entities/request"
|
require "diaspora_federation/entities/request"
|
||||||
require "diaspora_federation/entities/participation"
|
require "diaspora_federation/entities/participation"
|
||||||
|
|
@ -24,3 +26,4 @@ require "diaspora_federation/entities/relayable_retraction"
|
||||||
require "diaspora_federation/entities/reshare"
|
require "diaspora_federation/entities/reshare"
|
||||||
require "diaspora_federation/entities/retraction"
|
require "diaspora_federation/entities/retraction"
|
||||||
require "diaspora_federation/entities/signed_retraction"
|
require "diaspora_federation/entities/signed_retraction"
|
||||||
|
require "diaspora_federation/entities/poll_participation"
|
||||||
|
|
|
||||||
9
lib/diaspora_federation/entities/poll.rb
Normal file
9
lib/diaspora_federation/entities/poll.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
class Poll < Entity
|
||||||
|
property :guid
|
||||||
|
property :question
|
||||||
|
entity :poll_answers, [Entities::PollAnswer]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
8
lib/diaspora_federation/entities/poll_answer.rb
Normal file
8
lib/diaspora_federation/entities/poll_answer.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
class PollAnswer < Entity
|
||||||
|
property :guid
|
||||||
|
property :answer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
11
lib/diaspora_federation/entities/poll_participation.rb
Normal file
11
lib/diaspora_federation/entities/poll_participation.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
class PollParticipation < Entity
|
||||||
|
property :guid
|
||||||
|
property :parent_guid
|
||||||
|
property :parent_author_signature
|
||||||
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
property :poll_answer_guid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -4,6 +4,7 @@ module DiasporaFederation
|
||||||
property :raw_message
|
property :raw_message
|
||||||
entity :photos, [Entities::Photo], default: []
|
entity :photos, [Entities::Photo], default: []
|
||||||
entity :location, Entities::Location, default: nil
|
entity :location, Entities::Location, default: nil
|
||||||
|
entity :poll, Entities::Poll, default: nil
|
||||||
property :guid
|
property :guid
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
property :public, default: false
|
property :public, default: false
|
||||||
|
|
|
||||||
|
|
@ -52,3 +52,6 @@ require "diaspora_federation/validators/relayable_retraction_validator"
|
||||||
require "diaspora_federation/validators/reshare_validator"
|
require "diaspora_federation/validators/reshare_validator"
|
||||||
require "diaspora_federation/validators/retraction_validator"
|
require "diaspora_federation/validators/retraction_validator"
|
||||||
require "diaspora_federation/validators/signed_retraction_validator"
|
require "diaspora_federation/validators/signed_retraction_validator"
|
||||||
|
require "diaspora_federation/validators/poll_answer_validator"
|
||||||
|
require "diaspora_federation/validators/poll_validator"
|
||||||
|
require "diaspora_federation/validators/poll_participation_validator"
|
||||||
|
|
|
||||||
10
lib/diaspora_federation/validators/poll_answer_validator.rb
Normal file
10
lib/diaspora_federation/validators/poll_answer_validator.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Validators
|
||||||
|
class PollAnswerValidator < Validation::Validator
|
||||||
|
include Validation
|
||||||
|
|
||||||
|
rule :guid, :guid
|
||||||
|
rule :answer, [:not_empty, length: {maximum: 255}]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Validators
|
||||||
|
class PollParticipationValidator < Validation::Validator
|
||||||
|
include Validation
|
||||||
|
|
||||||
|
rule :guid, :guid
|
||||||
|
|
||||||
|
rule :parent_guid, :guid
|
||||||
|
|
||||||
|
rule :parent_author_signature, :not_empty
|
||||||
|
|
||||||
|
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||||
|
|
||||||
|
rule :poll_answer_guid, :guid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
lib/diaspora_federation/validators/poll_validator.rb
Normal file
10
lib/diaspora_federation/validators/poll_validator.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Validators
|
||||||
|
class PollValidator < Validation::Validator
|
||||||
|
include Validation
|
||||||
|
|
||||||
|
rule :guid, :guid
|
||||||
|
rule :question, [:not_empty, length: {maximum: 255}]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -5,6 +5,7 @@ def r_str
|
||||||
end
|
end
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
|
initialize_with { new(attributes) }
|
||||||
sequence(:guid) { UUID.generate :compact }
|
sequence(:guid) { UUID.generate :compact }
|
||||||
sequence(:diaspora_id) {|n| "person-#{n}-#{r_str}@localhost:3000" }
|
sequence(:diaspora_id) {|n| "person-#{n}-#{r_str}@localhost:3000" }
|
||||||
sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
|
sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
|
||||||
|
|
@ -53,8 +54,7 @@ FactoryGirl.define do
|
||||||
url "http://localhost:3000/"
|
url "http://localhost:3000/"
|
||||||
exported_key { generate(:public_key) }
|
exported_key { generate(:public_key) }
|
||||||
profile {
|
profile {
|
||||||
DiasporaFederation::Entities::Profile.new(
|
FactoryGirl.build(:profile_entity, diaspora_id: diaspora_id)
|
||||||
FactoryGirl.attributes_for(:profile_entity, diaspora_id: diaspora_id))
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -188,4 +188,23 @@ FactoryGirl.define do
|
||||||
sender_id { generate(:diaspora_id) }
|
sender_id { generate(:diaspora_id) }
|
||||||
target_author_signature { generate(:signature) }
|
target_author_signature { generate(:signature) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :poll_answer_entity, class: DiasporaFederation::Entities::PollAnswer do
|
||||||
|
guid
|
||||||
|
answer { "Obama is a bicycle" }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :poll_entity, class: DiasporaFederation::Entities::Poll do
|
||||||
|
guid
|
||||||
|
question { "Select an answer" }
|
||||||
|
poll_answers { 3.times.map { FactoryGirl.build(:poll_answer_entity) } }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :poll_participation_entity, class: DiasporaFederation::Entities::PollParticipation do
|
||||||
|
guid
|
||||||
|
parent_guid { generate(:guid) }
|
||||||
|
diaspora_id
|
||||||
|
parent_author_signature { generate(:signature) }
|
||||||
|
poll_answer_guid { generate(:guid) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,12 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe Entities::Conversation do
|
describe Entities::Conversation do
|
||||||
before do
|
let(:msg1) { FactoryGirl.build(:message_entity) }
|
||||||
@datetime = DateTime.now.utc
|
let(:msg2) { FactoryGirl.build(:message_entity) }
|
||||||
end
|
|
||||||
|
|
||||||
let(:msg1) { Entities::Message.new(FactoryGirl.attributes_for(:message_entity)) }
|
|
||||||
let(:msg2) { Entities::Message.new(FactoryGirl.attributes_for(:message_entity)) }
|
|
||||||
let(:data) {
|
let(:data) {
|
||||||
{guid: FactoryGirl.generate(:guid),
|
FactoryGirl.attributes_for(:conversation_entity).merge!(
|
||||||
subject: "very interesting conversation subject",
|
messages: [msg1, msg2],
|
||||||
created_at: @datetime,
|
participant_ids: "#{FactoryGirl.generate(:diaspora_id)};#{FactoryGirl.generate(:diaspora_id)}"
|
||||||
messages: [msg1, msg2],
|
)
|
||||||
diaspora_id: FactoryGirl.generate(:diaspora_id),
|
|
||||||
participant_ids: "#{FactoryGirl.generate(:diaspora_id)};#{FactoryGirl.generate(:diaspora_id)}"}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
|
|
|
||||||
18
spec/lib/diaspora_federation/entities/poll_answer_spec.rb
Normal file
18
spec/lib/diaspora_federation/entities/poll_answer_spec.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::PollAnswer do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:poll_answer_entity) }
|
||||||
|
|
||||||
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
|
<poll_answer>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<answer>#{data[:answer]}</answer>
|
||||||
|
</poll_answer>
|
||||||
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
it_behaves_like "an XML Entity"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::PollParticipation do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:poll_participation_entity) }
|
||||||
|
|
||||||
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
|
<poll_participation>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
||||||
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
|
<poll_answer_guid>#{data[:poll_answer_guid]}</poll_answer_guid>
|
||||||
|
</poll_participation>
|
||||||
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
it_behaves_like "an XML Entity"
|
||||||
|
end
|
||||||
|
end
|
||||||
19
spec/lib/diaspora_federation/entities/poll_spec.rb
Normal file
19
spec/lib/diaspora_federation/entities/poll_spec.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::Poll do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:poll_entity) }
|
||||||
|
|
||||||
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
|
<poll>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<question>#{data[:question]}</question>
|
||||||
|
#{data[:poll_answers].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
|
||||||
|
</poll>
|
||||||
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
it_behaves_like "an XML Entity"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,19 +1,15 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe Entities::StatusMessage do
|
describe Entities::StatusMessage do
|
||||||
let(:photo1) { Entities::Photo.new(FactoryGirl.attributes_for(:photo_entity)) }
|
let(:photo1) { FactoryGirl.build(:photo_entity) }
|
||||||
let(:photo2) { Entities::Photo.new(FactoryGirl.attributes_for(:photo_entity)) }
|
let(:photo2) { FactoryGirl.build(:photo_entity) }
|
||||||
let(:location) { Entities::Location.new(FactoryGirl.attributes_for(:location_entity)) }
|
let(:location) { FactoryGirl.build(:location_entity) }
|
||||||
let(:data) {
|
let(:data) {
|
||||||
{
|
FactoryGirl.attributes_for(:status_message_entity).merge!(
|
||||||
raw_message: "this is such an interesting text",
|
|
||||||
photos: [photo1, photo2],
|
photos: [photo1, photo2],
|
||||||
location: location,
|
location: location,
|
||||||
guid: FactoryGirl.generate(:guid),
|
poll: nil,
|
||||||
diaspora_id: FactoryGirl.generate(:diaspora_id),
|
|
||||||
public: true,
|
|
||||||
created_at: Time.zone.now,
|
|
||||||
provider_display_name: "something"
|
provider_display_name: "something"
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Validators::PollAnswerValidator do
|
||||||
|
let(:entity) { :poll_answer_entity }
|
||||||
|
|
||||||
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
describe "#guid" do
|
||||||
|
it_behaves_like "a guid validator" do
|
||||||
|
let(:property) { :guid }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#answer" do
|
||||||
|
it_behaves_like "a property with a value validation/restriction" do
|
||||||
|
let(:property) { :answer }
|
||||||
|
let(:wrong_values) { [nil, "", "a" * 256] }
|
||||||
|
let(:correct_values) { ["a" * 255] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Validators::PollParticipationValidator do
|
||||||
|
let(:entity) { :poll_participation_entity }
|
||||||
|
|
||||||
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
it_behaves_like "a diaspora id validator" do
|
||||||
|
let(:property) { :diaspora_id }
|
||||||
|
let(:mandatory) { true }
|
||||||
|
end
|
||||||
|
|
||||||
|
%i(guid parent_guid poll_answer_guid).each do |prop|
|
||||||
|
describe "##{prop}" do
|
||||||
|
it_behaves_like "a guid validator" do
|
||||||
|
let(:property) { prop }
|
||||||
|
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
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Validators::PollValidator do
|
||||||
|
let(:entity) { :poll_entity }
|
||||||
|
|
||||||
|
it_behaves_like "a common validator"
|
||||||
|
|
||||||
|
describe "#guid" do
|
||||||
|
it_behaves_like "a guid validator" do
|
||||||
|
let(:property) { :guid }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#question" do
|
||||||
|
it_behaves_like "a property with a value validation/restriction" do
|
||||||
|
let(:property) { :question }
|
||||||
|
let(:wrong_values) { [nil, "", "a" * 256] }
|
||||||
|
let(:correct_values) { ["a" * 255] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue