Skip to content

Commit

Permalink
Ignore the fixture API key in WeatherAgent (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
cantino committed Sep 21, 2016
1 parent 89cfe8e commit 0dd1c78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/agents/weather_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class WeatherAgent < Agent
default_schedule "8pm"

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

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

def default_options
Expand Down Expand Up @@ -102,7 +102,7 @@ def language
def validate_options
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, "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?
end

Expand Down
10 changes: 10 additions & 0 deletions spec/models/agents/weather_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
it "creates a valid agent" do
expect(agent).to be_valid
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
it "doesn't have a Service object attached" do
Expand Down

0 comments on commit 0dd1c78

Please sign in to comment.