From 63911c6616d8175e83fe3084ff604c062b36120f Mon Sep 17 00:00:00 2001 From: João M. M. da Silva + Alessandro Palmeira Date: Tue, 10 Jul 2012 17:09:22 -0300 Subject: [PATCH] [Mezuro] Fixed fixtures and added new test for new project model --- plugins/mezuro/lib/kalibro/project.rb | 15 ++++++++++++--- plugins/mezuro/test/fixtures/project_fixtures.rb | 20 +++++++++----------- plugins/mezuro/test/fixtures/repository_fixtures.rb | 5 +---- plugins/mezuro/test/unit/kalibro/project_test.rb | 30 +++++++++++++++++++----------- plugins/mezuro/test/unit/kalibro/repository_test.rb | 9 ++------- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/plugins/mezuro/lib/kalibro/project.rb b/plugins/mezuro/lib/kalibro/project.rb index 6cfc805..5f3f2c2 100644 --- a/plugins/mezuro/lib/kalibro/project.rb +++ b/plugins/mezuro/lib/kalibro/project.rb @@ -7,8 +7,12 @@ class Kalibro::Project < Kalibro::Model end def self.find_by_name(project_name) - attributes = request(:get_project, :project_name => project_name)[:project] - new attributes + begin + attributes = request(:get_project, :project_name => project_name)[:project] + new attributes + rescue Exception => error + nil + end end def self.destroy(project_name) @@ -29,7 +33,12 @@ class Kalibro::Project < Kalibro::Model end def save - self.class.request(:save_project, {:project => to_hash}) + begin + self.class.request(:save_project, {:project => to_hash}) + true + rescue Exception => error + false + end end def repository=(value) diff --git a/plugins/mezuro/test/fixtures/project_fixtures.rb b/plugins/mezuro/test/fixtures/project_fixtures.rb index 3af29d8..71ceaf7 100644 --- a/plugins/mezuro/test/fixtures/project_fixtures.rb +++ b/plugins/mezuro/test/fixtures/project_fixtures.rb @@ -3,20 +3,18 @@ require File.dirname(__FILE__) + '/repository_fixtures' class ProjectFixtures def self.qt_calculator - project = Kalibro::Project.new - project.name = 'Qt-Calculator' - project.license = 'GPL' - project.description = 'Calculator for Qt' - project.repository = RepositoryFixtures.qt_calculator - project.configuration_name = 'Kalibro for Java' - project.state = 'READY' - project + Kalibro::Project.new qt_calculator_hash end def self.qt_calculator_hash - {:name => 'Qt-Calculator', :license => 'GPL', :description => 'Calculator for Qt', - :repository => RepositoryFixtures.qt_calculator_hash, - :configuration_name => 'Kalibro for Java', :state => 'READY'} + { + :name => 'Qt-Calculator', + :license => 'GPL', + :description => 'Calculator for Qt', + :repository => RepositoryFixtures.qt_calculator_hash, + :configuration_name => 'Kalibro for Java', + :state => 'READY' + } end end diff --git a/plugins/mezuro/test/fixtures/repository_fixtures.rb b/plugins/mezuro/test/fixtures/repository_fixtures.rb index aea909b..ba1a19f 100644 --- a/plugins/mezuro/test/fixtures/repository_fixtures.rb +++ b/plugins/mezuro/test/fixtures/repository_fixtures.rb @@ -1,10 +1,7 @@ class RepositoryFixtures def self.qt_calculator - repository = Kalibro::Repository.new - repository.type = 'SUBVERSION' - repository.address = 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator' - repository + Kalibro::Repository.new qt_calculator_hash end def self.qt_calculator_hash diff --git a/plugins/mezuro/test/unit/kalibro/project_test.rb b/plugins/mezuro/test/unit/kalibro/project_test.rb index 9ace26d..740f92c 100644 --- a/plugins/mezuro/test/unit/kalibro/project_test.rb +++ b/plugins/mezuro/test/unit/kalibro/project_test.rb @@ -12,30 +12,38 @@ class ProjectTest < ActiveSupport::TestCase should 'get project by name' do request_body = {:project_name => @project.name} response_hash = {:project => @hash} + Kalibro::Project.expects(:new).with(@hash).returns(@project) Kalibro::Project.expects(:request).with(:get_project, request_body).returns(response_hash) assert_equal @project, Kalibro::Project.find_by_name(@project.name) end -=begin should 'raise error when project doesnt exist' do request_body = {:project_name => @project.name} - @port.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) - assert_nil Kalibro::Client::ProjectClient.project(@project.name) + Kalibro::Project.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) + assert_nil Kalibro::Project.find_by_name(@project.name) + end + + should 'return true when project is saved successfully' do + Kalibro::Project.expects(:request).with(:save_project, {:project => @project.to_hash}) + assert @project.save end - should 'save project' do - create_project_content_mock - @project.state = nil - @port.expects(:request).with(:save_project, {:project => @project.to_hash}) - Kalibro::Client::ProjectClient.save(@project_content) + should 'return false when project is not saved successfully' do + Kalibro::Project.expects(:request).with(:save_project, {:project => @project.to_hash}).raises(Exception.new) + assert !(@project.save) end should 'remove existent project from service' do - @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name}) - @port.expects(:request).with(:remove_project, {:project_name => @project.name}) - Kalibro::Client::ProjectClient.remove(@project.name) + Kalibro::Project.expects(:request).with(:remove_project, {:project_name => @project.name}) + Kalibro::Project.destroy(@project.name) end + should 'raise error when try to remove inexistent project from service' do + Kalibro::Project.expects(:request).with(:remove_project, {:project_name => @project.name}).raises(Exception.new) + assert_raise Exception do Kalibro::Project.destroy(@project.name) end + end + +=begin should 'not try to remove inexistent project from service' do @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never diff --git a/plugins/mezuro/test/unit/kalibro/repository_test.rb b/plugins/mezuro/test/unit/kalibro/repository_test.rb index 5ccaa77..b54da89 100644 --- a/plugins/mezuro/test/unit/kalibro/repository_test.rb +++ b/plugins/mezuro/test/unit/kalibro/repository_test.rb @@ -9,13 +9,8 @@ class RepositoryTest < ActiveSupport::TestCase @repository = RepositoryFixtures.qt_calculator end - #TODO como pegar o nome de TODAS as variáveis, mesmo as não setadas??? - should 'create repository from hash' do - repository = Kalibro::Repository.new(@hash) - attributes = repository.instance_variable_names.map { |variable| variable.to_s.sub(/@/, '') } - attributes.each { |field| assert_equal(@repository.send("#{field}"), repository.send("#{field}")) } - attributes = @repository.instance_variable_names.map { |variable| variable.to_s.sub(/@/, '') } - attributes.each { |field| assert_equal(@repository.send("#{field}"), repository.send("#{field}")) } + should 'new repository from hash' do + assert_equal @repository.type, Kalibro::Repository.new(@hash).type end should 'convert repository to hash' do -- libgit2 0.21.2