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