Commit cb6a718c3ae5648e092d96959921e3a866923945

Authored by Rafael Manzo
Committed by Paulo Meireles
1 parent 32fd0fb0

Graph dates formated

app/controllers/modules_controller.rb
1 class ModulesController < ApplicationController 1 class ModulesController < ApplicationController
2 -  
3 # GET /modules/1/metric_history 2 # GET /modules/1/metric_history
4 def metric_history 3 def metric_history
5 module_result = ModuleResult.new({ id: params[:id] }) 4 module_result = ModuleResult.new({ id: params[:id] })
@@ -28,15 +27,13 @@ class ModulesController &lt; ApplicationController @@ -28,15 +27,13 @@ class ModulesController &lt; ApplicationController
28 graphic.theme = { 27 graphic.theme = {
29 colors: ['grey'], 28 colors: ['grey'],
30 marker_color: 'black', 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 graphic.data('Values', values) 35 graphic.data('Values', values)
37 36
38 graphic.to_blob 37 graphic.to_blob
39 end 38 end
40 -  
41 -  
42 end 39 end
43 \ No newline at end of file 40 \ No newline at end of file
spec/controllers/modules_controller_spec.rb
@@ -16,12 +16,12 @@ describe ModulesController do @@ -16,12 +16,12 @@ describe ModulesController do
16 describe "metric_history" do 16 describe "metric_history" do
17 let (:module_id){ 1 } 17 let (:module_id){ 1 }
18 let (:metric_name ){ FactoryGirl.build(:loc).name } 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 let (:metric_result){ FactoryGirl.build(:metric_result) } 20 let (:metric_result){ FactoryGirl.build(:metric_result) }
21 let (:module_result){ FactoryGirl.build(:module_result) } 21 let (:module_result){ FactoryGirl.build(:module_result) }
22 22
23 before :each do 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 ModuleResult.expects(:new).at_least_once.with({id: module_result.id.to_s}).returns(module_result) 25 ModuleResult.expects(:new).at_least_once.with({id: module_result.id.to_s}).returns(module_result)
26 module_result.expects(:metric_history).with(metric_name).returns({date => metric_result.value}) 26 module_result.expects(:metric_history).with(metric_name).returns({date => metric_result.value})
27 end 27 end
@@ -43,7 +43,7 @@ describe ModulesController do @@ -43,7 +43,7 @@ describe ModulesController do
43 it "should return two arrays, one of dates and other of values" do 43 it "should return two arrays, one of dates and other of values" do
44 get :metric_history, id: module_result.id, metric_name: metric_name, module_id: module_id 44 get :metric_history, id: module_result.id, metric_name: metric_name, module_id: module_id
45 @graphic.maximum_value.should eq metric_result.value 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 end 47 end
48 end 48 end
49 49