class ACLogSubscriberTest

Public Instance Methods

logs() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 368
def logs
  @logs ||= @logger.logged(:info)
end
set_logger(logger) click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 114
def set_logger(logger)
  ActionController::Base.logger = logger
end
setup() click to toggle source
Calls superclass method
# File actionpack/test/controller/log_subscriber_test.rb, line 95
def setup
  super
  ActionController::Base.enable_fragment_cache_logging = true

  @old_logger = ActionController::Base.logger

  @cache_path = File.join Dir.tmpdir, Dir::Tmpname.make_tmpname("tmp", "cache")
  @controller.cache_store = :file_store, @cache_path
  ActionController::LogSubscriber.attach_to :action_controller
end
teardown() click to toggle source
Calls superclass method
# File actionpack/test/controller/log_subscriber_test.rb, line 106
def teardown
  super
  ActiveSupport::LogSubscriber.log_subscribers.clear
  FileUtils.rm_rf(@cache_path)
  ActionController::Base.logger = @old_logger
  ActionController::Base.enable_fragment_cache_logging = true
end
test_append_info_to_payload_is_called_even_with_exception() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 180
def test_append_info_to_payload_is_called_even_with_exception
  begin
    get :with_exception
    wait
  rescue Exception
  end

  assert_equal "test_value", @controller.last_payload[:test_key]
end
test_filter_redirect_url_by_regexp() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 227
def test_filter_redirect_url_by_regexp
  @request.env["action_dispatch.redirect_filter"] = [/secret\.foo.+/]
  get :filterable_redirector
  wait

  assert_equal 3, logs.size
  assert_equal "Redirected to [FILTERED]", logs[1]
end
test_filter_redirect_url_by_string() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 218
def test_filter_redirect_url_by_string
  @request.env["action_dispatch.redirect_filter"] = ["secret"]
  get :filterable_redirector
  wait

  assert_equal 3, logs.size
  assert_equal "Redirected to [FILTERED]", logs[1]
end
test_halted_callback() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 125
def test_halted_callback
  get :never_executed
  wait
  assert_equal 4, logs.size
  assert_equal "Filter chain halted as :redirector rendered or redirected", logs.third
end
test_multiple_process_with_parameters() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 154
def test_multiple_process_with_parameters
  get :show, params: { id: "10" }
  get :show, params: { id: "20" }

  wait

  assert_equal 6, logs.size
  assert_equal 'Parameters: {"id"=>"10"}', logs[1]
  assert_equal 'Parameters: {"id"=>"20"}', logs[4]
end
test_process_action() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 132
def test_process_action
  get :show
  wait
  assert_equal 2, logs.size
  assert_match(/Completed/, logs.last)
  assert_match(/200 OK/, logs.last)
end
test_process_action_headers() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 190
def test_process_action_headers
  get :show
  wait
  assert_equal "Quails Testing", @controller.last_payload[:headers]["User-Agent"]
end
test_process_action_with_exception_includes_http_status_code() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 339
def test_process_action_with_exception_includes_http_status_code
  begin
    get :with_exception
    wait
  rescue Exception
  end
  assert_equal 2, logs.size
  assert_match(/Completed 500/, logs.last)
end
test_process_action_with_filter_parameters() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 196
def test_process_action_with_filter_parameters
  @request.env["action_dispatch.parameter_filter"] = [:lifo, :amount]

  get :show, params: {
    lifo: "Pratik", amount: "420", step: "1"
  }
  wait

  params = logs[1]
  assert_match(/"amount"=>"\[FILTERED\]"/, params)
  assert_match(/"lifo"=>"\[FILTERED\]"/, params)
  assert_match(/"step"=>"1"/, params)
end
test_process_action_with_parameters() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 146
def test_process_action_with_parameters
  get :show, params: { id: "10" }
  wait

  assert_equal 3, logs.size
  assert_equal 'Parameters: {"id"=>"10"}', logs[1]
end
test_process_action_with_rescued_exception_includes_http_status_code() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 349
def test_process_action_with_rescued_exception_includes_http_status_code
  get :with_rescued_exception
  wait

  assert_equal 2, logs.size
  assert_match(/Completed 406/, logs.last)
end
test_process_action_with_view_runtime() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 174
def test_process_action_with_view_runtime
  get :show
  wait
  assert_match(/Completed 200 OK in \d+ms/, logs[1])
end
test_process_action_with_with_action_not_found_logs_404() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 357
def test_process_action_with_with_action_not_found_logs_404
  begin
    get :with_action_not_found
    wait
  rescue AbstractController::ActionNotFound
  end

  assert_equal 2, logs.size
  assert_match(/Completed 404/, logs.last)
