modules_controller_spec.rb
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'spec_helper'
describe ModulesController do
describe "load_module_tree" do
before :each do
ModuleResult.expects(:find).with(42).returns(FactoryGirl.build(:module_result))
request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS
post :load_module_tree, {id: 42}
end
it { should respond_with(:success) }
it { should render_template(:load_module_tree) }
end
describe "metric_history" do
let (:module_id){ 1 }
let (:metric_name ){ FactoryGirl.build(:loc).name }
let (:date ){ DateTime.parse("2011-10-20T18:26:43.151+00:00") }
let (:metric_result){ FactoryGirl.build(:metric_result) }
let! (:module_result){ FactoryGirl.build(:module_result) }
before :each do
ModuleResult.expects(:new).at_least_once.with({id: module_result.id.to_s}).returns(module_result)
module_result.expects(:metric_history).with(metric_name).returns({date => metric_result.value})
end
context "testing existence of the image in the response" do
pending "It brokes with graphic caching" do
it "should return an image" do
get :metric_history, id: module_result.id, metric_name: metric_name, module_id: module_id
response.content_type.should eq "image/png"
end
end
end
context "testing parameter values" do
before :each do
@graphic = Gruff::Line.new(400)
Gruff::Line.expects(:new).with(400).returns(@graphic)
end
pending "It brokes with graphic caching" do
it "should return two arrays, one of dates and other of values" do
get :metric_history, id: module_result.id, metric_name: metric_name, module_id: module_id
@graphic.maximum_value.should eq metric_result.value
@graphic.labels.first[1].should eq date.strftime("%Y/%m/%d")
end
end
end
end
end