Sha256: 11a18d1df6ecf9ee575dc6a79c45660a760cf2e36e28c0bdf3fd425a7a650c21

Contents?: true

Size: 1.59 KB

Versions: 10

Compression:

Stored size: 1.59 KB

Contents

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

describe "RhosyncApiStats" do
  it_should_behave_like "ApiHelper"
  
  before(:each) do
    Rhosync.stats = true
  end
  
  after(:each) do
    Rhosync.stats = false
  end
  
  it "should retrieve metric names" do
    Store.set_value('stat:foo', '1')
    Store.set_value('stat:bar', '2')
    post "/api/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/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/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/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
    Rhosync.stats = false
    post "/api/stats", {
      :api_token => @api_token, 
      :metric => 'foo'
    }
    last_response.status.should == 500    
    last_response.body.should == 'Stats not enabled'
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rhosync-2.1.11 spec/api/stats_spec.rb
rhosync-2.1.10 spec/api/stats_spec.rb
rhosync-2.1.7 spec/api/stats_spec.rb
rhosync-2.1.6 spec/api/stats_spec.rb
rhosync-2.1.3 spec/api/stats_spec.rb
rhosync-2.1.2 spec/api/stats_spec.rb
rhosync-2.1.1 spec/api/stats_spec.rb
rhosync-2.1.0 spec/api/stats_spec.rb
rhosync-2.1.0.beta.2 spec/api/stats_spec.rb
rhosync-2.1.0.beta.1 spec/api/stats_spec.rb