Do the same generalization for Relayable for validators taking
into account that "author_signature" and "parent_author_signature" are allowed to be empty, actually.
This commit is contained in:
parent
fd1f896d17
commit
b9b5ee6f7d
13 changed files with 47 additions and 69 deletions
|
|
@ -34,6 +34,7 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
require "diaspora_federation/validators/relayable_validator"
|
||||
require "diaspora_federation/validators/h_card_validator"
|
||||
require "diaspora_federation/validators/person_validator"
|
||||
require "diaspora_federation/validators/profile_validator"
|
||||
|
|
|
|||
|
|
@ -5,11 +5,7 @@ module DiasporaFederation
|
|||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :author_signature, :not_empty
|
||||
include RelayableValidator
|
||||
|
||||
rule :text, [:not_empty,
|
||||
length: {maximum: 65_535}]
|
||||
|
|
|
|||
|
|
@ -5,11 +5,7 @@ module DiasporaFederation
|
|||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :author_signature, :not_empty
|
||||
include RelayableValidator
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,11 +5,7 @@ module DiasporaFederation
|
|||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :author_signature, :not_empty
|
||||
include RelayableValidator
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,7 @@ module DiasporaFederation
|
|||
|
||||
rule :target_type, :not_empty
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :author_signature, :not_empty
|
||||
include RelayableValidator
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ module DiasporaFederation
|
|||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
include RelayableValidator
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
|
|
|
|||
11
lib/diaspora_federation/validators/relayable_validator.rb
Normal file
11
lib/diaspora_federation/validators/relayable_validator.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
module RelayableValidator
|
||||
def self.included(model)
|
||||
model.class_eval do
|
||||
rule :parent_guid, :guid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -4,22 +4,16 @@ module DiasporaFederation
|
|||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a relayable validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
%i(guid parent_guid).each do |prop|
|
||||
describe "#guid" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
|
||||
%i(author_signature parent_author_signature).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
let(:property) { :guid }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,11 @@ module DiasporaFederation
|
|||
let(:entity) { :like_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
%i(guid parent_guid).each do |prop|
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
it_behaves_like "a relayable validator"
|
||||
|
||||
%i(author_signature parent_author_signature).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
describe "#guid" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :guid }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,25 +3,19 @@ module DiasporaFederation
|
|||
let(:entity) { :message_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a relayable validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
%i(guid parent_guid conversation_guid).each do |prop|
|
||||
%i(guid conversation_guid).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%i(author_signature parent_author_signature).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,24 +4,22 @@ module DiasporaFederation
|
|||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a relayable validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
%i(guid parent_guid).each do |prop|
|
||||
describe "##{prop}" do
|
||||
describe "#guid" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
let(:property) { :guid }
|
||||
end
|
||||
end
|
||||
|
||||
%i(target_type author_signature parent_author_signature).each do |prop|
|
||||
describe "##{prop}" do
|
||||
describe "#target_type" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
let(:property) { :target_type }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,23 +4,19 @@ module DiasporaFederation
|
|||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a relayable validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
%i(guid parent_guid poll_answer_guid).each do |prop|
|
||||
%i(guid poll_answer_guid).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#parent_author_signature" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { :parent_author_signature }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,6 +16,14 @@ shared_examples "a common validator" do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples "a relayable validator" do
|
||||
describe "#parent_guid" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :parent_guid }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "a property with a value validation/restriction" do
|
||||
it "fails if a wrong value is supplied" do
|
||||
wrong_values.each do |val|
|
||||
|
|
|
|||
Loading…
Reference in a new issue