Commit b67cf9df33417521dbe4611a5df5307f2b7829a1

Authored by Rafael Manzo
Committed by Rafael Manzo
1 parent 9843d7f9

[Mezuro] Fixed RangeSnapshot model and view

plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb
... ... @@ -11,11 +11,24 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model
11 11 end
12 12  
13 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 21 end
16 22  
17 23 def range_snapshot
18 24 range
19 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 34 end
... ...
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb
... ... @@ -14,7 +14,7 @@ class MetricConfigurationSnapshotFixtures
14 14 :aggregation_form => 'AVERAGE',
15 15 :metric => MetricFixtures.amloc_hash,
16 16 :base_tool_name => "Analizo",
17   - :range => RangeSnapshotFixtures.range_snapshot_hash,
  17 + :range => [RangeSnapshotFixtures.range_snapshot_hash],
18 18 :attributes! => {
19 19 :metric => {
20 20 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
... ... @@ -26,6 +26,16 @@ class MetricConfigurationSnapshotFixtures
26 26 }
27 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 39 def self.compound_metric_configuration_snapshot
30 40 Kalibro::MetricConfigurationSnapshot.new compound_metric_configuration_snapshot_hash
31 41 end
... ...
plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb
... ... @@ -6,15 +6,19 @@ class MetricConfigurationSnapshotTest &lt; ActiveSupport::TestCase
6 6  
7 7 def setup
8 8 @hash = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash
  9 + @hash2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash_with_2_elements
9 10 @metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot
  11 + @metric_configuration_snapshot2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_with_2_elements
10 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 15 assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code
  16 + assert_equal @hash, @metric_configuration_snapshot.to_hash
14 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 22 end
19 23  
20 24 end
... ...
plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml
... ... @@ -9,13 +9,14 @@
9 9 <tbody>
10 10 <% @metric_results.each do |metric_result| %>
11 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 13 <% formatted_name = MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) %>
14   - <% if !range_snapshot.nil? %>
  14 + <% if !range_snapshots.nil? %>
15 15 <tr>
16 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 17 <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>
18 18 <td><%= metric_configuration_snapshot.weight %></td>
  19 + <% range_snapshots.each do |range_snapshot| %>
19 20 <% if range_snapshot.beginning.to_f <= metric_result.value and range_snapshot.end.to_f > metric_result.value %>
20 21 <td style="background-color: #<%= range_snapshot.color %>">
21 22 <span title="<%= range_snapshot.comments %>" >
... ... @@ -33,6 +34,7 @@
33 34 </td>
34 35 </tr>
35 36 <% end %>
  37 + <% end %>
36 38 <% end %>
37 39 <% end %>
38 40 </tbody>
... ...