diff --git a/spec/entities.rb b/spec/entities.rb index 1a73acc..b42c531 100644 --- a/spec/entities.rb +++ b/spec/entities.rb @@ -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 diff --git a/spec/lib/diaspora_federation/entity_spec.rb b/spec/lib/diaspora_federation/entity_spec.rb index 67a572f..88a9cd9 100644 --- a/spec/lib/diaspora_federation/entity_spec.rb +++ b/spec/lib/diaspora_federation/entity_spec.rb @@ -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 + + #{weird_value} + +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 + + #{weird_value} + +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