Commit d056407511404579f6c2d086d55e459feac01407
Committed by
Paulo Meireles
1 parent
63911c66
Exists in
master
and in
29 other branches
[Mezuro] Finished refactoring project model design.
Showing
7 changed files
with
64 additions
and
60 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin/project_content.rb
... | ... | @@ -21,7 +21,7 @@ class MezuroPlugin::ProjectContent < Article |
21 | 21 | |
22 | 22 | def project |
23 | 23 | begin |
24 | - @project ||= Kalibro::Client::ProjectClient.project(name) | |
24 | + @project ||= Kalibro::Project.find_by_name(name) | |
25 | 25 | rescue Exception => error |
26 | 26 | errors.add_to_base(error.message) |
27 | 27 | end |
... | ... | @@ -55,13 +55,13 @@ client.first_result_after(name, date) |
55 | 55 | end |
56 | 56 | |
57 | 57 | after_save :send_project_to_service |
58 | - after_destroy :remove_project_from_service | |
58 | + after_destroy :destroy_project_from_service | |
59 | 59 | |
60 | 60 | private |
61 | 61 | |
62 | 62 | def validate_kalibro_project_name |
63 | 63 | begin |
64 | - existing = Kalibro::Client::ProjectClient.new.project_names | |
64 | + existing = Kalibro::Project.all_names | |
65 | 65 | rescue Exception => error |
66 | 66 | errors.add_to_base(error.message) |
67 | 67 | end |
... | ... | @@ -79,7 +79,7 @@ client.first_result_after(name, date) |
79 | 79 | |
80 | 80 | def send_project_to_service |
81 | 81 | begin |
82 | - Kalibro::Client::ProjectClient.save(self) | |
82 | + Kalibro::Project.create(self).save | |
83 | 83 | Kalibro::Client::KalibroClient.process_project(name, periodicity_in_days) |
84 | 84 | rescue Exception => error |
85 | 85 | errors.add_to_base(error.message) |
... | ... | @@ -87,13 +87,12 @@ client.first_result_after(name, date) |
87 | 87 | |
88 | 88 | end |
89 | 89 | |
90 | - def remove_project_from_service | |
90 | + def destroy_project_from_service | |
91 | 91 | begin |
92 | - Kalibro::Client::ProjectClient.remove(name) | |
92 | + Kalibro::Project.destroy(name) | |
93 | 93 | rescue Exception => error |
94 | 94 | errors.add_to_base(error.message) |
95 | 95 | end |
96 | - | |
97 | 96 | end |
98 | 97 | |
99 | 98 | def module_result_client | ... | ... |
plugins/mezuro/test/fixtures/project_fixtures.rb
... | ... | @@ -2,16 +2,28 @@ require File.dirname(__FILE__) + '/repository_fixtures' |
2 | 2 | |
3 | 3 | class ProjectFixtures |
4 | 4 | |
5 | - def self.qt_calculator | |
6 | - Kalibro::Project.new qt_calculator_hash | |
5 | + def self.project | |
6 | + Kalibro::Project.new project_hash | |
7 | 7 | end |
8 | 8 | |
9 | - def self.qt_calculator_hash | |
9 | + def self.project_content | |
10 | + content = MezuroPlugin::ProjectContent.new | |
11 | + content.name = 'Qt-Calculator' | |
12 | + content.license = 'GPL' | |
13 | + content.description = 'Calculator for Qt' | |
14 | + content.repository_type = RepositoryFixtures.repository_hash[:type] | |
15 | + content.repository_url = RepositoryFixtures.repository_hash[:address] | |
16 | + content.configuration_name = 'Kalibro for Java' | |
17 | + content.periodicity_in_days = 1 | |
18 | + content | |
19 | + end | |
20 | + | |
21 | + def self.project_hash | |
10 | 22 | { |
11 | 23 | :name => 'Qt-Calculator', |
12 | 24 | :license => 'GPL', |
13 | 25 | :description => 'Calculator for Qt', |
14 | - :repository => RepositoryFixtures.qt_calculator_hash, | |
26 | + :repository => RepositoryFixtures.repository_hash, | |
15 | 27 | :configuration_name => 'Kalibro for Java', |
16 | 28 | :state => 'READY' |
17 | 29 | } | ... | ... |
plugins/mezuro/test/fixtures/project_result_fixtures.rb
... | ... | @@ -6,7 +6,7 @@ class ProjectResultFixtures |
6 | 6 | |
7 | 7 | def self.qt_calculator |
8 | 8 | result = Kalibro::Entities::ProjectResult.new |
9 | - result.project = ProjectFixtures.qt_calculator | |
9 | + result.project = ProjectFixtures.project | |
10 | 10 | result.date = ModuleResultFixtures.create.date |
11 | 11 | result.load_time = 14878 |
12 | 12 | result.analysis_time = 1022 |
... | ... | @@ -16,7 +16,7 @@ class ProjectResultFixtures |
16 | 16 | end |
17 | 17 | |
18 | 18 | def self.qt_calculator_hash |
19 | - {:project => ProjectFixtures.qt_calculator_hash, :date => ModuleResultFixtures.create_hash[:date], | |
19 | + {:project => ProjectFixtures.project_hash, :date => ModuleResultFixtures.create_hash[:date], | |
20 | 20 | :load_time => 14878, :analysis_time => 1022, :source_tree => ModuleNodeFixtures.qt_calculator_tree_hash, |
21 | 21 | :collect_time => 14878} |
22 | 22 | end | ... | ... |
plugins/mezuro/test/fixtures/repository_fixtures.rb
1 | 1 | class RepositoryFixtures |
2 | 2 | |
3 | - def self.qt_calculator | |
4 | - Kalibro::Repository.new qt_calculator_hash | |
3 | + def self.repository | |
4 | + Kalibro::Repository.new repository_hash | |
5 | 5 | end |
6 | 6 | |
7 | - def self.qt_calculator_hash | |
7 | + def self.repository_hash | |
8 | 8 | {:type => 'SUBVERSION', :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} |
9 | 9 | end |
10 | 10 | ... | ... |
plugins/mezuro/test/unit/kalibro/project_test.rb
... | ... | @@ -5,11 +5,18 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" |
5 | 5 | class ProjectTest < ActiveSupport::TestCase |
6 | 6 | |
7 | 7 | def setup |
8 | - @hash = ProjectFixtures.qt_calculator_hash | |
9 | - @project = ProjectFixtures.qt_calculator | |
8 | + @hash = ProjectFixtures.project_hash | |
9 | + @project = ProjectFixtures.project | |
10 | + @project_content = ProjectFixtures.project_content | |
10 | 11 | end |
11 | 12 | |
12 | - should 'get project by name' do | |
13 | + should 'get all project names' do | |
14 | + response_hash = {:project_name => [@project.name]} | |
15 | + Kalibro::Project.expects(:request).with(:get_project_names).returns(response_hash) | |
16 | + assert_equal response_hash[:project_name], Kalibro::Project.all_names | |
17 | + end | |
18 | + | |
19 | + should 'find project by name' do | |
13 | 20 | request_body = {:project_name => @project.name} |
14 | 21 | response_hash = {:project => @hash} |
15 | 22 | Kalibro::Project.expects(:new).with(@hash).returns(@project) |
... | ... | @@ -43,31 +50,24 @@ class ProjectTest < ActiveSupport::TestCase |
43 | 50 | assert_raise Exception do Kalibro::Project.destroy(@project.name) end |
44 | 51 | end |
45 | 52 | |
46 | -=begin | |
47 | - should 'not try to remove inexistent project from service' do | |
48 | - @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) | |
49 | - @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never | |
50 | - Kalibro::Client::ProjectClient.remove(@project.name) | |
51 | - end | |
52 | - | |
53 | - private | |
54 | - | |
55 | - def create_project_content_mock | |
56 | - @project_content = mock | |
57 | - @project_content.expects(:name).returns(@project.name) | |
58 | - @project_content.expects(:license).returns(@project.license) | |
59 | - @project_content.expects(:description).returns(@project.description) | |
60 | - @project_content.expects(:repository_type).returns(@project.repository.type) | |
61 | - @project_content.expects(:repository_url).returns(@project.repository.address) | |
62 | - @project_content.expects(:configuration_name).returns(@project.configuration_name) | |
53 | + should 'initialize new project from hash' do | |
54 | + project = Kalibro::Project.new @hash | |
55 | + assert_equal @project.name, project.name | |
56 | + assert_equal @project.repository.type, project.repository.type | |
63 | 57 | end |
64 | 58 | |
65 | - should 'create project from hash' do | |
66 | - assert_equal @project, Kalibro::Project.new(@hash) | |
59 | + should 'create project' do | |
60 | + project = Kalibro::Project.create @project_content | |
61 | + assert_equal @project.name, project.name | |
62 | + assert_equal @project.repository.type, project.repository.type | |
67 | 63 | end |
68 | 64 | |
69 | 65 | should 'convert project to hash' do |
70 | - assert_equal @hash, @project.to_hash | |
66 | + hash = @project.to_hash | |
67 | + assert_equal @hash[:name], hash[:name] | |
68 | + assert_equal @hash[:configuration_name], hash[:configuration_name] | |
69 | + assert_equal @hash[:repository], hash[:repository] | |
70 | + assert_equal @hash[:state], hash[:state] | |
71 | 71 | end |
72 | -=end | |
72 | + | |
73 | 73 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/repository_test.rb
... | ... | @@ -5,8 +5,8 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" |
5 | 5 | class RepositoryTest < ActiveSupport::TestCase |
6 | 6 | |
7 | 7 | def setup |
8 | - @hash = RepositoryFixtures.qt_calculator_hash | |
9 | - @repository = RepositoryFixtures.qt_calculator | |
8 | + @hash = RepositoryFixtures.repository_hash | |
9 | + @repository = RepositoryFixtures.repository | |
10 | 10 | end |
11 | 11 | |
12 | 12 | should 'new repository from hash' do | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
... | ... | @@ -6,15 +6,8 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" |
6 | 6 | class ProjectContentTest < ActiveSupport::TestCase |
7 | 7 | |
8 | 8 | def setup |
9 | - @project = ProjectFixtures.qt_calculator | |
10 | - @content = MezuroPlugin::ProjectContent.new | |
11 | - @content.name = @project.name | |
12 | - @content.license = @project.license | |
13 | - @content.description = @project.description | |
14 | - @content.repository_type = @project.repository.type | |
15 | - @content.repository_url = @project.repository.address | |
16 | - @content.configuration_name = @project.configuration_name | |
17 | - @content.periodicity_in_days = 1 | |
9 | + @project = ProjectFixtures.project | |
10 | + @content = ProjectFixtures.project_content | |
18 | 11 | end |
19 | 12 | |
20 | 13 | should 'be an article' do |
... | ... | @@ -34,7 +27,7 @@ class ProjectContentTest < ActiveSupport::TestCase |
34 | 27 | end |
35 | 28 | |
36 | 29 | should 'get project from service' do |
37 | - Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) | |
30 | + Kalibro::Project.expects(:find_by_name).with(@content.name).returns(@project) | |
38 | 31 | assert_equal @project, @content.project |
39 | 32 | end |
40 | 33 | |
... | ... | @@ -100,20 +93,20 @@ returns(module_result) |
100 | 93 | end |
101 | 94 | |
102 | 95 | should 'send correct project to service' do |
103 | - Kalibro::Client::ProjectClient.expects(:save).with(@content) | |
96 | + project = mock | |
97 | + Kalibro::Project.expects(:create).with(@content).returns(project) | |
98 | + project.expects(:save).returns(true) | |
104 | 99 | Kalibro::Client::KalibroClient.expects(:process_project).with(@content.name, @content.periodicity_in_days) |
105 | 100 | @content.send :send_project_to_service |
106 | 101 | end |
107 | 102 | |
108 | - should 'remove project from service' do | |
109 | - Kalibro::Client::ProjectClient.expects(:remove).with(@content.name) | |
110 | - @content.send :remove_project_from_service | |
103 | + should 'destroy project from service' do | |
104 | + Kalibro::Project.expects(:destroy).with(@content.name) | |
105 | + @content.send :destroy_project_from_service | |
111 | 106 | end |
112 | 107 | |
113 | 108 | should 'not save a project with an existing project name in kalibro' do |
114 | - client = mock | |
115 | - Kalibro::Client::ProjectClient.expects(:new).returns(client) | |
116 | - client.expects(:project_names).returns([@content.name]) | |
109 | + Kalibro::Project.expects(:all_names).returns([@content.name]) | |
117 | 110 | @content.send :validate_kalibro_project_name |
118 | 111 | assert_equal "Project name already exists in Kalibro", @content.errors.on_base |
119 | 112 | end |
... | ... | @@ -121,7 +114,7 @@ returns(module_result) |
121 | 114 | private |
122 | 115 | |
123 | 116 | def mock_project_client |
124 | - Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) | |
117 | + Kalibro::Project.expects(:find_by_name).with(@content.name).returns(@project) | |
125 | 118 | end |
126 | 119 | |
127 | 120 | def mock_project_result_client | ... | ... |