Commit b18ed7d246288a6fc84677b0c13e384fd00bcff6

Authored by João M. M. da Silva + Alessandro Palmeira
Committed by João M. M. da Silva
1 parent 80d599e0

[Mezuro] refactored module controller tests

plugins/mezuro/controllers/profile/mezuro_plugin_module_result_controller.rb
1 -#TODO refatorar todo o controller e seus testes funcionais  
2 class MezuroPluginModuleResultController < MezuroPluginProfileController 1 class MezuroPluginModuleResultController < MezuroPluginProfileController
3 2
4 append_view_path File.join(File.dirname(__FILE__) + '/../../views') 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
@@ -9,7 +8,8 @@ class MezuroPluginModuleResultController &lt; MezuroPluginProfileController @@ -9,7 +8,8 @@ class MezuroPluginModuleResultController &lt; MezuroPluginProfileController
9 end 8 end
10 9
11 def metric_results 10 def metric_results
12 - @metric_results = Kalibro::MetricResult.metric_results_of(params[:module_result_id].to_i) 11 + @module_result_id = params[:module_result_id].to_i
  12 + @metric_results = Kalibro::MetricResult.metric_results_of(@module_result_id)
13 render :partial => 'metric_results' 13 render :partial => 'metric_results'
14 end 14 end
15 15
plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb
1 -#TODO refatorar todo o controller e seus testes funcionais  
2 class MezuroPluginProcessingController < MezuroPluginProfileController 1 class MezuroPluginProcessingController < MezuroPluginProfileController
3 2
4 append_view_path File.join(File.dirname(__FILE__) + '/../../views') 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
plugins/mezuro/lib/kalibro/metric_result.rb
@@ -23,11 +23,17 @@ class Kalibro::MetricResult &lt; Kalibro::Model @@ -23,11 +23,17 @@ class Kalibro::MetricResult &lt; Kalibro::Model
23 end 23 end
24 24
25 def self.metric_results_of(module_result_id) 25 def self.metric_results_of(module_result_id)
26 - request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result].to_a.map {|metric_result| new metric_result} 26 + response = request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result]
  27 + response = [] if response.nil?
  28 + response = [response] if response.is_a?(Hash)
  29 + response.map {|metric_result| new metric_result}
27 end 30 end
28 31
29 def self.history_of(metric_name, module_result_id) 32 def self.history_of(metric_name, module_result_id)
30 - self.request(:history_of, {:metric_name => metric_name, :module_result_id => module_result_id})[:date_metric_result].to_a.map {|date_metric_result| Kalibro::DateMetricResult.new date_metric_result} 33 + response = self.request(:history_of, {:metric_name => metric_name, :module_result_id => module_result_id})[:date_metric_result]
  34 + response = [] if response.nil?
  35 + response = [response] if response.is_a?(Hash)
  36 + response.map {|date_metric_result| Kalibro::DateMetricResult.new date_metric_result}
31 end 37 end
32 38
33 end 39 end
plugins/mezuro/lib/kalibro/module_result.rb
@@ -20,7 +20,10 @@ class Kalibro::ModuleResult &lt; Kalibro::Model @@ -20,7 +20,10 @@ class Kalibro::ModuleResult &lt; Kalibro::Model
20 end 20 end
21 21
22 def self.history_of(module_result_id) 22 def self.history_of(module_result_id)
23 - self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result].to_a.map {|date_module_result| Kalibro::DateModuleResult.new date_module_result} 23 + response = self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result]
  24 + response = [] if response.nil?
  25 + response = [response] if response.is_a?(Hash)
  26 + response.map {|date_module_result| Kalibro::DateModuleResult.new date_module_result}
