Remove not_nil for diaspora IDs from validators
The diaspora ID validator now is not nil by default. Also: * mark root_author as optional for reshares. * make author for profiles mandatory (I don't remember why this was optional, we never generate a profile without author and we wouldn't receive a profile without author anyway, because we validate that the author is the sender). * refactor validator specs for diaspora IDs
This commit is contained in:
parent
5e3f510a88
commit
e663a65c7e
30 changed files with 28 additions and 40 deletions
|
|
@ -10,7 +10,7 @@ module DiasporaFederation
|
||||||
# The diaspora* ID of the person who posted the original post
|
# The diaspora* ID of the person who posted the original post
|
||||||
# @see Person#author
|
# @see Person#author
|
||||||
# @return [String] diaspora* ID
|
# @return [String] diaspora* ID
|
||||||
property :root_author, :string, xml_name: :root_diaspora_id
|
property :root_author, :string, optional: true, xml_name: :root_diaspora_id
|
||||||
|
|
||||||
# @!attribute [r] root_guid
|
# @!attribute [r] root_guid
|
||||||
# Guid of the original post
|
# Guid of the original post
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class AccountDeletionValidator < OptionalAwareValidator
|
class AccountDeletionValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class AccountMigrationValidator < OptionalAwareValidator
|
class AccountMigrationValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
|
|
||||||
rule :profile, :not_nil
|
rule :profile, :not_nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ module DiasporaFederation
|
||||||
class ContactValidator < OptionalAwareValidator
|
class ContactValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
rule :recipient, %i[not_empty diaspora_id]
|
rule :recipient, :diaspora_id
|
||||||
rule :following, :boolean
|
rule :following, :boolean
|
||||||
rule :sharing, :boolean
|
rule :sharing, :boolean
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class ConversationValidator < OptionalAwareValidator
|
class ConversationValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :subject, [:not_empty, length: {maximum: 255}]
|
rule :subject, [:not_empty, length: {maximum: 255}]
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class EventValidator < OptionalAwareValidator
|
class EventValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class MessageValidator < OptionalAwareValidator
|
class MessageValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
rule :conversation_guid, :guid
|
rule :conversation_guid, :guid
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class ParticipationValidator < OptionalAwareValidator
|
class ParticipationValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
rule :parent_guid, :guid
|
rule :parent_guid, :guid
|
||||||
rule :parent_type, [:not_empty, regular_expression: {regex: /\APost\z/}]
|
rule :parent_type, [:not_empty, regular_expression: {regex: /\APost\z/}]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
|
|
||||||
rule :url, %i[not_nil URI]
|
rule :url, %i[not_nil URI]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
|
|
||||||
rule :public, :boolean
|
rule :public, :boolean
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class RelatedEntityValidator < Validation::Validator
|
class RelatedEntityValidator < Validation::Validator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
rule :local, :boolean
|
rule :local, :boolean
|
||||||
rule :public, :boolean
|
rule :public, :boolean
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module DiasporaFederation
|
||||||
# @param [Validation::Validator] validator the validator in which it is included
|
# @param [Validation::Validator] validator the validator in which it is included
|
||||||
def self.included(validator)
|
def self.included(validator)
|
||||||
validator.class_eval do
|
validator.class_eval do
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
rule :parent_guid, :guid
|
rule :parent_guid, :guid
|
||||||
rule :parent, :not_nil
|
rule :parent, :not_nil
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :root_guid, :guid
|
rule :root_guid, :guid
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class RetractionValidator < OptionalAwareValidator
|
class RetractionValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
|
|
||||||
rule :target_guid, :guid
|
rule :target_guid, :guid
|
||||||
rule :target_type, :not_empty
|
rule :target_type, :not_empty
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
class StatusMessageValidator < OptionalAwareValidator
|
class StatusMessageValidator < OptionalAwareValidator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, :diaspora_id
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#person" do
|
describe "#person" do
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ module DiasporaFederation
|
||||||
describe "##{prop}" do
|
describe "##{prop}" do
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { prop }
|
let(:property) { prop }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#guid" do
|
describe "#guid" do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#guid" do
|
describe "#guid" do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#guid" do
|
describe "#guid" do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { false }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
%i[first_name last_name].each do |prop|
|
%i[first_name last_name].each do |prop|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
%i[local public].each do |prop|
|
%i[local public].each do |prop|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
describe "#author" do
|
describe "#author" do
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -23,9 +22,10 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#root_author" do
|
describe "#root_author" do
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a property with a value validation/restriction" do
|
||||||
let(:property) { :root_author }
|
let(:property) { :root_author }
|
||||||
let(:mandatory) { false }
|
let(:wrong_values) { ["i am a weird diaspora* ID @@@ ### 12345"] }
|
||||||
|
let(:correct_values) { [nil, "alice@example.org"] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#target_type" do
|
describe "#target_type" do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ module DiasporaFederation
|
||||||
|
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ end
|
||||||
shared_examples "a relayable validator" do
|
shared_examples "a relayable validator" do
|
||||||
it_behaves_like "a diaspora* ID validator" do
|
it_behaves_like "a diaspora* ID validator" do
|
||||||
let(:property) { :author }
|
let(:property) { :author }
|
||||||
let(:mandatory) { true }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#guid" do
|
describe "#guid" do
|
||||||
|
|
@ -74,16 +73,18 @@ shared_examples "a diaspora* ID validator" do
|
||||||
[nil, ""].each do |val|
|
[nil, ""].each do |val|
|
||||||
validator = described_class.new(entity_stub(entity, property => val))
|
validator = described_class.new(entity_stub(entity, property => val))
|
||||||
|
|
||||||
if mandatory
|
expect(validator).not_to be_valid
|
||||||
expect(validator).not_to be_valid
|
expect(validator.errors).to include(property)
|
||||||
expect(validator.errors).to include(property)
|
|
||||||
else
|
|
||||||
expect(validator).to be_valid
|
|
||||||
expect(validator.errors).to be_empty
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "validates a well-formed diaspora* ID" do
|
||||||
|
validator = described_class.new(entity_stub(entity, property => "alice@example.org"))
|
||||||
|
|
||||||
|
expect(validator).to be_valid
|
||||||
|
expect(validator.errors).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
it "must be a valid diaspora* ID" do
|
it "must be a valid diaspora* ID" do
|
||||||
validator = described_class.new(entity_stub(entity, property => "i am a weird diaspora* ID @@@ ### 12345"))
|
validator = described_class.new(entity_stub(entity, property => "i am a weird diaspora* ID @@@ ### 12345"))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue