File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,20 @@ module Created
22
22
# @example Set the created at time.
23
23
# person.set_created_at
24
24
def set_created_at
25
- if ! timeless? && ! created_at
25
+ if able_to_set_created_at?
26
26
time = Time . configured . now
27
27
self . updated_at = time if is_a? ( Updated ) && !updated_at_changed?
28
28
self . created_at = time
29
29
end
30
30
clear_timeless_option
31
31
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
32
39
end
33
40
end
34
41
end
Original file line number Diff line number Diff line change 43
43
expect ( quiz . created_at ) . to be_within ( 10 ) . of ( Time . now . utc )
44
44
end
45
45
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
46
69
end
You can’t perform that action at this time.
0 commit comments