24 end 27 end
25 28
26 end 29 end
plugins/mezuro/test/functional/profile/mezuro_plugin_module_result_controller_test.rb
1 require 'test_helper' 1 require 'test_helper'
2 2
3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
4 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures"  
5 -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" 4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures"
6 7
7 -#TODO refatorar todos os testes  
8 class MezuroPluginModuleResultControllerTest < ActionController::TestCase 8 class MezuroPluginModuleResultControllerTest < ActionController::TestCase
9 9
10 def setup 10 def setup
@@ -13,90 +13,48 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase @@ -13,90 +13,48 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase
13 @response = ActionController::TestResponse.new 13 @response = ActionController::TestResponse.new
14 @profile = fast_create(Community) 14 @profile = fast_create(Community)
15 15
16 -=begin  
17 - #@project_result = ProjectResultFixtures.project_result  
18 - @module_result = ModuleResultFixtures.module_result  
19 - @repository_url = RepositoryFixtures.repository.address  
20 - @project = ProjectFixtures.project  
21 - @date = "2012-04-13T20:39:41+04:00"  
22 -  
23 - #Kalibro::Project.expects(:all_names).returns([])  
24 - @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :project_id => @project.id)  
25 - @content.expects(:send_project_to_service).returns(nil)  
26 - @content.save  
27 -=end 16 + @module_result_hash = ModuleResultFixtures.module_result_hash
  17 + @metric_result_hash = MetricResultFixtures.native_metric_result_hash
  18 + @date_metric_result_hash = DateMetricResultFixtures.date_metric_result_hash
  19 + @date_module_result_hash = DateModuleResultFixtures.date_module_result_hash
28 end 20 end
29 21
30 - should 'get module result' do  
31 - end  
32 -  
33 -=begin  
34 - should 'get module result without date' do  
35 - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date)  
36 - Kalibro::ProjectResult.expects(:request).  
37 - with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).  
38 - returns({:project_result => @project_result.to_hash})  
39 - Kalibro::ModuleResult.expects(:request).  
40 - with("ModuleResult", :get_module_result, {:project_name => @project.name, :module_name => @project.name, :date => date_with_milliseconds}).  
41 - returns({:module_result => @module_result.to_hash})  
42 - get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil  
43 - assert_equal @content, assigns(:content)  
44 - assert_equal @module_result.grade, assigns(:module_result).grade 22 + should 'find module result on kalibro' do
  23 + Kalibro::ModuleResult.expects(:request).with(:get_module_result, { :module_result_id => @module_result_hash[:id] }).
  24 + returns({:module_result => @module_result_hash})
  25 + get :module_result, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]
  26 + assert_equal @module_result_hash[:grade], assigns(:module_result).grade
45 assert_response 200 27 assert_response 200
46 - assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') 28 + #TODO assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
47 end 29 end
48 30
49 - should 'get module result with a specific date' do  
50 - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date)  
51 - request_body = {:project_name => @project.name, :date => @project_result.date}  
52 - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})  
53 - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})  
54 - Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_module_result, {:project_name => @project.name, :module_name => @project.name, :date => date_with_milliseconds}).returns({:module_result => @module_result.to_hash})  
55 - get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date  
56 - assert_equal @content, assigns(:content)  
57 - assert_equal @module_result.grade, assigns(:module_result).grade 31 + should 'get metric_results' do
  32 + Kalibro::MetricResult.expects(:request).with(:metric_results_of, { :module_result_id => @module_result_hash[:id] }).
  33 + returns({:metric_result => @metric_result_hash})
  34 + get :metric_results, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]
  35 + assert_equal @metric_result_hash[:value], assigns(:metric_results).first.value
  36 + assert_equal @module_result_hash[:id], assigns(:module_result_id)
58 assert_response 200 37 assert_response 200
59 - assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') 38 + #TODO assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
60 end 39 end
61 40
62 - should 'test module metrics history' do  
63 - Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result})  
64 - get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name,  
65 - :metric_name => @module_result.metric_result.first.metric.name.delete("() ")  
66 - assert_equal @content, assigns(:content)  
67 - assert_equal [[@module_result.metric_result[0].value, @module_result.date.to_s[0..9]]], assigns(:score_history) 41 + should 'get metric result history' do
  42 + metric_name = @metric_result_hash[:configuration][:metric][:name]
  43 + Kalibro::MetricResult.expects(:request).with(:history_of, { :metric_name => metric_name, :module_result_id => @module_result_hash[:id] }).
  44 + returns({:date_metric_result => @date_metric_result_hash})
  45 + get :metric_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id], :metric_name => metric_name
  46 + assert_equal @date_metric_result_hash[:date], assigns(:date_metric_results).first.date