end
test_process_action_with_wrapped_parameters() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 165
def test_process_action_with_wrapped_parameters
  @request.env["CONTENT_TYPE"] = "application/json"
  post :show, params: { id: "10", name: "jose" }
  wait

  assert_equal 3, logs.size
  assert_match '"person"=>{"name"=>"jose"}', logs[1]
end
test_process_action_without_parameters() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 140
def test_process_action_without_parameters
  get :show
  wait
  assert_nil logs.detect { |l| l =~ /Parameters/ }
end
test_redirect_to() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 210
def test_redirect_to
  get :redirector
  wait

  assert_equal 3, logs.size
  assert_equal "Redirected to http://foo.bar/", logs[1]
end
test_send_data() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 236
def test_send_data
  get :data_sender
  wait

  assert_equal 3, logs.size
  assert_match(/Sent data file\.txt/, logs[1])
end
test_send_file() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 244
def test_send_file
  get :file_sender
  wait

  assert_equal 3, logs.size
  assert_match(/Sent file/, logs[1])
  assert_match(/test\/fixtures\/company\.rb/, logs[1])
end
test_start_processing() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 118
def test_start_processing
  get :show
  wait
  assert_equal 2, logs.size
  assert_equal "Processing by Another::LogSubscribersController#show as HTML", logs.first
end
test_with_fragment_cache() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 253
def test_with_fragment_cache
  @controller.config.perform_caching = true
  get :with_fragment_cache
  wait

  assert_equal 4, logs.size
  assert_match(/Read fragment views\/foo/, logs[1])
  assert_match(/Write fragment views\/foo/, logs[2])
ensure
  @controller.config.perform_caching = true
end
test_with_fragment_cache_and_percent_in_key() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 327
def test_with_fragment_cache_and_percent_in_key
  @controller.config.perform_caching = true
  get :with_fragment_cache_and_percent_in_key
  wait

  assert_equal 4, logs.size
  assert_match(/Read fragment views\/foo/, logs[1])
  assert_match(/Write fragment views\/foo/, logs[2])
ensure
  @controller.config.perform_caching = true
end
test_with_fragment_cache_if_with_false() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 291
def test_with_fragment_cache_if_with_false
  @controller.config.perform_caching = true
  get :with_fragment_cache_if_with_false_condition
  wait

  assert_equal 2, logs.size
  assert_no_match(/Read fragment views\/foo/, logs[1])
  assert_no_match(/Write fragment views\/foo/, logs[2])
ensure
  @controller.config.perform_caching = true
end
test_with_fragment_cache_if_with_true() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 279
def test_with_fragment_cache_if_with_true
  @controller.config.perform_caching = true
  get :with_fragment_cache_if_with_true_condition
  wait

  assert_equal 4, logs.size
  assert_match(/Read fragment views\/foo/, logs[1])
  assert_match(/Write fragment views\/foo/, logs[2])
ensure
  @controller.config.perform_caching = true
end
test_with_fragment_cache_unless_with_false() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 315
def test_with_fragment_cache_unless_with_false
  @controller.config.perform_caching = true
  get :with_fragment_cache_unless_with_false_condition
  wait

  assert_equal 4, logs.size
  assert_match(/Read fragment views\/foo/, logs[1])
  assert_match(/Write fragment views\/foo/, logs[2])
ensure
  @controller.config.perform_caching = true
end
test_with_fragment_cache_unless_with_true() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 303
def test_with_fragment_cache_unless_with_true
  @controller.config.perform_caching = true
  get :with_fragment_cache_unless_with_true_condition
  wait

  assert_equal 2, logs.size
  assert_no_match(/Read fragment views\/foo/, logs[1])
  assert_no_match(/Write fragment views\/foo/, logs[2])
ensure
  @controller.config.perform_caching = true
end
test_with_fragment_cache_when_log_disabled() click to toggle source
# File actionpack/test/controller/log_subscriber_test.rb, line 265
def test_with_fragment_cache_when_log_disabled
  @controller.config.perform_caching = true
  ActionController::Base.enable_fragment_cache_logging = false
  get :with_fragment_cache
  wait

  assert_equal 2, logs.size
  assert_equal "Processing by Another::LogSubscribersController#with_fragment_cache as HTML", logs[0]
  assert_match(/Completed 200 OK in \d+ms/, logs[1])
ensure
  @controller.config.perform_caching = true
  ActionController::Base.enable_fragment_cache_logging = true
end