test/unit/graphviz_test.rb in rails-erd-0.4.5 vs test/unit/graphviz_test.rb in rails-erd-1.0.0

- old
+ new

@@ -6,11 +6,11 @@ RailsERD.options.warn = false load "rails_erd/diagram/graphviz.rb" end def teardown - FileUtils.rm Dir["ERD.*"] rescue nil + FileUtils.rm Dir["erd.*"] rescue nil RailsERD::Diagram.send :remove_const, :Graphviz rescue nil end def diagram(options = {}) @diagram ||= Diagram::Graphviz.new(Domain.generate(options), options).tap do |diagram| @@ -52,13 +52,13 @@ # Diagram properties ======================================================= test "file name should depend on file type" do create_simple_domain begin - assert_equal "ERD.svg", Diagram::Graphviz.create(:filetype => :svg) + assert_equal "erd.svg", Diagram::Graphviz.create(:filetype => :svg) ensure - FileUtils.rm "ERD.svg" rescue nil + FileUtils.rm "erd.svg" rescue nil end end test "rank direction should be lr for horizontal orientation" do create_simple_domain @@ -75,23 +75,23 @@ create_model "Foo", :bar => :references, :column => :string do belongs_to :bar end create_model "Bar", :column => :string Diagram::Graphviz.create - assert File.exists?("ERD.png") + assert File.exists?("erd.png") end test "create should create output for domain without attributes" do create_simple_domain Diagram::Graphviz.create - assert File.exists?("ERD.png") + assert File.exists?("erd.png") end test "create should write to file with dot extension if type is dot" do create_simple_domain Diagram::Graphviz.create :filetype => :dot - assert File.exists?("ERD.dot") + assert File.exists?("erd.dot") end test "create should write to file with dot extension without requiring graphviz" do create_simple_domain begin @@ -113,22 +113,22 @@ create_model "Foo", :bar => :references, :column => :string do belongs_to :bar end create_model "Bar", :column => :string Diagram::Graphviz.create(:orientation => :vertical) - assert File.exists?("ERD.png") + assert File.exists?("erd.png") end test "create should create output for domain if orientation is vertical" do create_simple_domain Diagram::Graphviz.create(:orientation => :vertical) - assert File.exists?("ERD.png") + assert File.exists?("erd.png") end test "create should not create output if there are no connected models" do Diagram::Graphviz.create rescue nil - assert !File.exists?("ERD.png") + assert !File.exists?("erd.png") end test "create should abort and complain if there are no connected models" do message = nil begin @@ -339,11 +339,11 @@ test "generate should use normal arrow head and tail for many to many cardinalities with simple notation" do create_many_to_many_assoc_domain assert_equal [["normal", "normal"]], find_dot_edge_styles(diagram(:notation => :simple)) end - # Advanced notation style =================================================== + # Advanced notation style ================================================== 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 => :bachman)) end @@ -380,7 +380,50 @@ end More.class_eval do validates_presence_of :many end assert_equal [["dotnormal", "dotnormal"]], find_dot_edge_styles(diagram(:notation => :bachman)) + end + + # Crows-foot notation style ================================================ + test "generate should use 0/1 crowsfeet for one to one cardinalities with crowsfoot notation" do + create_one_to_one_assoc_domain + assert_equal [["teeodot", "teeodot"]], find_dot_edge_styles(diagram(:notation => :crowsfoot)) + end + + test "generate should use 1/1 crowsfeet for mandatory one to one cardinalities with crowsfoot notation" do + create_one_to_one_assoc_domain + One.class_eval do + validates_presence_of :other + end + assert_equal [["teeodot","teetee"]], find_dot_edge_styles(diagram(:notation => :crowsfoot)) + end + + test "generate should use 0/* crowsfeet with 0/1 crowsfeet for one to many cardinalities with crowsfoot notation" do + create_one_to_many_assoc_domain + assert_equal [["teeodot", "crowodot"]], find_dot_edge_styles(diagram(:notation => :crowsfoot)) + end + + test "generate should use 0/* crowsfeet with 1/1 crowsfett for mandatory one to many cardinalities with crowsfoot notation" do + create_one_to_many_assoc_domain + One.class_eval do + validates_presence_of :many + end + assert_equal [["teeodot", "crowtee"]], find_dot_edge_styles(diagram(:notation => :crowsfoot)) + end + + test "generate should use 0/* and 0/* crowsfeet for many to many cardinalities with crowsfoot notation" do + create_many_to_many_assoc_domain + assert_equal [["crowodot", "crowodot"]], find_dot_edge_styles(diagram(:notation => :crowsfoot)) + end + + test "generate should use 1/* and 1/* tail and head for mandatory many to many cardinalities with crowsfoot 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 [["crowtee", "crowtee"]], find_dot_edge_styles(diagram(:notation => :crowsfoot)) end end