test/unit/entity_test.rb in rails-erd-0.2.0 vs test/unit/entity_test.rb in rails-erd-0.3.0
- old
+ new
@@ -52,11 +52,41 @@
domain = Domain.generate
foo = domain.entity_for(Foo)
assert_equal domain.relationships.select { |r| r.destination == foo }, foo.relationships
end
-
+
+ test "parent should return nil for regular entities" do
+ create_model "Foo"
+ assert_nil Entity.new(Domain.new, Foo).parent
+ end
+
+ test "parent should return nil for descended models with distinct tables" do
+ create_model "Foo", :type => :string
+ Object.const_set :SpecialFoo, Class.new(Foo)
+ SpecialFoo.class_eval do
+ set_table_name "special_foo"
+ end
+ create_table "special_foo", {}, true
+ assert_nil Entity.new(Domain.new, SpecialFoo).parent
+ end
+
+ test "parent should return parent entity for child entities" do
+ create_model "Foo", :type => :string
+ Object.const_set :SpecialFoo, Class.new(Foo)
+ domain = Domain.generate
+ assert_equal domain.entity_for(Foo), Entity.new(domain, SpecialFoo).parent
+ end
+
+ test "parent should return parent entity for children of child entities" do
+ create_model "Foo", :type => :string
+ Object.const_set :SpecialFoo, Class.new(Foo)
+ Object.const_set :VerySpecialFoo, Class.new(SpecialFoo)
+ domain = Domain.generate
+ assert_equal domain.entity_for(SpecialFoo), Entity.new(domain, VerySpecialFoo).parent
+ end
+
# Entity properties ========================================================
test "connected should return false for unconnected entities" do
create_models "Foo", "Bar"
assert_equal [false, false], Domain.generate.entities.map(&:connected?)
end
@@ -65,9 +95,50 @@
create_model "Foo", :bar => :references do
belongs_to :bar
end
create_model "Bar"
assert_equal [true, true], Domain.generate.entities.map(&:connected?)
+ end
+
+ test "disconnected should return true for unconnected entities" do
+ create_models "Foo", "Bar"
+ assert_equal [true, true], Domain.generate.entities.map(&:disconnected?)
+ end
+
+ test "disconnected should return false for connected entities" do
+ create_model "Foo", :bar => :references do
+ belongs_to :bar
+ end
+ create_model "Bar"
+ assert_equal [false, false], Domain.generate.entities.map(&:disconnected?)
+ end
+
+ test "descendant should return false for regular entities" do
+ create_model "Foo"
+ assert_equal false, Entity.new(Domain.new, Foo).descendant?
+ end
+
+ test "descendant should return false for descended models with distinct tables" do
+ create_model "Foo", :type => :string
+ Object.const_set :SpecialFoo, Class.new(Foo)
+ SpecialFoo.class_eval do
+ set_table_name "special_foo"
+ end
+ create_table "special_foo", {}, true
+ assert_equal false, Entity.new(Domain.new, SpecialFoo).descendant?
+ end
+
+ test "descendant should return true for child entities" do
+ create_model "Foo", :type => :string
+ Object.const_set :SpecialFoo, Class.new(Foo)
+ assert_equal true, Entity.new(Domain.new, SpecialFoo).descendant?
+ end
+
+ test "descendant should return true for children of child entities" do
+ create_model "Foo", :type => :string
+ Object.const_set :SpecialFoo, Class.new(Foo)
+ Object.const_set :VerySpecialFoo, Class.new(SpecialFoo)
+ assert_equal true, Entity.new(Domain.new, VerySpecialFoo).descendant?
end
# Attribute processing =====================================================
test "attributes should return list of attributes" do
create_model "Bar", :some_column => :integer, :another_column => :string