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
23
23
# @example Set the created at time.
24
24
# person.set_created_at
25
25
def set_created_at
26
- if ! timeless? && ! created_at
26
+ if able_to_set_created_at?
27
27
now = Time . current
28
28
self . updated_at = now if is_a? ( Updated ) && !updated_at_changed?
29
29
self . created_at = now
30
30
end
31
31
clear_timeless_option
32
32
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
33
40
end
34
41
end
35
42
end
Original file line number Diff line number Diff line change 44
44
expect ( quiz . created_at ) . to be_within ( 10 ) . of ( Time . now . utc )
45
45
end
46
46
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
47
70
end
You can’t perform that action at this time.
0 commit comments