68 assert_response 200 47 assert_response 200
  48 + #TODO assert_select
69 end 49 end
70 -  
71 - should 'test grade history' do  
72 - Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result})  
73 - get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name  
74 - assert_equal @content, assigns(:content)  
75 - assert_equal [[@module_result.grade, @module_result.date.to_s[0..9]]], assigns(:score_history) 50 +
  51 + should 'get module result history' do
  52 + Kalibro::ModuleResult.expects(:request).with(:history_of_module, { :module_result_id => @module_result_hash[:id] }).
  53 + returns({:date_module_result => @date_module_result_hash})
  54 + get :module_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]
  55 + assert_equal @date_module_result_hash[:date], assigns(:date_module_results).first.date
76 assert_response 200 56 assert_response 200
  57 + #TODO assert_select
77 end 58 end
78 59
79 - should 'test project tree without date' do  
80 - Kalibro::Processing.expects(:request).with("Processing", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})  
81 - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})  
82 - get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil  
83 - assert_equal @content, assigns(:content)  
84 - assert_equal @project.name, assigns(:project_name)  
85 - assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name  
86 - assert_response 200  
87 - assert_select('h2', /Qt-Calculator/)  
88 - end  
89 -  
90 - should 'test project tree with a specific date' do  
91 - request_body = {:project_name => @project.name, :date => @project_result.date}  
92 - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})  
93 - Kalibro::Processing.expects(:request).with("Processing", :has_results_before, request_body).returns({:has_results => true})  
94 - Kalibro::Processing.expects(:request).with("Processing", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})  
95 - get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date  
96 - assert_equal @content, assigns(:content)  
97 - assert_equal @project.name, assigns(:project_name)  
98 - assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name  
99 - assert_response 200  
100 - end  
101 -=end  
102 end 60 end
plugins/mezuro/test/unit/kalibro/date_module_result_test.rb
@@ -5,7 +5,7 @@ require &quot;#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures&quot; @@ -5,7 +5,7 @@ require &quot;#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures&quot;
5 class DateModuleResultTest < ActiveSupport::TestCase 5 class DateModuleResultTest < ActiveSupport::TestCase
6 6
7 def setup 7 def setup
8 - @hash = DateModule.date_module_result_hash 8 + @hash = DateModuleResultFixtures.date_module_result_hash
9 @date_module_result = DateModuleResultFixtures.date_module_result 9 @date_module_result = DateModuleResultFixtures.date_module_result
10 end 10 end
11 11
plugins/mezuro/test/unit/kalibro/metric_result_test.rb
@@ -32,8 +32,8 @@ class MetricResultTest &lt; ActiveSupport::TestCase @@ -32,8 +32,8 @@ class MetricResultTest &lt; ActiveSupport::TestCase
32 end 32 end
33 33
34 should 'return history of a metric with a module result id' do 34 should 'return history of a metric with a module result id' do
35 - module_id = 31  
36 - Kalibro::MetricResult.expects(:request).with(:history_of, {:metric_name => @result.configuration.metric.name, :module_result_id => module_id}).returns({:date_metric_result => [DateMetricResultFixtures.date_metric_result_hash]}) 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]})
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 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 end 38 end
39 39
plugins/mezuro/test/unit/kalibro/module_result_test.rb
@@ -30,7 +30,7 @@ class ModuleResultTest &lt; ActiveSupport::TestCase @@ -30,7 +30,7 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
30 end 30 end
31 31
32 should 'return history of a module result' do 32 should 'return history of a module result' do
33 - Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => module_id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]}) 33 + Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => @module_result.id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]})
34 assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id], Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id 34 assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id], Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id
35 end 35 end
36 36