Skip to content

Commit 143e58c

Browse files
committed
Consolidate timestamps tests for rails#34970 and a939506
The `timestamps` tests for rails#34970 and a939506 are mostly overlapped, so consolidate these tests as "test timestamps with implicit defalut".
1 parent d25da2d commit 143e58c

File tree

1 file changed

+12
-63
lines changed

1 file changed

+12
-63
lines changed

activerecord/test/cases/active_record_schema_test.rb

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ def test_timestamps_with_and_without_zones
138138
end
139139
end
140140

141-
def test_timestamps_without_null_set_null_to_false_on_create_table
141+
def test_timestamps_with_implicit_default_on_create_table
142142
ActiveRecord::Schema.define do
143143
create_table :has_timestamps do |t|
144144
t.timestamps
145145
end
146146
end
147147

148-
assert @connection.column_exists?(:has_timestamps, :created_at, null: false)
149-
assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
148+
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
149+
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
150150
end
151151

152-
def test_timestamps_without_null_set_null_to_false_on_change_table
152+
def test_timestamps_with_implicit_default_on_change_table
153153
ActiveRecord::Schema.define do
154154
create_table :has_timestamps
155155

@@ -158,12 +158,12 @@ def test_timestamps_without_null_set_null_to_false_on_change_table
158158
end
159159
end
160160

161-
assert @connection.column_exists?(:has_timestamps, :created_at, null: false)
162-
assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
161+
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
162+
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
163163
end
164164

165165
if ActiveRecord::Base.lease_connection.supports_bulk_alter?
166-
def test_timestamps_without_null_set_null_to_false_on_change_table_with_bulk
166+
def test_timestamps_with_implicit_default_on_change_table_with_bulk
167167
ActiveRecord::Schema.define do
168168
create_table :has_timestamps
169169

@@ -172,69 +172,18 @@ def test_timestamps_without_null_set_null_to_false_on_change_table_with_bulk
172172
end
173173
end
174174

175-
assert @connection.column_exists?(:has_timestamps, :created_at, null: false)
176-
assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
175+
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
176+
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
177177
end
178178
end
179179

180-
def test_timestamps_without_null_set_null_to_false_on_add_timestamps
180+
def test_timestamps_with_implicit_default_on_add_timestamps
181181
ActiveRecord::Schema.define do
182182
create_table :has_timestamps
183183
add_timestamps :has_timestamps, default: Time.now
184184
end
185185

186-
assert @connection.column_exists?(:has_timestamps, :created_at, null: false)
187-
assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
188-
end
189-
190-
if supports_datetime_with_precision?
191-
def test_timestamps_sets_precision_on_create_table
192-
ActiveRecord::Schema.define do
193-
create_table :has_timestamps do |t|
194-
t.timestamps
195-
end
196-
end
197-
198-
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
199-
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
200-
end
201-
202-
def test_timestamps_sets_precision_on_change_table
203-
ActiveRecord::Schema.define do
204-
create_table :has_timestamps
205-
206-
change_table :has_timestamps do |t|
207-
t.timestamps default: Time.now
208-
end
209-
end
210-
211-
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
212-
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
213-
end
214-
215-
if ActiveRecord::Base.lease_connection.supports_bulk_alter?
216-
def test_timestamps_sets_precision_on_change_table_with_bulk
217-
ActiveRecord::Schema.define do
218-
create_table :has_timestamps
219-
220-
change_table :has_timestamps, bulk: true do |t|
221-
t.timestamps default: Time.now
222-
end
223-
end
224-
225-
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
226-
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
227-
end
228-
end
229-
230-
def test_timestamps_sets_precision_on_add_timestamps
231-
ActiveRecord::Schema.define do
232-
create_table :has_timestamps
233-
add_timestamps :has_timestamps, default: Time.now
234-
end
235-
236-
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
237-
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
238-
end
186+
assert @connection.column_exists?(:has_timestamps, :created_at, precision: 6, null: false)
187+
assert @connection.column_exists?(:has_timestamps, :updated_at, precision: 6, null: false)
239188
end
240189
end

0 commit comments

Comments
 (0)