Skip to content

Commit 8bdeb33

Browse files
Fix usage of nil primary key in tree builders related to active records
1 parent df8b680 commit 8bdeb33

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def call
2727

2828
t1.nested do |t2|
2929
t2.insert_separated_list(
30-
[id] + (object.attributes.keys.sort - [id])
30+
if id.nil?
31+
object.attributes.keys.sort
32+
else
33+
[id] + (object.attributes.keys.sort - [id])
34+
end
3135
) do |t3, name|
3236
t3.as_prefix_when_rendering_to_lines do |t4|
3337
t4.add_text "#{name}: "

lib/super_diff/active_record/operation_tree_builders/active_record_model.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def id
1616
end
1717

1818
def attribute_names
19+
return expected.attributes.keys.sort if id.nil?
20+
1921
[id] + (expected.attributes.keys.sort - [id])
2022
end
2123
end

0 commit comments

Comments
 (0)