Skip to content

Commit d9fd8f7

Browse files
authored
Show tenant earlier in inspect output (#191)
This PR changes the way inspect displays the tenant. Previously, the tenant was appended at the end of the string, e.g.: `#<User id: 1, email: "[email protected]", tenant="acme"> ` With this change, the tenant is injected immediately after the class token, making it one of the first pieces of information shown: `#<User tenant: "acme", id: 1, email: "[email protected]">` Why? In classes with many attributes, having the tenant all the way at the end makes it harder to notice. Since the tenant is a critical piece of context, showing it right after the class name makes it more visible and improves readability. I also updated the tests to reflect this new behavior.
2 parents 9e68c80 + 463df6f commit d9fd8f7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/active_record/tenanted/tenant.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def cache_key
1717
end
1818

1919
def inspect
20-
tenant ? super.sub(/>$/, ", tenant=#{tenant.inspect}>") : super
20+
return super unless tenant
21+
22+
super.sub(/\A#<\S+ /, "\\0tenant: #{tenant.inspect}, ")
2123
end
2224

2325
def to_global_id(options = {})

test/unit/tenant_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@
11941194
User.create!(email: "[email protected]")
11951195
end
11961196

1197-
assert_match(/, tenant="foo">$/, user.inspect)
1197+
assert_match(/\A#<User tenant: "foo", id:/, user.inspect)
11981198
end
11991199
end
12001200
end

0 commit comments

Comments
 (0)