default_scenario_importer_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'rails_helper'
  2. describe DefaultScenarioImporter do
  3. let(:user) { users(:bob) }
  4. describe '.import' do
  5. it 'imports a set of agents to get the user going when they are first created' do
  6. mock(DefaultScenarioImporter).seed(is_a(User))
  7. stub.proxy(ENV).[](anything)
  8. stub(ENV).[]('IMPORT_DEFAULT_SCENARIO_FOR_ALL_USERS') { 'true' }
  9. DefaultScenarioImporter.import(user)
  10. end
  11. it 'can be turned off' do
  12. stub(DefaultScenarioImporter).seed { fail "seed should not have been called"}
  13. stub.proxy(ENV).[](anything)
  14. stub(ENV).[]('IMPORT_DEFAULT_SCENARIO_FOR_ALL_USERS') { 'false' }
  15. DefaultScenarioImporter.import(user)
  16. end
  17. it 'is turned off for existing instances of Huginn' do
  18. stub(DefaultScenarioImporter).seed { fail "seed should not have been called"}
  19. stub.proxy(ENV).[](anything)
  20. stub(ENV).[]('IMPORT_DEFAULT_SCENARIO_FOR_ALL_USERS') { nil }
  21. DefaultScenarioImporter.import(user)
  22. end
  23. end
  24. describe '.seed' do
  25. it 'imports a set of agents to get the user going when they are first created' do
  26. expect { DefaultScenarioImporter.seed(user) }.to change(user.agents, :count).by(7)
  27. end
  28. it 'respects an environment variable that specifies a path or URL to a different scenario' do
  29. stub.proxy(ENV).[](anything)
  30. stub(ENV).[]('DEFAULT_SCENARIO_FILE') { File.join(Rails.root, "spec", "fixtures", "test_default_scenario.json") }
  31. expect { DefaultScenarioImporter.seed(user) }.to change(user.agents, :count).by(3)
  32. end
  33. it 'can not be turned off' do
  34. stub.proxy(ENV).[](anything)
  35. stub(ENV).[]('IMPORT_DEFAULT_SCENARIO_FOR_ALL_USERS') { 'true' }
  36. expect { DefaultScenarioImporter.seed(user) }.to change(user.agents, :count).by(7)
  37. end
  38. end
  39. end