diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 0000000..20438df --- /dev/null +++ b/.hound.yml @@ -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 diff --git a/app/models/service.rb b/app/models/service.rb index 9e9dc4e..8138ed0 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -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 diff --git a/spec/api/services_spec.rb b/spec/api/services_spec.rb index 7401761..890b8a3 100644 --- a/spec/api/services_spec.rb +++ b/spec/api/services_spec.rb @@ -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) diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 2252cb6..e115a12 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -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