Sha256: ed44415799accdd2614721194a5a3e745c402c6758476d14ff0d34c0acf23b82

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 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, "clients")
      stub_api_request(api_key, "metrics")
      @config = Chillout::Config.new(api_key)
      @client = Chillout::Client.new(@config, :logger => null_logger)
    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
      sleep 2
      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

5 entries across 5 versions & 1 rubygems

Version Path
chillout-0.8.2 test/integration/creations_monitor_rack_test.rb
chillout-0.8.1 test/integration/creations_monitor_rack_test.rb
chillout-0.8.0 test/integration/creations_monitor_rack_test.rb
chillout-0.6.0 test/integration/creations_monitor_rack_test.rb
chillout-0.5.4 test/integration/creations_monitor_rack_test.rb