Aucune description http://j1x-huginn.herokuapp.com

agents_exporter_spec.rb 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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(:source_url) { "http://yourhuginn.com/scenarios/2/export.json" }
  9. let(:agent_list) { [agents(:jane_weather_agent), agents(:jane_rain_notifier_agent)] }
  10. let(:exporter) { AgentsExporter.new(:agents => agent_list, :name => name, :description => description, :source_url => source_url, :guid => guid) }
  11. it "outputs a structure containing name, description, the date, all agents & their links" do
  12. data = exporter.as_json
  13. data[:name].should == name
  14. data[:description].should == description
  15. data[:source_url].should == source_url
  16. data[:guid].should == guid
  17. Time.parse(data[:exported_at]).should be_within(2).of(Time.now.utc)
  18. data[:links].should == [{ :source => 0, :receiver => 1 }]
  19. data[:agents].should == agent_list.map { |agent| exporter.agent_as_json(agent) }
  20. data[:agents].all? { |agent_json| agent_json[:source_system_agent_id] && agent_json[:type] && agent_json[:name] }.should be_true
  21. end
  22. it "does not output links to other agents" do
  23. Link.create!(:source_id => agents(:jane_weather_agent).id, :receiver_id => agents(:jane_website_agent).id)
  24. Link.create!(:source_id => agents(:jane_website_agent).id, :receiver_id => agents(:jane_rain_notifier_agent).id)
  25. exporter.as_json[:links].should == [{ :source => 0, :receiver => 1 }]
  26. end
  27. end
  28. describe "#filename" do
  29. it "strips special characters" do
  30. AgentsExporter.new(:name => "ƏfooƐƕƺbar").filename.should == "foo-bar.json"
  31. end
  32. it "strips punctuation" do
  33. AgentsExporter.new(:name => "foo,bar").filename.should == "foo-bar.json"
  34. end
  35. it "strips leading and trailing dashes" do
  36. AgentsExporter.new(:name => ",foo,").filename.should == "foo.json"
  37. end
  38. it "has a default when options[:name] is nil" do
  39. AgentsExporter.new(:name => nil).filename.should == "exported-agents.json"
  40. end
  41. it "has a default when the result is empty" do
  42. AgentsExporter.new(:name => "").filename.should == "exported-agents.json"
  43. AgentsExporter.new(:name => "Ə").filename.should == "exported-agents.json"
  44. AgentsExporter.new(:name => "-").filename.should == "exported-agents.json"
  45. AgentsExporter.new(:name => ",,").filename.should == "exported-agents.json"
  46. end
  47. end
  48. end