parent
71264f90af
commit
deed1c3f3e
6 changed files with 15 additions and 65 deletions
|
|
@ -18,20 +18,13 @@ module DiasporaFederation
|
|||
# @return [String] recipient ID
|
||||
property :recipient, :string, xml_name: :recipient_handle
|
||||
|
||||
# Use only {Contact} for receive
|
||||
# @return [Contact] instance as contact
|
||||
def to_contact
|
||||
Contact.new(author: author, recipient: recipient)
|
||||
end
|
||||
|
||||
# @return [String] string representation of this object
|
||||
def to_s
|
||||
"Request:#{author}:#{recipient}"
|
||||
def initialize(*)
|
||||
raise "Sending Request is not supported anymore! Use Contact instead!"
|
||||
end
|
||||
|
||||
# @return [Retraction] instance
|
||||
def self.from_hash(hash)
|
||||
super.to_contact
|
||||
Contact.new(hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -108,11 +108,6 @@ module DiasporaFederation
|
|||
created_at { Time.now.utc }
|
||||
end
|
||||
|
||||
Fabricator(:request_entity, class_name: DiasporaFederation::Entities::Request) do
|
||||
author { Fabricate.sequence(:diaspora_id) }
|
||||
recipient { Fabricate.sequence(:diaspora_id) }
|
||||
end
|
||||
|
||||
Fabricator(:contact_entity, class_name: DiasporaFederation::Entities::Contact) do
|
||||
author { Fabricate.sequence(:diaspora_id) }
|
||||
recipient { Fabricate.sequence(:diaspora_id) }
|
||||
|
|
|
|||
|
|
@ -62,6 +62,3 @@ require "diaspora_federation/validators/reshare_validator"
|
|||
require "diaspora_federation/validators/retraction_validator"
|
||||
require "diaspora_federation/validators/status_message_validator"
|
||||
require "diaspora_federation/validators/web_finger_validator"
|
||||
|
||||
# deprecated
|
||||
require "diaspora_federation/validators/request_validator"
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
# This validates a {Entities::Request}.
|
||||
# @deprecated The {Entities::Request} will be replaced with {Entities::Contact}.
|
||||
class RequestValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :author, %i(not_empty diaspora_id)
|
||||
rule :recipient, %i(not_empty diaspora_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,30 +1,19 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::Request do
|
||||
let(:data) { Fabricate.attributes_for(:request_entity) }
|
||||
let(:data) { {author: Fabricate.sequence(:diaspora_id), recipient: Fabricate.sequence(:diaspora_id)} }
|
||||
|
||||
let(:xml) { <<-XML }
|
||||
<request>
|
||||
<author>#{data[:author]}</author>
|
||||
<recipient>#{data[:recipient]}</recipient>
|
||||
<sender_handle>#{data[:author]}</sender_handle>
|
||||
<recipient_handle>#{data[:recipient]}</recipient_handle>
|
||||
</request>
|
||||
XML
|
||||
|
||||
let(:string) { "Request:#{data[:author]}:#{data[:recipient]}" }
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
|
||||
describe "#to_contact" do
|
||||
it "copies the attributes to a Contact" do
|
||||
request = Fabricate(:request_entity)
|
||||
contact = request.to_contact
|
||||
|
||||
expect(contact).to be_a(Entities::Contact)
|
||||
expect(contact.author).to eq(request.author)
|
||||
expect(contact.recipient).to eq(request.recipient)
|
||||
expect(contact.following).to be_truthy
|
||||
expect(contact.sharing).to be_truthy
|
||||
describe "#initialize" do
|
||||
it "raises because it is not supported anymore" do
|
||||
expect {
|
||||
Entities::Request.new(data)
|
||||
}.to raise_error RuntimeError, "Sending Request is not supported anymore! Use Contact instead!"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -32,6 +21,10 @@ XML
|
|||
it "parses the xml as a contact" do
|
||||
contact = Entities::Request.from_xml(Nokogiri::XML(xml).root)
|
||||
expect(contact).to be_a(Entities::Contact)
|
||||
expect(contact.author).to eq(data[:author])
|
||||
expect(contact.recipient).to eq(data[:recipient])
|
||||
expect(contact.following).to be_truthy
|
||||
expect(contact.sharing).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::RequestValidator do
|
||||
let(:entity) { :request_entity }
|
||||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
%i(author recipient).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a diaspora* ID validator" do
|
||||
let(:property) { prop }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue