Sha256: 3f2f849b1a44ac8a64d903c52ae8c48febe512ba441f26deb3d748945dc5029c

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require 'multiverse_helpers'
require File.join(File.dirname(__FILE__), 'example_app')
require 'new_relic/rack/browser_monitoring'
require 'new_relic/rack/agent_hooks'
require 'new_relic/rack/error_collector'

if NewRelic::Agent::Instrumentation::RackHelpers.rack_version_supported?

class HttpResponseCodeTest < Minitest::Test
  include MultiverseHelpers

  setup_and_teardown_agent

  include Rack::Test::Methods

  def app
    Rack::Builder.app do
      use ResponseCodeMiddleware
      use NewRelic::Rack::AgentHooks
      run ExampleApp.new
    end
  end

  def test_records_http_response_code_on_analytics_events
    rsp = get '/', { 'override-response-code' => 404 }
    assert_equal(404, rsp.status)
    assert_equal('404', get_last_analytics_event[0]['httpResponseCode'])

    rsp = get '/', { 'override-response-code' => 302 }
    assert_equal(302, rsp.status)
    assert_equal('302', get_last_analytics_event[0]['httpResponseCode'])
  end

  def test_skips_http_response_code_if_middleware_tracing_disabled
    with_config(:disable_middleware_instrumentation => true) do
      rsp = get '/', { 'override-response-code' => 404 }
      assert_equal(404, rsp.status)
      assert_nil get_last_analytics_event[0]['httpResponseCode']

      rsp = get '/', { 'override-response-code' => 302 }
      assert_equal(302, rsp.status)
      assert_nil get_last_analytics_event[0]['httpResponseCode']
    end
  end
end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
newrelic_rpm-3.10.0.279 test/multiverse/suites/rack/http_response_code_test.rb
newrelic_rpm-3.9.9.275 test/multiverse/suites/rack/http_response_code_test.rb
newrelic_rpm-3.9.8.273 test/multiverse/suites/rack/http_response_code_test.rb
newrelic_rpm-3.9.7.266 test/multiverse/suites/rack/http_response_code_test.rb
newrelic_rpm-3.9.6.257 test/multiverse/suites/rack/http_response_code_test.rb
newrelic_rpm-3.9.5.251 test/multiverse/suites/rack/http_response_code_test.rb