Skip to content

Commit 9ce2405

Browse files
authored
Merge branch 'master' into fresh-thread-tagged-logging
2 parents 143a6cf + 2d84a6b commit 9ce2405

File tree

10 files changed

+65
-9
lines changed

10 files changed

+65
-9
lines changed

activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ def requires_reloading?
439439
# This is done under the hood by calling #active?. If the connection
440440
# is no longer active, then this method will reconnect to the database.
441441
def verify!(*ignored)
442+
if ignored.size > 0
443+
ActiveSupport::Deprecation.warn("Passing arguments to #verify method of the connection has no effect and has been deprecated. Please remove all arguments from the #verify method call.")
444+
end
442445
reconnect! unless active?
443446
end
444447

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,11 +786,11 @@ def add_column_sql(table_name, column_name, type, options = {})
786786
def change_column_sql(table_name, column_name, type, options = {})
787787
column = column_for(table_name, column_name)
788788

789-
unless options_include_default?(options)
789+
unless options.key?(:default)
790790
options[:default] = column.default
791791
end
792792

793-
unless options.has_key?(:null)
793+
unless options.key?(:null)
794794
options[:null] = column.null
795795
end
796796

activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def change_column(table_name, column_name, type, options = {}) #:nodoc:
489489
end
490490
execute sql
491491

492-
change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
492+
change_column_default(table_name, column_name, options[:default]) if options.key?(:default)
493493
change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null)
494494
change_column_comment(table_name, column_name, options[:comment]) if options.key?(:comment)
495495
end

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,10 @@ def change_column_null(table_name, column_name, null, default = nil) #:nodoc:
420420

421421
def change_column(table_name, column_name, type, options = {}) #:nodoc:
422422
alter_table(table_name) do |definition|
423-
include_default = options_include_default?(options)
424423
definition[column_name].instance_eval do
425424
self.type = type
426425
self.limit = options[:limit] if options.include?(:limit)
427-
self.default = options[:default] if include_default
426+
self.default = options[:default] if options.include?(:default)
428427
self.null = options[:null] if options.include?(:null)
429428
self.precision = options[:precision] if options.include?(:precision)
430429
self.scale = options[:scale] if options.include?(:scale)

activerecord/test/cases/adapters/mysql2/connection_test.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_no_automatic_reconnection_after_timeout
4242
@connection.update("set @@wait_timeout=1")
4343
sleep 2
4444
assert !@connection.active?
45-
45+
ensure
4646
# Repair all fixture connections so other tests won't break.
4747
@fixture_connections.each(&:verify!)
4848
end
@@ -63,6 +63,18 @@ def test_successful_reconnection_after_timeout_with_verify
6363
assert @connection.active?
6464
end
6565

66+
def test_verify_with_args_is_deprecated
67+
assert_deprecated do
68+
@connection.verify!(option: true)
69+
end
70+
assert_deprecated do
71+
@connection.verify!([])
72+
end
73+
assert_deprecated do
74+
@connection.verify!({})
75+
end
76+
end
77+
6678
def test_execute_after_disconnect
6779
@connection.disconnect!
6880

activerecord/test/cases/adapters/postgresql/connection_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def test_reconnection_after_actual_disconnection_with_verify
178178
"umm -- looks like you didn't break the connection, because we're still " \
179179
"successfully querying with the same connection pid."
180180

181+
ensure
181182
# Repair all fixture connections so other tests won't break.
182183
@fixture_connections.each(&:verify!)
183184
end

activerecord/test/cases/migration/columns_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ def test_change_column_with_nil_default
225225
assert_nil TestModel.new.contributor
226226
end
227227

228+
def test_change_column_to_drop_default_with_null_false
229+
add_column "test_models", "contributor", :boolean, default: true, null: false
230+
assert TestModel.new.contributor?
231+
232+
change_column "test_models", "contributor", :boolean, default: nil, null: false
233+
TestModel.reset_column_information
234+
assert_not TestModel.new.contributor?
235+
assert_nil TestModel.new.contributor
236+
end
237+
228238
def test_change_column_with_new_default
229239
add_column "test_models", "administrator", :boolean, default: true
230240
assert TestModel.new.administrator?

activesupport/CHANGELOG.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
* Add `ActiveSupport::Duration#before` and `#after` as aliases for `#until` and `#since`
2+
3+
These read more like English and require less mental gymnastics to read and write.
4+
5+
Before:
6+
7+
2.weeks.since(customer_start_date)
8+
5.days.until(today)
9+
10+
After:
11+
12+
2.weeks.after(customer_start_date)
13+
5.days.before(today)
14+
15+
*Nick Johnstone*
16+
117
* Soft-deprecated the top-level `HashWithIndifferentAccess` constant.
218
`ActiveSupport::HashWithIndifferentAccess` should be used instead.
319

420
*Robin Dupret* (#28157)
521

622
* In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
723
argument for `Marshal#load( source [, proc] )`. This way we don't have to do
8-
`Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
24+
`Marshal.method(:load).super_method.call(source, proc)` just to be able to pass a proc.
925

1026
*Jeff Latz*
1127

@@ -20,7 +36,7 @@
2036

2137
*Adam Rice*
2238

23-
* Deprecate `.halt_callback_chains_on_return_false`.
39+
* Deprecate `ActiveSupport.halt_callback_chains_on_return_false`.
2440

2541
*Rafael Mendonça França*
2642

@@ -83,7 +99,7 @@
8399
duration's numeric value isn't used in calculations, only parts are used.
84100

85101
Methods on `Numeric` like `2.days` now use these predefined durations
86-
to avoid duplicating of duration constants through the codebase and
102+
to avoid duplication of duration constants through the codebase and
87103
eliminate creation of intermediate durations.
88104

89105
*Andrey Novikov, Andrew White*

activesupport/lib/active_support/duration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,15 @@ def since(time = ::Time.current)
180180
sum(1, time)
181181
end
182182
alias :from_now :since
183+
alias :after :since
183184

184185
# Calculates a new Time or Date that is as far in the past
185186
# as this Duration represents.
186187
def ago(time = ::Time.current)
187188
sum(-1, time)
188189
end
189190
alias :until :ago
191+
alias :before :ago
190192

191193
def inspect #:nodoc:
192194
parts.

activesupport/test/core_ext/duration_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@ def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set
179179
Time.zone = nil
180180
end
181181

182+
def test_before_and_afer
183+
t = Time.local(2000)
184+
assert_equal t + 1, 1.second.after(t)
185+
assert_equal t - 1, 1.second.before(t)
186+
end
187+
188+
def test_before_and_after_without_argument
189+
Time.stub(:now, Time.local(2000)) do
190+
assert_equal Time.now - 1.second, 1.second.before
191+
assert_equal Time.now + 1.second, 1.second.after
192+
end
193+
end
194+
182195
def test_adding_hours_across_dst_boundary
183196
with_env_tz "CET" do
184197
assert_equal Time.local(2009, 3, 29, 0, 0, 0) + 24.hours, Time.local(2009, 3, 30, 1, 0, 0)

0 commit comments

Comments
 (0)