Commit cb6a718c3ae5648e092d96959921e3a866923945
Committed by
Paulo Meireles
1 parent
32fd0fb0
Exists in
colab
and in
4 other branches
Graph dates formated
Showing
2 changed files
with
5 additions
and
8 deletions
Show diff stats
app/controllers/modules_controller.rb
1 | 1 | class ModulesController < ApplicationController |
2 | - | |
3 | 2 | # GET /modules/1/metric_history |
4 | 3 | def metric_history |
5 | 4 | module_result = ModuleResult.new({ id: params[:id] }) |
... | ... | @@ -28,15 +27,13 @@ class ModulesController < ApplicationController |
28 | 27 | graphic.theme = { |
29 | 28 | colors: ['grey'], |
30 | 29 | marker_color: 'black', |
31 | - background_colors: '#fff', | |
30 | + background_colors: '#fff' | |
32 | 31 | } |
33 | 32 | |
34 | - graphic.labels = Hash[dates.each_with_index.map{ |date, index| [index, date.to_s]}] | |
33 | + graphic.labels = Hash[dates.each_with_index.map{ |date, index| [index, date.strftime("%Y/%m/%d")]}] | |
35 | 34 | |
36 | 35 | graphic.data('Values', values) |
37 | 36 | |
38 | 37 | graphic.to_blob |
39 | 38 | end |
40 | - | |
41 | - | |
42 | 39 | end |
43 | 40 | \ No newline at end of file | ... | ... |
spec/controllers/modules_controller_spec.rb
... | ... | @@ -16,12 +16,12 @@ describe ModulesController do |
16 | 16 | describe "metric_history" do |
17 | 17 | let (:module_id){ 1 } |
18 | 18 | let (:metric_name ){ FactoryGirl.build(:loc).name } |
19 | - let (:date ){ "2011-10-20T18:26:43.151+00:00" } | |
19 | + let (:date ){ DateTime.parse("2011-10-20T18:26:43.151+00:00") } | |
20 | 20 | let (:metric_result){ FactoryGirl.build(:metric_result) } |
21 | 21 | let (:module_result){ FactoryGirl.build(:module_result) } |
22 | 22 | |
23 | 23 | before :each do |
24 | - module_result #TODO discovery why this line is fundamental, without this line the test generates a nil object for module_result | |
24 | + module_result #TODO discover why this line is fundamental, without this line the test generates a nil object for module_result | |
25 | 25 | ModuleResult.expects(:new).at_least_once.with({id: module_result.id.to_s}).returns(module_result) |
26 | 26 | module_result.expects(:metric_history).with(metric_name).returns({date => metric_result.value}) |
27 | 27 | end |
... | ... | @@ -43,7 +43,7 @@ describe ModulesController do |
43 | 43 | it "should return two arrays, one of dates and other of values" do |
44 | 44 | get :metric_history, id: module_result.id, metric_name: metric_name, module_id: module_id |
45 | 45 | @graphic.maximum_value.should eq metric_result.value |
46 | - @graphic.labels.first[1].should eq date | |
46 | + @graphic.labels.first[1].should eq date.strftime("%Y/%m/%d") | |
47 | 47 | end |
48 | 48 | end |
49 | 49 | ... | ... |