Commit 0f1414acc8043de1998162ecf65d7cabc99f2d6e

Authored by Carlos Morais
2 parents 625f9880 efe7e543

Merge branch 'functional-tests' into ajax-autoload

Conflicts:
	plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
	plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
	plugins/mezuro/test/fixtures/error_fixtures.rb
	plugins/mezuro/test/fixtures/metric_result_fixtures.rb
	plugins/mezuro/test/fixtures/module_result_fixtures.rb
	plugins/mezuro/test/fixtures/project_fixtures.rb
	plugins/mezuro/test/fixtures/project_result_fixtures.rb
	plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
	plugins/mezuro/test/mezuro_test.rb
	plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
	plugins/mezuro/test/unit/kalibro/client/project_result_client_test.rb
	plugins/mezuro/views/content_viewer/show_project.rhtml
plugins/mezuro/lib/kalibro/client/module_result_client.rb
1 1 class Kalibro::Client::ModuleResultClient
  2 +
  3 + # TODO test this
  4 + def self.module_result(project_content, module_name)
  5 + project_result = project_content.project_result
  6 + new.module_result(project_result.project.name, module_name, project_result.date)
  7 + end
2 8  
3 9 def initialize
4 10 @port = Kalibro::Client::Port.new('ModuleResult')
... ...
plugins/mezuro/lib/kalibro/client/project_client.rb
1 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 + instance = new
  14 + if (instance.project_names.include?(project_name))
  15 + instance.remove(project_name)
  16 + end
  17 + end
  18 +
  19 + def self.create_project (project_content)
  20 + project = Kalibro::Entities::Project.new
  21 + project.name = project_content.name
  22 + project.license = project_content.license
  23 + project.description = project_content.description
  24 + project.repository = create_repository(project_content)
  25 + project.configuration_name = project_content.configuration_name
  26 + project
  27 + end
  28 +
  29 + def self.create_repository(project_content)
  30 + repository = Kalibro::Entities::Repository.new
  31 + repository.type = project_content.repository_type
  32 + repository.address = project_content.repository_url
  33 + repository
  34 + end
  35 +
3 36 def initialize
4 37 @port = Kalibro::Client::Port.new('Project')
5 38 end
... ... @@ -8,16 +41,12 @@ class Kalibro::Client::ProjectClient
8 41 @port.request(:save_project, {:project => project.to_hash})
9 42 end
10 43  
11   - def self.save(project)
12   - new.save(project)
13   - end
14   -
15 44 def project_names
16 45 @port.request(:get_project_names)[:project_name].to_a
17 46 end
18 47  
19   - def project(name)
20   - hash = @port.request(:get_project, {:project_name => name})[:project]
  48 + def project(project_name)
  49 + hash = @port.request(:get_project, {:project_name => project_name})[:project]
21 50 Kalibro::Entities::Project.from_hash(hash)
22 51 end
23 52  
... ... @@ -25,7 +54,4 @@ class Kalibro::Client::ProjectClient
25 54 @port.request(:remove_project, {:project_name => project_name})
26 55 end
27 56  
28   - def self.remove(project_name)
29   - new.remove(project_name)
30   - end
31 57 end
... ...
plugins/mezuro/lib/kalibro/client/project_result_client.rb
1 1 class Kalibro::Client::ProjectResultClient
2 2  
  3 + # TODO test this
  4 + def self.last_result(project_name)
  5 + new.last_result(project_name)
  6 + end
  7 +
3 8 def initialize
4 9 @port = Kalibro::Client::Port.new('ProjectResult')
5 10 end
... ...
plugins/mezuro/lib/mezuro_plugin/project_content.rb
... ... @@ -17,18 +17,17 @@ class MezuroPlugin::ProjectContent < Article
17 17 end
18 18 end
19 19  
20   - # FIXME is this really needed?
  20 + # From ProjectClient
21 21 def project
22   - Kalibro::Client::ProjectClient.new.project(title)
  22 + @project ||= Kalibro::Client::ProjectClient.project(name)
23 23 end
24 24  
25 25 def project_result
26   - @project_result ||= Kalibro::Client::ProjectResultClient.new.last_result(title)
  26 + @project_result ||= Kalibro::Client::ProjectResultClient.last_result(name)
27 27 end
28 28  
29 29 def module_result(module_name)
30   - @module_client ||= Kalibro::Client::ModuleResultClient.new
31   - @module_client.module_result(title, module_name, project_result.date)
  30 + @module_client ||= Kalibro::Client::ModuleResultClient.module_result(self, module_name)
32 31 end
33 32  
34 33 after_save :send_project_to_service
... ... @@ -37,29 +36,12 @@ class MezuroPlugin::ProjectContent < Article
37 36 private
38 37  
39 38 def send_project_to_service
40   - Kalibro::Client::ProjectClient.save(create_project)
41   - Kalibro::Client::KalibroClient.process_project(title)
  39 + Kalibro::Client::ProjectClient.save(self)
  40 + Kalibro::Client::KalibroClient.process_project(name)
42 41 end
43 42  
44 43 def remove_project_from_service
45   - Kalibro::Client::ProjectClient.remove(title)
46   - end
47   -
48   - def create_project
49   - project = Kalibro::Entities::Project.new
50   - project.name = title
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
  44 + Kalibro::Client::ProjectClient.remove(name)
63 45 end
64 46  
65 47 end
... ...
plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
  1 +require File.dirname(__FILE__) + '/error_fixtures'
  2 +
1 3 class CompoundMetricWithErrorFixtures
2 4  
3 5 def self.create
... ...
plugins/mezuro/test/fixtures/error_fixtures.rb
  1 +require File.dirname(__FILE__) + '/stack_trace_element_fixtures'
  2 +
1 3 class ErrorFixtures
2 4  
3 5 def self.create
... ...
plugins/mezuro/test/fixtures/metric_result_fixtures.rb
  1 +require File.dirname(__FILE__) + '/compound_metric_fixtures'
  2 +require File.dirname(__FILE__) + '/native_metric_fixtures'
  3 +require File.dirname(__FILE__) + '/range_fixtures'
  4 +
1 5 class MetricResultFixtures
2 6  
3 7 def self.amloc_result
... ...
plugins/mezuro/test/fixtures/module_result_fixtures.rb
  1 +require File.dirname(__FILE__) + '/module_fixtures'
  2 +require File.dirname(__FILE__) + '/metric_result_fixtures'
  3 +require File.dirname(__FILE__) + '/compound_metric_with_error_fixtures'
  4 +
1 5 class ModuleResultFixtures
2 6  
3 7 def self.create
... ...
plugins/mezuro/test/fixtures/project_fixtures.rb
  1 +require File.dirname(__FILE__) + '/repository_fixtures'
  2 +
1 3 class ProjectFixtures
2 4  
3 5 def self.qt_calculator
... ...
plugins/mezuro/test/fixtures/project_result_fixtures.rb
  1 +require File.dirname(__FILE__) + '/project_fixtures'
  2 +require File.dirname(__FILE__) + '/module_node_fixtures'
  3 +require File.dirname(__FILE__) + '/module_result_fixtures'
  4 +
1 5 class ProjectResultFixtures
2 6  
3 7 def self.qt_calculator
... ...
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
1 1 require 'test_helper'
2 2  
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
  5 +
3 6 class MezuroPluginProfileControllerTest < ActionController::TestCase
4 7  
5 8 def setup
... ... @@ -8,59 +11,46 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
8 11 @response = ActionController::TestResponse.new
9 12 @profile = fast_create(Community)
10 13 @profile_id = @profile.identifier
11   - end
12 14  
13   -# def test_metrics_for_unknown_module
14   -# get :metrics, :profile => @profile_id, :id => 0
15   -# assert_response 404
16   -# end
  15 + @module_result = ModuleResultFixtures.create
  16 + @project_result = ProjectResultFixtures.qt_calculator
  17 + @project = @project_result.project
  18 + @project_content = create_project_content(@profile)
  19 + end
17 20  
18   -# def test_metric_unknown_module
19   -# get :metrics, :profile => @profile_id, :id => @project_content.id, :module_name => 'veryunlikelyname'
20   -# assert_response 404
21   -# end
  21 + def test_metrics_for_unknown_project
  22 + get :metrics, :profile => @profile_id
  23 + assert_response 404
  24 + end
22 25  
  26 + def test_metric_unknown_module
  27 + get :metrics, :profile => @profile_id, :id => @project_content.id, :module_name => 'veryunlikelyname'
  28 + assert_response 404
  29 + end
23 30  
24   -# def test_metrics_for_known_module
25   -# @project_content = create_project_content(@profile)
26   -# get :metrics, :profile => @profile_id, :id => @project_content.id, :module_name => @project_content.name
27   -# assert_response 200
28   -# # assert_tag # TODO
29   -# end
  31 + should 'get metrics from a known module' do
  32 + project_name = @project_content.name
  33 + module_name = project_name
  34 + Kalibro::Client::ProjectResultClient.expects(:last_result).with(project_name).returns(@project_result)
  35 + Kalibro::Client::ModuleResultClient.expects(:module_result).with(@project_content, module_name).
  36 + returns(@module_result)
  37 + get :metrics, :profile => @profile_id, :id => @project_content.id, :module_name => module_name
  38 + assert_response 200
  39 + # assert_tag # TODO
  40 + end
30 41  
31 42 protected
32 43  
33 44 # returns a new ProjectContent for the given profile
34 45 def create_project_content(profile)
35   - project_content = MezuroPlugin::ProjectContent.create!(:profile => profile, :name => 'foo')
36   -
37   - project = create_project(project_content.name)
38   - project_content.license = project.license
39   - project_content.description = project.description
40   - project_content.repository_type = project.repository.type
41   - project_content.repository_url = project.repository.address
42   - project_content.configuration_name = project.configuration_name
  46 + project_content = MezuroPlugin::ProjectContent.new(:profile => profile, :name => @project.name)
  47 + Kalibro::Client::ProjectClient.expects(:save).with(project_content)
  48 + Kalibro::Client::KalibroClient.expects(:process_project).with(project_content.name)
  49 + project_content.save
43 50  
44 51 MezuroPlugin::ProjectContent.any_instance.stubs(:project_content).returns(project_content)
45 52 project_content
46 53 end
47   -
48   - def create_project(name)
49   - project = Kalibro::Entities::Project.new
50   - project.name = name
51   - project.license = 'GPL'
52   - project.description = 'testing'
53   - project.repository = crieate_repository
54   - project.configuration_name = 'Kalibro Default'
55   - project
56   - end
57   -
58   - def create_repository
59   - repository = Kalibro::Entities::Repository.new
60   - repository.type = 'git'
61   - repository.address = 'http://git.git'
62   - repository
63   - end
64 54  
65 55 #TODO Adicionar module result manualmente
66 56 #TODO Ver testes do project content, refatorar o project content em cima dos testes
... ...
plugins/mezuro/test/mezuro_test.rb
... ... @@ -1,12 +0,0 @@
1   -require "test_helper"
2   -
3   -require File.dirname(__FILE__) + '/../controllers/mezuro_plugin_myprofile_controller'
4   -
5   -class MezuroTest < ActiveSupport::TestCase
6   -
7   - should 'create a mezuro project' do
8   - controller = MezuroPluginMyprofileController.new
9   - controller.create
10   - end
11   -
12   -end
plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
... ... @@ -7,52 +7,45 @@ class ProjectClientTest &lt; ActiveSupport::TestCase
7 7 def setup
8 8 @port = mock
9 9 Kalibro::Client::Port.expects(:new).with('Project').returns(@port)
10   - @client = Kalibro::Client::ProjectClient.new
  10 + @project = ProjectFixtures.qt_calculator
11 11 end
12 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
  13 + should 'get project by name' do
  14 + request_body = {:project_name => @project.name}
  15 + response_hash = {:project => @project.to_hash}
  16 + @port.expects(:request).with(:get_project, request_body).returns(response_hash)
  17 + assert_equal @project, Kalibro::Client::ProjectClient.project(@project.name)
22 18 end
23 19  
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
  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)
28 25 end
29 26  
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
  27 + should 'remove existent project from service' do
  28 + @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name})
  29 + @port.expects(:request).with(:remove_project, {:project_name => @project.name})
  30 + Kalibro::Client::ProjectClient.remove(@project.name)
34 31 end
35 32  
36   - 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}
40   - @port.expects(:request).with(:get_project, request_body).returns(response_hash)
41   - assert_equal project, @client.project(project.name)
  33 + should 'not try to remove inexistent project from service' do
  34 + @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'})
  35 + @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never
  36 + Kalibro::Client::ProjectClient.remove(@project.name)
42 37 end
43 38  
44   - should 'remove project by name' do
45   - name = 'ProjectClientTest'
46   - @port.expects(:request).with(:remove_project, {:project_name => name})
47   - @client.remove(name)
48   - end
  39 + private
49 40  
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)
  41 + def create_project_content_mock
  42 + @project_content = mock
  43 + @project_content.expects(:name).returns(@project.name)
  44 + @project_content.expects(:license).returns(@project.license)
  45 + @project_content.expects(:description).returns(@project.description)
  46 + @project_content.expects(:repository_type).returns(@project.repository.type)
  47 + @project_content.expects(:repository_url).returns(@project.repository.address)
  48 + @project_content.expects(:configuration_name).returns(@project.configuration_name)
56 49 end
57 50  
58 51 end
... ...
plugins/mezuro/test/unit/kalibro/client/project_result_client_test.rb
1 1 require "test_helper"
2 2  
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
4 4  
5 5 class ProjectResultClientTest < ActiveSupport::TestCase
6 6  
... ...
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
... ... @@ -31,13 +31,32 @@ class ProjectContentTest &lt; ActiveSupport::TestCase
31 31 assert_not_nil @content.to_html
32 32 end
33 33  
  34 + should 'get project from service' do
  35 + Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project)
  36 + assert_equal @project, @content.project
  37 + end
  38 +
  39 + should 'get project result from service' do
  40 + project_result = mock
  41 + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@content.name).returns(project_result)
  42 + assert_equal project_result, @content.project_result
  43 + end
  44 +
  45 + should 'get module result from service' do
  46 + module_name = 'My module name'
  47 + module_result = mock
  48 + Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, module_name).
  49 + returns(module_result)
  50 + assert_equal module_result, @content.module_result(module_name)
  51 + end
  52 +
34 53 should 'run send project to service on after_save callback' do
35 54 @content.expects :send_project_to_service
36 55 @content.run_callbacks :after_save
37 56 end
38 57  
39 58 should 'send correct project to service' do
40   - Kalibro::Client::ProjectClient.expects(:save).with(@project)
  59 + Kalibro::Client::ProjectClient.expects(:save).with(@content)
41 60 Kalibro::Client::KalibroClient.expects(:process_project).with(@project.name)
42 61 @content.send :send_project_to_service
43 62 end
... ...
plugins/mezuro/views/content_viewer/show_project.rhtml
1   -<% @project_content = @page
  1 +<% @project_content = @page
2 2 @project = @project_content.project %>
3 3  
4 4 <table id="project_info">
... ... @@ -35,4 +35,4 @@
35 35  
36 36 <script type="text/javascript">
37 37 jQuery(show_autoreload);
38   -</script>
39 38 \ No newline at end of file
  39 +</script>
... ...