Add tests for integer and timestamp parsing

This commit is contained in:
Benjamin Neff 2017-01-09 23:58:00 +01:00
parent b34b18759f
commit ef21f5c0d6
2 changed files with 36 additions and 0 deletions

View file

@ -38,6 +38,14 @@ module DiasporaFederation
class TestEntityWithBoolean < DiasporaFederation::Entity
property :test, :boolean
end
class TestEntityWithInteger < DiasporaFederation::Entity
property :test, :integer
end
class TestEntityWithTimestamp < DiasporaFederation::Entity
property :test, :timestamp
end
end
module Validators

View file

@ -218,6 +218,34 @@ XML
}.to raise_error Entity::ValidationError, "missing required properties: test"
end
end
it "parses integer fields with a randomly matching pattern as erroneous" do
%w(1,2,3 foobar two).each do |weird_value|
xml = <<-XML.strip
<test_entity_with_integer>
<test>#{weird_value}</test>
</test_entity_with_integer>
XML
expect {
Entities::TestEntityWithInteger.from_xml(Nokogiri::XML::Document.parse(xml).root)
}.to raise_error Entity::ValidationError, "missing required properties: test"
end
end
it "parses timestamp fields with a randomly matching pattern as erroneous" do
%w(foobar yesterday now 1.2.foo).each do |weird_value|
xml = <<-XML.strip
<test_entity_with_timestamp>
<test>#{weird_value}</test>
</test_entity_with_timestamp>
XML
expect {
Entities::TestEntityWithTimestamp.from_xml(Nokogiri::XML::Document.parse(xml).root)
}.to raise_error Entity::ValidationError, "missing required properties: test"
end
end
end
context "nested entities" do