このコミットが含まれているのは:
2026-07-16 19:35:21 +09:00
コミット d1de631eed
11個のファイルの変更396行の追加37行の削除
+38
ファイルの表示
@@ -244,6 +244,44 @@ RSpec.describe Post, type: :model do
end
describe 'original created datetime validation' do
it 'allows unrelated updates on persisted posts with second-bearing datetimes' do
post = described_class.create!(title: 'title', url: 'https://example.com/post')
post.update_columns(
original_created_from: Time.zone.parse('2024-01-01T12:34:30Z'),
original_created_before: Time.zone.parse('2024-01-01T12:35:30Z')
)
post.title = 'updated title'
expect(post).to be_valid
expect { post.save! }.not_to raise_error
end
it 'rejects second-bearing updates when the datetime field changes' do
post = described_class.create!(title: 'title', url: 'https://example.com/post')
post.original_created_from = '2024-01-01T12:34:30Z'
expect(post).to be_invalid
expect(post.errors[:original_created_from]).to eq(
[described_class::ORIGINAL_CREATED_MINUTE_PRECISION_MESSAGE]
)
end
it 'accepts fixing persisted datetimes to minute precision' do
post = described_class.create!(title: 'title', url: 'https://example.com/post')
post.update_columns(
original_created_from: Time.zone.parse('2024-01-01T12:34:30Z'),
original_created_before: Time.zone.parse('2024-01-01T12:35:30Z')
)
post.original_created_from = '2024-01-01T12:34Z'
post.original_created_before = '2024-01-01T12:35Z'
expect(post).to be_valid
expect { post.save! }.not_to raise_error
end
it 'adds only the minute-precision error for second precision values' do
post = described_class.new(
title: 'title',