Commit 63da545f5067dd19fa7f52d4b741a67a65f46274
1 parent
e33399ed
Exists in
colab
and in
4 other branches
Metric history graphic cached
Missing acceptance tests Signed off by: Renan Fichberg <rfichberg@gmail.com>
Showing
5 changed files
with
20 additions
and
25 deletions
Show diff stats
Gemfile
| @@ -48,9 +48,6 @@ gem "chart-js-rails", "~> 0.0.6" | @@ -48,9 +48,6 @@ gem "chart-js-rails", "~> 0.0.6" | ||
| 48 | # JQueryUI | 48 | # JQueryUI |
| 49 | gem 'jquery-ui-rails', '~> 4.1.0' | 49 | gem 'jquery-ui-rails', '~> 4.1.0' |
| 50 | 50 | ||
| 51 | -# Enables cache to actions | ||
| 52 | -gem 'actionpack-action_caching', "~> 1.1.1" | ||
| 53 | - | ||
| 54 | group :doc do | 51 | group :doc do |
| 55 | # bundle exec rake doc:rails generates the API under doc/api. | 52 | # bundle exec rake doc:rails generates the API under doc/api. |
| 56 | gem 'sdoc', require: false | 53 | gem 'sdoc', require: false |
Gemfile.lock
| @@ -10,8 +10,6 @@ GEM | @@ -10,8 +10,6 @@ GEM | ||
| 10 | erubis (~> 2.7.0) | 10 | erubis (~> 2.7.0) |
| 11 | rack (~> 1.5.2) | 11 | rack (~> 1.5.2) |
| 12 | rack-test (~> 0.6.2) | 12 | rack-test (~> 0.6.2) |
| 13 | - actionpack-action_caching (1.1.1) | ||
| 14 | - actionpack (>= 4.0.0, < 5.0) | ||
| 15 | activemodel (4.0.2) | 13 | activemodel (4.0.2) |
| 16 | activesupport (= 4.0.2) | 14 | activesupport (= 4.0.2) |
| 17 | builder (~> 3.1.0) | 15 | builder (~> 3.1.0) |
| @@ -268,7 +266,6 @@ PLATFORMS | @@ -268,7 +266,6 @@ PLATFORMS | ||
| 268 | ruby | 266 | ruby |
| 269 | 267 | ||
| 270 | DEPENDENCIES | 268 | DEPENDENCIES |
| 271 | - actionpack-action_caching (~> 1.1.1) | ||
| 272 | better_errors | 269 | better_errors |
| 273 | binding_of_caller | 270 | binding_of_caller |
| 274 | capistrano (~> 3.0.1) | 271 | capistrano (~> 3.0.1) |
app/controllers/modules_controller.rb
| 1 | class ModulesController < ApplicationController | 1 | class ModulesController < ApplicationController |
| 2 | - #caches_action :metric_history, cache_path: Proc.new{"#{params[:id]}_#{params[:metric_name]}"}, expires_in: 1.day, layout: false | ||
| 3 | - | ||
| 4 | # POST /modules/1/metric_history | 2 | # POST /modules/1/metric_history |
| 5 | def metric_history | 3 | def metric_history |
| 6 | - module_result = ModuleResult.find(params[:id].to_i) | 4 | + @module_result = ModuleResult.find(params[:id].to_i) |
| 7 | @container = params[:container] | 5 | @container = params[:container] |
| 8 | - @metric_history = module_result.metric_history(params[:metric_name]) # pending: sort this hash. | 6 | + @metric_name = params[:metric_name] |
| 9 | end | 7 | end |
| 10 | 8 | ||
| 11 | # POST /modules/1/tree | 9 | # POST /modules/1/tree |
app/views/modules/metric_history.js.erb
| 1 | -var dates = []; | ||
| 2 | -var values = []; | 1 | +<% cache("#{@module_result.id}_#{@metric_name}") do %> |
| 2 | + <% metric_history = @module_result.metric_history(@metric_name) %> | ||
| 3 | 3 | ||
| 4 | -<% @metric_history.keys.each do |date| %> | ||
| 5 | - dates.push("<%= date %>"); | ||
| 6 | - values.push(<%= @metric_history[date] %>); | ||
| 7 | -<% end %> | 4 | + var dates = []; |
| 5 | + var values = []; | ||
| 8 | 6 | ||
| 9 | -$("#loader_<%= @container %>").hide() | ||
| 10 | -if (dates.length > 1) { | ||
| 11 | - $("canvas#<%= @container %>").show() | ||
| 12 | - Module.Graphic.display(dates, values, '<%= @container %>'); | ||
| 13 | -} | ||
| 14 | -else { | ||
| 15 | - $('span#<%= @container %>').show() | ||
| 16 | -} | ||
| 17 | \ No newline at end of file | 7 | \ No newline at end of file |
| 8 | + <% metric_history.keys.each do |date| %> | ||
| 9 | + dates.push("<%= date %>"); | ||
| 10 | + values.push(<%= metric_history[date] %>); | ||
| 11 | + <% end %> | ||
| 12 | + | ||
| 13 | + $("#loader_<%= @container %>").hide(); | ||
| 14 | + if (dates.length > 1) { | ||
| 15 | + $("canvas#<%= @container %>").show(); | ||
| 16 | + Module.Graphic.display(dates, values, '<%= @container %>'); | ||
| 17 | + } | ||
| 18 | + else { | ||
| 19 | + $('span#<%= @container %>').show(); | ||
| 20 | + } | ||
| 21 | +<% end %> | ||
| 18 | \ No newline at end of file | 22 | \ No newline at end of file |
spec/controllers/modules_controller_spec.rb
| @@ -22,7 +22,6 @@ describe ModulesController do | @@ -22,7 +22,6 @@ describe ModulesController do | ||
| 22 | 22 | ||
| 23 | before :each do | 23 | before :each do |
| 24 | ModuleResult.expects(:find).at_least_once.with(module_result.id).returns(module_result) | 24 | ModuleResult.expects(:find).at_least_once.with(module_result.id).returns(module_result) |
| 25 | - module_result.expects(:metric_history).with(metric_name).returns({date => metric_result.value}) | ||
| 26 | subject.expire_fragment("#{module_result.id}_#{metric_name}") | 25 | subject.expire_fragment("#{module_result.id}_#{metric_name}") |
| 27 | 26 | ||
| 28 | request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS | 27 | request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS |