Validate Conversation subject
also reordered fields of Conversation
This commit is contained in:
parent
4136fb973e
commit
0980294a0d
4 changed files with 24 additions and 16 deletions
|
|
@ -4,6 +4,12 @@ module DiasporaFederation
|
|||
#
|
||||
# @see Validators::ConversationValidator
|
||||
class Conversation < Entity
|
||||
# @!attribute [r] author
|
||||
# The diaspora* ID of the person initiated the conversation
|
||||
# @see Person#author
|
||||
# @return [String] diaspora* ID
|
||||
property :author, xml_name: :diaspora_handle
|
||||
|
||||
# @!attribute [r] guid
|
||||
# A random string of at least 16 chars
|
||||
# @see Validation::Rule::Guid
|
||||
|
|
@ -18,21 +24,15 @@ module DiasporaFederation
|
|||
# @return [Time] Conversation creation time
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
|
||||
# @!attribute [r] messages
|
||||
# @return [[Entities::Message]] Messages of this conversation
|
||||
entity :messages, [Entities::Message], default: []
|
||||
|
||||
# @!attribute [r] author
|
||||
# The diaspora* ID of the person initiated the conversation
|
||||
# @see Person#author
|
||||
# @return [String] diaspora* ID
|
||||
property :author, xml_name: :diaspora_handle
|
||||
|
||||
# @!attribute [r] participants
|
||||
# The diaspora* IDs of the persons participating the conversation separated by ";"
|
||||
# @return [String] participants diaspora* IDs
|
||||
property :participants, xml_name: :participant_handles
|
||||
|
||||
# @!attribute [r] messages
|
||||
# @return [[Entities::Message]] Messages of this conversation
|
||||
entity :messages, [Entities::Message], default: []
|
||||
|
||||
private
|
||||
|
||||
def validate
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ module DiasporaFederation
|
|||
class ConversationValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :author, %i(not_empty diaspora_id)
|
||||
rule :guid, :guid
|
||||
|
||||
rule :messages, :not_nil
|
||||
|
||||
rule :author, %i(not_empty diaspora_id)
|
||||
rule :subject, [:not_empty, length: {maximum: 255}]
|
||||
|
||||
rule :participants, diaspora_id_count: {maximum: 20}
|
||||
rule :messages, :not_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ module DiasporaFederation
|
|||
let(:xml) {
|
||||
<<-XML
|
||||
<conversation>
|
||||
<diaspora_handle>#{data[:author]}</diaspora_handle>
|
||||
<guid>#{parent.guid}</guid>
|
||||
<subject>#{data[:subject]}</subject>
|
||||
<created_at>#{data[:created_at]}</created_at>
|
||||
#{data[:messages].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
|
||||
<diaspora_handle>#{data[:author]}</diaspora_handle>
|
||||
<participant_handles>#{data[:participants]}</participant_handles>
|
||||
#{data[:messages].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
|
||||
</conversation>
|
||||
XML
|
||||
}
|
||||
|
|
@ -41,10 +41,10 @@ XML
|
|||
let(:minimal_xml) {
|
||||
<<-XML
|
||||
<conversation>
|
||||
<author>#{data[:author]}</author>
|
||||
<guid>#{parent.guid}</guid>
|
||||
<subject>#{data[:subject]}</subject>
|
||||
<created_at>#{data[:created_at]}</created_at>
|
||||
<author>#{data[:author]}</author>
|
||||
<participant_handles>#{data[:participants]}</participant_handles>
|
||||
</conversation>
|
||||
XML
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@ module DiasporaFederation
|
|||
let(:property) { :guid }
|
||||
end
|
||||
|
||||
describe "#subject" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :subject }
|
||||
let(:wrong_values) { [nil, "", "a" * 256] }
|
||||
let(:correct_values) { ["a" * 255] }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#messages" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :messages }
|
||||
|
|
|
|||
Loading…
Reference in a new issue