From 1c08281cf046bc42f48f9d92d2d4fc4d33d52d4a Mon Sep 17 00:00:00 2001 From: Alessandro Palmeira + Diego Araújo Date: Fri, 11 Jan 2013 17:18:33 -0200 Subject: [PATCH] [Mezuro] Content helper tests. --- plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb | 8 ++++---- plugins/mezuro/test/fixtures/date_metric_result_fixtures.rb | 9 +++++++++ plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb | 47 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb b/plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb index 75ec092..db12ddf 100644 --- a/plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb +++ b/plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb @@ -7,7 +7,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper end def self.periodicity_options - [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] + [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweekly", 15], ["Monthly", 30]] end def self.periodicity_option(periodicity) @@ -47,9 +47,9 @@ class MezuroPlugin::Helpers::ContentViewerHelper metric_configuration_snapshot.metric.name.delete("() ") end - def self.format_time(time) - time /= 1000 # transform miliseconds to seconds - MezuroPluginModuleResultController.helpers.distance_of_time_in_words(0, time, include_seconds = true) + def self.format_time(miliseconds) + seconds = miliseconds/1000 + MezuroPluginModuleResultController.helpers.distance_of_time_in_words(0, seconds, include_seconds = true) end private diff --git a/plugins/mezuro/test/fixtures/date_metric_result_fixtures.rb b/plugins/mezuro/test/fixtures/date_metric_result_fixtures.rb index e1c0290..c537f9f 100644 --- a/plugins/mezuro/test/fixtures/date_metric_result_fixtures.rb +++ b/plugins/mezuro/test/fixtures/date_metric_result_fixtures.rb @@ -21,4 +21,13 @@ class DateMetricResultFixtures } end + def self.score_history + result = [] + result << date_metric_result + newer_date_metric_result = date_metric_result + newer_date_metric_result.date = '2011-10-25T18:26:43.151+00:00' + newer_date_metric_result.metric_result.value = 5.0 + result << newer_date_metric_result + end + end diff --git a/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb b/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb index db1176d..7490463 100644 --- a/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb +++ b/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb @@ -1,21 +1,58 @@ require "test_helper" require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures" class ContentViewerHelperTest < ActiveSupport::TestCase + def setup + @helper = MezuroPlugin::Helpers::ContentViewerHelper + end + should 'get the number rounded by two decimal points' do - assert_equal '4.22', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.22344') - assert_equal '4.10', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.1') - assert_equal '4.00', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4') + assert_equal '4.22', @helper.format_grade('4.22344') + assert_equal '4.10', @helper.format_grade('4.1') + assert_equal '4.00', @helper.format_grade('4') end should 'create the periodicity options array' do - assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.periodicity_options + assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweekly", 15], ["Monthly", 30]], @helper.periodicity_options + end + + should 'return the correct string for a given periodicity' do + assert_equal "Not Periodically", @helper.periodicity_option(0) + assert_equal "1 day", @helper.periodicity_option(1) + assert_equal "2 days", @helper.periodicity_option(2) + assert_equal "Weekly", @helper.periodicity_option(7) + assert_equal "Biweekly", @helper.periodicity_option(15) + assert_equal "Monthly", @helper.periodicity_option(30) + end + + should 'create the license options array' do + options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yml") + options = options.split(";") + formated_options = [] + options.each { |option| formated_options << [option, option] } + assert_equal formated_options, @helper.license_options end + should 'generate chart from metric result history' do + chart = "http://chart.apis.google.com/chart?chxt=y,x&chco=c4a000&chf=bg,ls,90,efefef,0.2,ffffff,0.2&chd=s:A9&chl=2011-10-20T18%3A26%3A43%2B00%3A00|2011-10-25T18%3A26%3A43%2B00%3A00&cht=lc&chs=600x180&chxr=0,0.0,5.0" + metric_history = DateMetricResultFixtures.score_history + + assert_equal chart, @helper.generate_chart(metric_history) + end + + should 'format time to show a sentence' do + assert_equal 'less than 5 seconds', @helper.format_time(0) + assert_equal 'less than 5 seconds', @helper.format_time(4999) + assert_equal 'less than 10 seconds', @helper.format_time(5000) + assert_equal '1 minute', @helper.format_time(70000) + assert_equal 'about 2 hours', @helper.format_time(7000000) + end + should 'format metric name for metric configuration snapshot' do metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot - assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) + assert_equal 'AverageMethodLOC', @helper.format_name(metric_configuration_snapshot) end end -- libgit2 0.21.2