Commit 0ea98e348e04355a4ee208c243d5aa262114be1c
1 parent
9b8c21ed
Exists in
colab
and in
4 other branches
Displaying metric results for the root module
Signed-off by: Renan Fichberg <rfichberg@gmail.com>
Showing
14 changed files
with
206 additions
and
13 deletions
Show diff stats
Gemfile
Gemfile.lock
... | ... | @@ -101,7 +101,7 @@ GEM |
101 | 101 | railties (>= 3.0, < 5.0) |
102 | 102 | thor (>= 0.14, < 2.0) |
103 | 103 | json (1.8.1) |
104 | - kalibro_entities (0.0.1.rc3) | |
104 | + kalibro_entities (0.0.1.rc4) | |
105 | 105 | activesupport (~> 4.0.0) |
106 | 106 | savon-ng-1.6 (~> 2.4.1) |
107 | 107 | konacha (3.0.0) |
... | ... | @@ -116,7 +116,7 @@ GEM |
116 | 116 | treetop (~> 1.4.8) |
117 | 117 | metaclass (0.0.1) |
118 | 118 | mime-types (1.25) |
119 | - mini_portile (0.5.1) | |
119 | + mini_portile (0.5.2) | |
120 | 120 | minitest (4.7.5) |
121 | 121 | mocha (0.14.0) |
122 | 122 | metaclass (~> 0.0.1) |
... | ... | @@ -255,7 +255,7 @@ DEPENDENCIES |
255 | 255 | factory_girl_rails |
256 | 256 | jbuilder (~> 1.2) |
257 | 257 | jquery-rails |
258 | - kalibro_entities (~> 0.0.1.rc3) | |
258 | + kalibro_entities (~> 0.0.1.rc4) | |
259 | 259 | konacha (~> 3.0.0) |
260 | 260 | mocha |
261 | 261 | modernizr-rails | ... | ... |
app/controllers/repositories_controller.rb
... | ... | @@ -9,15 +9,16 @@ class RepositoriesController < ApplicationController |
9 | 9 | # GET /projects/1/repositories/1 |
10 | 10 | # GET /projects/1/repositories/1.json |
11 | 11 | def show |
12 | - @configuration = KalibroEntities::Entities::Configuration.find(@repository.configuration_id) #FIXME: As soon as the Configuration model gets created refactor this! | |
13 | - @processing = @repository.last_processing | |
12 | + @configuration = KalibroEntities::Entities::Configuration.find(@repository.configuration_id) #FIXME: As soon as the Configuration model gets created refactor this! | |
13 | + @processing = @repository.last_processing | |
14 | + @metric_results = @processing.metric_results if @processing.ready? | |
14 | 15 | end |
15 | 16 | |
16 | 17 | # GET projects/1/repositories/new |
17 | 18 | def new |
18 | - @project_id = params[:project_id] | |
19 | - @repository = Repository.new | |
20 | - @repository_types = Repository.repository_types | |
19 | + @project_id = params[:project_id] | |
20 | + @repository = Repository.new | |
21 | + @repository_types = Repository.repository_types | |
21 | 22 | end |
22 | 23 | |
23 | 24 | # GET /repositories/1/edit | ... | ... |
app/helpers/processings_helper.rb
... | ... | @@ -2,4 +2,16 @@ module ProcessingsHelper |
2 | 2 | def humanize_eplased_time duration_in_milliseconds |
3 | 3 | distance_of_time_in_words(Time.now, (duration_in_milliseconds/1000.0).seconds.from_now) |
4 | 4 | end |
5 | + | |
6 | + def format_grade(grade) | |
7 | + sprintf("%.2f", grade.to_f) | |
8 | + end | |
9 | + | |
10 | + def find_range_snapshot(metric_result) | |
11 | + range_snapshots = metric_result.metric_configuration_snapshot.range_snapshot | |
12 | + | |
13 | + range_snapshots.each do |range_snapshot| | |
14 | + return range_snapshot if (range_snapshot.beginning <= metric_result.value && range_snapshot.end >= metric_result.value) | |
15 | + end | |
16 | + end | |
5 | 17 | end |
6 | 18 | \ No newline at end of file | ... | ... |
app/models/processing.rb
1 | 1 | class Processing < KalibroEntities::Entities::Processing |
2 | 2 | include KalibroRecord |
3 | -end | |
4 | 3 | \ No newline at end of file |
4 | + | |
5 | + def ready? | |
6 | + @state == "READY" | |
7 | + end | |
8 | + | |
9 | + def metric_results | |
10 | + KalibroEntities::Entities::MetricResult.metric_results_of(@results_root_id) | |
11 | + end | |
12 | +end | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +<% metric_configuration_snapshot = metric_result.metric_configuration_snapshot %> | |
2 | +<% unless metric_configuration_snapshot.range_snapshot.nil? %> | |
3 | + <% range_snapshot = find_range_snapshot(metric_result) %> | |
4 | + <tr> | |
5 | + <td><%= metric_configuration_snapshot.metric.name %></td> | |
6 | + <td><%= format_grade(metric_result.value) %></td> | |
7 | + <td><%= metric_configuration_snapshot.weight %></td> | |
8 | + <td><span style="color: #<%= range_snapshot.color %>"><%= range_snapshot.label %></span></td> | |
9 | + </tr> | |
10 | +<% end %> | |
0 | 11 | \ No newline at end of file | ... | ... |
app/views/repositories/show.html.erb
... | ... | @@ -37,6 +37,24 @@ |
37 | 37 | |
38 | 38 | <hr/> |
39 | 39 | |
40 | +<% if @processing.ready? %> | |
41 | + <table class="table table-hover"> | |
42 | + <thead> | |
43 | + <th>Metric</th> | |
44 | + <th>Value</th> | |
45 | + <th>Weight</th> | |
46 | + <th>Threshold</th> | |
47 | + </thead> | |
48 | + | |
49 | + <tbody> | |
50 | + <%= render partial: 'metric_result', collection: @metric_results %> | |
51 | + </tbody> | |
52 | + | |
53 | + </table> | |
54 | +<% end %> | |
55 | + | |
56 | +<hr/> | |
57 | + | |
40 | 58 | <%= link_to 'Back', project_path(@repository.project_id), class: 'btn btn-default' %> |
41 | 59 | <% if project_owner? @repository.project_id %> |
42 | 60 | <%= link_to 'Destroy', project_repository_path(@repository.project_id, @repository.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %> | ... | ... |
features/repository/show.feature
... | ... | @@ -21,6 +21,10 @@ Feature: Show Repository |
21 | 21 | And I should see "LOADING time" |
22 | 22 | And I should see "COLLECTING time" |
23 | 23 | And I should see "ANALYZING time" |
24 | + And I should see "Metric" | |
25 | + And I should see "Value" | |
26 | + And I should see "Weight" | |
27 | + And I should see "Threshold" | |
24 | 28 | |
25 | 29 | @kalibro_restart |
26 | 30 | Scenario: Just after start to process |
... | ... | @@ -35,4 +39,8 @@ Feature: Show Repository |
35 | 39 | And I should see "Address" |
36 | 40 | And I should see "Configuration" |
37 | 41 | And I should see "State" |
38 | - And I should see "Creation date" | |
39 | 42 | \ No newline at end of file |
43 | + And I should see "Creation date" | |
44 | + And I should not see Metric | |
45 | + And I should not see Value | |
46 | + And I should not see Weight | |
47 | + And I should not see Threshold | |
40 | 48 | \ No newline at end of file | ... | ... |
spec/controllers/repositories_controller_spec.rb
... | ... | @@ -80,9 +80,13 @@ describe RepositoriesController do |
80 | 80 | end |
81 | 81 | |
82 | 82 | describe 'show' do |
83 | - let(:repository) { FactoryGirl.build(:repository)} | |
83 | + let(:repository) { FactoryGirl.build(:repository) } | |
84 | + | |
84 | 85 | before :each do |
85 | - repository.expects(:last_processing).returns(FactoryGirl.build(:processing)) | |
86 | + processing = FactoryGirl.build(:processing) | |
87 | + | |
88 | + processing.expects(:metric_results).returns(nil) | |
89 | + repository.expects(:last_processing).returns(processing) | |
86 | 90 | KalibroEntities::Entities::Configuration.expects(:find).with(repository.id).returns(FactoryGirl.build(:configuration)) |
87 | 91 | Repository.expects(:find).with(repository.id).returns(repository) |
88 | 92 | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +# This file is part of KalibroEntities | |
2 | +# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file) | |
3 | +# | |
4 | +# This program is free software: you can redistribute it and/or modify | |
5 | +# it under the terms of the GNU General Public License as published by | |
6 | +# the Free Software Foundation, either version 3 of the License, or | |
7 | +# (at your option) any later version. | |
8 | +# | |
9 | +# This program is distributed in the hope that it will be useful, | |
10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | +# GNU General Public License for more details. | |
13 | + | |
14 | +# You should have received a copy of the GNU General Public License | |
15 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | + | |
17 | +FactoryGirl.define do | |
18 | + factory :metric_configuration_snapshot, class: KalibroEntities::Entities::MetricConfigurationSnapshot do | |
19 | + code "code" | |
20 | + weight "1.0" | |
21 | + aggregation_form 'AVERAGE' | |
22 | + metric {FactoryGirl.build(:metric)} | |
23 | + base_tool_name "Analizo" | |
24 | + range {FactoryGirl.build(:range_snapshot)} | |
25 | + end | |
26 | +end | |
0 | 27 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +# This file is part of KalibroEntities | |
2 | +# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file) | |
3 | +# | |
4 | +# This program is free software: you can redistribute it and/or modify | |
5 | +# it under the terms of the GNU General Public License as published by | |
6 | +# the Free Software Foundation, either version 3 of the License, or | |
7 | +# (at your option) any later version. | |
8 | +# | |
9 | +# This program is distributed in the hope that it will be useful, | |
10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | +# GNU General Public License for more details. | |
13 | + | |
14 | +# You should have received a copy of the GNU General Public License | |
15 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | + | |
17 | +FactoryGirl.define do | |
18 | + factory :metric_result, class: KalibroEntities::Entities::MetricResult do | |
19 | + id "42" | |
20 | + self.configuration { FactoryGirl.build(:metric_configuration_snapshot) } | |
21 | + value "10.0" | |
22 | + aggregated_value "21" | |
23 | + end | |
24 | +end | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +# This file is part of KalibroEntities | |
2 | +# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file) | |
3 | +# | |
4 | +# This program is free software: you can redistribute it and/or modify | |
5 | +# it under the terms of the GNU General Public License as published by | |
6 | +# the Free Software Foundation, either version 3 of the License, or | |
7 | +# (at your option) any later version. | |
8 | +# | |
9 | +# This program is distributed in the hope that it will be useful, | |
10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | +# GNU General Public License for more details. | |
13 | + | |
14 | +# You should have received a copy of the GNU General Public License | |
15 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | + | |
17 | +FactoryGirl.define do | |
18 | + factory :range_snapshot, class: KalibroEntities::Entities::RangeSnapshot do | |
19 | + beginning 1.1 | |
20 | + self.end 5.1 | |
21 | + label "Snapshot" | |
22 | + grade 10.1 | |
23 | + color "FF2284" | |
24 | + comments "Comment" | |
25 | + end | |
26 | +end | |
0 | 27 | \ No newline at end of file | ... | ... |
spec/helpers/processings_helper_spec.rb
... | ... | @@ -6,4 +6,29 @@ describe ProcessingsHelper do |
6 | 6 | helper.humanize_eplased_time(6000).should eq('less than a minute') |
7 | 7 | end |
8 | 8 | end |
9 | + | |
10 | + describe 'format_grade' do | |
11 | + it 'should format a Float to a readable format' do | |
12 | + helper.format_grade(1.333333333).should eq("1.33") | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + describe 'find_range_snapshot' do | |
17 | + let(:metric_configuration_snapshot) { FactoryGirl.build(:metric_configuration_snapshot)} | |
18 | + let(:metric_result) { FactoryGirl.build(:metric_result, {value: 6.0, configuration: metric_configuration_snapshot})} | |
19 | + let(:range_snapshot_1_to_5) { FactoryGirl.build(:range_snapshot, {beginning: 1.0, end: 5.0}) } | |
20 | + let(:range_snapshot_5dot1_to_10) { FactoryGirl.build(:range_snapshot, {beginning: 5.1, end: 10.0}) } | |
21 | + let(:range_snapshot_10dot1_to_15) { FactoryGirl.build(:range_snapshot, {beginning: 10.1, end: 15.0}) } | |
22 | + | |
23 | + before :each do | |
24 | + metric_configuration_snapshot.expects(:range_snapshot). | |
25 | + returns([range_snapshot_1_to_5, | |
26 | + range_snapshot_5dot1_to_10, | |
27 | + range_snapshot_10dot1_to_15]) | |
28 | + end | |
29 | + | |
30 | + it 'should return the range snapshot in which the value was in between' do | |
31 | + helper.find_range_snapshot(metric_result).should eq(range_snapshot_5dot1_to_10) | |
32 | + end | |
33 | + end | |
9 | 34 | end |
10 | 35 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe Processing do | |
4 | + describe 'methods' do | |
5 | + subject { FactoryGirl.build(:processing) } | |
6 | + | |
7 | + describe 'ready?' do | |
8 | + context 'with a READY processing' do | |
9 | + it 'should return true' do | |
10 | + subject.ready?.should be_true | |
11 | + end | |
12 | + end | |
13 | + | |
14 | + context 'without a READY processing' do | |
15 | + subject { FactoryGirl.build(:processing, state: 'COLLECTING') } | |
16 | + | |
17 | + it 'should return false' do | |
18 | + subject.ready?.should be_false | |
19 | + end | |
20 | + end | |
21 | + end | |
22 | + | |
23 | + describe 'metric_results' do | |
24 | + it 'should call the metric_results_of method' do | |
25 | + KalibroEntities::Entities::MetricResult.expects(:metric_results_of).with(subject.results_root_id).returns(nil) | |
26 | + | |
27 | + subject.metric_results | |
28 | + end | |
29 | + end | |
30 | + end | |
31 | +end | |
0 | 32 | \ No newline at end of file | ... | ... |