Commit f1d10294816a68a7f9f7e63997bad0d6c896aa35
Committed by
Paulo Meireles
1 parent
ed0bfc14
Exists in
master
and in
29 other branches
[Mezuro] refactored module_result action in my_profile controller.
Showing
3 changed files
with
23 additions
and
8 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
| @@ -24,9 +24,7 @@ class MezuroPluginProfileController < ProfileController | @@ -24,9 +24,7 @@ class MezuroPluginProfileController < ProfileController | ||
| 24 | 24 | ||
| 25 | def module_result | 25 | def module_result |
| 26 | @content = profile.articles.find(params[:id]) | 26 | @content = profile.articles.find(params[:id]) |
| 27 | - date = params[:date] | ||
| 28 | - date.nil? ? @content.project_result : @content.project_result_with_date(date) | ||
| 29 | - @module_result = @content.module_result(params[:module_name]) | 27 | + @module_result = @content.module_result(params) |
| 30 | render :partial => 'content_viewer/module_result' | 28 | render :partial => 'content_viewer/module_result' |
| 31 | end | 29 | end |
| 32 | 30 |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| @@ -45,9 +45,10 @@ Kalibro::ProjectResult.first_result_after(name, date) | @@ -45,9 +45,10 @@ Kalibro::ProjectResult.first_result_after(name, date) | ||
| 45 | end | 45 | end |
| 46 | end | 46 | end |
| 47 | 47 | ||
| 48 | - def module_result(module_name) | ||
| 49 | - module_name ||= project.name | ||
| 50 | - @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(project.name, module_name, project_result.date) | 48 | + def module_result(attributes) |
| 49 | + module_name = attributes[:module_name].nil? ? project.name : attributes[:module_name] | ||
| 50 | + date = attributes[:date].nil? ? project_result.date : project_result_with_date(attributes[:date]).date | ||
| 51 | + @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(project.name, module_name, date) | ||
| 51 | end | 52 | end |
| 52 | 53 | ||
| 53 | def result_history(module_name) | 54 | def result_history(module_name) |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
| @@ -51,7 +51,7 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -51,7 +51,7 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 51 | assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time | 51 | assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | - should 'get module result from service' do | 54 | + should 'get module result from service without date' do |
| 55 | date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | 55 | date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) |
| 56 | Kalibro::ProjectResult.expects(:request).with('ProjectResult', :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | 56 | Kalibro::ProjectResult.expects(:request).with('ProjectResult', :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) |
| 57 | Kalibro::ModuleResult.expects(:request).with( | 57 | Kalibro::ModuleResult.expects(:request).with( |
| @@ -62,7 +62,23 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -62,7 +62,23 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 62 | :module_name => @module.name, | 62 | :module_name => @module.name, |
| 63 | :date => date_with_milliseconds | 63 | :date => date_with_milliseconds |
| 64 | }).returns({:module_result => @module_result.to_hash}) | 64 | }).returns({:module_result => @module_result.to_hash}) |
| 65 | - assert_equal @module_result.grade, @content.module_result(@module.name).grade | 65 | + assert_equal @module_result.grade, @content.module_result({:module_name => @module.name}).grade |
| 66 | + end | ||
| 67 | + | ||
| 68 | + should 'get module result from service with date' do | ||
| 69 | + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | ||
| 70 | + request_body = {:project_name => @project.name, :date => @project_result.date} | ||
| 71 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false}) | ||
| 72 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash}) | ||
| 73 | + Kalibro::ModuleResult.expects(:request).with( | ||
| 74 | + 'ModuleResult', | ||
| 75 | + :get_module_result, | ||
| 76 | + { | ||
| 77 | + :project_name => @project.name, | ||
| 78 | + :module_name => @module.name, | ||
| 79 | + :date => date_with_milliseconds | ||
| 80 | + }).returns({:module_result => @module_result.to_hash}) | ||
| 81 | + assert_equal @module_result.grade, @content.module_result({:module_name => @module.name, :date => @project_result.date}).grade | ||
| 66 | end | 82 | end |
| 67 | 83 | ||
| 68 | should 'get result history' do | 84 | should 'get result history' do |