From 8d632abacc029f050a973e0a67c4712c57fe8e3f Mon Sep 17 00:00:00 2001
From: João M. M. da Silva + Diego Araújo
Date: Wed, 12 Dec 2012 16:06:12 -0200
Subject: [PATCH] [Mezuro] source_tree partials and parents method.
---
plugins/mezuro/lib/kalibro/module_result.rb | 15 +++++++++++++--
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb | 10 ++++++++--
plugins/mezuro/test/fixtures/module_result_fixtures.rb | 18 ++++++++++++++++++
plugins/mezuro/test/unit/kalibro/metric_result_test.rb | 2 +-
plugins/mezuro/test/unit/kalibro/module_result_test.rb | 10 ++++++++++
plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml | 2 +-
plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml | 69 +++++++++++++++++++++++++++++++--------------------------------------
plugins/mezuro/views/mezuro_plugin_repository/show.html.erb | 1 -
8 files changed, 82 insertions(+), 45 deletions(-)
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} %>
<%= _('Metric results for: #{@module_result.module.name} (#{@module_result.module.granularity}) ') %>
diff --git a/plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml b/plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml
index cd4b8d4..7409a88 100644
--- a/plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml
+++ b/plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml
@@ -1,41 +1,34 @@
<%= _('Source tree') %>
-<% module_name = @source_tree.module.name %>
-<% module_label = "#{module_name} (#{@source_tree.module.granularity})" %>
+<% module_name = @module_result.module.name %>
+<% module_label = "#{module_name} (#{@module_result.module.granularity})" %>
-
- <% if module_name != @project_name %>
-
- <%= @project_name %>
-
- <% end %>
-
-
- <% split_link = @source_tree.module.ancestor_names %>
- <% split_link.each do |link| %>
- /
- <%= link.split(".").last %>
-
- <% end %>
-
+
+
+ <% parents = @module_result.parents %>
+ <% parents.each do |parent| %>
+ /
+ <%= parent.module.name %>
+
+ <% end %>
+
+
-<% if @source_tree.children %>
-
- <% @source_tree.children.each do |child| %>
- <% if child.module.granularity=='PACKAGE' %>
-
- <%= image_tag('/plugins/mezuro/images/folder.png')%> |
- <%= child.module.name %> |
-
- <% else %>
-
- <%= image_tag('/plugins/mezuro/images/file.png') %> |
-
-
- <%= child.module.name %>
-
- |
-
- <% end %>
- <% end %>
-
-<% end %>
+
+ <% @module_result.children.each do |child| %>
+ <% if child.module.granularity=='PACKAGE' %>
+
+ <%= image_tag('/plugins/mezuro/images/folder.png')%> |
+ <%= child.module.name %> |
+
+ <% else %>
+
+ <%= image_tag('/plugins/mezuro/images/file.png') %> |
+
+
+ <%= child.module.name %>
+
+ |
+
+ <% end %>
+ <% end %>
+
diff --git a/plugins/mezuro/views/mezuro_plugin_repository/show.html.erb b/plugins/mezuro/views/mezuro_plugin_repository/show.html.erb
index 4773b83..64a3799 100644
--- a/plugins/mezuro/views/mezuro_plugin_repository/show.html.erb
+++ b/plugins/mezuro/views/mezuro_plugin_repository/show.html.erb
@@ -42,5 +42,4 @@
-
--
libgit2 0.21.2