Commit ecd1b5dcad0213100bbab00cd401bd394dd3b996
Committed by
Rafael Manzo
1 parent
8f262e7b
Exists in
colab
and in
4 other branches
Updated kalibro_client gem and fixed unit tests.
Metric Configuration with snapshot Factory should be deleted in the future. Signed off by: Heitor Reis <marcheing@gmail.com>
Showing
10 changed files
with
34 additions
and
17 deletions
Show diff stats
Gemfile.lock
1 | GIT | 1 | GIT |
2 | remote: https://github.com/mezuro/kalibro_client | 2 | remote: https://github.com/mezuro/kalibro_client |
3 | - revision: e8367929a341a2eaf16599a858972703151a8967 | 3 | + revision: 434108322137611d54314ffb16206fe05c0dac08 |
4 | specs: | 4 | specs: |
5 | kalibro_client (0.0.1) | 5 | kalibro_client (0.0.1) |
6 | activeresource (~> 4.0.0) | 6 | activeresource (~> 4.0.0) |
@@ -57,8 +57,8 @@ GEM | @@ -57,8 +57,8 @@ GEM | ||
57 | binding_of_caller (0.7.2) | 57 | binding_of_caller (0.7.2) |
58 | debug_inspector (>= 0.0.1) | 58 | debug_inspector (>= 0.0.1) |
59 | builder (3.2.2) | 59 | builder (3.2.2) |
60 | - capistrano (3.3.3) | ||
61 | - capistrano-stats (~> 1.0.3) | 60 | + capistrano (3.3.4) |
61 | + capistrano-stats (~> 1.1.0) | ||
62 | i18n | 62 | i18n |
63 | rake (>= 10.0.0) | 63 | rake (>= 10.0.0) |
64 | sshkit (~> 1.3) | 64 | sshkit (~> 1.3) |
@@ -71,7 +71,7 @@ GEM | @@ -71,7 +71,7 @@ GEM | ||
71 | capistrano-rvm (0.1.2) | 71 | capistrano-rvm (0.1.2) |
72 | capistrano (~> 3.0) | 72 | capistrano (~> 3.0) |
73 | sshkit (~> 1.2) | 73 | sshkit (~> 1.2) |
74 | - capistrano-stats (1.0.3) | 74 | + capistrano-stats (1.1.0) |
75 | capybara (2.4.4) | 75 | capybara (2.4.4) |
76 | mime-types (>= 1.16) | 76 | mime-types (>= 1.16) |
77 | nokogiri (>= 1.3.3) | 77 | nokogiri (>= 1.3.3) |
app/controllers/metric_configurations_controller.rb
@@ -8,12 +8,12 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | @@ -8,12 +8,12 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | ||
8 | def new | 8 | def new |
9 | super | 9 | super |
10 | metric_configuration.metric_collector_name = params[:metric_collector_name] | 10 | metric_configuration.metric_collector_name = params[:metric_collector_name] |
11 | - metric_configuration.metric = KalibroClient::Processor::MetricCollector.find_by_name(params[:metric_collector_name]).metric params[:metric_name] | 11 | + metric_configuration.metric = KalibroClient::Processor::MetricCollector.find(params[:metric_collector_name]).metric params[:metric_name] |
12 | end | 12 | end |
13 | 13 | ||
14 | def create | 14 | def create |
15 | super | 15 | super |
16 | - @metric_configuration.metric = KalibroClient::Processor::MetricCollector.find_by_name(params[:metric_collector_name]).metric params[:metric_name] | 16 | + @metric_configuration.metric = KalibroClient::Processor::MetricCollector.find(params[:metric_collector_name]).metric params[:metric_name] |
17 | @metric_configuration.metric_collector_name = params[:metric_collector_name] | 17 | @metric_configuration.metric_collector_name = params[:metric_collector_name] |
18 | @metric_configuration.code = @metric_configuration.metric.code | 18 | @metric_configuration.code = @metric_configuration.metric.code |
19 | respond_to do |format| | 19 | respond_to do |format| |
app/helpers/processings_helper.rb
@@ -8,7 +8,7 @@ module ProcessingsHelper | @@ -8,7 +8,7 @@ module ProcessingsHelper | ||
8 | end | 8 | end |
9 | 9 | ||
10 | def find_range_snapshot(metric_result) | 10 | def find_range_snapshot(metric_result) |
11 | - range_snapshots = metric_result.metric_configuration_snapshot.range_snapshot | 11 | + range_snapshots = metric_result.metric_configuration.kalibro_ranges |
12 | 12 | ||
13 | range_snapshots.each do |range_snapshot| | 13 | range_snapshots.each do |range_snapshot| |
14 | return range_snapshot if ((range_snapshot.beginning <= metric_result.value || range_snapshot.beginning == '-INF') && (range_snapshot.end >= metric_result.value || range_snapshot.beginning == '+INF')) | 14 | return range_snapshot if ((range_snapshot.beginning <= metric_result.value || range_snapshot.beginning == '-INF') && (range_snapshot.end >= metric_result.value || range_snapshot.beginning == '+INF')) |
@@ -26,4 +26,4 @@ module ProcessingsHelper | @@ -26,4 +26,4 @@ module ProcessingsHelper | ||
26 | module_name.to_s | 26 | module_name.to_s |
27 | end | 27 | end |
28 | end | 28 | end |
29 | -end | ||
30 | \ No newline at end of file | 29 | \ No newline at end of file |
30 | +end |
app/models/module_result.rb
@@ -13,6 +13,6 @@ class ModuleResult < KalibroClient::Processor::ModuleResult | @@ -13,6 +13,6 @@ class ModuleResult < KalibroClient::Processor::ModuleResult | ||
13 | private | 13 | private |
14 | 14 | ||
15 | def find_grade_by_metric_name(metric_results, name) | 15 | def find_grade_by_metric_name(metric_results, name) |
16 | - metric_results.each { |metric_result| return metric_result.value if metric_result.metric_configuration_snapshot.metric.name == name } | 16 | + metric_results.each { |metric_result| return metric_result.value if metric_result.metric_configuration.metric_snapshot.name == name } |
17 | end | 17 | end |
18 | end | 18 | end |
spec/controllers/metric_configurations_controller_spec.rb
@@ -29,7 +29,7 @@ describe MetricConfigurationsController, :type => :controller do | @@ -29,7 +29,7 @@ describe MetricConfigurationsController, :type => :controller do | ||
29 | context 'when the current user owns the mezuro configuration' do | 29 | context 'when the current user owns the mezuro configuration' do |
30 | before :each do | 30 | before :each do |
31 | subject.expects(:mezuro_configuration_owner?).returns true | 31 | subject.expects(:mezuro_configuration_owner?).returns true |
32 | - KalibroClient::Processor::MetricCollector.expects(:find_by_name).with(metric_collector.name).returns(metric_collector) | 32 | + KalibroClient::Processor::MetricCollector.expects(:find).with(metric_collector.name).returns(metric_collector) |
33 | post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", metric_collector_name: metric_collector.name | 33 | post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", metric_collector_name: metric_collector.name |
34 | end | 34 | end |
35 | 35 | ||
@@ -65,7 +65,7 @@ describe MetricConfigurationsController, :type => :controller do | @@ -65,7 +65,7 @@ describe MetricConfigurationsController, :type => :controller do | ||
65 | context 'with valid fields' do | 65 | context 'with valid fields' do |
66 | before :each do | 66 | before :each do |
67 | MetricConfiguration.any_instance.expects(:save).returns(true) | 67 | MetricConfiguration.any_instance.expects(:save).returns(true) |
68 | - KalibroClient::Processor::MetricCollector.expects(:find_by_name).with(metric_collector.name).returns(metric_collector) | 68 | + KalibroClient::Processor::MetricCollector.expects(:find).with(metric_collector.name).returns(metric_collector) |
69 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) | 69 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) |
70 | 70 | ||
71 | post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_name: metric_configuration.metric.name | 71 | post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_name: metric_configuration.metric.name |
@@ -77,7 +77,7 @@ describe MetricConfigurationsController, :type => :controller do | @@ -77,7 +77,7 @@ describe MetricConfigurationsController, :type => :controller do | ||
77 | context 'with invalid fields' do | 77 | context 'with invalid fields' do |
78 | before :each do | 78 | before :each do |
79 | MetricConfiguration.any_instance.expects(:save).returns(false) | 79 | MetricConfiguration.any_instance.expects(:save).returns(false) |
80 | - KalibroClient::Processor::MetricCollector.expects(:find_by_name).with(metric_collector.name).returns(metric_collector) | 80 | + KalibroClient::Processor::MetricCollector.expects(:find).with(metric_collector.name).returns(metric_collector) |
81 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) | 81 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) |
82 | 82 | ||
83 | post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_name: metric_configuration.metric.name | 83 | post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_name: metric_configuration.metric.name |
spec/factories/metric_collectors.rb
1 | FactoryGirl.define do | 1 | FactoryGirl.define do |
2 | factory :metric_collector, class: KalibroClient::Processor::MetricCollector do | 2 | factory :metric_collector, class: KalibroClient::Processor::MetricCollector do |
3 | name 'Analizo' | 3 | name 'Analizo' |
4 | + description 'A metric collector' | ||
4 | supported_metrics { { "total_abstract_classes" => FactoryGirl.build(:metric), "loc" => FactoryGirl.build(:loc)} } | 5 | supported_metrics { { "total_abstract_classes" => FactoryGirl.build(:metric), "loc" => FactoryGirl.build(:loc)} } |
6 | + | ||
7 | + initialize_with { new({"name" => name, "description" => description, "supported_metrics" => supported_metrics}) } | ||
5 | end | 8 | end |
6 | end | 9 | end |
spec/factories/metric_configurations.rb
@@ -19,4 +19,16 @@ FactoryGirl.define do | @@ -19,4 +19,16 @@ FactoryGirl.define do | ||
19 | reading_group_id 1 | 19 | reading_group_id 1 |
20 | configuration_id 1 | 20 | configuration_id 1 |
21 | end | 21 | end |
22 | + | ||
23 | + factory :metric_configuration_with_snapshot, class: MetricConfiguration do | ||
24 | + id 1 | ||
25 | + code 'total_modules' | ||
26 | + metric_snapshot {FactoryGirl.build(:metric)} | ||
27 | + metric_collector_name "Analizo" | ||
28 | + weight 1 | ||
29 | + aggregation_form "MEDIAN" | ||
30 | + reading_group_id 1 | ||
31 | + configuration_id 1 | ||
32 | + end | ||
33 | + | ||
22 | end | 34 | end |
spec/factories/metric_results.rb
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | FactoryGirl.define do | 17 | FactoryGirl.define do |
18 | factory :metric_result, class: KalibroClient::Processor::MetricResult do | 18 | factory :metric_result, class: KalibroClient::Processor::MetricResult do |
19 | id "42" | 19 | id "42" |
20 | - self.configuration { FactoryGirl.build(:metric_configuration_snapshot) } | 20 | + self.configuration { FactoryGirl.build(:metric_configuration) } |
21 | value "10.0" | 21 | value "10.0" |
22 | aggregated_value "21" | 22 | aggregated_value "21" |
23 | end | 23 | end |
spec/helpers/processings_helper_spec.rb
@@ -21,7 +21,8 @@ describe ProcessingsHelper, :type => :helper do | @@ -21,7 +21,8 @@ describe ProcessingsHelper, :type => :helper do | ||
21 | let(:range_snapshot_10dot1_to_15) { FactoryGirl.build(:range_snapshot, {beginning: 10.1, end: 15.0}) } | 21 | let(:range_snapshot_10dot1_to_15) { FactoryGirl.build(:range_snapshot, {beginning: 10.1, end: 15.0}) } |
22 | 22 | ||
23 | before :each do | 23 | before :each do |
24 | - metric_configuration_snapshot.expects(:range_snapshot). | 24 | + metric_result.expects(:metric_configuration).returns(metric_result.configuration) |
25 | + metric_configuration_snapshot.expects(:kalibro_ranges). | ||
25 | returns([range_snapshot_1_to_5, | 26 | returns([range_snapshot_1_to_5, |
26 | range_snapshot_5dot1_to_10, | 27 | range_snapshot_5dot1_to_10, |
27 | range_snapshot_10dot1_to_15]) | 28 | range_snapshot_10dot1_to_15]) |
@@ -59,4 +60,4 @@ describe ProcessingsHelper, :type => :helper do | @@ -59,4 +60,4 @@ describe ProcessingsHelper, :type => :helper do | ||
59 | end | 60 | end |
60 | end | 61 | end |
61 | end | 62 | end |
62 | -end | ||
63 | \ No newline at end of file | 63 | \ No newline at end of file |
64 | +end |
spec/models/module_result_spec.rb
@@ -6,19 +6,20 @@ describe ModuleResult, :type => :model do | @@ -6,19 +6,20 @@ describe ModuleResult, :type => :model do | ||
6 | 6 | ||
7 | describe 'metric_history' do | 7 | describe 'metric_history' do |
8 | let(:date_module_result) {FactoryGirl.build(:date_module_result)} | 8 | let(:date_module_result) {FactoryGirl.build(:date_module_result)} |
9 | - let(:metric_result) {FactoryGirl.build(:metric_result)} | 9 | + let(:metric_result) { FactoryGirl.build(:metric_result, configuration: FactoryGirl.build(:metric_configuration_with_snapshot)) } |
10 | let(:processing) {FactoryGirl.build(:processing)} | 10 | let(:processing) {FactoryGirl.build(:processing)} |
11 | let(:repository) {FactoryGirl.build(:repository)} | 11 | let(:repository) {FactoryGirl.build(:repository)} |
12 | 12 | ||
13 | before :each do | 13 | before :each do |
14 | subject.expects(:processing).returns(processing) | 14 | subject.expects(:processing).returns(processing) |
15 | + metric_result.expects(:metric_configuration).returns(metric_result.configuration) | ||
15 | processing.expects(:repository).returns(repository) | 16 | processing.expects(:repository).returns(repository) |
16 | repository.expects(:module_result_history_of).with(subject).returns([date_module_result]) | 17 | repository.expects(:module_result_history_of).with(subject).returns([date_module_result]) |
17 | ModuleResult.any_instance.expects(:metric_results).returns([metric_result]) | 18 | ModuleResult.any_instance.expects(:metric_results).returns([metric_result]) |
18 | end | 19 | end |
19 | 20 | ||
20 | it 'should return the history for the given metric name' do | 21 | it 'should return the history for the given metric name' do |
21 | - expect(subject.metric_history(metric_result.metric_configuration_snapshot.metric.name)).to eq({date_module_result.date => metric_result.value}) | 22 | + expect(subject.metric_history(metric_result.configuration.metric_snapshot.name)).to eq({date_module_result.date => metric_result.value}) |
22 | end | 23 | end |
23 | end | 24 | end |
24 | end | 25 | end |