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