test/entity_test.rb in ruby-xcdm-0.0.4 vs test/entity_test.rb in ruby-xcdm-0.0.5

- old
+ new

@@ -5,13 +5,16 @@ require 'rexml/document' module XCDM class EntityTest < Test::Unit::TestCase - def e + attr_reader :e, :pub + + def setup s = Schema.new("0.0.1", "4.6") - @e ||= Entity.new(s, "Article") + @pub ||= Entity.new(s, "Publication", abstract: true) + @e ||= Entity.new(s, "Article", parent: "Publication") end def test_initialize assert_equal "Article", e.name end @@ -54,10 +57,18 @@ assert_equal 'Date', Entity.convert_type(:datetime) assert_equal 'Binary Data', Entity.convert_type(:binary) assert_equal 'Transformable', Entity.convert_type(:transformable) end + def test_parent_entity + assert_equal 'Publication', e.parent + end + + def test_abstract_entity + assert pub.abstract + end + def test_raw_relationship opts = { name: "author", minCount: "1", maxCount: "1", destinationEntity: "Author", inverseName: "articles", inverseEntity: "Author" } e.raw_relationship(opts) assert_equal [opts.merge(optional: "YES", deletionRule: "Nullify", syncable: "YES")], e.relationships end @@ -97,11 +108,11 @@ "Author", inverseName: "primary_articles", inverseEntity: "Author" }], e.relationships end def test_to_xml expected = REXML::Document.new %{ -<entity name="Article" representedClassName="Article" syncable="YES"> +<entity name="Article" representedClassName="Article" parentEntity="Publication" syncable="YES"> <attribute name="body" optional="NO" attributeType="String" syncable="YES"/> <attribute name="length" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/> <attribute name="published" optional="YES" attributeType="Boolean" defaultValueString="NO" syncable="YES"/> <attribute name="publishedAt" optional="YES" attributeType="Date" defaultValueString="NO" syncable="YES"/> <attribute name="title" optional="NO" attributeType="String" syncable="YES"/> @@ -117,9 +128,15 @@ e.belongs_to :author assert_equal expected.to_s.strip, REXML::Document.new(e.to_xml).to_s.strip + expected = REXML::Document.new %{ +<entity name="Publication" representedClassName="Publication" isAbstract="YES" syncable="YES"> +</entity> + } + + assert_equal expected.to_s.strip, REXML::Document.new(pub.to_xml).to_s.strip end end end