Commit b3bcb7b1a3cf73facb74f5c94bdda08e18af6308
1 parent
7b8853af
Exists in
master
and in
23 other branches
[Mezuro] Refactoring controller
Showing
2 changed files
with
19 additions
and
39 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
... | ... | @@ -8,8 +8,10 @@ class MezuroPluginProfileController < ProfileController |
8 | 8 | render :partial => 'content_viewer/module_result', :locals => { :module_result => module_result} |
9 | 9 | end |
10 | 10 | |
11 | - def autoreload | |
12 | - @project_content = profile.articles.find(params[:id]) | |
13 | - render :partial => 'content_viewer/autoreload' | |
11 | + def project_result | |
12 | + project_content = profile.articles.find(params[:id]) | |
13 | + project_result = project_content.project_result | |
14 | + render :partial => 'content_viewer/project_result', :locals => { :project_result => project_result } | |
14 | 15 | end |
16 | + | |
15 | 17 | end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
1 | 1 | require 'test_helper' |
2 | 2 | |
3 | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" |
4 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | |
5 | 4 | |
6 | 5 | class MezuroPluginProfileControllerTest < ActionController::TestCase |
7 | 6 | |
... | ... | @@ -10,49 +9,28 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase |
10 | 9 | @request = ActionController::TestRequest.new |
11 | 10 | @response = ActionController::TestResponse.new |
12 | 11 | @profile = fast_create(Community) |
13 | - @profile_id = @profile.identifier | |
14 | - | |
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 | |
20 | - | |
21 | - def test_metrics_for_unknown_project | |
22 | - get :metrics, :profile => @profile_id | |
23 | - assert_response 404 | |
24 | 12 | end |
25 | 13 | |
26 | - def test_metric_unknown_module | |
27 | - get :metrics, :profile => @profile_id, :id => @project_content.id, :module_name => 'veryunlikelyname' | |
14 | + should 'not find module result for inexistent project content' do | |
15 | + get :module_result, :profile => @profile.id, :id => -1, :module_name => '' | |
28 | 16 | assert_response 404 |
29 | 17 | end |
30 | 18 | |
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 | |
19 | + should 'get metric results for a module' do | |
20 | + create_project_content | |
21 | + get :module_result, :profile => @profile.id, :id => @project_content.id, :module_name => @module_name | |
38 | 22 | assert_response 200 |
39 | - # assert_tag # TODO | |
40 | 23 | end |
41 | 24 | |
42 | - protected | |
43 | - | |
44 | - # returns a new ProjectContent for the given profile | |
45 | - def create_project_content(profile) | |
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 | |
25 | + private | |
50 | 26 | |
51 | - MezuroPlugin::ProjectContent.any_instance.stubs(:project_content).returns(project_content) | |
52 | - project_content | |
27 | + def create_project_content | |
28 | + @module_result = ModuleResultFixtures.create | |
29 | + @module_name = @module_result.module.name | |
30 | + @project_content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @module_name) | |
31 | + @project_content.expects(:send_project_to_service).returns(nil) | |
32 | + @project_content.expects(:module_result).with(@module_name).returns(@module_result) | |
33 | + @project_content.save | |
53 | 34 | end |
54 | - | |
55 | - #TODO Adicionar module result manualmente | |
56 | - #TODO Ver testes do project content, refatorar o project content em cima dos testes | |
57 | - #TODO Repensar design OO: nao amarrar o project_content ao webservice. Criar um modelo abstrato do webservice | |
35 | + | |
58 | 36 | end | ... | ... |