Keine Beschreibung http://j1x-huginn.herokuapp.com

agents_exporter_spec.rb 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # encoding: utf-8
  2. require 'spec_helper'
  3. describe AgentsExporter do
  4. describe "#as_json" do
  5. let(:name) { "My set of Agents" }
  6. let(:description) { "These Agents work together nicely!" }
  7. let(:guid) { "some-guid" }
  8. let(:tag_fg_color) { "#ffffff" }
  9. let(:tag_bg_color) { "#000000" }
  10. let(:source_url) { "http://yourhuginn.com/scenarios/2/export.json" }
  11. let(:agent_list) { [agents(:jane_weather_agent), agents(:jane_rain_notifier_agent)] }
  12. let(:exporter) { AgentsExporter.new(
  13. :agents => agent_list, :name => name, :description => description, :source_url => source_url,
  14. :guid => guid, :tag_fg_color => tag_fg_color, :tag_bg_color => tag_bg_color) }
  15. it "outputs a structure containing name, description, the date, all agents & their links" do
  16. data = exporter.as_json
  17. data[:name].should == name
  18. data[:description].should == description
  19. data[:source_url].should == source_url
  20. data[:guid].should == guid
  21. data[:tag_fg_color].should == tag_fg_color
  22. data[:tag_bg_color].should == tag_bg_color
  23. Time.parse(data[:exported_at]).should be_within(2).of(Time.now.utc)
  24. data[:links].should == [{ :source => 0, :receiver => 1 }]
  25. data[:agents].should == agent_list.map { |agent| exporter.agent_as_json(agent) }
  26. data[:agents].all? { |agent_json| agent_json[:guid].present? && agent_json[:type].present? && agent_json[:name].present? }.should be_truthy
  27. data[:agents][0].should_not have_key(:propagate_immediately) # can't receive events
  28. data[:agents][1].should_not have_key(:schedule) # can't be scheduled
  29. end
  30. it "does not output links to other agents outside of the incoming set" do
  31. Link.create!(:source_id => agents(:jane_weather_agent).id, :receiver_id => agents(:jane_website_agent).id)
  32. Link.create!(:source_id => agents(:jane_website_agent).id, :receiver_id => agents(:jane_rain_notifier_agent).id)
  33. exporter.as_json[:links].should == [{ :source => 0, :receiver => 1 }]
  34. end
  35. end
  36. describe "#filename" do
  37. it "strips special characters" do
  38. AgentsExporter.new(:name => "ƏfooƐƕƺbar").filename.should == "foo-bar.json"
  39. end
  40. it "strips punctuation" do
  41. AgentsExporter.new(:name => "foo,bar").filename.should == "foo-bar.json"
  42. end
  43. it "strips leading and trailing dashes" do
  44. AgentsExporter.new(:name => ",foo,").filename.should == "foo.json"
  45. end
  46. it "has a default when options[:name] is nil" do
  47. AgentsExporter.new(:name => nil).filename.should == "exported-agents.json"
  48. end
  49. it "has a default when the result is empty" do
  50. AgentsExporter.new(:name => "").filename.should == "exported-agents.json"
  51. AgentsExporter.new(:name => "Ə").filename.should == "exported-agents.json"
  52. AgentsExporter.new(:name => "-").filename.should == "exported-agents.json"
  53. AgentsExporter.new(:name => ",,").filename.should == "exported-agents.json"
  54. end
  55. end
  56. end