Commit 7f902334b6c1064aba48bfbfeb83419854fbe09e
Committed by
Carlos Morais
1 parent
a2ba74c1
Exists in
master
and in
29 other branches
[mezuro] Fix unit tests for updated entities
Showing
11 changed files
with
28 additions
and
14 deletions
Show diff stats
plugins/mezuro/lib/kalibro/client/module_result_client.rb
... | ... | @@ -13,7 +13,7 @@ class Kalibro::Client::ModuleResultClient |
13 | 13 | def module_result(project_name, module_name, date) |
14 | 14 | hash = @port.request(:get_module_result, |
15 | 15 | {:project_name => project_name, :module_name => module_name, |
16 | - :date => Kalibro::Entitites::Entity.date_with_milliseconds(date)})[:module_result] | |
16 | + :date => Kalibro::Entities::Entity.date_with_milliseconds(date)})[:module_result] | |
17 | 17 | Kalibro::Entities::ModuleResult.from_hash(hash) |
18 | 18 | end |
19 | 19 | ... | ... |
plugins/mezuro/lib/kalibro/entities/entity.rb
... | ... | @@ -2,10 +2,14 @@ class Kalibro::Entities::Entity |
2 | 2 | |
3 | 3 | def self.from_hash(hash) |
4 | 4 | entity = self.new |
5 | - hash.each { |field, value| entity.set(field, value) if field.to_s[0] != '@'} | |
5 | + hash.each { |field, value| entity.set(field, value) if is_valid?(field) } | |
6 | 6 | entity |
7 | 7 | end |
8 | 8 | |
9 | + def self.is_valid?(field) | |
10 | + field.to_s[0] != '@' and field != :attributes! | |
11 | + end | |
12 | + | |
9 | 13 | def self.date_with_milliseconds(date) |
10 | 14 | milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s |
11 | 15 | date.to_s[0..18] + milliseconds + date.to_s[19..-1] |
... | ... | @@ -60,7 +64,7 @@ class Kalibro::Entities::Entity |
60 | 64 | def convert_to_hash(value) |
61 | 65 | return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) |
62 | 66 | return value.to_hash if value.is_a?(Kalibro::Entities::Entity) |
63 | - return date_with_milliseconds(value) if value.is_a?(DateTime) | |
67 | + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime) | |
64 | 68 | return 'INF' if value.is_a?(Float) and value.infinite? == 1 |
65 | 69 | return '-INF' if value.is_a?(Float) and value.infinite? == -1 |
66 | 70 | value | ... | ... |
plugins/mezuro/lib/kalibro/entities/metric_result.rb
... | ... | @@ -23,7 +23,8 @@ class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity |
23 | 23 | end |
24 | 24 | |
25 | 25 | def descendent_result=(value) |
26 | - @descendent_result = value.collect {|element| element.to_f} | |
26 | + array = value.kind_of?(Array) ? value : [value] | |
27 | + @descendent_result = array.collect {|element| element.to_f} | |
27 | 28 | end |
28 | 29 | |
29 | 30 | def descendent_results | ... | ... |
plugins/mezuro/lib/kalibro/entities/module_result.rb
... | ... | @@ -6,6 +6,11 @@ class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity |
6 | 6 | @module = to_entity(value, Kalibro::Entities::Module) |
7 | 7 | end |
8 | 8 | |
9 | + def date=(value) | |
10 | + @date = value | |
11 | + @date = DateTime.parse(value) if value.is_a?(String) | |
12 | + end | |
13 | + | |
9 | 14 | def grade=(value) |
10 | 15 | @grade = value.to_f |
11 | 16 | end | ... | ... |
plugins/mezuro/lib/kalibro/entities/project_result.rb
... | ... | @@ -6,6 +6,11 @@ class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity |
6 | 6 | @project = to_entity(value, Kalibro::Entities::Project) |
7 | 7 | end |
8 | 8 | |
9 | + def date=(value) | |
10 | + @date = value | |
11 | + @date = DateTime.parse(value) if value.is_a?(String) | |
12 | + end | |
13 | + | |
9 | 14 | def load_time=(value) |
10 | 15 | @load_time = value.to_i |
11 | 16 | end | ... | ... |
plugins/mezuro/test/fixtures/module_result_fixtures.rb
... | ... | @@ -18,7 +18,7 @@ class ModuleResultFixtures |
18 | 18 | |
19 | 19 | def self.create_hash |
20 | 20 | {:module => ModuleFixtures.qt_calculator_hash, |
21 | - :date => DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000'), :grade => 10.0, :metric_result => [ | |
21 | + :date => '2011-10-20T18:26:43.151+00:00', :grade => 10.0, :metric_result => [ | |
22 | 22 | MetricResultFixtures.amloc_result_hash, |
23 | 23 | MetricResultFixtures.sc_result_hash], |
24 | 24 | :compound_metric_with_error => [CompoundMetricWithErrorFixtures.create_hash]} | ... | ... |
plugins/mezuro/test/fixtures/project_result_fixtures.rb
... | ... | @@ -15,7 +15,7 @@ class ProjectResultFixtures |
15 | 15 | end |
16 | 16 | |
17 | 17 | def self.qt_calculator_hash |
18 | - {:project => ProjectFixtures.qt_calculator_hash, :date => ModuleResultFixtures.create.date, | |
18 | + {:project => ProjectFixtures.qt_calculator_hash, :date => ModuleResultFixtures.create_hash[:date], | |
19 | 19 | :load_time => 14878, :analysis_time => 1022, :source_tree => ModuleNodeFixtures.qt_calculator_tree_hash} |
20 | 20 | end |
21 | 21 | ... | ... |
plugins/mezuro/test/fixtures/range_fixtures.rb
... | ... | @@ -27,7 +27,7 @@ class RangeFixtures |
27 | 27 | end |
28 | 28 | |
29 | 29 | def self.amloc_bad_hash |
30 | - {:beginning => 19.5, :end => Infinity, :label => 'Bad',:grade => 0.0, :color => 'ffff0000'} | |
30 | + {:beginning => 19.5, :end => "INF", :label => 'Bad',:grade => 0.0, :color => 'ffff0000'} | |
31 | 31 | end |
32 | 32 | |
33 | 33 | end | ... | ... |
plugins/mezuro/test/functional/echo_port_test.rb
... | ... | @@ -9,8 +9,7 @@ class EchoPortTest < ActiveSupport::TestCase |
9 | 9 | |
10 | 10 | def setup |
11 | 11 | @port = Kalibro::Client::Port.new('Echo') |
12 | -# @port.service_address=('http://valinhos.ime.usp.br:50688/KalibroFake/'); | |
13 | - @port.service_address=('http://localhost:8080/KalibroFake/'); | |
12 | + @port.service_address=('http://valinhos.ime.usp.br:50688/KalibroFake/'); | |
14 | 13 | end |
15 | 14 | |
16 | 15 | should 'echo base tool' do | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb
... | ... | @@ -27,12 +27,12 @@ class ProjectResultTest < ActiveSupport::TestCase |
27 | 27 | |
28 | 28 | should 'retrieve module node' do |
29 | 29 | node = @result.get_node("main") |
30 | - assert_equal @hash[:source_tree][:child][1], node.to_hash | |
30 | + assert_equal @hash[:source_tree][:child][2], node.to_hash | |
31 | 31 | end |
32 | 32 | |
33 | 33 | should 'retrive complex module' do |
34 | 34 | node = @result.get_node("org.Window") |
35 | - assert_equal @hash[:source_tree][:child][2][:child].first, node.to_hash | |
35 | + assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash | |
36 | 36 | end |
37 | 37 | |
38 | 38 | should 'return source tree node when nil is given' do |
... | ... | @@ -44,6 +44,6 @@ class ProjectResultTest < ActiveSupport::TestCase |
44 | 44 | end |
45 | 45 | |
46 | 46 | should 'return correct node when module name is given' do |
47 | - assert_equal @hash[:source_tree][:child][1], @result.node_of("main").to_hash | |
47 | + assert_equal @hash[:source_tree][:child][2], @result.node_of("main").to_hash | |
48 | 48 | end |
49 | 49 | end | ... | ... |
plugins/mezuro/views/content_viewer/_module_result.rhtml
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | <% range = metric_result.range %> |
20 | 20 | <tr title="<%= range.nil? ? '' : range.comments %>"> |
21 | 21 | <td><%= metric_result.metric.name %></td> |
22 | - <td><%= metric_result.value.slice(/[0-9]+\.[0-9]{1,2}/) %></td> <!--FIXME: Move to helper eventually--> | |
22 | + <td><%= "%.02f" % metric_result.value %></td> | |
23 | 23 | <td><%= metric_result.weight %></td> |
24 | 24 | <% if range.nil? %> |
25 | 25 | <td></td> |
... | ... | @@ -34,7 +34,7 @@ |
34 | 34 | <td colspan = "4" align = "right"> |
35 | 35 | <strong> |
36 | 36 | <%= _('Grade:') %> |
37 | - <%= module_result.grade.slice(/[0-9]+\.[0-9]{1,2}/) %> <!--FIXME: Move to helper eventually --> | |
37 | + <%= "%.02f" % module_result.grade %> | |
38 | 38 | </strong> |
39 | 39 | </td> |
40 | 40 | </tr> | ... | ... |