File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -6,17 +6,32 @@ module PendingChangesConcern
6
6
included { attribute :pending_changes , :jsonb , default : { } }
7
7
8
8
def stage_changes ( attributes )
9
+ need_save = false
10
+
9
11
new_pending_changes =
10
12
attributes . each_with_object ( { } ) do |( attr , new_value ) , staged_changes |
11
13
current_value = public_send ( attr )
12
- staged_changes [ attr . to_s ] = new_value if new_value != current_value
14
+
15
+ if normalise_for_comparison ( new_value ) ==
16
+ normalise_for_comparison ( current_value )
17
+ if new_value != current_value
18
+ public_send ( "#{ attr } =" , new_value )
19
+ need_save = true
20
+ end
21
+ else
22
+ staged_changes [ attr . to_s ] = new_value
23
+ end
13
24
end
14
25
15
- if new_pending_changes . any?
26
+ if new_pending_changes . any? || need_save
16
27
update! ( pending_changes : pending_changes . merge ( new_pending_changes ) )
17
28
end
18
29
end
19
30
31
+ def normalise_for_comparison ( value )
32
+ value . respond_to? ( :downcase ) ? value . downcase : value
33
+ end
34
+
20
35
def with_pending_changes
21
36
return self if pending_changes . blank?
22
37
You can’t perform that action at this time.
0 commit comments