test/unit/graphviz_test.rb in rails-erd-1.4.3 vs test/unit/graphviz_test.rb in rails-erd-1.4.4
- old
+ new
@@ -2,11 +2,11 @@
require "rails_erd/diagram/graphviz"
class GraphvizTest < ActiveSupport::TestCase
def setup
RailsERD.options.filetype = :png
- RailsERD.options.warn = false
+ RailsERD.options.warn = false
end
def teardown
FileUtils.rm Dir["erd*.*"] rescue nil
end
@@ -73,41 +73,45 @@
test "create should create output for domain with attributes" do
create_model "Foo", :bar => :references, :column => :string do
belongs_to :bar
end
create_model "Bar", :column => :string
+
+ Diagram.any_instance.expects(:save)
Diagram::Graphviz.create
- assert File.exists?("erd.png")
end
test "create should create output for domain without attributes" do
create_simple_domain
+
+ Diagram.any_instance.expects(:save)
Diagram::Graphviz.create
- 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")
+
+ Diagram.any_instance.expects(:save)
+ Diagram::Graphviz.create(:filetype => :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")
+
+ Diagram.any_instance.expects(:save)
+ Diagram::Graphviz.create(:filename => "erd with spaces")
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
def output_and_errors_from_command(*args); raise end
end
assert_nothing_raised do
- Diagram::Graphviz.create :filetype => :dot
+ Diagram::Graphviz.create(:filetype => :dot)
end
ensure
GraphViz.class_eval do
alias_method :output_and_errors_from_command, :old_output_and_errors_from_command
end
@@ -117,18 +121,20 @@
test "create should create output for domain with attributes if orientation is vertical" do
create_model "Foo", :bar => :references, :column => :string do
belongs_to :bar
end
create_model "Bar", :column => :string
+
+ Diagram.any_instance.expects(:save)
Diagram::Graphviz.create(:orientation => :vertical)
- assert File.exists?("erd.png")
end
test "create should create output for domain if orientation is vertical" do
create_simple_domain
+
+ Diagram.any_instance.expects(:save)
Diagram::Graphviz.create(:orientation => :vertical)
- 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")
@@ -142,27 +148,19 @@
message = e.message
end
assert_match /No entities found/, message
end
- test "create should write to given file name plus extension if present" do
- begin
- create_simple_domain
- Diagram::Graphviz.create :filename => "foobar"
- 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"
+ 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
test "create should not fail when reserved words are used as node names" do
create_model "Node", :name => :string