aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2018-03-15 11:52:16 +0100
committerTeddy Wing2018-03-15 11:53:39 +0100
commit9291d45e825edbaf52cb556c102498366985496f (patch)
tree5097c7510df8cb00dcd4e326ff800f54da7a22b4 /spec
parent9dc7c942fd7e0c0b298bfff08088c830841f666c (diff)
downloadchouette-core-9291d45e825edbaf52cb556c102498366985496f.tar.bz2
Route: Don't run `#calculate_costs!` on callback if TomTom disabled
We say `TomTom` is disabled when no API key is present. If this is the case, the `after_save` callback that uses it shouldn't be executed. I had to change my `API_KEY` constant to an instance variable to be able to change it for testing. Refs #6095
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/tom_tom_spec.rb15
-rw-r--r--spec/models/chouette/route/route_base_spec.rb18
2 files changed, 33 insertions, 0 deletions
diff --git a/spec/lib/tom_tom_spec.rb b/spec/lib/tom_tom_spec.rb
new file mode 100644
index 000000000..71584e242
--- /dev/null
+++ b/spec/lib/tom_tom_spec.rb
@@ -0,0 +1,15 @@
+RSpec.describe TomTom do
+ describe ".enabled?" do
+ it "returns true when API key is set" do
+ TomTom.instance_variable_set(:@api_key, 'fake key')
+
+ expect(TomTom.enabled?).to be true
+ end
+
+ it "returns false without an API key" do
+ TomTom.instance_variable_set(:@api_key, '')
+
+ expect(TomTom.enabled?).to be false
+ end
+ end
+end
diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb
index 98cb3e358..d24ad6348 100644
--- a/spec/models/chouette/route/route_base_spec.rb
+++ b/spec/models/chouette/route/route_base_spec.rb
@@ -61,4 +61,22 @@ RSpec.describe Chouette::Route, :type => :model do
end
end
end
+
+ context "callbacks" do
+ it "calls #calculate_costs! after_save when TomTom is enabled" do
+ allow(TomTom).to receive(:enabled?).and_return(true)
+ route = create(:route)
+
+ expect(route).to receive(:calculate_costs!)
+ route.save
+ end
+
+ it "doesn't call #calculate_costs! after_save if TomTom is disabled" do
+ allow(TomTom).to receive(:enabled?).and_return(false)
+ route = create(:route)
+
+ expect(route).not_to receive(:calculate_costs!)
+ route.save
+ end
+ end
end