dot_helper_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. require 'spec_helper'
  2. describe DotHelper do
  3. describe "#dot_id" do
  4. it "properly escapes double quotaion and backslash" do
  5. dot_id('hello\\"').should == '"hello\\\\\\""'
  6. end
  7. end
  8. describe "with example Agents" do
  9. class Agents::DotFoo < Agent
  10. default_schedule "2pm"
  11. def check
  12. create_event :payload => {}
  13. end
  14. end
  15. class Agents::DotBar < Agent
  16. cannot_be_scheduled!
  17. def check
  18. create_event :payload => {}
  19. end
  20. end
  21. before do
  22. stub(Agents::DotFoo).valid_type?("Agents::DotFoo") { true }
  23. stub(Agents::DotBar).valid_type?("Agents::DotBar") { true }
  24. end
  25. describe "#agents_dot" do
  26. it "generates a DOT script" do
  27. @foo = Agents::DotFoo.new(:name => "foo")
  28. @foo.user = users(:bob)
  29. @foo.save!
  30. @bar = Agents::DotBar.new(:name => "bar")
  31. @bar.user = users(:bob)
  32. @bar.sources << @foo
  33. @bar.save!
  34. agents_dot([@foo, @bar]).should == 'digraph foo {"foo";"foo"->"bar";"bar";}'
  35. agents_dot([@foo, @bar], true).should == 'digraph foo {"foo"[URL="/agents/%d"];"foo"->"bar";"bar"[URL="/agents/%d"];}' % [@foo.id, @bar.id]
  36. end
  37. end
  38. end
  39. end