Sha256: 0c215b4675cb6d25f66d4803de9a73dbdd45dba1aee9d96a88823758208de1af

Contents?: true

Size: 1.93 KB

Versions: 8

Compression:

Stored size: 1.93 KB

Contents

require File.join(File.dirname(__FILE__),'..','api_helper')

describe "RhoconnectApiStats" do
  it_should_behave_like "ApiHelper" do
    
    def app
      @app ||= Rhoconnect::Server.new
    end
    
    before(:each) do
      Rhoconnect::Server.set :stats, true
      Rhoconnect.stats = true
    end
    
    after(:each) do
      Rhoconnect::Server.set :stats, false
      Rhoconnect.stats = false
    end

    it "should retrieve metric names" do
      Store.set_value('stat:foo', '1')
      Store.set_value('stat:bar', '2')
      post "/api/admin/stats", {
        :api_token => @api_token, 
        :names => '*'
      }
      last_response.should be_ok
      JSON.parse(last_response.body).sort.should == ['bar', 'foo']
    end

    it "should retrieve range metric" do
      Store.db.zadd('stat:foo', 2, "1:2")
      Store.db.zadd('stat:foo', 3, "1:3")
      post "/api/admin/stats", {
        :api_token => @api_token, 
        :metric => 'foo', 
        :start => 0,
        :finish => -1
      }
      last_response.should be_ok
      JSON.parse(last_response.body).should == ["1:2", "1:3"]
    end

    it "should retrieve string metric" do
      Store.db.set('stat:foo', 'bar')
      post "/api/admin/stats", {
        :api_token => @api_token, 
        :metric => 'foo'
      }
      last_response.should be_ok
      last_response.body.should == 'bar'
    end

    it "should raise error on unknown metric" do
      post "/api/admin/stats", {
        :api_token => @api_token, 
        :metric => 'foo'
      }
      last_response.status.should == 404    
      last_response.body.should == 'Unknown metric'
    end

    it "should raise error if stats not enabled" do
      Rhoconnect::Server.set :stats, false
      Rhoconnect.stats = false
      post "/api/admin/stats", {
        :api_token => @api_token, 
        :metric => 'foo'
      }
      last_response.status.should == 500    
      last_response.body.should == 'Stats not enabled'
    end
  end  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rhoconnect-3.2.1 spec/api/admin/stats_spec.rb
rhoconnect-3.2.0 spec/api/admin/stats_spec.rb
rhoconnect-3.2.0.beta5 spec/api/admin/stats_spec.rb
rhoconnect-3.2.0.beta4 spec/api/admin/stats_spec.rb
rhoconnect-3.2.0.beta3 spec/api/admin/stats_spec.rb
rhoconnect-3.2.0.beta2 spec/api/admin/stats_spec.rb
rhoconnect-3.2.0.beta1 spec/api/admin/stats_spec.rb
rhoconnect-3.1.2 spec/api/admin/stats_spec.rb