Sha256: d3c778ffa7a3d521350e794ab4b90a339a389422e07cf0ae73612f993b16886c

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

require 'test_helper'
require 'chillout/creations_container'

module Chillout
  class CreationsMonitorRackTest < ChilloutTestCase
    include Rack::Test::Methods

    def setup
      api_key = "xyz123"
      stub_api_request(api_key, "metrics")
      @config = Chillout::Config.new(api_key)
      @config.ssl = false
      @client = Chillout::Client.new(@config)
      @client.start_worker
    end

    def app
      client = @client
      deepest_level = lambda do |env|
        Thread.current[:creations] = CreationsContainer.new
        2.times { Thread.current[:creations].increment!("User") }
        3.times { Thread.current[:creations].increment!("Cart") }
        [200, env, ['hello']]
      end
      Rack::Builder.new do
        use Middleware::CreationsMonitor, client
        run(deepest_level)
      end
    end

    def test_creations_values
      get "/"
      Thread.pass
      assert_equal 2, request_body["content"]["creations"]["User"]
      assert_equal 3, request_body["content"]["creations"]["Cart"]
    end

    private
      def request_body
        assert_request_body("metrics") { |body| return body }
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chillout-0.3.0 test/integration/creations_monitor_rack_test.rb
chillout-0.2.3 test/integration/creations_monitor_rack_test.rb
chillout-0.2.2 test/integration/creations_monitor_rack_test.rb