From 2ba073133d607356d2e8860e4665ee04797826ad Mon Sep 17 00:00:00 2001 From: Guilherme Rojas V. de Lima Date: Tue, 26 Nov 2013 19:43:43 -0200 Subject: [PATCH] Unit tests for module controller. --- spec/controllers/modules_controller_spec.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+), 0 deletions(-) diff --git a/spec/controllers/modules_controller_spec.rb b/spec/controllers/modules_controller_spec.rb index ad4a070..eec4e10 100644 --- a/spec/controllers/modules_controller_spec.rb +++ b/spec/controllers/modules_controller_spec.rb @@ -12,4 +12,44 @@ describe ModulesController do it { should respond_with(:success) } it { should render_template(:load_module_tree) } end + + describe "metric_history" do + + + before :each do + @module_id = 1 + @date = "2011-10-20T18:26:43.151+00:00" + @metric_name = FactoryGirl.build(:loc).name + @metric_result = FactoryGirl.build(:metric_result) + + @module_result = FactoryGirl.build(:module_result) + 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 + 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 + + context "testing parameter values" do + + before :each do + @graphic = Gruff::Line.new(400) + Gruff::Line.expects(:new).with(400).returns(@graphic) + end + + 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 + end + end + + + + + end end \ No newline at end of file -- libgit2 0.21.2