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 | 1 | GIT |
2 | 2 | remote: https://github.com/mezuro/kalibro_client |
3 | - revision: e8367929a341a2eaf16599a858972703151a8967 | |
3 | + revision: 434108322137611d54314ffb16206fe05c0dac08 | |
4 | 4 | specs: |
5 | 5 | kalibro_client (0.0.1) |
6 | 6 | activeresource (~> 4.0.0) |
... | ... | @@ -57,8 +57,8 @@ GEM |
57 | 57 | binding_of_caller (0.7.2) |
58 | 58 | debug_inspector (>= 0.0.1) |
59 | 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 | 62 | i18n |
63 | 63 | rake (>= 10.0.0) |
64 | 64 | sshkit (~> 1.3) |
... | ... | @@ -71,7 +71,7 @@ GEM |
71 | 71 | capistrano-rvm (0.1.2) |
72 | 72 | capistrano (~> 3.0) |
73 | 73 | sshkit (~> 1.2) |
74 | - capistrano-stats (1.0.3) | |
74 | + capistrano-stats (1.1.0) | |
75 | 75 | capybara (2.4.4) |
76 | 76 | mime-types (>= 1.16) |
77 | 77 | nokogiri (>= 1.3.3) | ... | ... |
app/controllers/metric_configurations_controller.rb
... | ... | @@ -8,12 +8,12 @@ class MetricConfigurationsController < BaseMetricConfigurationsController |
8 | 8 | def new |
9 | 9 | super |
10 | 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 | 12 | end |
13 | 13 | |
14 | 14 | def create |
15 | 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 | 17 | @metric_configuration.metric_collector_name = params[:metric_collector_name] |
18 | 18 | @metric_configuration.code = @metric_configuration.metric.code |
19 | 19 | respond_to do |format| | ... | ... |
app/helpers/processings_helper.rb
... | ... | @@ -8,7 +8,7 @@ module ProcessingsHelper |
8 | 8 | end |
9 | 9 | |
10 | 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 | 13 | range_snapshots.each do |range_snapshot| |
14 | 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 | 26 | module_name.to_s |
27 | 27 | end |
28 | 28 | end |
29 | -end | |
30 | 29 | \ No newline at end of file |
30 | +end | ... | ... |
app/models/module_result.rb
... | ... | @@ -13,6 +13,6 @@ class ModuleResult < KalibroClient::Processor::ModuleResult |
13 | 13 | private |
14 | 14 | |
15 | 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 | 17 | end |
18 | 18 | end | ... | ... |
spec/controllers/metric_configurations_controller_spec.rb
... | ... | @@ -29,7 +29,7 @@ describe MetricConfigurationsController, :type => :controller do |
29 | 29 | context 'when the current user owns the mezuro configuration' do |
30 | 30 | before :each do |
31 | 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 | 33 | post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", metric_collector_name: metric_collector.name |
34 | 34 | end |
35 | 35 | |
... | ... | @@ -65,7 +65,7 @@ describe MetricConfigurationsController, :type => :controller do |
65 | 65 | context 'with valid fields' do |
66 | 66 | before :each do |
67 | 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 | 69 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) |
70 | 70 | |
71 | 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 | 77 | context 'with invalid fields' do |
78 | 78 | before :each do |
79 | 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 | 81 | metric_collector.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) |
82 | 82 | |
83 | 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 | 1 | FactoryGirl.define do |
2 | 2 | factory :metric_collector, class: KalibroClient::Processor::MetricCollector do |
3 | 3 | name 'Analizo' |
4 | + description 'A metric collector' | |
4 | 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 | 8 | end |
6 | 9 | end | ... | ... |
spec/factories/metric_configurations.rb
... | ... | @@ -19,4 +19,16 @@ FactoryGirl.define do |
19 | 19 | reading_group_id 1 |
20 | 20 | configuration_id 1 |
21 | 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 | 34 | end | ... | ... |
spec/factories/metric_results.rb
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | FactoryGirl.define do |
18 | 18 | factory :metric_result, class: KalibroClient::Processor::MetricResult do |
19 | 19 | id "42" |
20 | - self.configuration { FactoryGirl.build(:metric_configuration_snapshot) } | |
20 | + self.configuration { FactoryGirl.build(:metric_configuration) } | |
21 | 21 | value "10.0" |
22 | 22 | aggregated_value "21" |
23 | 23 | end | ... | ... |
spec/helpers/processings_helper_spec.rb
... | ... | @@ -21,7 +21,8 @@ describe ProcessingsHelper, :type => :helper do |
21 | 21 | let(:range_snapshot_10dot1_to_15) { FactoryGirl.build(:range_snapshot, {beginning: 10.1, end: 15.0}) } |
22 | 22 | |
23 | 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 | 26 | returns([range_snapshot_1_to_5, |
26 | 27 | range_snapshot_5dot1_to_10, |
27 | 28 | range_snapshot_10dot1_to_15]) |
... | ... | @@ -59,4 +60,4 @@ describe ProcessingsHelper, :type => :helper do |
59 | 60 | end |
60 | 61 | end |
61 | 62 | end |
62 | -end | |
63 | 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 | 6 | |
7 | 7 | describe 'metric_history' do |
8 | 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 | 10 | let(:processing) {FactoryGirl.build(:processing)} |
11 | 11 | let(:repository) {FactoryGirl.build(:repository)} |
12 | 12 | |
13 | 13 | before :each do |
14 | 14 | subject.expects(:processing).returns(processing) |
15 | + metric_result.expects(:metric_configuration).returns(metric_result.configuration) | |
15 | 16 | processing.expects(:repository).returns(repository) |
16 | 17 | repository.expects(:module_result_history_of).with(subject).returns([date_module_result]) |
17 | 18 | ModuleResult.any_instance.expects(:metric_results).returns([metric_result]) |
18 | 19 | end |
19 | 20 | |
20 | 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 | 23 | end |
23 | 24 | end |
24 | 25 | end | ... | ... |