|
85 | 85 | user = staging_model.first |
86 | 86 | expect(user.created_at).to be_within(1.second).of(now) |
87 | 87 | end |
| 88 | + |
| 89 | + it "automatically sets created_at and updated_at when not provided" do |
| 90 | + records = [ |
| 91 | + {name: "John", email: "john@example.com"} |
| 92 | + ] |
| 93 | + |
| 94 | + freeze_time = Time.current |
| 95 | + allow(Time).to receive(:current).and_return(freeze_time) |
| 96 | + |
| 97 | + inserter.insert(records) |
| 98 | + |
| 99 | + user = staging_model.first |
| 100 | + expect(user.created_at).to be_within(1.second).of(freeze_time) |
| 101 | + expect(user.updated_at).to be_within(1.second).of(freeze_time) |
| 102 | + end |
| 103 | + |
| 104 | + it "does not override provided timestamps" do |
| 105 | + custom_time = 1.day.ago |
| 106 | + records = [ |
| 107 | + {name: "John", email: "john@example.com", created_at: custom_time, updated_at: custom_time} |
| 108 | + ] |
| 109 | + |
| 110 | + inserter.insert(records) |
| 111 | + |
| 112 | + user = staging_model.first |
| 113 | + expect(user.created_at).to be_within(1.second).of(custom_time) |
| 114 | + expect(user.updated_at).to be_within(1.second).of(custom_time) |
| 115 | + end |
| 116 | + |
| 117 | + it "handles string keys for timestamps" do |
| 118 | + custom_time = 2.days.ago |
| 119 | + records = [ |
| 120 | + {"name" => "John", "email" => "john@example.com", "created_at" => custom_time, "updated_at" => custom_time} |
| 121 | + ] |
| 122 | + |
| 123 | + inserter.insert(records) |
| 124 | + |
| 125 | + user = staging_model.first |
| 126 | + expect(user.created_at).to be_within(1.second).of(custom_time) |
| 127 | + expect(user.updated_at).to be_within(1.second).of(custom_time) |
| 128 | + end |
88 | 129 | end |
89 | 130 | end |
90 | 131 |
|
|
0 commit comments