Sha256: 8c976158f7aadb35bcd7b64314f0cae105662a47f6c1ffbe187a825a1b29221d

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

describe Metric::Receive do
  it "generates correct hash via secret_token" do
    Metric::Receive.generate_token("hits").should == "c6daa87bcf8bf7cb4d1c74d872793e5e"
  end

  context "generating correct url" do
    it "total" do
      request = "https://api.metric.io/receive?api_key=spec&token=c6daa87bcf8bf7cb4d1c74d872793e5e&metric=hits&range=total"
      Metric::Receive.compose("hits", "total").should == request
    end

    it "today" do
      request = "https://api.metric.io/receive?api_key=spec&token=c6daa87bcf8bf7cb4d1c74d872793e5e&metric=hits&range=today"
      Metric::Receive.compose("hits", "today").should == request
    end

    it "week" do
      request = "https://api.metric.io/receive?api_key=spec&token=c6daa87bcf8bf7cb4d1c74d872793e5e&metric=hits&range=week"
      Metric::Receive.compose("hits", "week").should == request
    end

    it "month" do
      request = "https://api.metric.io/receive?api_key=spec&token=c6daa87bcf8bf7cb4d1c74d872793e5e&metric=hits&range=month"
      Metric::Receive.compose("hits", "month").should == request
    end
  end

  it "grabs actual data" do
    stub_request(:get, "https://api.metric.io/receive?api_key=spec&metric=hits&range=total&token=c6daa87bcf8bf7cb4d1c74d872793e5e").
      to_return(:status => 200, :body => "{\"total\":\"1\"}", :headers => {})
    Metric::Receive.receive("hits", "total").should == {"total" => "1"}
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metric-0.0.9 spec/metric/receive_spec.rb
metric-0.0.8 spec/metric/receive_spec.rb