Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug that prevented #pretty_print from displaying records unsaved in collection association. #48653

Merged
merged 1 commit into from Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1107,6 +1107,11 @@ def inspect # :nodoc:
super
end

def pretty_print(pp) # :nodoc:
load_target if find_from_target?
super
end

delegate_methods = [
QueryMethods,
SpawnMethods,
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/associations_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "pp"
require "cases/helper"
require "models/computer"
require "models/developer"
Expand Down Expand Up @@ -451,6 +452,15 @@ def test_inspect_does_not_reload_a_not_yet_loaded_target
assert_predicate andreas.audit_logs, :loaded?
end

def test_pretty_print_does_not_reload_a_not_yet_loaded_target
andreas = Developer.new(log: "new developer added")
assert_not_predicate andreas.audit_logs, :loaded?
out = StringIO.new
PP.pp(andreas.audit_logs, out)
assert_match(/message: "new developer added"/, out.string)
assert_predicate andreas.audit_logs, :loaded?
end

def test_save_on_parent_saves_children
developer = Developer.create name: "Bryan", salary: 50_000
assert_equal 1, developer.reload.audit_logs.size
Expand Down