Add created_at to comment

Fixes diaspora/diaspora#4269
This commit is contained in:
Benjamin Neff 2017-06-05 23:54:13 +02:00
parent d901ceb500
commit 5b22d04626
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
3 changed files with 5 additions and 27 deletions

View file

@ -17,12 +17,6 @@ module DiasporaFederation
# Comment entity creation time
# @return [Time] creation time
property :created_at, :timestamp, default: -> { Time.now.utc }
# Remove "created_at" when no order was received.
# @deprecated TODO: Remove this, this will break compatibility with pods older than 0.6.3.0.
def signature_order
@signature_order || super.tap {|order| order.delete(:created_at) }
end
end
end
end

View file

@ -19,6 +19,7 @@ module DiasporaFederation
<guid>#{data[:guid]}</guid>
<parent_guid>#{parent.guid}</parent_guid>
<text>#{data[:text]}</text>
<created_at>#{data[:created_at].utc.iso8601}</created_at>
<author_signature>#{data[:author_signature]}</author_signature>
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
</comment>
@ -39,7 +40,8 @@ XML
"author",
"guid",
"parent_guid",
"text"
"text",
"created_at"
]
}
JSON
@ -55,23 +57,5 @@ JSON
it_behaves_like "a relayable Entity"
it_behaves_like "a relayable JSON entity"
describe "#created_at" do
it "has a created_at after parse" do
entity = described_class.from_xml(Nokogiri::XML(xml).root)
expect(entity.created_at).to be_within(1).of(Time.now.utc)
end
it "parses the created_at from the xml if it is included and correctly signed" do
created_at = change_time(Time.now.utc) - 60
comment_data = Fabricate.attributes_for(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid)
comment_data[:created_at] = created_at
comment_data[:parent] = parent_entity
comment = described_class.new(comment_data, %i(author guid parent_guid text created_at))
parsed_comment = described_class.from_xml(comment.to_xml)
expect(parsed_comment.created_at).to eq(created_at)
end
end
end
end

View file

@ -107,8 +107,8 @@ shared_examples "a relayable Entity" do
end
it "computes correct signatures for the entity" do
order = described_class.class_props.keys - %i(author_signature parent_author_signature parent created_at)
signed_string = order.map {|name| data[name] }.join(";")
order = described_class.class_props.keys - %i(author_signature parent_author_signature parent)
signed_string = order.map {|name| data[name].is_a?(Time) ? data[name].iso8601 : data[name] }.join(";")
xml = instance.to_xml