File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,10 +97,18 @@ def mongoid_persist
9797
9898 # Yields the reloaded record. Used by the _persistence plugin.
9999 def mongoid_reload
100- record_copy = record . dup
101- record_copy . id = record . id
102-
103- record_copy . reload unless record_copy . embedded?
100+ if record . embedded?
101+ parent_copy = record . _parent . dup
102+ parent_copy . id = record . _parent . id
103+ parent_copy . reload
104+ record_copy = parent_copy . _children . find do |child |
105+ child . id == record . id
106+ end
107+ else
108+ record_copy = record . dup
109+ record_copy . id = record . id
110+ record_copy . reload
111+ end
104112
105113 yield record_copy
106114 end
Original file line number Diff line number Diff line change @@ -639,6 +639,22 @@ def validate
639639 assert_equal file , attacher . file
640640 end
641641 end
642+
643+ describe "#atomic_promote" do
644+ it "promotes cached file to permanent storage" do
645+ photo = Photo . new ( user : @user )
646+ attacher = @shrine ::Attacher . from_model ( photo , :image )
647+
648+ attacher . attach_cached ( fakeio )
649+ photo . save
650+
651+ attacher . atomic_promote
652+
653+ assert attacher . stored?
654+ attacher . reload
655+ assert attacher . stored?
656+ end
657+ end
642658 end
643659 end
644660 end
You can’t perform that action at this time.
0 commit comments