test/unit/graphviz_test.rb in rails-erd-1.0.0 vs test/unit/graphviz_test.rb in rails-erd-1.1.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| @@ -90,10 +90,16 @@ create_simple_domain Diagram::Graphviz.create :filetype => :dot assert File.exists?("erd.dot") end + test "create should create output for filenames that have spaces" do + create_simple_domain + Diagram::Graphviz.create :filename => "erd with spaces" + assert File.exists?("erd with spaces.png") + end + test "create should write to file with dot extension without requiring graphviz" do create_simple_domain begin GraphViz.class_eval do alias_method :old_output_and_errors_from_command, :output_and_errors_from_command @@ -296,11 +302,11 @@ belongs_to :foo end assert_equal [["m_Bar", "m_Foo"], ["m_Foo", "m_Bar"]], find_dot_node_pairs(diagram).sort end - test "generate should create edge to generalized entity if polymorphism is true" do + test "generate should create edge to polymorphic 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 @@ -310,20 +316,49 @@ end assert_equal [["m_Defensible", "m_Cannon"], ["m_Defensible", "m_Galleon"], ["m_Defensible", "m_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 + test "generate should create edge to each child of polymorphic 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 [["m_Galleon", "m_Cannon"], ["m_Stronghold", "m_Cannon"]], find_dot_node_pairs(diagram).sort + end + + test "generate should create edge to abstract entity if polymorphism is true" do + create_model "Person", :settlement => :references + create_model "Country" do + has_many :settlements + end + create_model "Settlement" do + self.abstract_class = true + belongs_to :country + has_many :people + end + create_model "City", Settlement, :country => :references + assert_equal [["m_Country", "m_Settlement"], ["m_Settlement", "m_City"], ["m_Settlement", "m_Person"]], + find_dot_node_pairs(diagram(:polymorphism => true)).sort + end + + test "generate should create edge to each child of abstract entity if polymorphism is false" do + create_model "Person", :settlement => :references + create_model "Country" do + has_many :settlements + end + create_model "Settlement" do + self.abstract_class = true + belongs_to :country + has_many :people + end + create_model "City", Settlement, :country => :references + assert_equal [["m_City", "m_Person"], ["m_Country", "m_City"]], 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