Commit 2ba073133d607356d2e8860e4665ee04797826ad

Authored by Guilherme Rojas V. de Lima
Committed by Guilherme Rojas
1 parent 80e5af82

Unit tests for module controller.

It should be refactored to use let pattern.

Signed-off By: Fellipe Souto <fllsouto@gmail.com>
Showing 1 changed file with 40 additions and 0 deletions   Show diff stats
spec/controllers/modules_controller_spec.rb
... ... @@ -12,4 +12,44 @@ describe ModulesController do
12 12 it { should respond_with(:success) }
13 13 it { should render_template(:load_module_tree) }
14 14 end
  15 +
  16 + describe "metric_history" do
  17 +
  18 +
  19 + 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})
  28 + end
  29 +
  30 + context "testing existence of the image in the response" do
  31 + it "should return an image" do
  32 + get :metric_history, id: @module_result.id, metric_name: @metric_name, module_id: @module_id
  33 + response.content_type.should eq "image/png"
  34 + end
  35 + end
  36 +
  37 + context "testing parameter values" do
  38 +
  39 + before :each do
  40 + @graphic = Gruff::Line.new(400)
  41 + Gruff::Line.expects(:new).with(400).returns(@graphic)
  42 + end
  43 +
  44 + 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
  48 + end
  49 + end
  50 +
  51 +
  52 +
  53 +
  54 + end
15 55 end
16 56 \ No newline at end of file
... ...