Commit 63911c6616d8175e83fe3084ff604c062b36120f
Committed by
Paulo Meireles
1 parent
59b3e458
Exists in
master
and in
22 other branches
[Mezuro] Fixed fixtures and added new test for new project model
Showing
5 changed files
with
43 additions
and
36 deletions
Show diff stats
plugins/mezuro/lib/kalibro/project.rb
@@ -7,8 +7,12 @@ class Kalibro::Project < Kalibro::Model | @@ -7,8 +7,12 @@ class Kalibro::Project < Kalibro::Model | ||
7 | end | 7 | end |
8 | 8 | ||
9 | def self.find_by_name(project_name) | 9 | def self.find_by_name(project_name) |
10 | - attributes = request(:get_project, :project_name => project_name)[:project] | ||
11 | - new attributes | 10 | + begin |
11 | + attributes = request(:get_project, :project_name => project_name)[:project] | ||
12 | + new attributes | ||
13 | + rescue Exception => error | ||
14 | + nil | ||
15 | + end | ||
12 | end | 16 | end |
13 | 17 | ||
14 | def self.destroy(project_name) | 18 | def self.destroy(project_name) |
@@ -29,7 +33,12 @@ class Kalibro::Project < Kalibro::Model | @@ -29,7 +33,12 @@ class Kalibro::Project < Kalibro::Model | ||
29 | end | 33 | end |
30 | 34 | ||
31 | def save | 35 | def save |
32 | - self.class.request(:save_project, {:project => to_hash}) | 36 | + begin |
37 | + self.class.request(:save_project, {:project => to_hash}) | ||
38 | + true | ||
39 | + rescue Exception => error | ||
40 | + false | ||
41 | + end | ||
33 | end | 42 | end |
34 | 43 | ||
35 | def repository=(value) | 44 | def repository=(value) |
plugins/mezuro/test/fixtures/project_fixtures.rb
@@ -3,20 +3,18 @@ require File.dirname(__FILE__) + '/repository_fixtures' | @@ -3,20 +3,18 @@ require File.dirname(__FILE__) + '/repository_fixtures' | ||
3 | class ProjectFixtures | 3 | class ProjectFixtures |
4 | 4 | ||
5 | def self.qt_calculator | 5 | def self.qt_calculator |
6 | - project = Kalibro::Project.new | ||
7 | - project.name = 'Qt-Calculator' | ||
8 | - project.license = 'GPL' | ||
9 | - project.description = 'Calculator for Qt' | ||
10 | - project.repository = RepositoryFixtures.qt_calculator | ||
11 | - project.configuration_name = 'Kalibro for Java' | ||
12 | - project.state = 'READY' | ||
13 | - project | 6 | + Kalibro::Project.new qt_calculator_hash |
14 | end | 7 | end |
15 | 8 | ||
16 | def self.qt_calculator_hash | 9 | def self.qt_calculator_hash |
17 | - {:name => 'Qt-Calculator', :license => 'GPL', :description => 'Calculator for Qt', | ||
18 | - :repository => RepositoryFixtures.qt_calculator_hash, | ||
19 | - :configuration_name => 'Kalibro for Java', :state => 'READY'} | 10 | + { |
11 | + :name => 'Qt-Calculator', | ||
12 | + :license => 'GPL', | ||
13 | + :description => 'Calculator for Qt', | ||
14 | + :repository => RepositoryFixtures.qt_calculator_hash, | ||
15 | + :configuration_name => 'Kalibro for Java', | ||
16 | + :state => 'READY' | ||
17 | + } | ||
20 | end | 18 | end |
21 | 19 | ||
22 | end | 20 | end |
plugins/mezuro/test/fixtures/repository_fixtures.rb
1 | class RepositoryFixtures | 1 | class RepositoryFixtures |
2 | 2 | ||
3 | def self.qt_calculator | 3 | def self.qt_calculator |
4 | - repository = Kalibro::Repository.new | ||
5 | - repository.type = 'SUBVERSION' | ||
6 | - repository.address = 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator' | ||
7 | - repository | 4 | + Kalibro::Repository.new qt_calculator_hash |
8 | end | 5 | end |
9 | 6 | ||
10 | def self.qt_calculator_hash | 7 | def self.qt_calculator_hash |
plugins/mezuro/test/unit/kalibro/project_test.rb
@@ -12,30 +12,38 @@ class ProjectTest < ActiveSupport::TestCase | @@ -12,30 +12,38 @@ class ProjectTest < ActiveSupport::TestCase | ||
12 | should 'get project by name' do | 12 | should 'get project by name' do |
13 | request_body = {:project_name => @project.name} | 13 | request_body = {:project_name => @project.name} |
14 | response_hash = {:project => @hash} | 14 | response_hash = {:project => @hash} |
15 | + Kalibro::Project.expects(:new).with(@hash).returns(@project) | ||
15 | Kalibro::Project.expects(:request).with(:get_project, request_body).returns(response_hash) | 16 | Kalibro::Project.expects(:request).with(:get_project, request_body).returns(response_hash) |
16 | assert_equal @project, Kalibro::Project.find_by_name(@project.name) | 17 | assert_equal @project, Kalibro::Project.find_by_name(@project.name) |
17 | end | 18 | end |
18 | 19 | ||
19 | -=begin | ||
20 | should 'raise error when project doesnt exist' do | 20 | should 'raise error when project doesnt exist' do |
21 | request_body = {:project_name => @project.name} | 21 | request_body = {:project_name => @project.name} |
22 | - @port.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) | ||
23 | - assert_nil Kalibro::Client::ProjectClient.project(@project.name) | 22 | + Kalibro::Project.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) |
23 | + assert_nil Kalibro::Project.find_by_name(@project.name) | ||
24 | + end | ||
25 | + | ||
26 | + should 'return true when project is saved successfully' do | ||
27 | + Kalibro::Project.expects(:request).with(:save_project, {:project => @project.to_hash}) | ||
28 | + assert @project.save | ||
24 | end | 29 | end |
25 | 30 | ||
26 | - should 'save project' do | ||
27 | - create_project_content_mock | ||
28 | - @project.state = nil | ||
29 | - @port.expects(:request).with(:save_project, {:project => @project.to_hash}) | ||
30 | - Kalibro::Client::ProjectClient.save(@project_content) | 31 | + should 'return false when project is not saved successfully' do |
32 | + Kalibro::Project.expects(:request).with(:save_project, {:project => @project.to_hash}).raises(Exception.new) | ||
33 | + assert !(@project.save) | ||
31 | end | 34 | end |
32 | 35 | ||
33 | should 'remove existent project from service' do | 36 | should 'remove existent project from service' do |
34 | - @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name}) | ||
35 | - @port.expects(:request).with(:remove_project, {:project_name => @project.name}) | ||
36 | - Kalibro::Client::ProjectClient.remove(@project.name) | 37 | + Kalibro::Project.expects(:request).with(:remove_project, {:project_name => @project.name}) |
38 | + Kalibro::Project.destroy(@project.name) | ||
37 | end | 39 | end |
38 | 40 | ||
41 | + should 'raise error when try to remove inexistent project from service' do | ||
42 | + Kalibro::Project.expects(:request).with(:remove_project, {:project_name => @project.name}).raises(Exception.new) | ||
43 | + assert_raise Exception do Kalibro::Project.destroy(@project.name) end | ||
44 | + end | ||
45 | + | ||
46 | +=begin | ||
39 | should 'not try to remove inexistent project from service' do | 47 | should 'not try to remove inexistent project from service' do |
40 | @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) | 48 | @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) |
41 | @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never | 49 | @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never |
plugins/mezuro/test/unit/kalibro/repository_test.rb
@@ -9,13 +9,8 @@ class RepositoryTest < ActiveSupport::TestCase | @@ -9,13 +9,8 @@ class RepositoryTest < ActiveSupport::TestCase | ||
9 | @repository = RepositoryFixtures.qt_calculator | 9 | @repository = RepositoryFixtures.qt_calculator |
10 | end | 10 | end |
11 | 11 | ||
12 | - #TODO como pegar o nome de TODAS as variáveis, mesmo as não setadas??? | ||
13 | - should 'create repository from hash' do | ||
14 | - repository = Kalibro::Repository.new(@hash) | ||
15 | - attributes = repository.instance_variable_names.map { |variable| variable.to_s.sub(/@/, '') } | ||
16 | - attributes.each { |field| assert_equal(@repository.send("#{field}"), repository.send("#{field}")) } | ||
17 | - attributes = @repository.instance_variable_names.map { |variable| variable.to_s.sub(/@/, '') } | ||
18 | - attributes.each { |field| assert_equal(@repository.send("#{field}"), repository.send("#{field}")) } | 12 | + should 'new repository from hash' do |
13 | + assert_equal @repository.type, Kalibro::Repository.new(@hash).type | ||
19 | end | 14 | end |
20 | 15 | ||
21 | should 'convert repository to hash' do | 16 | should 'convert repository to hash' do |