Commit 7fe4689a228c9abd78b112864aeb2c09c353f8f0
Committed by
João M. M. da Silva
1 parent
0b1977c2
Exists in
master
and in
28 other branches
[Mezuro] Started ProjectContent tests
Showing
4 changed files
with
52 additions
and
54 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| @@ -3,7 +3,7 @@ class MezuroPlugin::ProjectContent < Article | @@ -3,7 +3,7 @@ class MezuroPlugin::ProjectContent < Article | ||
| 3 | 3 | ||
| 4 | settings_items :project_id | 4 | settings_items :project_id |
| 5 | 5 | ||
| 6 | - validate_on_create :validate_kalibro_project_name | 6 | + validate_on_create :validate_kalibro_project_name |
| 7 | validate_on_create :validate_repository_url | 7 | validate_on_create :validate_repository_url |
| 8 | 8 | ||
| 9 | def self.short_description | 9 | def self.short_description |
| @@ -48,12 +48,12 @@ class MezuroPlugin::ProjectContent < Article | @@ -48,12 +48,12 @@ class MezuroPlugin::ProjectContent < Article | ||
| 48 | end | 48 | end |
| 49 | @processing | 49 | @processing |
| 50 | end | 50 | end |
| 51 | - | 51 | + |
| 52 | def processing_with_date(repository_id, date) | 52 | def processing_with_date(repository_id, date) |
| 53 | begin | 53 | begin |
| 54 | if Kalibro::Processing.has_processing_before(repository_id, date) | 54 | if Kalibro::Processing.has_processing_before(repository_id, date) |
| 55 | @processing ||= Kalibro::Processing.last_processing_before(repository_id, date) | 55 | @processing ||= Kalibro::Processing.last_processing_before(repository_id, date) |
| 56 | - else if Kalibro::Processing.has_processing_after(repository_id, date) | 56 | + elsif Kalibro::Processing.has_processing_after(repository_id, date) |
| 57 | @processing ||= Kalibro::Processing.last_processing_after(repository_id, date) | 57 | @processing ||= Kalibro::Processing.last_processing_after(repository_id, date) |
| 58 | end | 58 | end |
| 59 | rescue Exception => error | 59 | rescue Exception => error |
| @@ -92,7 +92,7 @@ class MezuroPlugin::ProjectContent < Article | @@ -92,7 +92,7 @@ class MezuroPlugin::ProjectContent < Article | ||
| 92 | def self.to_object value | 92 | def self.to_object value |
| 93 | value.kind_of?(Hash) ? Kalibro::Repository.new(value) : value | 93 | value.kind_of?(Hash) ? Kalibro::Repository.new(value) : value |
| 94 | end | 94 | end |
| 95 | - | 95 | + |
| 96 | after_save :send_project_to_service | 96 | after_save :send_project_to_service |
| 97 | after_destroy :destroy_project_from_service | 97 | after_destroy :destroy_project_from_service |
| 98 | 98 | ||
| @@ -103,7 +103,7 @@ class MezuroPlugin::ProjectContent < Article | @@ -103,7 +103,7 @@ class MezuroPlugin::ProjectContent < Article | ||
| 103 | errors.add_to_base("Repository URL is mandatory") | 103 | errors.add_to_base("Repository URL is mandatory") |
| 104 | end | 104 | end |
| 105 | end | 105 | end |
| 106 | - | 106 | + |
| 107 | def send_project_to_service | 107 | def send_project_to_service |
| 108 | created_project = create_kalibro_project | 108 | created_project = create_kalibro_project |
| 109 | created_project.process_project(periodicity_in_days) | 109 | created_project.process_project(periodicity_in_days) |
plugins/mezuro/test/fixtures/project_content_fixtures.rb
0 → 100644
| @@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
| 1 | +class ProjectContentFixtures | ||
| 2 | + | ||
| 3 | + def self.project_content | ||
| 4 | + content = MezuroPlugin::ProjectContent.new | ||
| 5 | + content.project_id = 42 | ||
| 6 | + #content.name = 'Qt-Calculator' | ||
| 7 | + #content.project_license = 'GPL' | ||
| 8 | + #content.description = 'Calculator for Qt' | ||
| 9 | + #content.repository_type = [RepositoryFixtures.repository_hash[:type]] | ||
| 10 | + #content.repository_url = [RepositoryFixtures.repository_hash[:address]] | ||
| 11 | + #content.configuration_name = 'Kalibro for Java' | ||
| 12 | + #content.periodicity_in_days = 1 | ||
| 13 | + content | ||
| 14 | + end | ||
| 15 | + | ||
| 16 | +end | ||
| 0 | \ No newline at end of file | 17 | \ No newline at end of file |
plugins/mezuro/test/fixtures/project_fixtures.rb
| @@ -17,17 +17,4 @@ class ProjectFixtures | @@ -17,17 +17,4 @@ class ProjectFixtures | ||
| 17 | :description => 'Calculator for Qt' | 17 | :description => 'Calculator for Qt' |
| 18 | } | 18 | } |
| 19 | end | 19 | end |
| 20 | - | ||
| 21 | - def self.project_content | ||
| 22 | - content = MezuroPlugin::ProjectContent.new | ||
| 23 | - content.name = 'Qt-Calculator' | ||
| 24 | - content.project_license = 'GPL' | ||
| 25 | - content.description = 'Calculator for Qt' | ||
| 26 | - content.repository_type = [RepositoryFixtures.repository_hash[:type]] | ||
| 27 | - content.repository_url = [RepositoryFixtures.repository_hash[:address]] | ||
| 28 | - content.configuration_name = 'Kalibro for Java' | ||
| 29 | - content.periodicity_in_days = 1 | ||
| 30 | - content | ||
| 31 | - end | ||
| 32 | - | ||
| 33 | end | 20 | end |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
| 1 | require "test_helper" | 1 | require "test_helper" |
| 2 | 2 | ||
| 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" |
| 4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_content_fixtures" | ||
| 5 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures" | ||
| 4 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" | 6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" |
| 5 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" | 7 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" |
| 6 | 8 | ||
| @@ -8,8 +10,8 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -8,8 +10,8 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 8 | 10 | ||
| 9 | def setup | 11 | def setup |
| 10 | @project = ProjectFixtures.project | 12 | @project = ProjectFixtures.project |
| 11 | - @content = ProjectFixtures.project_content | ||
| 12 | - @project_result = ProjectResultFixtures.project_result | 13 | + @project_content = ProjectContentFixtures.project_content |
| 14 | + @processing = ProcessingFixtures.processing | ||
| 13 | @module = ModuleFixtures.module | 15 | @module = ModuleFixtures.module |
| 14 | @module_result = ModuleResultFixtures.module_result | 16 | @module_result = ModuleResultFixtures.module_result |
| 15 | end | 17 | end |
| @@ -23,31 +25,24 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -23,31 +25,24 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 23 | end | 25 | end |
| 24 | 26 | ||
| 25 | should 'have an html view' do | 27 | should 'have an html view' do |
| 26 | - assert_not_nil @content.to_html | 28 | + assert_not_nil @project_content.to_html |
| 27 | end | 29 | end |
| 28 | 30 | ||
| 29 | should 'get project from service' do | 31 | should 'get project from service' do |
| 30 | - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | ||
| 31 | - assert_equal @project.name, @content.project.name | 32 | + Kalibro::Project.expects(:find).with(@project.id).returns(@project) |
| 33 | + assert_equal @project, @project_content.project | ||
| 32 | end | 34 | end |
| 33 | 35 | ||
| 34 | - should 'get project result from service' do | ||
| 35 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | ||
| 36 | - assert_equal @project_result.load_time, @content.project_result.load_time | ||
| 37 | - end | ||
| 38 | - | ||
| 39 | - should 'get date result from service when has_result_before is true' do | ||
| 40 | - request_body = {:project_name => @project.name, :date => @project_result.date} | ||
| 41 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | ||
| 42 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | ||
| 43 | - assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time | 36 | + should 'add error when the project does not exist' do |
| 37 | + Kalibro::Project.expects(:find).with(@project.id).raises(Kalibro::Errors::RecordNotFound) | ||
| 38 | + @project_content.project | ||
| 39 | + | ||
| 40 | + assert_not_nil @project_content.errors | ||
| 44 | end | 41 | end |
| 45 | 42 | ||
| 46 | - should 'get date result from service when has_result_before is false' do | ||
| 47 | - request_body = {:project_name => @project.name, :date => @project_result.date} | ||
| 48 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false}) | ||
| 49 | - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash}) | ||
| 50 | - assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time | 43 | +=begin |
| 44 | + should 'get repositories of the project from service' do | ||
| 45 | + | ||
| 51 | end | 46 | end |
| 52 | 47 | ||
| 53 | should 'get module result from service without date' do | 48 | should 'get module result from service without date' do |
| @@ -57,11 +52,11 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -57,11 +52,11 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 57 | 'ModuleResult', | 52 | 'ModuleResult', |
| 58 | :get_module_result, | 53 | :get_module_result, |
| 59 | { | 54 | { |
| 60 | - :project_name => @project.name, | 55 | + :project_name => @project.name, |
| 61 | :module_name => @module.name, | 56 | :module_name => @module.name, |
| 62 | :date => date_with_milliseconds | 57 | :date => date_with_milliseconds |
| 63 | }).returns({:module_result => @module_result.to_hash}) | 58 | }).returns({:module_result => @module_result.to_hash}) |
| 64 | - assert_equal @module_result.grade, @content.module_result({:module_name => @module.name}).grade | 59 | + assert_equal @module_result.grade, @project_content.module_result({:module_name => @module.name}).grade |
| 65 | end | 60 | end |
| 66 | 61 | ||
| 67 | should 'get module result from service with date' do | 62 | should 'get module result from service with date' do |
| @@ -73,11 +68,11 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -73,11 +68,11 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 73 | 'ModuleResult', | 68 | 'ModuleResult', |
| 74 | :get_module_result, | 69 | :get_module_result, |
| 75 | { | 70 | { |
| 76 | - :project_name => @project.name, | 71 | + :project_name => @project.name, |
| 77 | :module_name => @module.name, | 72 | :module_name => @module.name, |
| 78 | :date => date_with_milliseconds | 73 | :date => date_with_milliseconds |
| 79 | }).returns({:module_result => @module_result.to_hash}) | 74 | }).returns({:module_result => @module_result.to_hash}) |
| 80 | - assert_equal @module_result.grade, @content.module_result({:module_name => @module.name, :date => @project_result.date}).grade | 75 | + assert_equal @module_result.grade, @project_content.module_result({:module_name => @module.name, :date => @project_result.date}).grade |
| 81 | end | 76 | end |
| 82 | 77 | ||
| 83 | should 'get result history' do | 78 | should 'get result history' do |
| @@ -85,15 +80,15 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -85,15 +80,15 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 85 | 'ModuleResult', | 80 | 'ModuleResult', |
| 86 | :get_result_history, | 81 | :get_result_history, |
| 87 | { | 82 | { |
| 88 | - :project_name => @project.name, | 83 | + :project_name => @project.name, |
| 89 | :module_name => @module.name | 84 | :module_name => @module.name |
| 90 | }).returns({:module_result => @module_result.to_hash}) | 85 | }).returns({:module_result => @module_result.to_hash}) |
| 91 | - @content.result_history(@module.name) | 86 | + @project_content.result_history(@module.name) |
| 92 | end | 87 | end |
| 93 | 88 | ||
| 94 | should 'send project to service after saving' do | 89 | should 'send project to service after saving' do |
| 95 | - @content.expects :send_project_to_service | ||
| 96 | - @content.run_callbacks :after_save | 90 | + @project_content.expects :send_project_to_service |
| 91 | + @project_content.run_callbacks :after_save | ||
| 97 | end | 92 | end |
| 98 | 93 | ||
| 99 | should 'send correct project to service' do | 94 | should 'send correct project to service' do |
| @@ -101,20 +96,20 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -101,20 +96,20 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 101 | hash.delete(:attributes!) | 96 | hash.delete(:attributes!) |
| 102 | hash.delete(:state) | 97 | hash.delete(:state) |
| 103 | Kalibro::Project.expects(:create).with(hash).returns(@project) | 98 | Kalibro::Project.expects(:create).with(hash).returns(@project) |
| 104 | - @project.expects(:process_project).with(@content.periodicity_in_days) | ||
| 105 | - @content.send :send_project_to_service | 99 | + @project.expects(:process_project).with(@project_content.periodicity_in_days) |
| 100 | + @project_content.send :send_project_to_service | ||
| 106 | end | 101 | end |
| 107 | 102 | ||
| 108 | should 'destroy project from service' do | 103 | should 'destroy project from service' do |
| 109 | Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | 104 | Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) |
| 110 | Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) | 105 | Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) |
| 111 | - @content.send :destroy_project_from_service | 106 | + @project_content.send :destroy_project_from_service |
| 112 | end | 107 | end |
| 113 | - | 108 | + |
| 114 | should 'not save a project with an existing project name in kalibro' do | 109 | should 'not save a project with an existing project name in kalibro' do |
| 115 | - Kalibro::Project.expects(:all_names).returns([@content.name]) | ||
| 116 | - @content.send :validate_kalibro_project_name | ||
| 117 | - assert_equal "Project name already exists in Kalibro", @content.errors.on_base | 110 | + Kalibro::Project.expects(:all_names).returns([@project_content.name]) |
| 111 | + @project_content.send :validate_kalibro_project_name | ||
| 112 | + assert_equal "Project name already exists in Kalibro", @project_content.errors.on_base | ||
| 118 | end | 113 | end |
| 119 | - | 114 | +=end |
| 120 | end | 115 | end |