Commit 2058c115cbd25bfbf1cd4d18ba98fe3919f6470e
Committed by
Carlos Morais
1 parent
f3edd5ca
Exists in
master
and in
28 other branches
[Mezuro] Refactoring ProjectClient, ProjectContent
Showing
5 changed files
with
61 additions
and
67 deletions
Show diff stats
plugins/mezuro/lib/kalibro/client/project_client.rb
| 1 | class Kalibro::Client::ProjectClient | 1 | class Kalibro::Client::ProjectClient |
| 2 | 2 | ||
| 3 | + def self.project(project_name) | ||
| 4 | + new.project(project_name) | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def self.save(project_content) | ||
| 8 | + project = create_project(project_content) | ||
| 9 | + new.save(project) | ||
| 10 | + end | ||
| 11 | + | ||
| 12 | + def self.remove(project_name) | ||
| 13 | + new.remove(project_name) | ||
| 14 | + end | ||
| 15 | + | ||
| 16 | + def self.create_project (project_content) | ||
| 17 | + project = Kalibro::Entities::Project.new | ||
| 18 | + project.name = project_content.name | ||
| 19 | + project.license = project_content.license | ||
| 20 | + project.description = project_content.description | ||
| 21 | + project.repository = create_repository(project_content) | ||
| 22 | + project.configuration_name = project_content.configuration_name | ||
| 23 | + project | ||
| 24 | + end | ||
| 25 | + | ||
| 26 | + def self.create_repository(project_content) | ||
| 27 | + repository = Kalibro::Entities::Repository.new | ||
| 28 | + repository.type = project_content.repository_type | ||
| 29 | + repository.address = project_content.repository_url | ||
| 30 | + repository | ||
| 31 | + end | ||
| 32 | + | ||
| 3 | def initialize | 33 | def initialize |
| 4 | @port = Kalibro::Client::Port.new('Project') | 34 | @port = Kalibro::Client::Port.new('Project') |
| 5 | end | 35 | end |
| @@ -8,16 +38,12 @@ class Kalibro::Client::ProjectClient | @@ -8,16 +38,12 @@ class Kalibro::Client::ProjectClient | ||
| 8 | @port.request(:save_project, {:project => project.to_hash}) | 38 | @port.request(:save_project, {:project => project.to_hash}) |
| 9 | end | 39 | end |
| 10 | 40 | ||
| 11 | - def self.save(project) | ||
| 12 | - new.save(project) | ||
| 13 | - end | ||
| 14 | - | ||
| 15 | def project_names | 41 | def project_names |
| 16 | @port.request(:get_project_names)[:project_name].to_a | 42 | @port.request(:get_project_names)[:project_name].to_a |
| 17 | end | 43 | end |
| 18 | 44 | ||
| 19 | - def project(name) | ||
| 20 | - hash = @port.request(:get_project, {:project_name => name})[:project] | 45 | + def project(project_name) |
| 46 | + hash = @port.request(:get_project, {:project_name => project_name})[:project] | ||
| 21 | Kalibro::Entities::Project.from_hash(hash) | 47 | Kalibro::Entities::Project.from_hash(hash) |
| 22 | end | 48 | end |
| 23 | 49 | ||
| @@ -25,7 +51,4 @@ class Kalibro::Client::ProjectClient | @@ -25,7 +51,4 @@ class Kalibro::Client::ProjectClient | ||
| 25 | @port.request(:remove_project, {:project_name => project_name}) | 51 | @port.request(:remove_project, {:project_name => project_name}) |
| 26 | end | 52 | end |
| 27 | 53 | ||
| 28 | - def self.remove(project_name) | ||
| 29 | - new.remove(project_name) | ||
| 30 | - end | ||
| 31 | end | 54 | end |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| @@ -17,9 +17,9 @@ class MezuroPlugin::ProjectContent < Article | @@ -17,9 +17,9 @@ class MezuroPlugin::ProjectContent < Article | ||
| 17 | end | 17 | end |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | - # FIXME is this really needed? | 20 | + # From ProjectClient |
| 21 | def project | 21 | def project |
| 22 | - Kalibro::Client::ProjectClient.new.project(name) | 22 | + Kalibro::Client::ProjectClient.project(name) |
| 23 | end | 23 | end |
| 24 | 24 | ||
| 25 | def project_result | 25 | def project_result |
| @@ -37,7 +37,7 @@ class MezuroPlugin::ProjectContent < Article | @@ -37,7 +37,7 @@ class MezuroPlugin::ProjectContent < Article | ||
| 37 | private | 37 | private |
| 38 | 38 | ||
| 39 | def send_project_to_service | 39 | def send_project_to_service |
| 40 | - Kalibro::Client::ProjectClient.save(create_project) | 40 | + Kalibro::Client::ProjectClient.save(self) |
| 41 | Kalibro::Client::KalibroClient.process_project(name) | 41 | Kalibro::Client::KalibroClient.process_project(name) |
| 42 | end | 42 | end |
| 43 | 43 | ||
| @@ -45,22 +45,5 @@ class MezuroPlugin::ProjectContent < Article | @@ -45,22 +45,5 @@ class MezuroPlugin::ProjectContent < Article | ||
| 45 | Kalibro::Client::ProjectClient.remove(name) | 45 | Kalibro::Client::ProjectClient.remove(name) |
| 46 | end | 46 | end |
| 47 | 47 | ||
| 48 | - def create_project | ||
| 49 | - project = Kalibro::Entities::Project.new | ||
| 50 | - project.name = name | ||
| 51 | - project.license = license | ||
| 52 | - project.description = description | ||
| 53 | - project.repository = create_repository | ||
| 54 | - project.configuration_name = configuration_name | ||
| 55 | - project | ||
| 56 | - end | ||
| 57 | - | ||
| 58 | - def create_repository | ||
| 59 | - repository = Kalibro::Entities::Repository.new | ||
| 60 | - repository.type = repository_type | ||
| 61 | - repository.address = repository_url | ||
| 62 | - repository | ||
| 63 | - end | ||
| 64 | - | ||
| 65 | end | 48 | end |
| 66 | 49 |
plugins/mezuro/test/fixtures/project_fixtures.rb
plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
| @@ -7,52 +7,38 @@ class ProjectClientTest < ActiveSupport::TestCase | @@ -7,52 +7,38 @@ class ProjectClientTest < ActiveSupport::TestCase | ||
| 7 | def setup | 7 | def setup |
| 8 | @port = mock | 8 | @port = mock |
| 9 | Kalibro::Client::Port.expects(:new).with('Project').returns(@port) | 9 | Kalibro::Client::Port.expects(:new).with('Project').returns(@port) |
| 10 | - @client = Kalibro::Client::ProjectClient.new | ||
| 11 | - end | ||
| 12 | - | ||
| 13 | - should 'save project' do | ||
| 14 | - project = ProjectFixtures.qt_calculator | ||
| 15 | - @port.expects(:request).with(:save_project, {:project => project.to_hash}) | ||
| 16 | - @client.save(project) | ||
| 17 | - end | ||
| 18 | - | ||
| 19 | - should 'get project names (zero)' do | ||
| 20 | - @port.expects(:request).with(:get_project_names).returns({}) | ||
| 21 | - assert_equal [], @client.project_names | ||
| 22 | - end | ||
| 23 | - | ||
| 24 | - should 'get project names (one)' do | ||
| 25 | - name = 'Qt-Calculator' | ||
| 26 | - @port.expects(:request).with(:get_project_names).returns({:project_name => name}) | ||
| 27 | - assert_equal [name], @client.project_names | ||
| 28 | - end | ||
| 29 | - | ||
| 30 | - should 'get project names' do | ||
| 31 | - names = ['Hello World', 'Qt-Calculator'] | ||
| 32 | - @port.expects(:request).with(:get_project_names).returns({:project_name => names}) | ||
| 33 | - assert_equal names, @client.project_names | 10 | + @project = ProjectFixtures.qt_calculator |
| 34 | end | 11 | end |
| 35 | 12 | ||
| 36 | should 'get project by name' do | 13 | should 'get project by name' do |
| 37 | - project = ProjectFixtures.qt_calculator | ||
| 38 | - request_body = {:project_name => project.name} | ||
| 39 | - response_hash = {:project => project.to_hash} | 14 | + request_body = {:project_name => @project.name} |
| 15 | + response_hash = {:project => @project.to_hash} | ||
| 40 | @port.expects(:request).with(:get_project, request_body).returns(response_hash) | 16 | @port.expects(:request).with(:get_project, request_body).returns(response_hash) |
| 41 | - assert_equal project, @client.project(project.name) | 17 | + assert_equal @project, Kalibro::Client::ProjectClient.project(@project.name) |
| 18 | + end | ||
| 19 | + | ||
| 20 | + should 'save project' do | ||
| 21 | + create_project_content_mock | ||
| 22 | + @project.state = nil | ||
| 23 | + @port.expects(:request).with(:save_project, {:project => @project.to_hash}) | ||
| 24 | + Kalibro::Client::ProjectClient.save(@project_content) | ||
| 42 | end | 25 | end |
| 43 | 26 | ||
| 44 | should 'remove project by name' do | 27 | should 'remove project by name' do |
| 45 | - name = 'ProjectClientTest' | ||
| 46 | - @port.expects(:request).with(:remove_project, {:project_name => name}) | ||
| 47 | - @client.remove(name) | 28 | + @port.expects(:request).with(:remove_project, {:project_name => @project.name}) |
| 29 | + Kalibro::Client::ProjectClient.remove(@project.name) | ||
| 48 | end | 30 | end |
| 49 | 31 | ||
| 50 | - should 'instantiate for saving a project' do | ||
| 51 | - project = mock | ||
| 52 | - instance = mock | ||
| 53 | - Kalibro::Client::ProjectClient.expects(:new).returns(instance) | ||
| 54 | - instance.expects(:save).with(project) | ||
| 55 | - Kalibro::Client::ProjectClient.save(project) | 32 | + private |
| 33 | + | ||
| 34 | + def create_project_content_mock | ||
| 35 | + @project_content = mock | ||
| 36 | + @project_content.expects(:name).returns(@project.name) | ||
| 37 | + @project_content.expects(:license).returns(@project.license) | ||
| 38 | + @project_content.expects(:description).returns(@project.description) | ||
| 39 | + @project_content.expects(:repository_type).returns(@project.repository.type) | ||
| 40 | + @project_content.expects(:repository_url).returns(@project.repository.address) | ||
| 41 | + @project_content.expects(:configuration_name).returns(@project.configuration_name) | ||
| 56 | end | 42 | end |
| 57 | 43 | ||
| 58 | end | 44 | end |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
| @@ -37,7 +37,7 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -37,7 +37,7 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | should 'send correct project to service' do | 39 | should 'send correct project to service' do |
| 40 | - Kalibro::Client::ProjectClient.expects(:save).with(@project) | 40 | + Kalibro::Client::ProjectClient.expects(:save).with(@content) |
| 41 | Kalibro::Client::KalibroClient.expects(:process_project).with(@project.name) | 41 | Kalibro::Client::KalibroClient.expects(:process_project).with(@project.name) |
| 42 | @content.send :send_project_to_service | 42 | @content.send :send_project_to_service |
| 43 | end | 43 | end |