add created_at to comment entity
this is a preparation for diaspora/diaspora#4269
This commit is contained in:
parent
588e2fc3a2
commit
57ed20719f
3 changed files with 28 additions and 5 deletions
|
|
@ -14,6 +14,11 @@ module DiasporaFederation
|
|||
# @return [String] the comment text
|
||||
property :text
|
||||
|
||||
# @!attribute [r] created_at
|
||||
# comment entity creation time
|
||||
# @return [Time] creation time
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
|
||||
# The {Comment} parent is a Post
|
||||
# @return [String] parent type
|
||||
def parent_type
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ module DiasporaFederation
|
|||
let(:parent) { FactoryGirl.create(:post, author: bob) }
|
||||
let(:data) {
|
||||
FactoryGirl.build(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid).send(:xml_elements)
|
||||
.merge(created_at: Time.now.utc)
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
|
|
@ -20,10 +21,27 @@ XML
|
|||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
it_behaves_like "an XML Entity", [:created_at]
|
||||
|
||||
it_behaves_like "a relayable Entity"
|
||||
|
||||
describe "#created_at" do
|
||||
it "has a created_at after parse" do
|
||||
entity = described_class.from_xml(Nokogiri::XML::Document.parse(xml).root)
|
||||
expect(entity.created_at).to be_within(1.second).of(Time.now.utc)
|
||||
end
|
||||
|
||||
it "parses the created_at from the xml if it is included and correctly signed" do
|
||||
created_at = Time.now.utc - 1.minute
|
||||
comment_data = FactoryGirl.build(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid).to_h
|
||||
comment_data[:created_at] = created_at
|
||||
comment = described_class.new(comment_data, [: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.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#parent_type" do
|
||||
it "returns \"Post\" as parent type" do
|
||||
expect(described_class.new(data).parent_type).to eq("Post")
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ shared_examples "an Entity subclass" do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples "an XML Entity" do
|
||||
shared_examples "an XML Entity" do |ignored_props=[]|
|
||||
let(:instance) { described_class.new(data) }
|
||||
|
||||
describe "#to_xml" do
|
||||
|
|
@ -46,13 +46,13 @@ shared_examples "an XML Entity" do
|
|||
packed_xml = DiasporaFederation::Salmon::XmlPayload.pack(instance)
|
||||
parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(packed_xml)
|
||||
|
||||
check_entity(instance, parsed_instance)
|
||||
check_entity(instance, parsed_instance, ignored_props)
|
||||
end
|
||||
end
|
||||
|
||||
def check_entity(entity, parsed_entity)
|
||||
def check_entity(entity, parsed_entity, ignored_props=[])
|
||||
entity.class.class_props.each do |name, type|
|
||||
validate_values(entity.send(name), parsed_entity.send(name), type)
|
||||
validate_values(entity.send(name), parsed_entity.send(name), type) unless ignored_props.include?(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue