Commit 6e215742ed1bc7fae681a00d0e6001d8c682d746
1 parent
7960d5d0
Exists in
master
and in
28 other branches
[Mezuro] Controller.project_state returns error state
Showing
2 changed files
with
30 additions
and
19 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
| ... | ... | @@ -3,21 +3,22 @@ class MezuroPluginProfileController < ProfileController |
| 3 | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../views') |
| 4 | 4 | |
| 5 | 5 | def module_result |
| 6 | - project_content = profile.articles.find(params[:id]) | |
| 7 | - module_result = project_content.module_result(params[:module_name]) | |
| 6 | + content = profile.articles.find(params[:id]) | |
| 7 | + module_result = content.module_result(params[:module_name]) | |
| 8 | 8 | render :partial => 'content_viewer/module_result', :locals => { :module_result => module_result} |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def project_result |
| 12 | - project_content = profile.articles.find(params[:id]) | |
| 13 | - project_result = project_content.project_result | |
| 12 | + content = profile.articles.find(params[:id]) | |
| 13 | + project_result = content.project_result | |
| 14 | 14 | render :partial => 'content_viewer/project_result', :locals => { :project_result => project_result } |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 17 | def project_state |
| 18 | - project_content = profile.articles.find(params[:id]) | |
| 19 | - project_content.project.state | |
| 20 | - render :text => "READY" | |
| 18 | + content = profile.articles.find(params[:id]) | |
| 19 | + project = content.project | |
| 20 | + state = project.error.nil? ? project.state : "ERROR" | |
| 21 | + render :text => state | |
| 21 | 22 | end |
| 22 | 23 | |
| 23 | 24 | end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
| ... | ... | @@ -11,9 +11,10 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase |
| 11 | 11 | @response = ActionController::TestResponse.new |
| 12 | 12 | @profile = fast_create(Community) |
| 13 | 13 | |
| 14 | - @module_result = ModuleResultFixtures.create | |
| 15 | - @module_name = @module_result.module.name | |
| 16 | 14 | @project_result = ProjectResultFixtures.qt_calculator |
| 15 | + @module_result = ModuleResultFixtures.create | |
| 16 | + @project = @project_result.project | |
| 17 | + @name = @project.name | |
| 17 | 18 | end |
| 18 | 19 | |
| 19 | 20 | should 'not find module result for inexistent project content' do |
| ... | ... | @@ -23,34 +24,43 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase |
| 23 | 24 | |
| 24 | 25 | should 'get metric results for a module' do |
| 25 | 26 | create_project_content |
| 26 | - Kalibro::Client::ModuleResultClient.expects(:module_result).with(@project_content, @module_name).returns(@module_result) | |
| 27 | - get :module_result, :profile => @profile.identifier, :id => @project_content.id, :module_name => @module_name | |
| 27 | + Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @name).returns(@module_result) | |
| 28 | + get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name | |
| 28 | 29 | assert_response 200 |
| 29 | 30 | assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') |
| 30 | 31 | end |
| 31 | 32 | |
| 32 | 33 | should 'get project results' do |
| 33 | 34 | create_project_content |
| 34 | - Kalibro::Client::ProjectResultClient.expects(:last_result).with(@project_content.name).returns(@project_result) | |
| 35 | - get :project_result, :profile => @profile.identifier, :id => @project_content.id | |
| 35 | + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | |
| 36 | + get :project_result, :profile => @profile.identifier, :id => @content.id | |
| 36 | 37 | assert_response 200 |
| 37 | 38 | assert_select('h3', 'LAST RESULT') |
| 38 | 39 | end |
| 39 | 40 | |
| 40 | 41 | should 'get project state' do |
| 41 | 42 | create_project_content |
| 42 | - Kalibro::Client::ProjectClient.expects(:project).with(@project_content.name).returns(@project_result.project) | |
| 43 | - get :project_state, :profile => @profile.identifier, :id => @project_content.id | |
| 43 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | |
| 44 | + get :project_state, :profile => @profile.identifier, :id => @content.id | |
| 45 | + assert_response 200 | |
| 46 | + assert_equal @project.state, @response.body | |
| 47 | + end | |
| 48 | + | |
| 49 | + should 'get error state if project has error' do | |
| 50 | + create_project_content | |
| 51 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | |
| 52 | + @project.expects(:error).returns("") | |
| 53 | + get :project_state, :profile => @profile.identifier, :id => @content.id | |
| 44 | 54 | assert_response 200 |
| 45 | - assert_equal "READY", @response.body | |
| 55 | + assert_equal "ERROR", @response.body | |
| 46 | 56 | end |
| 47 | 57 | |
| 48 | 58 | private |
| 49 | 59 | |
| 50 | 60 | def create_project_content |
| 51 | - @project_content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @module_name) | |
| 52 | - @project_content.expects(:send_project_to_service).returns(nil) | |
| 53 | - @project_content.save | |
| 61 | + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @name) | |
| 62 | + @content.expects(:send_project_to_service).returns(nil) | |
| 63 | + @content.save | |
| 54 | 64 | end |
| 55 | 65 | |
| 56 | 66 | end | ... | ... |