diff --git a/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb b/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb index 56b475c..99c3628 100644 --- a/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb +++ b/plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb @@ -11,11 +11,24 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model end def range=(value) - @range = Kalibro::RangeSnapshot.to_object value + value.to_a + @range = [] + + value.each do |range_snapshot| + @range << Kalibro::RangeSnapshot.to_object(range_snapshot) + end + end def range_snapshot range end + def to_hash + hash = super + hash[:attributes!][:range] = {'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:type' => 'kalibro:rangeSnapshotXml' } + hash + end + end diff --git a/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb b/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb index 51e2f69..24f0c82 100644 --- a/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb +++ b/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb @@ -14,7 +14,7 @@ class MetricConfigurationSnapshotFixtures :aggregation_form => 'AVERAGE', :metric => MetricFixtures.amloc_hash, :base_tool_name => "Analizo", - :range => RangeSnapshotFixtures.range_snapshot_hash, + :range => [RangeSnapshotFixtures.range_snapshot_hash], :attributes! => { :metric => { 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', @@ -26,6 +26,16 @@ class MetricConfigurationSnapshotFixtures } end + def self.metric_configuration_snapshot_with_2_elements + Kalibro::MetricConfigurationSnapshot.new metric_configuration_snapshot_hash_with_2_elements + end + + def self.metric_configuration_snapshot_hash_with_2_elements + hash = self.metric_configuration_snapshot_hash + hash[:range] << RangeSnapshotFixtures.range_snapshot_hash + hash + end + def self.compound_metric_configuration_snapshot Kalibro::MetricConfigurationSnapshot.new compound_metric_configuration_snapshot_hash end diff --git a/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb b/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb index 18b42cb..acab488 100644 --- a/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb +++ b/plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb @@ -6,15 +6,19 @@ class MetricConfigurationSnapshotTest < ActiveSupport::TestCase def setup @hash = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash + @hash2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash_with_2_elements @metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot + @metric_configuration_snapshot2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_with_2_elements end - should 'create metric configuration snapshot from hash' do + should 'create and convert metric configuration snapshot from hash' do assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code + assert_equal @hash, @metric_configuration_snapshot.to_hash end - should 'convert metric configuration snapshot to hash' do - assert_equal @hash, @metric_configuration_snapshot.to_hash + should 'create and convert metric configuration snapshot from hash with 2 elements' do + assert_equal @hash2[:code], Kalibro::MetricConfigurationSnapshot.new(@hash2).code + assert_equal @hash2, @metric_configuration_snapshot2.to_hash end end diff --git a/plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml b/plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml index ab1d243..18ab68d 100644 --- a/plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml +++ b/plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml @@ -9,13 +9,14 @@ <% @metric_results.each do |metric_result| %> <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot%> - <% range_snapshot = metric_configuration_snapshot.range_snapshot %> + <% range_snapshots = metric_configuration_snapshot.range_snapshot %> <% formatted_name = MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) %> - <% if !range_snapshot.nil? %> + <% if !range_snapshots.nil? %> <%= metric_configuration_snapshot.metric.name %> <%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %> <%= metric_configuration_snapshot.weight %> + <% range_snapshots.each do |range_snapshot| %> <% if range_snapshot.beginning.to_f <= metric_result.value and range_snapshot.end.to_f > metric_result.value %> @@ -33,6 +34,7 @@ <% end %> + <% end %> <% end %> <% end %> -- libgit2 0.21.2