From 6512befb2a74c3838c6293ea02bd3ade6c056a43 Mon Sep 17 00:00:00 2001 From: Joao M. M. da Silva + Jefferson Fernandes Date: Fri, 11 May 2012 17:05:47 -0300 Subject: [PATCH] [Mezuro] Added validation to Project saving. --- plugins/mezuro/lib/mezuro_plugin/project_content.rb | 16 ++++++++++++---- plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb | 30 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/plugins/mezuro/lib/mezuro_plugin/project_content.rb b/plugins/mezuro/lib/mezuro_plugin/project_content.rb index 096d805..82c8cd2 100644 --- a/plugins/mezuro/lib/mezuro_plugin/project_content.rb +++ b/plugins/mezuro/lib/mezuro_plugin/project_content.rb @@ -1,4 +1,5 @@ class MezuroPlugin::ProjectContent < Article + validate :validate_kalibro_project_name def self.short_description 'Kalibro project' @@ -26,13 +27,13 @@ class MezuroPlugin::ProjectContent < Article end def get_date_result(date) - client = Kalibro::Client::ProjectResultClient.new + client = Kalibro::Client::ProjectResultClient.new @project_result ||= client.has_results_before(name, date) ? client.last_result_before(name, date) : client.first_result_after(name, date) end def module_result(module_name) module_name = project.name if module_name.nil? - @module_client ||= module_result_client.module_result(project.name, module_name, project_result.date) + @module_client ||= module_result_client.module_result(project.name, module_name, project_result.date) end def result_history(module_name) @@ -48,13 +49,20 @@ class MezuroPlugin::ProjectContent < Article private + def validate_kalibro_project_name + begin + Kalibro::Client::ProjectClient.project(name) + errors.add_to_base("Project name already exists in Kalibro") + rescue + end + end + def send_project_to_service Kalibro::Client::ProjectClient.save(self) - Kalibro::Client::KalibroClient.process_project(name, periodicity_in_days) + Kalibro::Client::KalibroClient.process_project(name, periodicity_in_days) end def remove_project_from_service Kalibro::Client::ProjectClient.remove(name) end - end diff --git a/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb b/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb index 7afab93..7202674 100644 --- a/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb +++ b/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb @@ -14,6 +14,15 @@ class ProjectContentTest < ActiveSupport::TestCase @content.repository_url = @project.repository.address @content.configuration_name = @project.configuration_name @content.periodicity_in_days = 1 + + @content2 = MezuroPlugin::ProjectContent.new + @content2.name = @content.name + @content2.license = @project.license + @content2.description = @project.description + @content2.repository_type = @project.repository.type + @content2.repository_url = @project.repository.address + @content2.configuration_name = @project.configuration_name + @content2.periodicity_in_days = 1 end should 'be an article' do @@ -91,6 +100,12 @@ returns(module_result) @content.send :remove_project_from_service end + should 'not save a project with an existing project name in kalibro' do + Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(mock) + @content.send :validate_kalibro_project_name + assert_equal @content.errors.on_base, "Project name already exists in Kalibro" + end + private def mock_project_client Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) @@ -103,18 +118,3 @@ returns(module_result) end end - - - - - - - - - - - - - - - -- libgit2 0.21.2