Skip to content

Commit

Permalink
Add working and url to AgentDrop for diagnostic purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
knu committed Sep 8, 2017
1 parent 48afe27 commit ed9da9f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/models/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,12 @@ def type
@object.__send__(attr)
} unless method_defined?(attr)
}

def working
@object.working?
end

def url
Rails.application.routes.url_helpers.agent_url(@object, Rails.application.config.action_mailer.default_url_options)
end
end
4 changes: 2 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr

config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
config.action_mailer.default_url_options = { host: ENV['DOMAIN'] || 'localhost' }
config.action_mailer.perform_deliveries = true
end
end
18 changes: 18 additions & 0 deletions spec/models/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1041,4 +1041,22 @@ def interpolate(string, agent)
expect(interpolate(t, @wsa2)).to eq('1: Formatter')
expect(interpolate(t, @efa)).to eq('0: ')
end

it 'should have .working' do
stub(@wsa1).working? { false }
stub(@wsa2).working? { true }
stub(@efa).working? { false }

t = '{% if agent.working %}healthy{% else %}unhealthy{% endif %}'
expect(interpolate(t, @wsa1)).to eq('unhealthy')
expect(interpolate(t, @wsa2)).to eq('healthy')
expect(interpolate(t, @efa)).to eq('unhealthy')
end

it 'should have .url' do
t = '{{ agent.url }}'
expect(interpolate(t, @wsa1)).to eq("http://localhost/agents/#{@wsa1.id}")
expect(interpolate(t, @wsa2)).to eq("http://localhost/agents/#{@wsa2.id}")
expect(interpolate(t, @efa)).to eq("http://localhost/agents/#{@efa.id}")
end
end

0 comments on commit ed9da9f

Please sign in to comment.