Skip to content

Commit eecc9f0

Browse files
Automatically accept incoming changes which only differ in case
1 parent 437a78c commit eecc9f0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/models/concerns/pending_changes_concern.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@ def stage_changes(attributes)
99
new_pending_changes =
1010
attributes.each_with_object({}) do |(attr, new_value), staged_changes|
1111
current_value = public_send(attr)
12-
staged_changes[attr.to_s] = new_value if new_value != current_value
12+
13+
if normalise_for_comparison(new_value) ==
14+
normalise_for_comparison(current_value)
15+
public_send("#{attr}=", new_value) if new_value != current_value
16+
else
17+
staged_changes[attr.to_s] = new_value
18+
end
1319
end
1420

1521
if new_pending_changes.any?
1622
update!(pending_changes: pending_changes.merge(new_pending_changes))
1723
end
1824
end
1925

26+
def normalise_for_comparison(value)
27+
value.respond_to?(:downcase) ? value.downcase : value
28+
end
29+
2030
def with_pending_changes
2131
return self if pending_changes.blank?
2232

0 commit comments

Comments
 (0)