Skip to content

Commit

Permalink
Use Likeno errors instead of KalibroClient errors
Browse files Browse the repository at this point in the history
Since the same errors are raised, we do not need to duplicate the code.
Notice that this breaks the KalibroClient API.

Signed-off-by: Daniel Miranda <[email protected]>
  • Loading branch information
diegoamc committed Mar 30, 2016
1 parent b4ef614 commit 49cccf1
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 200 deletions.
4 changes: 2 additions & 2 deletions features/step_definitions/metric_configuration_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
inexistent_id = rand(Time.now.to_i)
begin
KalibroClient::Entities::Configurations::MetricConfiguration.find(inexistent_id)
rescue KalibroClient::Errors::RecordNotFound
rescue Likeno::Errors::RecordNotFound
@is_error = true
end
end
Expand Down Expand Up @@ -81,7 +81,7 @@
end

Then(/^the metric configuration should no longer exist$/) do
expect { KalibroClient::Entities::Configurations::MetricConfiguration.find(@metric_configuration.id)}.to raise_error(KalibroClient::Errors::RecordNotFound)
expect { KalibroClient::Entities::Configurations::MetricConfiguration.find(@metric_configuration.id)}.to raise_error(Likeno::Errors::RecordNotFound)
end

Then(/^the metric configuration should exist$/) do
Expand Down
1 change: 1 addition & 0 deletions lib/kalibro_client/entities/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'likeno'
require 'kalibro_client/errors'

module KalibroClient
module Entities
Expand Down
18 changes: 0 additions & 18 deletions lib/kalibro_client/entities/configurations/metric_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,6 @@ def self.metric_configurations_of(configuration_id)
create_objects_array_from_hash(request('', {}, :get, "kalibro_configurations/#{configuration_id}"))
end

def self.find(id)
begin
metric_configuration = request(':id', {id: id}, :get)
return new(metric_configuration['metric_configuration'], true)
#FIXME Temporary until KalibroProcessor returns proper http statuses
rescue Likeno::Errors::RequestError
raise KalibroClient::Errors::RecordNotFound
end
end

def self.exists?(id)
begin
return true unless find(id).nil?
rescue Likeno::Errors::RecordNotFound
return false
end
end

def kalibro_ranges
KalibroClient::Entities::Configurations::KalibroRange.create_objects_array_from_hash(self.class.request(':id/kalibro_ranges', {id: id}, :get))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def find_metric_by_name(name)

def find_metric_by_name!(name)
metric = self.find_metric_by_name(name)
raise KalibroClient::Errors::RecordNotFound if metric.nil?
raise Likeno::Errors::RecordNotFound if metric.nil?
metric
end

Expand All @@ -48,7 +48,7 @@ def find_metric_by_code(metric_code)

def find_metric_by_code!(metric_code)
metric = self.find_metric_by_code(metric_code)
raise KalibroClient::Errors::RecordNotFound if metric.nil?
raise Likeno::Errors::RecordNotFound if metric.nil?
metric
end

Expand Down
13 changes: 0 additions & 13 deletions lib/kalibro_client/entities/processor/module_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ def hotspot_metric_results
HotspotMetricResult.create_objects_array_from_hash(self.class.request(":id/hotspot_metric_results",
{id: self.id}, :get))
end

# FIXME: KalibroProcessor should return a 404 if the object does not exist instead of 422
def self.find(id)
begin
super
rescue Likeno::Errors::RequestError => e
if(e.response.status == 422)
raise KalibroClient::Errors::RecordNotFound.new(response: e.response)
else
raise e
end
end
end
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/kalibro_client/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'kalibro_client/errors/request_error'
require 'kalibro_client/errors/record_not_found'
require 'kalibro_client/errors/record_invalid'
require 'likeno/errors'
10 changes: 0 additions & 10 deletions lib/kalibro_client/errors/record_invalid.rb

This file was deleted.

26 changes: 0 additions & 26 deletions lib/kalibro_client/errors/record_not_found.rb

This file was deleted.

26 changes: 0 additions & 26 deletions lib/kalibro_client/errors/request_error.rb

This file was deleted.

