Permalink
Browse files

Added crows feet notation - I think

  • Loading branch information...
awebneck committed May 16, 2011
1 parent 4deeedf commit d86979e4fa2cebbd43ce1b0ffda7c0aae859e6cc
Showing with 63 additions and 0 deletions.
  1. +20 −0 lib/rails_erd/diagram/graphviz.rb
  2. +43 −0 test/unit/graphviz_test.rb
@@ -103,6 +103,26 @@ def specialization_style(specialization)
end
end
+ module Crowsfoot
+ include Simple
+ def relationship_style(relationship)
+ {}.tap do |options|
+ options[:style] = :dotted if relationship.indirect?
+
+ # Cardinality is "look-across".
+ dst = relationship.to_many? ? "crow" : "tee"
+ src = relationship.many_to? ? "crow" : "tee"
+
+ # Participation is "look-here".
+ dst << (relationship.source_optional? ? "odot" : "tee")
+ src << (relationship.destination_optional? ? "odot" : "tee")
+
+ options[:arrowsize] = 0.6
+ options[:arrowhead], options[:arrowtail] = dst, src
+ end
+ end
+ end
+
module Bachman
include Simple
def relationship_style(relationship)
View
@@ -383,4 +383,47 @@ def output_and_errors_from_command(*args); raise end
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 [["teetee","teeodot"]], 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 [["teetee", "crowodot"]], 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

0 comments on commit d86979e

Please sign in to comment.