Commit 0e3b40f3d969e6cc6e267f20a3dbe4bf722d1e2c

Authored by Fellipe Souto Sampaio
Committed by Guilherme Rojas
1 parent 35da2495

Finished Unit test for modules controller.

Signed-off By: Guilherme Rojas V. de Lima <guilhermehrojas@gmail.com>
Signed-off By: Renan Fichberg <rfichberg@gmail.com>
Showing 1 changed file with 12 additions and 13 deletions   Show diff stats
spec/controllers/modules_controller_spec.rb
@@ -14,22 +14,21 @@ describe ModulesController do @@ -14,22 +14,21 @@ describe ModulesController do
14 end 14 end
15 15
16 describe "metric_history" do 16 describe "metric_history" do
17 - 17 + let (:module_id){ 1 }
  18 + let (:metric_name ){ FactoryGirl.build(:loc).name }
  19 + let (:date ){ "2011-10-20T18:26:43.151+00:00" }
  20 + let (:metric_result){ FactoryGirl.build(:metric_result) }
  21 + let (:module_result){ FactoryGirl.build(:module_result) }
18 22
19 before :each do 23 before :each do
20 - @module_id = 1  
21 - @date = "2011-10-20T18:26:43.151+00:00"  
22 - @metric_name = FactoryGirl.build(:loc).name  
23 - @metric_result = FactoryGirl.build(:metric_result)  
24 -  
25 - @module_result = FactoryGirl.build(:module_result)  
26 - ModuleResult.expects(:new).at_least_once.with({id: @module_result.id.to_s}).returns(@module_result)  
27 - @module_result.expects(:metric_history).with(@metric_name).returns({@date => @metric_result.value}) 24 + module_result #TODO discovery 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)
  26 + module_result.expects(:metric_history).with(metric_name).returns({date => metric_result.value})
28 end 27 end
29 28
30 context "testing existence of the image in the response" do 29 context "testing existence of the image in the response" do
31 it "should return an image" do 30 it "should return an image" do
32 - get :metric_history, id: @module_result.id, metric_name: @metric_name, module_id: @module_id 31 + get :metric_history, id: module_result.id, metric_name: metric_name, module_id: module_id
33 response.content_type.should eq "image/png" 32 response.content_type.should eq "image/png"
34 end 33 end
35 end 34 end
@@ -42,9 +41,9 @@ describe ModulesController do @@ -42,9 +41,9 @@ describe ModulesController do
42 end 41 end
43 42
44 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
45 - get :metric_history, id: @module_result.id, metric_name: @metric_name, module_id: @module_id  
46 - @graphic.maximum_value.should eq @metric_result.value  
47 - @graphic.labels.first[1].should eq @date 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
  46 + @graphic.labels.first[1].should eq date
48 end 47 end
49 end 48 end
50 49