File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -23,13 +23,20 @@ module Created
2323 # @example Set the created at time.
2424 # person.set_created_at
2525 def set_created_at
26- if ! timeless? && ! created_at
26+ if able_to_set_created_at?
2727 now = Time . current
2828 self . updated_at = now if is_a? ( Updated ) && !updated_at_changed?
2929 self . created_at = now
3030 end
3131 clear_timeless_option
3232 end
33+
34+ # Is the created timestamp able to be set?
35+ #
36+ # @return [ true, false ] If the timestamp can be set.
37+ def able_to_set_created_at?
38+ !frozen? && !timeless? && !created_at
39+ end
3340 end
3441 end
3542end
Original file line number Diff line number Diff line change 4444 expect ( quiz . created_at ) . to be_within ( 10 ) . of ( Time . now . utc )
4545 end
4646 end
47+
48+ context "when the document is destroyed" do
49+ let ( :book ) do
50+ Book . create!
51+ end
52+
53+ before do
54+ Cover . before_save do
55+ destroy if title == "delete me"
56+ end
57+ end
58+
59+ after do
60+ Cover . reset_callbacks ( :save )
61+ end
62+
63+ it "does not set the created_at timestamp" do
64+ book . covers << Cover . new ( title : "delete me" )
65+ expect {
66+ book . save
67+ } . not_to raise_error
68+ end
69+ end
4770end
You can’t perform that action at this time.
0 commit comments