diff --git a/plugins/mezuro/lib/kalibro/module_result.rb b/plugins/mezuro/lib/kalibro/module_result.rb index 745fd69..0124f74 100644 --- a/plugins/mezuro/lib/kalibro/module_result.rb +++ b/plugins/mezuro/lib/kalibro/module_result.rb @@ -7,10 +7,21 @@ class Kalibro::ModuleResult < Kalibro::Model end def children - hash_array = self.class.request(:children_of, {:module_result_id => self.id})[:module_result].to_a - hash_array.map { |module_result| self.class.new module_result } + response = self.class.request(:children_of, {:module_result_id => self.id})[:module_result] + response = [] if response.nil? + response = [response] if response.is_a?(Hash) + response.map {|module_result| Kalibro::ModuleResult.new module_result} end + def parents + if parent_id.nil? + [] + else + parent = self.class.find(parent_id) + parent.parents << parent + end + end + def module=(value) @module = Kalibro::Module.to_object value end diff --git a/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb b/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb index 8494fe1..51e2f69 100644 --- a/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb +++ b/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb @@ -18,7 +18,10 @@ class MetricConfigurationSnapshotFixtures :attributes! => { :metric => { 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:type' => 'kalibro:metricXml' } + 'xsi:type' => 'kalibro:metricXml' }, + :range => { + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:type' => 'kalibro:rangeSnapshotXml' } } } end @@ -38,7 +41,10 @@ class MetricConfigurationSnapshotFixtures :attributes! => { :metric => { 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:type' => 'kalibro:metricXml' } + 'xsi:type' => 'kalibro:metricXml' }, + :range => { + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:type' => 'kalibro:rangeSnapshotXml' } } } end diff --git a/plugins/mezuro/test/fixtures/module_result_fixtures.rb b/plugins/mezuro/test/fixtures/module_result_fixtures.rb index 1b0b0d6..87f5743 100644 --- a/plugins/mezuro/test/fixtures/module_result_fixtures.rb +++ b/plugins/mezuro/test/fixtures/module_result_fixtures.rb @@ -23,4 +23,22 @@ class ModuleResultFixtures } end + def self.parent_module_result_hash + { + :id => 31, + :module => { + :name => 'Qt-Calculator Parent', + :granularity => 'APPLICATION' + }, + :grade => 10.0, + :attributes! => + { + :module => + { + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", + "xsi:type"=>"kalibro:moduleXml" + } + } + } + end end diff --git a/plugins/mezuro/test/unit/kalibro/metric_result_test.rb b/plugins/mezuro/test/unit/kalibro/metric_result_test.rb index d72e258..3277da5 100644 --- a/plugins/mezuro/test/unit/kalibro/metric_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/metric_result_test.rb @@ -33,7 +33,7 @@ class MetricResultTest < ActiveSupport::TestCase should 'return history of a metric with a module result id' do module_result_id = 31 - Kalibro::MetricResult.expects(:request).with(:history_of, {:metric_name => @result.configuration.metric.name, :module_result_id => module_result_id}).returns({:date_metric_result => [DateMetricResultFixtures.date_metric_result_hash]}) + Kalibro::MetricResult.expects(:request).with(:history_of, {:metric_name => @result.configuration.metric.name, :module_result_id => module_result_id}).returns({:date_metric_result => DateMetricResultFixtures.date_metric_result_hash}) assert_equal DateMetricResultFixtures.date_metric_result_hash[:metric_result][:id], Kalibro::MetricResult.history_of(@result.configuration.metric.name, module_result_id).first.metric_result.id end diff --git a/plugins/mezuro/test/unit/kalibro/module_result_test.rb b/plugins/mezuro/test/unit/kalibro/module_result_test.rb index d3df2b9..a389b01 100644 --- a/plugins/mezuro/test/unit/kalibro/module_result_test.rb +++ b/plugins/mezuro/test/unit/kalibro/module_result_test.rb @@ -1,6 +1,7 @@ require "test_helper" require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures" class ModuleResultTest < ActiveSupport::TestCase @@ -29,6 +30,15 @@ class ModuleResultTest < ActiveSupport::TestCase assert @hash[:id], @module_result.children.first.id end + should 'return parents of a module result' do + parent_module_result = ModuleResultFixtures.parent_module_result_hash + response = {:module_result => parent_module_result} + Kalibro::ModuleResult.expects(:request).with(:get_module_result, {:module_result_id => @module_result.parent_id}).returns(response) + parents = @module_result.parents + assert parent_module_result[:module][:name], parents.first.module.name + assert parent_module_result[:module][:name], parents.last.module.name + end + should 'return history of a module result' do Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => @module_result.id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]}) assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id], Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id diff --git a/plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml b/plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml index 0caa93c..e45dbeb 100644 --- a/plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml +++ b/plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml @@ -1,4 +1,4 @@ -<% TODO source tree %> +<% render :partial => "source_tree", :locals => {:module_result => @module_result} %>
+
<%= image_tag('/plugins/mezuro/images/folder.png')%> | -<%= child.module.name %> | -
<%= image_tag('/plugins/mezuro/images/file.png') %> | -- - <%= child.module.name %> - - | -
<%= image_tag('/plugins/mezuro/images/folder.png')%> | +<%= child.module.name %> | +
<%= image_tag('/plugins/mezuro/images/file.png') %> | ++ + <%= child.module.name %> + + | +