Commit 54bdf4c4714f25d0b36aa8e8b0bc6c75131a2859
Committed by
Paulo Meireles
1 parent
57daefcb
Exists in
master
and in
28 other branches
[Mezuro] Finished refactoring mezuro_profile controller functional tests.
Showing
6 changed files
with
94 additions
and
146 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
| @@ -18,14 +18,14 @@ class MezuroPluginProfileController < ProfileController | @@ -18,14 +18,14 @@ class MezuroPluginProfileController < ProfileController | ||
| 18 | def project_result | 18 | def project_result |
| 19 | @content = profile.articles.find(params[:id]) | 19 | @content = profile.articles.find(params[:id]) |
| 20 | date = params[:date] | 20 | date = params[:date] |
| 21 | - @project_result = date.nil? ? @content.project_result : @content.get_date_result(date) | 21 | + @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) |
| 22 | render :partial => 'content_viewer/project_result' | 22 | render :partial => 'content_viewer/project_result' |
| 23 | end | 23 | end |
| 24 | 24 | ||
| 25 | def module_result | 25 | def module_result |
| 26 | @content = profile.articles.find(params[:id]) | 26 | @content = profile.articles.find(params[:id]) |
| 27 | date = params[:date] | 27 | date = params[:date] |
| 28 | - date.nil? ? @content.project_result : @content.get_date_result(date) | 28 | + date.nil? ? @content.project_result : @content.project_result_with_date(date) |
| 29 | @module_result = @content.module_result(params[:module_name]) | 29 | @module_result = @content.module_result(params[:module_name]) |
| 30 | render :partial => 'content_viewer/module_result' | 30 | render :partial => 'content_viewer/module_result' |
| 31 | end | 31 | end |
| @@ -33,7 +33,7 @@ class MezuroPluginProfileController < ProfileController | @@ -33,7 +33,7 @@ class MezuroPluginProfileController < ProfileController | ||
| 33 | def project_tree | 33 | def project_tree |
| 34 | @content = profile.articles.find(params[:id]) | 34 | @content = profile.articles.find(params[:id]) |
| 35 | date = params[:date] | 35 | date = params[:date] |
| 36 | - project_result = date.nil? ? @content.project_result : @content.get_date_result(date) | 36 | + project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) |
| 37 | @project_name = @content.project.name | 37 | @project_name = @content.project.name |
| 38 | @source_tree = project_result.node_of(params[:module_name]) | 38 | @source_tree = project_result.node_of(params[:module_name]) |
| 39 | render :partial =>'content_viewer/source_tree' | 39 | render :partial =>'content_viewer/source_tree' |
plugins/mezuro/lib/kalibro/module_result.rb
| @@ -3,7 +3,7 @@ class Kalibro::ModuleResult < Kalibro::Model | @@ -3,7 +3,7 @@ class Kalibro::ModuleResult < Kalibro::Model | ||
| 3 | attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error | 3 | attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error |
| 4 | 4 | ||
| 5 | def self.find_by_project_name_and_module_name_and_date(project_name, module_name, date) | 5 | def self.find_by_project_name_and_module_name_and_date(project_name, module_name, date) |
| 6 | - response = request( | 6 | + new request( |
| 7 | 'ModuleResult', | 7 | 'ModuleResult', |
| 8 | :get_module_result, | 8 | :get_module_result, |
| 9 | { | 9 | { |
| @@ -11,7 +11,6 @@ class Kalibro::ModuleResult < Kalibro::Model | @@ -11,7 +11,6 @@ class Kalibro::ModuleResult < Kalibro::Model | ||
| 11 | :module_name => module_name, | 11 | :module_name => module_name, |
| 12 | :date => date_with_milliseconds(date) | 12 | :date => date_with_milliseconds(date) |
| 13 | })[:module_result] | 13 | })[:module_result] |
| 14 | - new response | ||
| 15 | end | 14 | end |
| 16 | 15 | ||
| 17 | def self.all_by_project_name_and_module_name(project_name, module_name) | 16 | def self.all_by_project_name_and_module_name(project_name, module_name) |
| @@ -20,7 +19,7 @@ class Kalibro::ModuleResult < Kalibro::Model | @@ -20,7 +19,7 @@ class Kalibro::ModuleResult < Kalibro::Model | ||
| 20 | :get_result_history, | 19 | :get_result_history, |
| 21 | { | 20 | { |
| 22 | :project_name => project_name, | 21 | :project_name => project_name, |
| 23 | - :module_name => module_name, | 22 | + :module_name => module_name |
| 24 | })[:module_result] | 23 | })[:module_result] |
| 25 | Kalibro::ModuleResult.to_objects_array(response) | 24 | Kalibro::ModuleResult.to_objects_array(response) |
| 26 | end | 25 | end |
plugins/mezuro/lib/kalibro/project.rb
| @@ -40,4 +40,8 @@ class Kalibro::Project < Kalibro::Model | @@ -40,4 +40,8 @@ class Kalibro::Project < Kalibro::Model | ||
| 40 | @repository = Kalibro::Repository.to_object value | 40 | @repository = Kalibro::Repository.to_object value |
| 41 | end | 41 | end |
| 42 | 42 | ||
| 43 | + def error=(value) | ||
| 44 | + @error = Kalibro::Error.to_object value | ||
| 45 | + end | ||
| 46 | + | ||
| 43 | end | 47 | end |
plugins/mezuro/lib/kalibro/project_result.rb
| @@ -3,35 +3,31 @@ class Kalibro::ProjectResult < Kalibro::Model | @@ -3,35 +3,31 @@ class Kalibro::ProjectResult < Kalibro::Model | ||
| 3 | attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time | 3 | attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time |
| 4 | 4 | ||
| 5 | def self.last_result(project_name) | 5 | def self.last_result(project_name) |
| 6 | - last_result = request('ProjectResult', :get_last_result_of, {:project_name => project_name})[:project_result] | ||
| 7 | - new last_result | 6 | + new request('ProjectResult', :get_last_result_of, {:project_name => project_name})[:project_result] |
| 8 | end | 7 | end |
| 9 | 8 | ||
| 10 | def self.first_result(project_name) | 9 | def self.first_result(project_name) |
| 11 | - first_result = request('ProjectResult',:get_first_result_of, {:project_name => project_name})[:project_result] | ||
| 12 | - new first_result | 10 | + new request('ProjectResult', :get_first_result_of, {:project_name => project_name})[:project_result] |
| 13 | end | 11 | end |
| 14 | 12 | ||
| 15 | def self.first_result_after(project_name, date) | 13 | def self.first_result_after(project_name, date) |
| 16 | - first_result_after = request('ProjectResult',:get_first_result_after, {:project_name => project_name, :date => date})[:project_result] | ||
| 17 | - new first_result_after | 14 | + new request('ProjectResult', :get_first_result_after, {:project_name => project_name, :date => date})[:project_result] |
| 18 | end | 15 | end |
| 19 | 16 | ||
| 20 | def self.last_result_before(project_name, date) | 17 | def self.last_result_before(project_name, date) |
| 21 | - last_result_before = request('ProjectResult',:get_last_result_before, {:project_name => project_name, :date => date})[:project_result] | ||
| 22 | - new last_result_before | 18 | + new request('ProjectResult', :get_last_result_before, {:project_name => project_name, :date => date})[:project_result] |
| 23 | end | 19 | end |
| 24 | 20 | ||
| 25 | def self.has_results?(project_name) | 21 | def self.has_results?(project_name) |
| 26 | - request('ProjectResult',:has_results_for, {:project_name => project_name})[:has_results] | 22 | + request('ProjectResult', :has_results_for, {:project_name => project_name})[:has_results] |
| 27 | end | 23 | end |
| 28 | 24 | ||
| 29 | def self.has_results_before?(project_name, date) | 25 | def self.has_results_before?(project_name, date) |
| 30 | - request('ProjectResult',:has_results_before, {:project_name => project_name, :date => date})[:has_results] | 26 | + request('ProjectResult', :has_results_before, {:project_name => project_name, :date => date})[:has_results] |
| 31 | end | 27 | end |
| 32 | 28 | ||
| 33 | def self.has_results_after?(project_name, date) | 29 | def self.has_results_after?(project_name, date) |
| 34 | - request('ProjectResult',:has_results_after, {:project_name => project_name, :date => date})[:has_results] | 30 | + request('ProjectResult', :has_results_after, {:project_name => project_name, :date => date})[:has_results] |
| 35 | end | 31 | end |
| 36 | 32 | ||
| 37 | def project=(value) | 33 | def project=(value) |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| @@ -35,9 +35,9 @@ class MezuroPlugin::ProjectContent < Article | @@ -35,9 +35,9 @@ class MezuroPlugin::ProjectContent < Article | ||
| 35 | end | 35 | end |
| 36 | end | 36 | end |
| 37 | 37 | ||
| 38 | - def get_date_result(date) | 38 | + def project_result_with_date(date) |
| 39 | begin | 39 | begin |
| 40 | - @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before?(name, date) : | 40 | + @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before(name, date) : |
| 41 | Kalibro::ProjectResult.first_result_after(name, date) | 41 | Kalibro::ProjectResult.first_result_after(name, date) |
| 42 | rescue Exception => error | 42 | rescue Exception => error |
| 43 | errors.add_to_base(error.message) | 43 | errors.add_to_base(error.message) |
| @@ -46,11 +46,11 @@ Kalibro::ProjectResult.first_result_after(name, date) | @@ -46,11 +46,11 @@ Kalibro::ProjectResult.first_result_after(name, date) | ||
| 46 | 46 | ||
| 47 | def module_result(module_name) | 47 | def module_result(module_name) |
| 48 | module_name = project.name if module_name.nil? | 48 | module_name = project.name if module_name.nil? |
| 49 | - @module_client ||= module_result_client.module_result(project.name, module_name, project_result.date) | 49 | + @module_client ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(project.name, module_name, @project_result.date) |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | def result_history(module_name) | 52 | def result_history(module_name) |
| 53 | - @result_history ||= module_result_client.result_history(project.name, module_name) | 53 | + @result_history ||= Kalibro::ModuleResult.all_by_project_name_and_module_name(project.name, module_name) |
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | after_save :send_project_to_service | 56 | after_save :send_project_to_service |
| @@ -78,7 +78,7 @@ Kalibro::ProjectResult.first_result_after(name, date) | @@ -78,7 +78,7 @@ Kalibro::ProjectResult.first_result_after(name, date) | ||
| 78 | 78 | ||
| 79 | def send_project_to_service | 79 | def send_project_to_service |
| 80 | begin | 80 | begin |
| 81 | - Kalibro::Project.create(self).save | 81 | + Kalibro::Project.create(self) |
| 82 | Kalibro::Kalibro.process_project(name, periodicity_in_days) | 82 | Kalibro::Kalibro.process_project(name, periodicity_in_days) |
| 83 | rescue Exception => error | 83 | rescue Exception => error |
| 84 | errors.add_to_base(error.message) | 84 | errors.add_to_base(error.message) |
| @@ -94,11 +94,4 @@ Kalibro::ProjectResult.first_result_after(name, date) | @@ -94,11 +94,4 @@ Kalibro::ProjectResult.first_result_after(name, date) | ||
| 94 | end | 94 | end |
| 95 | end | 95 | end |
| 96 | 96 | ||
| 97 | - def module_result_client | ||
| 98 | - begin | ||
| 99 | - @module_result_client ||= Kalibro::Client::ModuleResultClient.new | ||
| 100 | - rescue Exception => error | ||
| 101 | - errors.add_to_base(error.message) | ||
| 102 | - end | ||
| 103 | - end | ||
| 104 | end | 97 | end |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
| @@ -13,167 +13,123 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | @@ -13,167 +13,123 @@ class MezuroPluginProfileControllerTest < 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 | - @project_result = ProjectResultFixtures.qt_calculator | ||
| 17 | - @module_result = ModuleResultFixtures.create | 16 | + @project_result = ProjectResultFixtures.project_result |
| 17 | + @module_result = ModuleResultFixtures.module_result | ||
| 18 | @repository_url = RepositoryFixtures.repository.address | 18 | @repository_url = RepositoryFixtures.repository.address |
| 19 | @project = @project_result.project | 19 | @project = @project_result.project |
| 20 | - @name = @project.name | ||
| 21 | - | ||
| 22 | @date = "2012-04-13T20:39:41+04:00" | 20 | @date = "2012-04-13T20:39:41+04:00" |
| 23 | - | 21 | + |
| 22 | + Kalibro::Project.expects(:all_names).returns([]) | ||
| 23 | + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url) | ||
| 24 | + @content.expects(:send_project_to_service).returns(nil) | ||
| 25 | + @content.save | ||
| 24 | end | 26 | end |
| 25 | 27 | ||
| 26 | - should 'not find project state for inexistent project content' do | ||
| 27 | - get :project_state, :profile => '', :id => -1 | ||
| 28 | - assert_response 404 | ||
| 29 | - end | ||
| 30 | - | ||
| 31 | - should 'get project state' do | ||
| 32 | - create_project_content | ||
| 33 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | 28 | + should 'test project state without error' do |
| 29 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | ||
| 34 | get :project_state, :profile => @profile.identifier, :id => @content.id | 30 | get :project_state, :profile => @profile.identifier, :id => @content.id |
| 35 | assert_response 200 | 31 | assert_response 200 |
| 32 | + assert_equal @content, assigns(:content) | ||
| 36 | end | 33 | end |
| 37 | 34 | ||
| 38 | - should 'get error state if project has error' do | ||
| 39 | - create_project_content | ||
| 40 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 41 | - @project.expects(:error).returns(ErrorFixtures.create) | 35 | + should 'test project state with error' do |
| 36 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})}) | ||
| 42 | get :project_state, :profile => @profile.identifier, :id => @content.id | 37 | get :project_state, :profile => @profile.identifier, :id => @content.id |
| 43 | assert_response 200 | 38 | assert_response 200 |
| 39 | + assert_equal "ERROR", @response.body | ||
| 40 | + assert_equal @content, assigns(:content) | ||
| 44 | end | 41 | end |
| 45 | 42 | ||
| 46 | - should 'not find content in project error for inexistent project content' do | ||
| 47 | - get :project_error, :profile => '', :id => -1 | ||
| 48 | - assert_response 404 | ||
| 49 | - end | ||
| 50 | - | ||
| 51 | - should 'get project error' do | ||
| 52 | - create_project_content | ||
| 53 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 54 | - @project.expects(:error).returns(ErrorFixtures.create) | 43 | + should 'test project error' do |
| 44 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})}) | ||
| 55 | get :project_error, :profile => @profile.identifier, :id => @content.id | 45 | get :project_error, :profile => @profile.identifier, :id => @content.id |
| 56 | assert_response 200 | 46 | assert_response 200 |
| 57 | assert_select('h3', 'ERROR') | 47 | assert_select('h3', 'ERROR') |
| 48 | + assert_equal @content, assigns(:content) | ||
| 49 | + assert_equal @project.name, assigns(:project).name | ||
| 58 | end | 50 | end |
| 59 | 51 | ||
| 60 | - should 'not find project result for inexistent project content' do | ||
| 61 | - get :project_result, :profile => '', :id => -1 | ||
| 62 | - assert_response 404 | ||
| 63 | - end | ||
| 64 | - | ||
| 65 | - should 'get project results without date' do | ||
| 66 | - create_project_content | ||
| 67 | - Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | ||
| 68 | - get :project_result, :profile => @profile.identifier, :id => @content.id | 52 | + should 'test project result without date' do |
| 53 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | ||
| 54 | + get :project_result, :profile => @profile.identifier, :id => @content.id, :date => nil | ||
| 55 | + assert_equal @content, assigns(:content) | ||
| 56 | + assert_equal @project_result.project.name, assigns(:project_result).project.name | ||
| 69 | assert_response 200 | 57 | assert_response 200 |
| 70 | assert_select('h4', 'Last Result') | 58 | assert_select('h4', 'Last Result') |
| 71 | end | 59 | end |
| 72 | 60 | ||
| 73 | - should 'get project results from a specific date' do | ||
| 74 | - create_project_content | ||
| 75 | - mock_project_result | ||
| 76 | - get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @project_result.date | 61 | + should 'test project results from a specific date' do |
| 62 | + request_body = {:project_name => @project.name, :date => @date} | ||
| 63 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | ||
| 64 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | ||
| 65 | + get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @date | ||
| 66 | + assert_equal @content, assigns(:content) | ||
| 67 | + assert_equal @project_result.project.name, assigns(:project_result).project.name | ||
| 77 | assert_response 200 | 68 | assert_response 200 |
| 69 | + assert_select('h4', 'Last Result') | ||
| 78 | end | 70 | end |
| 79 | 71 | ||
| 80 | - should 'not find module result for inexistent project content' do | ||
| 81 | - get :module_result, :profile => '', :id => -1, :module_name => '' | ||
| 82 | - assert_response 404 | ||
| 83 | - end | ||
| 84 | 72 | ||
| 85 | should 'get module result without date' do | 73 | should 'get module result without date' do |
| 86 | - create_project_content | ||
| 87 | - mock_module_result | ||
| 88 | - Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | ||
| 89 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 90 | - get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name | 74 | + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) |
| 75 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | ||
| 76 | + 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}) | ||
| 77 | + get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name, :date => nil | ||
| 78 | + assert_equal @content, assigns(:content) | ||
| 79 | + assert_equal @module_result.grade, assigns(:module_result).grade | ||
| 91 | assert_response 200 | 80 | assert_response 200 |
| 92 | assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | 81 | assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') |
| 93 | end | 82 | end |
| 94 | 83 | ||
| 95 | - should 'get module result from a specific date' do | ||
| 96 | - create_project_content | ||
| 97 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 98 | - mock_module_result | ||
| 99 | - mock_project_result | ||
| 100 | - get :module_result, :profile => @profile.identifier, :id => @content.id, :date => @project_result.date, :module_name => @name | ||
| 101 | - assert_response 200 | ||
| 102 | - assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | ||
| 103 | - end | ||
| 104 | - | ||
| 105 | - should 'not find project tree for inexistent project content' do | ||
| 106 | - get :project_tree, :profile => '', :id => -1, :module_name => '' | ||
| 107 | - assert_response 404 | 84 | + should 'get module result with a specific date' do |
| 85 | + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | ||
| 86 | + request_body = {:project_name => @project.name, :date => @project_result.date} | ||
| 87 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | ||
| 88 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | ||
| 89 | + 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}) | ||
| 90 | + get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date | ||
| 91 | + assert_equal @content, assigns(:content) | ||
| 92 | + assert_equal @module_result.grade, assigns(:module_result).grade | ||
| 93 | + assert_response 200 | ||
| 94 | + assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | ||
| 108 | end | 95 | end |
| 109 | 96 | ||
| 110 | - should 'get project tree without date' do | ||
| 111 | - create_project_content | ||
| 112 | - Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | ||
| 113 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 114 | - get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name | 97 | + should 'test project tree without date' do |
| 98 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | ||
| 99 | + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil | ||
| 100 | + assert_equal @content, assigns(:content) | ||
| 101 | + assert_equal @project.name, assigns(:project_name) | ||
| 102 | + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name | ||
| 115 | assert_response 200 | 103 | assert_response 200 |
| 116 | assert_select('h2', /Qt-Calculator/) | 104 | assert_select('h2', /Qt-Calculator/) |
| 117 | end | 105 | end |
| 118 | 106 | ||
| 119 | - should 'get project tree from a specific date' do | ||
| 120 | - create_project_content | ||
| 121 | - mock_project_result | ||
| 122 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 123 | - get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name, :date => "2012-04-13T20:39:41+04:00" | 107 | + should 'test project tree with a specific date' do |
| 108 | + request_body = {:project_name => @project.name, :date => @project_result.date} | ||
| 109 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | ||
| 110 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | ||
| 111 | + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date | ||
| 112 | + assert_equal @content, assigns(:content) | ||
| 113 | + assert_equal @project.name, assigns(:project_name) | ||
| 114 | + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name | ||
| 124 | assert_response 200 | 115 | assert_response 200 |
| 125 | end | 116 | end |
| 126 | 117 | ||
| 127 | - should 'get grade history' do | ||
| 128 | - create_project_content | ||
| 129 | - mock_module_result_history | ||
| 130 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 131 | - get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @name | ||
| 132 | - assert_response 200 | ||
| 133 | - end | ||
| 134 | - | ||
| 135 | - should 'not find metrics history for inexistent project content' do | ||
| 136 | - get :module_metrics_history, :profile => '', :id => -1, :module_name => '' | ||
| 137 | - assert_response 404 | ||
| 138 | - end | ||
| 139 | - #copied from 'get grade history' test | ||
| 140 | - should 'get metrics history' do | ||
| 141 | - create_project_content | ||
| 142 | - mock_module_result_history | ||
| 143 | - Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
| 144 | - get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @name, | 118 | + should 'test module metrics history' do |
| 119 | + Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) | ||
| 120 | + get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, | ||
| 145 | :metric_name => @module_result.metric_result.first.metric.name.delete("() ") | 121 | :metric_name => @module_result.metric_result.first.metric.name.delete("() ") |
| 122 | + assert_equal @content, assigns(:content) | ||
| 123 | + assert_equal [@module_result.metric_result[0].value], assigns(:score_history) | ||
| 146 | assert_response 200 | 124 | assert_response 200 |
| 147 | end | 125 | end |
| 148 | - | ||
| 149 | - private | ||
| 150 | - | ||
| 151 | - def create_project_content | ||
| 152 | - client = mock | ||
| 153 | - @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @name) | ||
| 154 | - @content.expects(:send_project_to_service).returns(nil) | ||
| 155 | - Kalibro::Client::ProjectClient.expects(:new).returns(client) | ||
| 156 | - @content.repository_url = @repository_url | ||
| 157 | - client.expects(:project_names).returns([]) | ||
| 158 | - @content.save | ||
| 159 | - end | ||
| 160 | 126 | ||
| 161 | - def mock_project_result | ||
| 162 | - project_result_client = mock | ||
| 163 | - Kalibro::Client::ProjectResultClient.expects(:new).returns(project_result_client) | ||
| 164 | - project_result_client.expects(:has_results_before).returns(true) | ||
| 165 | - project_result_client.expects(:last_result_before).returns(@project_result) | ||
| 166 | - end | ||
| 167 | - | ||
| 168 | - def mock_module_result | ||
| 169 | - module_result_client = mock | ||
| 170 | - Kalibro::Client::ModuleResultClient.expects(:new).returns(module_result_client) | ||
| 171 | - module_result_client.expects(:module_result).with(@name, @name, @project_result.date).returns(@module_result) | 127 | + should 'test grade history' do |
| 128 | + Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) | ||
| 129 | + get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name | ||
| 130 | + assert_equal @content, assigns(:content) | ||
| 131 | + assert_equal [@module_result.grade], assigns(:score_history) | ||
| 132 | + assert_response 200 | ||
| 172 | end | 133 | end |
| 173 | 134 | ||
| 174 | - def mock_module_result_history | ||
| 175 | - module_result_client = mock | ||
| 176 | - module_result_client.expects(:result_history).with(@name, @name).returns([@module_result]) | ||
| 177 | - Kalibro::Client::ModuleResultClient.expects(:new).returns(module_result_client) | ||
| 178 | - end | ||
| 179 | end | 135 | end |