Commit 90446ad24db0edb3f618d2d283fd111aeca1da71
Committed by
Diego Camarinha
1 parent
55f8c3a1
Exists in
master
and in
29 other branches
[Mezuro] Refactored node_of and get_node methods.
Showing
3 changed files
with
13 additions
and
23 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
... | ... | @@ -56,7 +56,7 @@ class MezuroPluginProfileController < ProfileController |
56 | 56 | if project_content_has_errors? |
57 | 57 | redirect_to_error_page(@content.errors[:base]) |
58 | 58 | else |
59 | - @source_tree = project_result.node_of(params[:module_name]) | |
59 | + @source_tree = project_result.node(params[:module_name]) | |
60 | 60 | render :partial =>'content_viewer/source_tree' |
61 | 61 | end |
62 | 62 | end | ... | ... |
plugins/mezuro/lib/kalibro/project_result.rb
... | ... | @@ -75,21 +75,17 @@ class Kalibro::ProjectResult < Kalibro::Model |
75 | 75 | ('%2d' % amount).sub(/\s/, '0') |
76 | 76 | end |
77 | 77 | |
78 | - def node_of(module_name) | |
78 | + def node(module_name) | |
79 | 79 | if module_name.nil? or module_name == project.name |
80 | 80 | node = source_tree |
81 | 81 | else |
82 | - node = get_node(module_name) | |
83 | - end | |
84 | - end | |
85 | - | |
86 | - def get_node(module_name) | |
87 | - path = Kalibro::Module.parent_names(module_name) | |
88 | - parent = @source_tree | |
89 | - path.each do |node_name| | |
90 | - parent = get_leaf_from(parent, node_name) | |
91 | - end | |
92 | - return parent | |
82 | + path = Kalibro::Module.parent_names(module_name) | |
83 | + parent = @source_tree | |
84 | + path.each do |node_name| | |
85 | + parent = get_leaf_from(parent, node_name) | |
86 | + end | |
87 | + parent | |
88 | + end | |
93 | 89 | end |
94 | 90 | |
95 | 91 | private | ... | ... |
plugins/mezuro/test/unit/kalibro/project_result_test.rb
... | ... | @@ -69,26 +69,20 @@ class ProjectResultTest < ActiveSupport::TestCase |
69 | 69 | assert_equal '00:00:01', @project_result.formatted_analysis_time |
70 | 70 | end |
71 | 71 | |
72 | - should 'retrieve module node' do | |
73 | - node = @project_result.get_node("main") | |
74 | - assert_equal @hash[:source_tree][:child][2], node.to_hash | |
75 | - end | |
76 | - | |
77 | 72 | should 'retrive complex module' do |
78 | - node = @project_result.get_node("org.Window") | |
79 | - assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash | |
73 | + assert_equal @hash[:source_tree][:child][0][:child].first, @project_result.node("org.Window").to_hash | |
80 | 74 | end |
81 | 75 | |
82 | 76 | should 'return source tree node when nil is given' do |
83 | - assert_equal @hash[:source_tree], @project_result.node_of(nil).to_hash | |
77 | + assert_equal @hash[:source_tree], @project_result.node(nil).to_hash | |
84 | 78 | end |
85 | 79 | |
86 | 80 | should 'return source tree node when project name is given' do |
87 | - assert_equal @hash[:source_tree], @project_result.node_of(@project_result.project.name).to_hash | |
81 | + assert_equal @hash[:source_tree], @project_result.node(@project_result.project.name).to_hash | |
88 | 82 | end |
89 | 83 | |
90 | 84 | should 'return correct node when module name is given' do |
91 | - assert_equal @hash[:source_tree][:child][2], @project_result.node_of("main").to_hash | |
85 | + assert_equal @hash[:source_tree][:child][2], @project_result.node("main").to_hash | |
92 | 86 | end |
93 | 87 | |
94 | 88 | end | ... | ... |