Commit bbeb3b9eadd2f0f5b280e314596845d7383778e4
Committed by
Diego Camarinha
1 parent
f4aecdff
Exists in
master
and in
23 other branches
[Mezuro] Refactored project_tree controller and created some tests
Showing
4 changed files
with
23 additions
and
7 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
@@ -31,11 +31,7 @@ class MezuroPluginProfileController < ProfileController | @@ -31,11 +31,7 @@ class MezuroPluginProfileController < ProfileController | ||
31 | def project_tree | 31 | def project_tree |
32 | content = profile.articles.find(params[:id]) | 32 | content = profile.articles.find(params[:id]) |
33 | project_result = content.project_result | 33 | project_result = content.project_result |
34 | - if params[:module_name].nil? or params[:module_name] == content.project.name | ||
35 | - source_tree = project_result.source_tree | ||
36 | - else | ||
37 | - source_tree = project_result.get_node(params[:module_name]) | ||
38 | - end | 34 | + source_tree = project_result.node_of(params[:module_name]) |
39 | render :partial =>'content_viewer/source_tree', :locals => { :source_tree => source_tree, :project_name => content.project.name} | 35 | render :partial =>'content_viewer/source_tree', :locals => { :source_tree => source_tree, :project_name => content.project.name} |
40 | end | 36 | end |
41 | 37 |
plugins/mezuro/lib/kalibro/entities/project_result.rb
@@ -31,6 +31,14 @@ class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | @@ -31,6 +31,14 @@ class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | ||
31 | ('%2d' % amount).sub(/\s/, '0') | 31 | ('%2d' % amount).sub(/\s/, '0') |
32 | end | 32 | end |
33 | 33 | ||
34 | + def node_of(module_name) | ||
35 | + if module_name.nil? or module_name == project.name | ||
36 | + node = source_tree | ||
37 | + else | ||
38 | + node = get_node(module_name) | ||
39 | + end | ||
40 | + end | ||
41 | + | ||
34 | def get_node(module_name) | 42 | def get_node(module_name) |
35 | path = Kalibro::Entities::Module.parent_names(module_name) | 43 | path = Kalibro::Entities::Module.parent_names(module_name) |
36 | parent = @source_tree | 44 | parent = @source_tree |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -54,10 +54,10 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | @@ -54,10 +54,10 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | ||
54 | Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | 54 | Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) |
55 | get :project_result, :profile => @profile.identifier, :id => @content.id | 55 | get :project_result, :profile => @profile.identifier, :id => @content.id |
56 | assert_response 200 | 56 | assert_response 200 |
57 | - assert_select('h3', 'LAST RESULT') | 57 | + assert_select('h4', 'Last Result') |
58 | end | 58 | end |
59 | 59 | ||
60 | - should 'get metric results for a module' do | 60 | + should 'get module result' do |
61 | create_project_content | 61 | create_project_content |
62 | Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @name).returns(@module_result) | 62 | Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @name).returns(@module_result) |
63 | get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name | 63 | get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name |
plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb
@@ -34,4 +34,16 @@ class ProjectResultTest < ActiveSupport::TestCase | @@ -34,4 +34,16 @@ class ProjectResultTest < ActiveSupport::TestCase | ||
34 | node = @result.get_node("org.Window") | 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][2][:child].first, node.to_hash |
36 | end | 36 | end |
37 | + | ||
38 | + should 'return source tree node when nil is given' do | ||
39 | + assert_equal @hash[:source_tree], @result.node_of(nil).to_hash | ||
40 | + end | ||
41 | + | ||
42 | + should 'return source tree node when project name is given' do | ||
43 | + assert_equal @hash[:source_tree], @result.node_of(@result.project.name).to_hash | ||
44 | + end | ||
45 | + | ||
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 | ||
48 | + end | ||
37 | end | 49 | end |