Ignore the fixture API key in WeatherAgent (#1694)

This commit is contained in:
Andrew Cantino 2016-09-20 20:31:44 -04:00 committed by GitHub
parent 89cfe8e6a0
commit 0dd1c78ae0
2 changed files with 13 additions and 3 deletions

View file

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

View file

@ -20,6 +20,16 @@ describe Agents::WeatherAgent do
expect(agent).to be_valid expect(agent).to be_valid
end end
it "is valid with put-your-key-here or your-key" do
agent.options['api_key'] = 'put-your-key-here'
expect(agent).to be_valid
expect(agent.working?).to be_falsey
agent.options['api_key'] = 'your-key'
expect(agent).to be_valid
expect(agent.working?).to be_falsey
end
describe "#service" do describe "#service" do
it "doesn't have a Service object attached" do it "doesn't have a Service object attached" do
expect(agent.service).to be_nil expect(agent.service).to be_nil