57 changes: 0 additions & 57 deletions spec/entities/configurations/metric_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,63 +169,6 @@
end
end

describe 'exists?' do
subject {FactoryGirl.build(:metric_configuration_with_id)}

context 'when the metric configuration exists' do
before :each do
KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).with(subject.id).returns(subject)
end

it 'should return true' do
expect(KalibroClient::Entities::Configurations::MetricConfiguration.exists?(subject.id)).to be_truthy
end
end

context 'when the metric configuration does not exist' do
before :each do
KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).with(subject.id).raises(Likeno::Errors::RecordNotFound)
end

it 'should return false' do
expect(KalibroClient::Entities::Configurations::MetricConfiguration.exists?(subject.id)).to be_falsey
end
end
end

describe 'find' do
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }

context 'with an existant MetricConfiguration' do
before :each do
KalibroClient::Entities::Configurations::MetricConfiguration.
expects(:request).
with(':id', {id: metric_configuration.id}, :get).
returns({'metric_configuration' => metric_configuration.to_hash})
end

it 'should return the metric_configuration' do
found_metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.find(metric_configuration.id)
expect(found_metric_configuration.id).to eq(metric_configuration.id)
expect(found_metric_configuration.persisted).to be_truthy
end
end

context 'with an inexistant MetricConfiguration' do
before :each do
KalibroClient::Entities::Configurations::MetricConfiguration.
expects(:request).
with(':id', {id: metric_configuration.id}, :get).
raises(Likeno::Errors::RequestError)
end

it 'should raise the RecordNotFound error' do
expect {KalibroClient::Entities::Configurations::MetricConfiguration.find(metric_configuration.id)}.
to raise_error(KalibroClient::Errors::RecordNotFound)
end
end
end

describe 'kalibro ranges' do
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
let(:kalibro_range_1) { FactoryGirl.build(:range, metric_configuration_id: metric_configuration.id) }
Expand Down
4 changes: 2 additions & 2 deletions spec/entities/processor/metric_collector_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
let(:metric) { subject.supported_metrics["loc"] }

it 'should return nil with an inexistent name' do
expect { subject.find_metric_by_name!("fake name") }.to raise_error(KalibroClient::Errors::RecordNotFound)
expect { subject.find_metric_by_name!("fake name") }.to raise_error(Likeno::Errors::RecordNotFound)
end

it 'should return a metric with an existent name' do
Expand All @@ -172,7 +172,7 @@
let(:metric) { subject.supported_metrics["loc"] }

it 'should return nil with an inexistent code' do
expect{subject.find_metric_by_code!("fake code")}.to raise_error(KalibroClient::Errors::RecordNotFound)
expect{subject.find_metric_by_code!("fake code")}.to raise_error(Likeno::Errors::RecordNotFound)
end

it 'should return a metric with an existent code' do
Expand Down
41 changes: 0 additions & 41 deletions spec/entities/processor/module_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,45 +223,4 @@
expect(subject.processing).to eq(processing)
end
end

describe 'find' do
let(:id) { 1 }

context 'when the ModuleResult exists' do
let!(:module_result) { FactoryGirl.build(:module_result) }
before :each do
KalibroClient::Entities::Base.expects(:find).with(id).returns(module_result)
end

it 'is expected to return the found module result' do
expect(described_class.find(id)).to eq(module_result)
end
end

context 'when the ModuleResult does not exist' do
before :each do
response = mock('response')
response.expects(:status).at_least_once.returns(422)

KalibroClient::Entities::Base.expects(:find).with(id).raises(Likeno::Errors::RequestError.new(response: response))
end

it 'is expected to raise a RecordNotFound error' do
expect { described_class.find(id) }.to raise_error(KalibroClient::Errors::RecordNotFound)
end
end

context 'when there is an unexpected server error' do
before :each do
response = mock('response')
response.expects(:status).at_least_once.returns(500)

KalibroClient::Entities::Base.expects(:find).with(id).raises(Likeno::Errors::RequestError.new(response: response))
end

it 'is expected to raise a RequestError' do
expect { described_class.find(id) }.to raise_error(Likeno::Errors::RequestError)
end
end
end
end

0 comments on commit 49cccf1

Please sign in to comment.