Skip to content

Commit

Permalink
stop translating fleet status
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmamike committed Nov 24, 2014
1 parent 28b9925 commit 787b784
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 36 deletions.
41 changes: 41 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
LineLength:
Description: 'Limit lines to 120 characters.'
Max: 120

StringLiterals:
EnforcedStyle: single_quotes

RedundantSelf:
Enabled: false

SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space

AlignParameters:
Enabled: false

DotPosition:
EnforcedStyle: leading

EmptyLinesAroundBody:
Enabled: false

NumericLiterals:
Enabled: false

CollectionMethods:
PreferredMethods:
collect: 'map'
collect!: 'map!'
inject: 'reduce'
detect: 'find'
find_all: 'select'

CyclomaticComplexity:
Enabled: false

MethodLength:
Enabled: false

ClassLength:
Enabled: false
10 changes: 4 additions & 6 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ def destroy
end

def refresh
@status = case fleet.status(id)[:active_state]
when 'active'
'started'
when 'failed'
'stopped'
if status = fleet.status(id)
status.select! { |k, _| %i(active_state load_state sub_state).include?(k) }
@status = status.each_with_object('') { |(k, v), state| state << "#{k}: #{v}; "}.chomp('; ')
else
'error'
@status = 'error'
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/api/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
describe 'GET /services/:id' do

let(:model) { Service.new(id: id) }
let(:status) { 'started' }
let(:status) { 'load_state: loaded; active_state: active; sub_state: running' }

before do
allow(Service).to receive(:find).and_return(model)
Expand Down
37 changes: 8 additions & 29 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,42 +132,21 @@
describe '#refresh' do
before do
allow(Fleet).to receive(:new) { fake_fleet_client }
fake_fleet_client.stub(:status).and_return(active_state: 'active',
load_state: 'loaded',
sub_state: 'running',
machine_state: 'wtf')
end

it 'gets the status of a unit' do
expect(fake_fleet_client).to receive(:status).with(subject.id)
subject.refresh
expect(subject.status).to match /load_state: loaded/
expect(subject.status).to match /active_state: active/
expect(subject.status).to match /sub_state: running/
expect(subject.status).not_to match /machine_state/
end

context 'when the service is active' do
before do
fake_fleet_client.stub(:status).and_return({ active_state: 'active' })
end

it 'returns started' do
expect(subject.refresh).to eq('started')
end
end

context 'when the service is failed' do
before do
fake_fleet_client.stub(:status).and_return({ active_state: 'failed' })
end

it 'returns stopped' do
expect(subject.refresh).to eq('stopped')
end
end

context 'when the service is neither active nor failed' do
before do
fake_fleet_client.stub(:status).and_return({ active_state: 'foo' })
end

it 'returns error' do
expect(subject.refresh).to eq('error')
end
end
end

describe '#docker_run_string' do
Expand Down

0 comments on commit 787b784

Please sign in to comment.