Commit 7fe4689a228c9abd78b112864aeb2c09c353f8f0
Committed by
João M. M. da Silva
1 parent
0b1977c2
Exists in
staging
and in
42 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 | 3 | |
| 4 | 4 | settings_items :project_id |
| 5 | 5 | |
| 6 | - validate_on_create :validate_kalibro_project_name | |
| 6 | + validate_on_create :validate_kalibro_project_name | |
| 7 | 7 | validate_on_create :validate_repository_url |
| 8 | 8 | |
| 9 | 9 | def self.short_description |
| ... | ... | @@ -48,12 +48,12 @@ class MezuroPlugin::ProjectContent < Article |
| 48 | 48 | end |
| 49 | 49 | @processing |
| 50 | 50 | end |
| 51 | - | |
| 51 | + | |
| 52 | 52 | def processing_with_date(repository_id, date) |
| 53 | 53 | begin |
| 54 | 54 | if Kalibro::Processing.has_processing_before(repository_id, date) |
| 55 | 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 | 57 | @processing ||= Kalibro::Processing.last_processing_after(repository_id, date) |
| 58 | 58 | end |
| 59 | 59 | rescue Exception => error |
| ... | ... | @@ -92,7 +92,7 @@ class MezuroPlugin::ProjectContent < Article |
| 92 | 92 | def self.to_object value |
| 93 | 93 | value.kind_of?(Hash) ? Kalibro::Repository.new(value) : value |
| 94 | 94 | end |
| 95 | - | |
| 95 | + | |
| 96 | 96 | after_save :send_project_to_service |
| 97 | 97 | after_destroy :destroy_project_from_service |
| 98 | 98 | |
| ... | ... | @@ -103,7 +103,7 @@ class MezuroPlugin::ProjectContent < Article |
| 103 | 103 | errors.add_to_base("Repository URL is mandatory") |
| 104 | 104 | end |
| 105 | 105 | end |
| 106 | - | |
| 106 | + | |
| 107 | 107 | def send_project_to_service |
| 108 | 108 | created_project = create_kalibro_project |
| 109 | 109 | created_project.process_project(periodicity_in_days) | ... | ... |
plugins/mezuro/test/fixtures/project_content_fixtures.rb
0 → 100644
| ... | ... | @@ -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 | 17 | \ No newline at end of file | ... | ... |
plugins/mezuro/test/fixtures/project_fixtures.rb
| ... | ... | @@ -17,17 +17,4 @@ class ProjectFixtures |
| 17 | 17 | :description => 'Calculator for Qt' |
| 18 | 18 | } |
| 19 | 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 | 20 | end | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
| 1 | 1 | require "test_helper" |
| 2 | 2 | |
| 3 | 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 | 6 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" |
| 5 | 7 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" |
| 6 | 8 | |
| ... | ... | @@ -8,8 +10,8 @@ class ProjectContentTest < ActiveSupport::TestCase |
| 8 | 10 | |
| 9 | 11 | def setup |
| 10 | 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 | 15 | @module = ModuleFixtures.module |
| 14 | 16 | @module_result = ModuleResultFixtures.module_result |
| 15 | 17 | end |
| ... | ... | @@ -23,31 +25,24 @@ class ProjectContentTest < ActiveSupport::TestCase |
| 23 | 25 | end |
| 24 | 26 | |
| 25 | 27 | should 'have an html view' do |
| 26 | - assert_not_nil @content.to_html | |
| 28 | + assert_not_nil @project_content.to_html | |
| 27 | 29 | end |
| 28 | 30 | |
| 29 | 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 | 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 | 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 | 46 | end |
| 52 | 47 | |
| 53 | 48 | should 'get module result from service without date' do |
| ... | ... | @@ -57,11 +52,11 @@ class ProjectContentTest < ActiveSupport::TestCase |
| 57 | 52 | 'ModuleResult', |
| 58 | 53 | :get_module_result, |
| 59 | 54 | { |
| 60 | - :project_name => @project.name, | |
| 55 | + :project_name => @project.name, | |
| 61 | 56 | :module_name => @module.name, |
| 62 | 57 | :date => date_with_milliseconds |
| 63 | 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 | 60 | end |
| 66 | 61 | |
| 67 | 62 | should 'get module result from service with date' do |
| ... | ... | @@ -73,11 +68,11 @@ class ProjectContentTest < ActiveSupport::TestCase |
| 73 | 68 | 'ModuleResult', |
| 74 | 69 | :get_module_result, |
| 75 | 70 | { |
| 76 | - :project_name => @project.name, | |
| 71 | + :project_name => @project.name, | |
| 77 | 72 | :module_name => @module.name, |
| 78 | 73 | :date => date_with_milliseconds |
| 79 | 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 | 76 | end |
| 82 | 77 | |
| 83 | 78 | should 'get result history' do |
| ... | ... | @@ -85,15 +80,15 @@ class ProjectContentTest < ActiveSupport::TestCase |
| 85 | 80 | 'ModuleResult', |
| 86 | 81 | :get_result_history, |
| 87 | 82 | { |
| 88 | - :project_name => @project.name, | |
| 83 | + :project_name => @project.name, | |
| 89 | 84 | :module_name => @module.name |
| 90 | 85 | }).returns({:module_result => @module_result.to_hash}) |
| 91 | - @content.result_history(@module.name) | |
| 86 | + @project_content.result_history(@module.name) | |
| 92 | 87 | end |
| 93 | 88 | |
| 94 | 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 | 92 | end |
| 98 | 93 | |
| 99 | 94 | should 'send correct project to service' do |
| ... | ... | @@ -101,20 +96,20 @@ class ProjectContentTest < ActiveSupport::TestCase |
| 101 | 96 | hash.delete(:attributes!) |
| 102 | 97 | hash.delete(:state) |
| 103 | 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 | 101 | end |
| 107 | 102 | |
| 108 | 103 | should 'destroy project from service' do |
| 109 | 104 | Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) |
| 110 | 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 | 107 | end |
| 113 | - | |
| 108 | + | |
| 114 | 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 | 113 | end |
| 119 | - | |
| 114 | +=end | |
| 120 | 115 | end | ... | ... |