Sha256: 4dba496ceaf77dd5c54a344f00d8356c9167d3c6703c9a9aa3279bf990d44128

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'test_helper'

module Chillout
  module Middleware
    class CreationsMonitorTest < ChilloutTestCase
      def setup
        @env = { 'HOST' => 'example.net' }
        @logger = stub(info: "", debug: "")
        @client = stub(logger: @logger)
      end

      def call_with_model_creation
        @app = lambda do |env|
          Thread.current[:creations] = :creations
          [200, env, ['hello']]
        end
        @middleware = CreationsMonitor.new(@app, @client)
      end

      def test_behaves_like_rack_middleware
        call_with_model_creation
        @client.stubs(:enqueue)
        response = @middleware.call(@env)
        assert_equal [200, @env, ['hello']], response
      end

      def test_clients_queue_receive_creations
        call_with_model_creation
        @client.expects(:enqueue).with(:creations)

        @middleware.call(@env)
      end

      def call_without_model_creation
        @app = lambda do |env|
          [200, env, ['hello']]
        end
        @middleware = CreationsMonitor.new(@app, @client)
      end

      def test_behaves_like_rack_middleware
        call_without_model_creation
        response = @middleware.call(@env)

        assert_equal [200, @env, ['hello']], response
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chillout-0.8.3 test/middleware/creations_monitor_test.rb
chillout-0.8.2 test/middleware/creations_monitor_test.rb
chillout-0.8.1 test/middleware/creations_monitor_test.rb
chillout-0.8.0 test/middleware/creations_monitor_test.rb