default_scenario_importer_spec.rb 1.9 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. expect(DefaultScenarioImporter).to receive(:seed).with(kind_of(User))
  7. allow(ENV).to receive(:[]) { nil }
  8. allow(ENV).to receive(:[]).with('IMPORT_DEFAULT_SCENARIO_FOR_ALL_USERS') { 'true' }
  9. DefaultScenarioImporter.import(user)
  10. end
  11. it 'can be turned off' do
  12. allow(DefaultScenarioImporter).to receive(:seed) { fail "seed should not have been called"}
  13. allow(ENV).to receive(:[]) { nil }
  14. allow(ENV).to receive(:[]).with('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. allow(DefaultScenarioImporter).to receive(:seed) { fail "seed should not have been called"}
  19. allow(ENV).to receive(:[]) { nil }
  20. allow(ENV).to receive(:[]).with('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. allow(ENV).to receive(:[]) { nil }
  30. allow(ENV).to receive(:[]).with('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. allow(ENV).to receive(:[]) { nil }
  35. allow(ENV).to receive(:[]).with('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