Commit 8d632abacc029f050a973e0a67c4712c57fe8e3f
Committed by
João M. M. da Silva
1 parent
782f5a15
Exists in
master
and in
29 other branches
[Mezuro] source_tree partials and parents method.
Showing
8 changed files
with
82 additions
and
45 deletions
Show diff stats
plugins/mezuro/lib/kalibro/module_result.rb
... | ... | @@ -7,10 +7,21 @@ class Kalibro::ModuleResult < Kalibro::Model |
7 | 7 | end |
8 | 8 | |
9 | 9 | def children |
10 | - hash_array = self.class.request(:children_of, {:module_result_id => self.id})[:module_result].to_a | |
11 | - hash_array.map { |module_result| self.class.new module_result } | |
10 | + response = self.class.request(:children_of, {:module_result_id => self.id})[:module_result] | |
11 | + response = [] if response.nil? | |
12 | + response = [response] if response.is_a?(Hash) | |
13 | + response.map {|module_result| Kalibro::ModuleResult.new module_result} | |
12 | 14 | end |
13 | 15 | |
16 | + def parents | |
17 | + if parent_id.nil? | |
18 | + [] | |
19 | + else | |
20 | + parent = self.class.find(parent_id) | |
21 | + parent.parents << parent | |
22 | + end | |
23 | + end | |
24 | + | |
14 | 25 | def module=(value) |
15 | 26 | @module = Kalibro::Module.to_object value |
16 | 27 | end | ... | ... |
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb
... | ... | @@ -18,7 +18,10 @@ class MetricConfigurationSnapshotFixtures |
18 | 18 | :attributes! => { |
19 | 19 | :metric => { |
20 | 20 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
21 | - 'xsi:type' => 'kalibro:metricXml' } | |
21 | + 'xsi:type' => 'kalibro:metricXml' }, | |
22 | + :range => { | |
23 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
24 | + 'xsi:type' => 'kalibro:rangeSnapshotXml' } | |
22 | 25 | } |
23 | 26 | } |
24 | 27 | end |
... | ... | @@ -38,7 +41,10 @@ class MetricConfigurationSnapshotFixtures |
38 | 41 | :attributes! => { |
39 | 42 | :metric => { |
40 | 43 | 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', |
41 | - 'xsi:type' => 'kalibro:metricXml' } | |
44 | + 'xsi:type' => 'kalibro:metricXml' }, | |
45 | + :range => { | |
46 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
47 | + 'xsi:type' => 'kalibro:rangeSnapshotXml' } | |
42 | 48 | } |
43 | 49 | } |
44 | 50 | end | ... | ... |
plugins/mezuro/test/fixtures/module_result_fixtures.rb
... | ... | @@ -23,4 +23,22 @@ class ModuleResultFixtures |
23 | 23 | } |
24 | 24 | end |
25 | 25 | |
26 | + def self.parent_module_result_hash | |
27 | + { | |
28 | + :id => 31, | |
29 | + :module => { | |
30 | + :name => 'Qt-Calculator Parent', | |
31 | + :granularity => 'APPLICATION' | |
32 | + }, | |
33 | + :grade => 10.0, | |
34 | + :attributes! => | |
35 | + { | |
36 | + :module => | |
37 | + { | |
38 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
39 | + "xsi:type"=>"kalibro:moduleXml" | |
40 | + } | |
41 | + } | |
42 | + } | |
43 | + end | |
26 | 44 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/metric_result_test.rb
... | ... | @@ -33,7 +33,7 @@ class MetricResultTest < ActiveSupport::TestCase |
33 | 33 | |
34 | 34 | should 'return history of a metric with a module result id' do |
35 | 35 | module_result_id = 31 |
36 | - 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]}) | |
36 | + 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}) | |
37 | 37 | 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 |
38 | 38 | end |
39 | 39 | ... | ... |
plugins/mezuro/test/unit/kalibro/module_result_test.rb
1 | 1 | require "test_helper" |
2 | 2 | |
3 | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" |
4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures" | |
4 | 5 | |
5 | 6 | class ModuleResultTest < ActiveSupport::TestCase |
6 | 7 | |
... | ... | @@ -29,6 +30,15 @@ class ModuleResultTest < ActiveSupport::TestCase |
29 | 30 | assert @hash[:id], @module_result.children.first.id |
30 | 31 | end |
31 | 32 | |
33 | + should 'return parents of a module result' do | |
34 | + parent_module_result = ModuleResultFixtures.parent_module_result_hash | |
35 | + response = {:module_result => parent_module_result} | |
36 | + Kalibro::ModuleResult.expects(:request).with(:get_module_result, {:module_result_id => @module_result.parent_id}).returns(response) | |
37 | + parents = @module_result.parents | |
38 | + assert parent_module_result[:module][:name], parents.first.module.name | |
39 | + assert parent_module_result[:module][:name], parents.last.module.name | |
40 | + end | |
41 | + | |
32 | 42 | should 'return history of a module result' do |
33 | 43 | Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => @module_result.id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]}) |
34 | 44 | assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id], Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id | ... | ... |
plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml
plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml
1 | 1 | <h4><%= _('Source tree') %></h4> |
2 | -<% module_name = @source_tree.module.name %> | |
3 | -<% module_label = "#{module_name} (#{@source_tree.module.granularity})" %> | |
2 | +<% module_name = @module_result.module.name %> | |
3 | +<% module_label = "#{module_name} (#{@module_result.module.granularity})" %> | |
4 | 4 | |
5 | -<p><h2 class="path"> | |
6 | - <% if module_name != @project_name %> | |
7 | - <a href="#" class="source-tree-link" data-module-name="<%= @project_name %>"> | |
8 | - <%= @project_name %> | |
9 | - </a> | |
10 | - <% end %> | |
11 | - | |
12 | - | |
13 | - <% split_link = @source_tree.module.ancestor_names %> | |
14 | - <% split_link.each do |link| %> | |
15 | - /<a href="#" class="source-tree-link" data-module-name="<%= link %>"> | |
16 | - <%= link.split(".").last %> | |
17 | - </a> | |
18 | - <% end %> | |
19 | -</h2></p> | |
5 | +<p> | |
6 | + <h2 class="path"> | |
7 | + <% parents = @module_result.parents %> | |
8 | + <% parents.each do |parent| %> | |
9 | + /<a href="#" class="source-tree-link" data-module-id="<%= parent.id %>"> | |
10 | + <%= parent.module.name %> | |
11 | + </a> | |
12 | + <% end %> | |
13 | + </h2> | |
14 | +</p> | |
20 | 15 | |
21 | -<% if @source_tree.children %> | |
22 | - <table border="0" class="source-tree"> | |
23 | - <% @source_tree.children.each do |child| %> | |
24 | - <% if child.module.granularity=='PACKAGE' %> | |
25 | - <tr> | |
26 | - <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td> | |
27 | - <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"><%= child.module.name %></a></td> | |
28 | - </tr> | |
29 | - <% else %> | |
30 | - <tr> | |
31 | - <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td> | |
32 | - <td class="source-tree-text"> | |
33 | - <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"> | |
34 | - <%= child.module.name %> | |
35 | - </a> | |
36 | - </td> | |
37 | - </tr> | |
38 | - <% end %> | |
39 | - <% end %> | |
40 | - </table> | |
41 | -<% end %> | |
16 | +<table border="0" class="source-tree"> | |
17 | + <% @module_result.children.each do |child| %> | |
18 | + <% if child.module.granularity=='PACKAGE' %> | |
19 | + <tr> | |
20 | + <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td> | |
21 | + <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-id="<%= child.id %>"><%= child.module.name %></a></td> | |
22 | + </tr> | |
23 | + <% else %> | |
24 | + <tr> | |
25 | + <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td> | |
26 | + <td class="source-tree-text"> | |
27 | + <a href='#' class="source-tree-link" data-module-id="<%= child.id %>"> | |
28 | + <%= child.module.name %> | |
29 | + </a> | |
30 | + </td> | |
31 | + </tr> | |
32 | + <% end %> | |
33 | + <% end %> | |
34 | +</table> | ... | ... |
plugins/mezuro/views/mezuro_plugin_repository/show.html.erb