From 771bfe3fbe869b2316fcf03b497aa27f60d69017 Mon Sep 17 00:00:00 2001 From: Alessandro Palmeira + Diego Araújo + João M. M. da Silva Date: Thu, 10 Jan 2013 17:50:11 -0200 Subject: [PATCH] [Mezuro] Fixed aggregated value. --- plugins/mezuro/lib/kalibro/metric_result.rb | 8 ++------ plugins/mezuro/test/unit/kalibro/metric_result_test.rb | 8 ++++++++ plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/mezuro/lib/kalibro/metric_result.rb b/plugins/mezuro/lib/kalibro/metric_result.rb index 7b58ce7..d4ddb90 100644 --- a/plugins/mezuro/lib/kalibro/metric_result.rb +++ b/plugins/mezuro/lib/kalibro/metric_result.rb @@ -4,9 +4,9 @@ class Kalibro::MetricResult < Kalibro::Model def initialize(attributes={}) value = attributes[:value] - value == "NaN" ? @value = attributes[:agreggated_value] : @value = value.to_f + @value = (value == "NaN") ? attributes[:aggregated_value].to_f : value.to_f attributes.each do |field, value| - if field!="value" and field!="agreggated_value" and self.class.is_valid?(field) + if field!= :value and field!= :aggregated_value and self.class.is_valid?(field) send("#{field}=", value) end end @@ -25,10 +25,6 @@ class Kalibro::MetricResult < Kalibro::Model configuration end - def value=(value) - @value = value.to_f - end - def error=(value) @error = Kalibro::Throwable.to_object value end diff --git a/plugins/mezuro/test/unit/kalibro/metric_result_test.rb b/plugins/mezuro/test/unit/kalibro/metric_result_test.rb index dc2b6bf..dfd78ff 100644 --- a/plugins/mezuro/test/unit/kalibro/metric_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/metric_result_test.rb @@ -18,6 +18,14 @@ class MetricResultTest < ActiveSupport::TestCase assert_equal @native_hash[:value].to_f, metric_result.value end + should 'create metric result with aggregated value from hash' do + hash = @native_hash + hash[:aggregated_value] = "2.0" + hash[:value] = "NaN" + metric_result = Kalibro::MetricResult.new(hash) + assert_equal @native_hash[:aggregated_value].to_f, metric_result.value + end + should 'convert metric result to hash' do assert_equal @native_hash, @result.to_hash 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 14d6b69..603769c 100644 --- a/plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml +++ b/plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml @@ -18,7 +18,7 @@ <%= 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 %> + <% if range_snapshot.beginning <= metric_result.value and range_snapshot.end > metric_result.value %> <%= range_snapshot.label %> -- libgit2 0.21.2