test/unit/graphviz_test.rb in rails-erd-0.3.0 vs test/unit/graphviz_test.rb in rails-erd-0.4.0

- old
+ new

@@ -7,11 +7,11 @@ load "rails_erd/diagram/graphviz.rb" end def teardown FileUtils.rm Dir["ERD.*"] rescue nil - RailsERD::Diagram.send :remove_const, :Graphviz + RailsERD::Diagram.send :remove_const, :Graphviz rescue nil end def diagram(options = {}) @diagram ||= Diagram::Graphviz.new(Domain.generate(options), options).tap do |diagram| diagram.generate @@ -146,10 +146,21 @@ assert File.exists?("foobar.png") ensure FileUtils.rm "foobar.png" rescue nil end end + + test "create should abort and complain if output directory does not exist" do + message = nil + begin + create_simple_domain + Diagram::Graphviz.create :filename => "does_not_exist/foo" + rescue => e + message = e.message + end + assert_match /Output directory 'does_not_exist' does not exist/, message + end # Graphviz output ========================================================== test "generate should create directed graph" do create_simple_domain assert_equal "digraph", diagram.graph.type @@ -206,11 +217,11 @@ test "generate should not add any attributes to entity labels if attributes is set to false" do create_model "Jar", :contents => :string create_model "Lid", :jar => :references do belongs_to :jar end - assert_not_match %r{contents}, find_dot_node(diagram(:attributes => false), "Jar")[:label].to_gv + assert_no_match %r{contents}, find_dot_node(diagram(:attributes => false), "Jar")[:label].to_gv end test "generate should create edge for each relationship" do create_model "Foo", :bar => :references do belongs_to :bar @@ -235,10 +246,37 @@ end create_model "Author", :name => :string assert_match %r(\A<\s*<.*\|.*>\s*>\Z)m, find_dot_node(diagram(:orientation => :horizontal), "Author")[:label].to_gv end + test "generate should create edge to generalized entity if polymorphism is true" do + create_model "Cannon", :defensible => :references do + belongs_to :defensible, :polymorphic => true + end + create_model "Stronghold" do + has_many :cannons, :as => :defensible + end + create_model "Galleon" do + has_many :cannons, :as => :defensible + end + assert_equal [["Defensible", "Cannon"], ["Defensible", "Galleon"], ["Defensible", "Stronghold"]], + find_dot_node_pairs(diagram(:polymorphism => true)).sort + end + + test "generate should create edge to each child of generalized entity if polymorphism is false" do + create_model "Cannon", :defensible => :references do + belongs_to :defensible, :polymorphic => true + end + create_model "Stronghold" do + has_many :cannons, :as => :defensible + end + create_model "Galleon" do + has_many :cannons, :as => :defensible + end + assert_equal [["Galleon", "Cannon"], ["Stronghold", "Cannon"]], find_dot_node_pairs(diagram).sort + end + # Simple notation style ==================================================== test "generate should use no style for one to one cardinalities with simple notation" do create_one_to_one_assoc_domain assert_equal [["none", "none"]], find_dot_edge_styles(diagram(:notation => :simple)) end @@ -252,47 +290,47 @@ create_many_to_many_assoc_domain assert_equal [["normal", "normal"]], find_dot_edge_styles(diagram(:notation => :simple)) end # Advanced notation style =================================================== - test "generate should use open dots for one to one cardinalities with advanced notation" do + test "generate should use open dots for one to one cardinalities with bachman notation" do create_one_to_one_assoc_domain - assert_equal [["odot", "odot"]], find_dot_edge_styles(diagram(:notation => :advanced)) + assert_equal [["odot", "odot"]], find_dot_edge_styles(diagram(:notation => :bachman)) end - test "generate should use dots for mandatory one to one cardinalities with advanced notation" do + test "generate should use dots for mandatory one to one cardinalities with bachman notation" do create_one_to_one_assoc_domain One.class_eval do validates_presence_of :other end - assert_equal [["odot", "dot"]], find_dot_edge_styles(diagram(:notation => :advanced)) + assert_equal [["dot", "odot"]], find_dot_edge_styles(diagram(:notation => :bachman)) end - test "generate should use normal arrow and open dot head with dot tail for one to many cardinalities with advanced notation" do + test "generate should use normal arrow and open dot head with dot tail for one to many cardinalities with bachman notation" do create_one_to_many_assoc_domain - assert_equal [["odot", "odotnormal"]], find_dot_edge_styles(diagram(:notation => :advanced)) + assert_equal [["odot", "odotnormal"]], find_dot_edge_styles(diagram(:notation => :bachman)) end - test "generate should use normal arrow and dot head for mandatory one to many cardinalities with advanced notation" do + test "generate should use normal arrow and dot head for mandatory one to many cardinalities with bachman notation" do create_one_to_many_assoc_domain One.class_eval do validates_presence_of :many end - assert_equal [["odot", "dotnormal"]], find_dot_edge_styles(diagram(:notation => :advanced)) + assert_equal [["dot", "odotnormal"]], find_dot_edge_styles(diagram(:notation => :bachman)) end - test "generate should use normal arrow and open dot head and tail for many to many cardinalities with advanced notation" do + test "generate should use normal arrow and open dot head and tail for many to many cardinalities with bachman notation" do create_many_to_many_assoc_domain - assert_equal [["odotnormal", "odotnormal"]], find_dot_edge_styles(diagram(:notation => :advanced)) + assert_equal [["odotnormal", "odotnormal"]], find_dot_edge_styles(diagram(:notation => :bachman)) end - test "generate should use normal arrow and dot tail and head for mandatory many to many cardinalities with advanced notation" do + test "generate should use normal arrow and dot tail and head for mandatory many to many cardinalities with bachman notation" do create_many_to_many_assoc_domain Many.class_eval do validates_presence_of :more end More.class_eval do validates_presence_of :many end - assert_equal [["dotnormal", "dotnormal"]], find_dot_edge_styles(diagram(:notation => :advanced)) + assert_equal [["dotnormal", "dotnormal"]], find_dot_edge_styles(diagram(:notation => :bachman)) end end