1
0

dot_helper_spec.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. require 'spec_helper'
  2. describe DotHelper do
  3. describe "with example Agents" do
  4. class Agents::DotFoo < Agent
  5. default_schedule "2pm"
  6. def check
  7. create_event :payload => {}
  8. end
  9. end
  10. class Agents::DotBar < Agent
  11. cannot_be_scheduled!
  12. def check
  13. create_event :payload => {}
  14. end
  15. end
  16. before do
  17. stub(Agents::DotFoo).valid_type?("Agents::DotFoo") { true }
  18. stub(Agents::DotBar).valid_type?("Agents::DotBar") { true }
  19. end
  20. describe "#agents_dot" do
  21. before do
  22. @agents = [
  23. @foo = Agents::DotFoo.new(name: "foo").tap { |agent|
  24. agent.user = users(:bob)
  25. agent.save!
  26. },
  27. @bar1 = Agents::DotBar.new(name: "bar1").tap { |agent|
  28. agent.user = users(:bob)
  29. agent.sources << @foo
  30. agent.save!
  31. },
  32. @bar2 = Agents::DotBar.new(name: "bar2").tap { |agent|
  33. agent.user = users(:bob)
  34. agent.sources << @foo
  35. agent.propagate_immediately = true
  36. agent.disabled = true
  37. agent.save!
  38. },
  39. @bar3 = Agents::DotBar.new(name: "bar3").tap { |agent|
  40. agent.user = users(:bob)
  41. agent.sources << @bar2
  42. agent.save!
  43. },
  44. ]
  45. end
  46. it "generates a DOT script" do
  47. agents_dot(@agents).should =~ %r{
  48. \A
  49. digraph \x20 "Agent \x20 Event \x20 Flow" \{
  50. node \[ [^\]]+ \];
  51. edge \[ [^\]]+ \];
  52. (?<foo>\w+) \[label=foo\];
  53. \k<foo> -> (?<bar1>\w+) \[style=dashed\];
  54. \k<foo> -> (?<bar2>\w+) \[color="\#999999"\];
  55. \k<bar1> \[label=bar1\];
  56. \k<bar2> \[label=bar2,style="rounded,dashed",color="\#999999",fontcolor="\#999999"\];
  57. \k<bar2> -> (?<bar3>\w+) \[style=dashed,color="\#999999"\];
  58. \k<bar3> \[label=bar3\];
  59. \}
  60. \z
  61. }x
  62. end
  63. it "generates a richer DOT script" do
  64. agents_dot(@agents, true).should =~ %r{
  65. \A
  66. digraph \x20 "Agent \x20 Event \x20 Flow" \{
  67. node \[ [^\]]+ \];
  68. edge \[ [^\]]+ \];
  69. (?<foo>\w+) \[label=foo,tooltip="Dot \x20 Foo",URL="#{Regexp.quote(agent_path(@foo))}"\];
  70. \k<foo> -> (?<bar1>\w+) \[style=dashed\];
  71. \k<foo> -> (?<bar2>\w+) \[color="\#999999"\];
  72. \k<bar1> \[label=bar1,tooltip="Dot \x20 Bar",URL="#{Regexp.quote(agent_path(@bar1))}"\];
  73. \k<bar2> \[label=bar2,tooltip="Dot \x20 Bar",URL="#{Regexp.quote(agent_path(@bar2))}",style="rounded,dashed",color="\#999999",fontcolor="\#999999"\];
  74. \k<bar2> -> (?<bar3>\w+) \[style=dashed,color="\#999999"\];
  75. \k<bar3> \[label=bar3,tooltip="Dot \x20 Bar",URL="#{Regexp.quote(agent_path(@bar3))}"\];
  76. \}
  77. \z
  78. }x
  79. end
  80. end
  81. end
  82. describe "DotHelper::DotDrawer" do
  83. describe "#id" do
  84. it "properly escapes double quotaion and backslash" do
  85. DotHelper::DotDrawer.draw(foo: "") {
  86. id('hello\\"')
  87. }.should == '"hello\\\\\\""'
  88. end
  89. end
  90. end
  91. end