Repository: rails/rails
File: activesupport/test/event_reporter_test.rb (Ruby)

Code before:
      end
      assert_equal "Uh oh!", error_report.error.message
    end

    test "#notify raises subscriber errors when raise_on_error is true" do
      @reporter.subscribe(ErrorSubscriber.new)

      error = assert_raises(StandardError) do
        @reporter.notify(:test_event)
      end

      assert_equal("Uh oh!", error.message)
    end

    test "#notify with filtered payloads" do
      filter = ActiveSupport::ParameterFilter.new([:zomg], mask: "[FILTERED]")
      @reporter.stub(:payload_filter, filter) do
        assert_called_with(@subscriber, :emit, [
          event_matcher(name: "test_event", payload: { key: "value", zomg: "[FILTERED]" })
        ]) do
          @reporter.notify(:test_event, { key: "value", zomg: "secret" })
        end
      end
    end

    test "default filter_patameters is used by default" do
      old_filter_parameters = ActiveSupport.filter_parameters
      ActiveSupport.filter_parameters = [:secret]

      assert_called_with(@subscriber, :emit, [
        event_matcher(name: "test_event", payload: { key: "value", secret: "[FILTERED]" })
      ]) do
        @reporter.notify(:test_event, { key: "value", secret: "hello" })
      end
    ensure
      ActiveSupport.filter_parameters = old_filter_parameters
    end

    test ".filter_patameters is used when present" do
      old_filter_parameters = EventReporter.filter_parameters
      EventReporter.filter_parameters = [:foo]

      assert_called_with(@subscriber, :emit, [
        event_matcher(name: "test_event", payload: { key: "value", foo: "[FILTERED]" })
      ]) do
        @reporter.notify(:test_event, { key: "value", foo: "hello" })
      end
    ensure
      EventReporter.filter_parameters = old_filter_parameters
    end


Review comment (suggestion):
```suggestion
    test "default filter_parameters is used by default" do
```

Code after:
      end
      assert_equal "Uh oh!", error_report.error.message
    end

    test "#notify raises subscriber errors when raise_on_error is true" do
      @reporter.subscribe(ErrorSubscriber.new)

      error = assert_raises(StandardError) do
        @reporter.notify(:test_event)
      end

      assert_equal("Uh oh!", error.message)
    end

    test "#notify with filtered payloads" do
      filter = ActiveSupport::ParameterFilter.new([:zomg], mask: "[FILTERED]")
      @reporter.stub(:payload_filter, filter) do
        assert_called_with(@subscriber, :emit, [
          event_matcher(name: "test_event", payload: { key: "value", zomg: "[FILTERED]" })
        ]) do
          @reporter.notify(:test_event, { key: "value", zomg: "secret" })
        end
      end
    end

    test "default filter_parameters is used by default" do
      old_filter_parameters = ActiveSupport.filter_parameters
      ActiveSupport.filter_parameters = [:secret]

      assert_called_with(@subscriber, :emit, [
        event_matcher(name: "test_event", payload: { key: "value", secret: "[FILTERED]" })
      ]) do
        @reporter.notify(:test_event, { key: "value", secret: "hello" })
      end
    ensure
      ActiveSupport.filter_parameters = old_filter_parameters
    end

    test ".filter_parameters is used when present" do
      old_filter_parameters = EventReporter.filter_parameters
      EventReporter.filter_parameters = [:foo]

      assert_called_with(@subscriber, :emit, [
        event_matcher(name: "test_event", payload: { key: "value", foo: "[FILTERED]" })
      ]) do
        @reporter.notify(:test_event, { key: "value", foo: "hello" })
      end
    ensure
      EventReporter.filter_parameters = old_filter_parameters
    end