add validators for empty arrays

This commit is contained in:
Benjamin Neff 2016-04-29 03:59:24 +02:00
parent 28ab54abef
commit c9d0b978d4
5 changed files with 23 additions and 2 deletions

View file

@ -6,6 +6,8 @@ module DiasporaFederation
rule :guid, :guid rule :guid, :guid
rule :messages, :not_nil
rule :author, %i(not_empty diaspora_id) rule :author, %i(not_empty diaspora_id)
rule :participants, diaspora_id_count: {maximum: 20} rule :participants, diaspora_id_count: {maximum: 20}

View file

@ -8,6 +8,8 @@ module DiasporaFederation
rule :guid, :guid rule :guid, :guid
rule :photos, :not_nil
rule :public, :boolean rule :public, :boolean
end end
end end

View file

@ -13,7 +13,15 @@ module DiasporaFederation
let(:property) { :guid } let(:property) { :guid }
end end
describe "participant_ids" do describe "#messages" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :messages }
let(:wrong_values) { [nil] }
let(:correct_values) { [[], [FactoryGirl.build(:message_entity)]] }
end
end
describe "#participant_ids" do
# must not contain more than 20 participant handles # must not contain more than 20 participant handles
it_behaves_like "a property with a value validation/restriction" do it_behaves_like "a property with a value validation/restriction" do
let(:property) { :participants } let(:property) { :participants }

View file

@ -13,6 +13,14 @@ module DiasporaFederation
let(:property) { :guid } let(:property) { :guid }
end end
describe "#photos" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :photos }
let(:wrong_values) { [nil] }
let(:correct_values) { [[], [FactoryGirl.build(:photo_entity)]] }
end
end
it_behaves_like "a boolean validator" do it_behaves_like "a boolean validator" do
let(:property) { :public } let(:property) { :public }
end end

View file

@ -1,5 +1,6 @@
def entity_stub(entity, data={}) def entity_stub(entity, data={})
OpenStruct.new(FactoryGirl.attributes_for(entity).merge(data)) OpenStruct.new(FactoryGirl.factory_by_name(entity).build_class.default_values
.merge(FactoryGirl.attributes_for(entity)).merge(data))
end end
ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"].freeze ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"].freeze