test/entity_test.rb in ruby-xcdm-0.0.9 vs test/entity_test.rb in ruby-xcdm-0.0.10
- old
+ new
@@ -89,10 +89,17 @@
assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
name: "author", minCount: "1", maxCount: "1", destinationEntity:
"Author", inverseName: "article", inverseEntity: "Author" }], e.relationships
end
+ def test_has_one_should_not_plural
+ e.has_one 'address'
+ assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
+ name: "address", minCount: "1", maxCount: "1", destinationEntity:
+ "Address", inverseName: "article", inverseEntity: "Address" }], e.relationships
+ end
+
def test_belongs_to
e.belongs_to 'author'
assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
name: "author", minCount: "1", maxCount: "1", destinationEntity:
"Author", inverseName: "articles", inverseEntity: "Author" }], e.relationships
@@ -103,20 +110,27 @@
assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
name: "authors", minCount: "1", maxCount: "-1", destinationEntity:
"Author", inverseName: "article", inverseEntity: "Author" }], e.relationships
end
+ def test_deletion_cascade
+ e.has_many 'authors', { deletionRule: 'Cascade'}
+ assert_equal [{ optional: "YES", deletionRule: "Cascade", syncable: "YES",
+ name: "authors", minCount: "1", maxCount: "-1", destinationEntity:
+ "Author", inverseName: "article", inverseEntity: "Author" }], e.relationships
+ end
+
def test_non_inferrable_relationship_with_inverse
e.belongs_to 'primary_author', inverse: 'Author.primary_articles'
assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
name: "primary_author", minCount: "1", maxCount: "1", destinationEntity:
"Author", inverseName: "primary_articles", inverseEntity: "Author" }], e.relationships
end
def test_to_xml
expected = REXML::Document.new %{
-<entity name="Article" representedClassName="Article" parentEntity="Publication" syncable="YES">
+<entity name="Article" codeGenerationType='class' 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"/>
@@ -133,10 +147,10 @@
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 name="Publication" representedClassName="Publication" codeGenerationType='class' isAbstract="YES" syncable="YES">
</entity>
}
assert_equal expected.to_s.strip, REXML::Document.new(pub.to_xml).to_s.strip
end