Commit b67cf9df33417521dbe4611a5df5307f2b7829a1
Committed by
Rafael Manzo
1 parent
9843d7f9
Exists in
master
and in
28 other branches
[Mezuro] Fixed RangeSnapshot model and view
Showing
4 changed files
with
36 additions
and
7 deletions
Show diff stats
plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb
| @@ -11,11 +11,24 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model | @@ -11,11 +11,24 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model | ||
| 11 | end | 11 | end |
| 12 | 12 | ||
| 13 | def range=(value) | 13 | def range=(value) |
| 14 | - @range = Kalibro::RangeSnapshot.to_object value | 14 | + value.to_a |
| 15 | + @range = [] | ||
| 16 | + | ||
| 17 | + value.each do |range_snapshot| | ||
| 18 | + @range << Kalibro::RangeSnapshot.to_object(range_snapshot) | ||
| 19 | + end | ||
| 20 | + | ||
| 15 | end | 21 | end |
| 16 | 22 | ||
| 17 | def range_snapshot | 23 | def range_snapshot |
| 18 | range | 24 | range |
| 19 | end | 25 | end |
| 20 | 26 | ||
| 27 | + def to_hash | ||
| 28 | + hash = super | ||
| 29 | + hash[:attributes!][:range] = {'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
| 30 | + 'xsi:type' => 'kalibro:rangeSnapshotXml' } | ||
| 31 | + hash | ||
| 32 | + end | ||
| 33 | + | ||
| 21 | end | 34 | end |
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb
| @@ -14,7 +14,7 @@ class MetricConfigurationSnapshotFixtures | @@ -14,7 +14,7 @@ class MetricConfigurationSnapshotFixtures | ||
| 14 | :aggregation_form => 'AVERAGE', | 14 | :aggregation_form => 'AVERAGE', |
| 15 | :metric => MetricFixtures.amloc_hash, | 15 | :metric => MetricFixtures.amloc_hash, |
| 16 | :base_tool_name => "Analizo", | 16 | :base_tool_name => "Analizo", |
| 17 | - :range => RangeSnapshotFixtures.range_snapshot_hash, | 17 | + :range => [RangeSnapshotFixtures.range_snapshot_hash], |
| 18 | :attributes! => { | 18 | :attributes! => { |
| 19 | :metric => { | 19 | :metric => { |
| 20 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | 20 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
| @@ -26,6 +26,16 @@ class MetricConfigurationSnapshotFixtures | @@ -26,6 +26,16 @@ class MetricConfigurationSnapshotFixtures | ||
| 26 | } | 26 | } |
| 27 | end | 27 | end |
| 28 | 28 | ||
| 29 | + def self.metric_configuration_snapshot_with_2_elements | ||
| 30 | + Kalibro::MetricConfigurationSnapshot.new metric_configuration_snapshot_hash_with_2_elements | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + def self.metric_configuration_snapshot_hash_with_2_elements | ||
| 34 | + hash = self.metric_configuration_snapshot_hash | ||
| 35 | + hash[:range] << RangeSnapshotFixtures.range_snapshot_hash | ||
| 36 | + hash | ||
| 37 | + end | ||
| 38 | + | ||
| 29 | def self.compound_metric_configuration_snapshot | 39 | def self.compound_metric_configuration_snapshot |
| 30 | Kalibro::MetricConfigurationSnapshot.new compound_metric_configuration_snapshot_hash | 40 | Kalibro::MetricConfigurationSnapshot.new compound_metric_configuration_snapshot_hash |
| 31 | end | 41 | end |
plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb
| @@ -6,15 +6,19 @@ class MetricConfigurationSnapshotTest < ActiveSupport::TestCase | @@ -6,15 +6,19 @@ class MetricConfigurationSnapshotTest < ActiveSupport::TestCase | ||
| 6 | 6 | ||
| 7 | def setup | 7 | def setup |
| 8 | @hash = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash | 8 | @hash = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash |
| 9 | + @hash2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash_with_2_elements | ||
| 9 | @metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot | 10 | @metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot |
| 11 | + @metric_configuration_snapshot2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_with_2_elements | ||
| 10 | end | 12 | end |
| 11 | 13 | ||
| 12 | - should 'create metric configuration snapshot from hash' do | 14 | + should 'create and convert metric configuration snapshot from hash' do |
| 13 | assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code | 15 | assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code |
| 16 | + assert_equal @hash, @metric_configuration_snapshot.to_hash | ||
| 14 | end | 17 | end |
| 15 | 18 | ||
| 16 | - should 'convert metric configuration snapshot to hash' do | ||
| 17 | - assert_equal @hash, @metric_configuration_snapshot.to_hash | 19 | + should 'create and convert metric configuration snapshot from hash with 2 elements' do |
| 20 | + assert_equal @hash2[:code], Kalibro::MetricConfigurationSnapshot.new(@hash2).code | ||
| 21 | + assert_equal @hash2, @metric_configuration_snapshot2.to_hash | ||
| 18 | end | 22 | end |
| 19 | 23 | ||
| 20 | end | 24 | end |
plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml
| @@ -9,13 +9,14 @@ | @@ -9,13 +9,14 @@ | ||
| 9 | <tbody> | 9 | <tbody> |
| 10 | <% @metric_results.each do |metric_result| %> | 10 | <% @metric_results.each do |metric_result| %> |
| 11 | <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot%> | 11 | <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot%> |
| 12 | - <% range_snapshot = metric_configuration_snapshot.range_snapshot %> | 12 | + <% range_snapshots = metric_configuration_snapshot.range_snapshot %> |
| 13 | <% formatted_name = MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) %> | 13 | <% formatted_name = MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) %> |
| 14 | - <% if !range_snapshot.nil? %> | 14 | + <% if !range_snapshots.nil? %> |
| 15 | <tr> | 15 | <tr> |
| 16 | <td style="width: 74%"><a href="#" show-metric-history="<%= formatted_name %>" data-module-id="<%= @module_result.id %>"><%= metric_configuration_snapshot.metric.name %></a></td> | 16 | <td style="width: 74%"><a href="#" show-metric-history="<%= formatted_name %>" data-module-id="<%= @module_result.id %>"><%= metric_configuration_snapshot.metric.name %></a></td> |
| 17 | <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td> | 17 | <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td> |
| 18 | <td><%= metric_configuration_snapshot.weight %></td> | 18 | <td><%= metric_configuration_snapshot.weight %></td> |
| 19 | + <% range_snapshots.each do |range_snapshot| %> | ||
| 19 | <% if range_snapshot.beginning.to_f <= metric_result.value and range_snapshot.end.to_f > metric_result.value %> | 20 | <% if range_snapshot.beginning.to_f <= metric_result.value and range_snapshot.end.to_f > metric_result.value %> |
| 20 | <td style="background-color: #<%= range_snapshot.color %>"> | 21 | <td style="background-color: #<%= range_snapshot.color %>"> |
| 21 | <span title="<%= range_snapshot.comments %>" > | 22 | <span title="<%= range_snapshot.comments %>" > |
| @@ -33,6 +34,7 @@ | @@ -33,6 +34,7 @@ | ||
| 33 | </td> | 34 | </td> |
| 34 | </tr> | 35 | </tr> |
| 35 | <% end %> | 36 | <% end %> |
| 37 | + <% end %> | ||
| 36 | <% end %> | 38 | <% end %> |
| 37 | <% end %> | 39 | <% end %> |
| 38 | </tbody> | 40 | </tbody> |