Ignore the fixture API key in WeatherAgent (#1694)

Andrew Cantino преди 8 години
родител
ревизия
0dd1c78ae0
променени са 2 файла, в които са добавени 13 реда и са изтрити 3 реда
  1. 3 3
      app/models/agents/weather_agent.rb
  2. 10 0
      spec/models/agents/weather_agent_spec.rb

+ 3 - 3
app/models/agents/weather_agent.rb

@@ -57,11 +57,11 @@ module Agents
57 57
     default_schedule "8pm"
58 58
 
59 59
     def working?
60
-      event_created_within?((interpolated['expected_update_period_in_days'].presence || 2).to_i) && !recent_error_logs?
60
+      event_created_within?((interpolated['expected_update_period_in_days'].presence || 2).to_i) && !recent_error_logs? && key_setup?
61 61
     end
62 62
 
63 63
     def key_setup?
64
-      interpolated['api_key'].present? && interpolated['api_key'] != "your-key"
64
+      interpolated['api_key'].present? && interpolated['api_key'] != "your-key" && interpolated['api_key'] != "put-your-key-here"
65 65
     end
66 66
 
67 67
     def default_options
@@ -102,7 +102,7 @@ module Agents
102 102
     def validate_options
103 103
       errors.add(:base, "service must be set to 'forecastio' or 'wunderground'") unless ["forecastio", "wunderground"].include?(weather_provider)
104 104
       errors.add(:base, "location is required") unless location.present?
105
-      errors.add(:base, "api_key is required") unless key_setup?
105
+      errors.add(:base, "api_key is required") unless interpolated['api_key'].present?
106 106
       errors.add(:base, "which_day selection is required") unless which_day.present?
107 107
     end
108 108
 

+ 10 - 0
spec/models/agents/weather_agent_spec.rb

@@ -19,6 +19,16 @@ describe Agents::WeatherAgent do
19 19
   it "creates a valid agent" do
20 20
     expect(agent).to be_valid
21 21
   end
22
+
23
+  it "is valid with put-your-key-here or your-key" do
24
+    agent.options['api_key'] = 'put-your-key-here'
25
+    expect(agent).to be_valid
26
+    expect(agent.working?).to be_falsey
27
+
28
+    agent.options['api_key'] = 'your-key'
29
+    expect(agent).to be_valid
30
+    expect(agent.working?).to be_falsey
31
+  end
22 32
   
23 33
   describe "#service" do
24 34
     it "doesn't have a Service object attached" do