From 08e781569aea7f0e084c169c70b452e337aa1b5f Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Sat, 25 Feb 2017 16:33:06 -0600 Subject: Deprecate AbstractAdapter#verify! with arguments --- .../active_record/connection_adapters/abstract_adapter.rb | 3 +++ activerecord/test/cases/adapters/mysql2/connection_test.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index fd11cab5c0..b66d3a2e14 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -439,6 +439,9 @@ module ActiveRecord # This is done under the hood by calling #active?. If the connection # is no longer active, then this method will reconnect to the database. def verify!(*ignored) + if ignored.size > 0 + ActiveSupport::Deprecation.warn("Passing arguments to #verify method of the connection has no affect and has been deprecated. Please remove all arguments from the #verify method call.") + end reconnect! unless active? end diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index bae283a048..20f1b77f31 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -63,6 +63,18 @@ class Mysql2ConnectionTest < ActiveRecord::Mysql2TestCase assert @connection.active? end + def test_verify_with_args_is_deprecated + assert_deprecated do + @connection.verify!(option: true) + end + assert_deprecated do + @connection.verify!([]) + end + assert_deprecated do + @connection.verify!({}) + end + end + def test_execute_after_disconnect @connection.disconnect! -- cgit v1.2.3 From cb3270cf4e13cfb6ba554e0fa52402657c51d171 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Sat, 25 Feb 2017 19:44:42 -0600 Subject: Use ensure block for things we cleanup in tests --- activerecord/test/cases/adapters/mysql2/connection_test.rb | 2 +- activerecord/test/cases/adapters/postgresql/connection_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index bae283a048..58bf3003b8 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -42,7 +42,7 @@ class Mysql2ConnectionTest < ActiveRecord::Mysql2TestCase @connection.update("set @@wait_timeout=1") sleep 2 assert !@connection.active? - + ensure # Repair all fixture connections so other tests won't break. @fixture_connections.each(&:verify!) end diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb index 3cbd4ca212..98d392f25a 100644 --- a/activerecord/test/cases/adapters/postgresql/connection_test.rb +++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb @@ -178,6 +178,7 @@ module ActiveRecord "umm -- looks like you didn't break the connection, because we're still " \ "successfully querying with the same connection pid." + ensure # Repair all fixture connections so other tests won't break. @fixture_connections.each(&:verify!) end -- cgit v1.2.3 From e842db501f5240fd547e904f173ad8d7b1304f8c Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sun, 26 Feb 2017 10:19:48 +0530 Subject: AS CHANGELOG Pass [ci skip] --- activesupport/CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 6dc301e5b4..2f08d8bc82 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -5,7 +5,7 @@ * In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional argument for `Marshal#load( source [, proc] )`. This way we don't have to do - `Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc. + `Marshal.method(:load).super_method.call(source, proc)` just to be able to pass a proc. *Jeff Latz* @@ -20,7 +20,7 @@ *Adam Rice* -* Deprecate `.halt_callback_chains_on_return_false`. +* Deprecate `ActiveSupport.halt_callback_chains_on_return_false`. *Rafael Mendonça França* @@ -83,7 +83,7 @@ duration's numeric value isn't used in calculations, only parts are used. Methods on `Numeric` like `2.days` now use these predefined durations - to avoid duplicating of duration constants through the codebase and + to avoid duplication of duration constants through the codebase and eliminate creation of intermediate durations. *Andrey Novikov, Andrew White* -- cgit v1.2.3 From c92757fb68f5a281be0f2ea67e369672e9c4ec6d Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 22 Sep 2016 21:22:14 +0900 Subject: Fix `change_column` to drop default with `null: false` Currently `change_column` cannot drop default if `null: false` is specified at the same time. This change fixes the issue. ```ruby # cannot drop default change_column "tests", "contributor", :boolean, default: nil, null: false # we need the following workaround currently change_column "tests", "contributor", :boolean, null: false change_column "tests", "contributor", :boolean, default: nil ``` Closes #26582 --- .../connection_adapters/abstract_mysql_adapter.rb | 4 ++-- .../connection_adapters/postgresql/schema_statements.rb | 2 +- .../lib/active_record/connection_adapters/sqlite3_adapter.rb | 3 +-- activerecord/test/cases/migration/columns_test.rb | 10 ++++++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 5f86a11c2d..f14ac92cf9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -786,11 +786,11 @@ module ActiveRecord def change_column_sql(table_name, column_name, type, options = {}) column = column_for(table_name, column_name) - unless options_include_default?(options) + unless options.key?(:default) options[:default] = column.default end - unless options.has_key?(:null) + unless options.key?(:null) options[:null] = column.null end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index a61d920a73..f91547d148 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -489,7 +489,7 @@ module ActiveRecord end execute sql - change_column_default(table_name, column_name, options[:default]) if options_include_default?(options) + change_column_default(table_name, column_name, options[:default]) if options.key?(:default) change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null) change_column_comment(table_name, column_name, options[:comment]) if options.key?(:comment) end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 16ef195bfc..f55efe7d07 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -420,11 +420,10 @@ module ActiveRecord def change_column(table_name, column_name, type, options = {}) #:nodoc: alter_table(table_name) do |definition| - include_default = options_include_default?(options) definition[column_name].instance_eval do self.type = type self.limit = options[:limit] if options.include?(:limit) - self.default = options[:default] if include_default + self.default = options[:default] if options.include?(:default) self.null = options[:null] if options.include?(:null) self.precision = options[:precision] if options.include?(:precision) self.scale = options[:scale] if options.include?(:scale) diff --git a/activerecord/test/cases/migration/columns_test.rb b/activerecord/test/cases/migration/columns_test.rb index 55c06da411..2329888345 100644 --- a/activerecord/test/cases/migration/columns_test.rb +++ b/activerecord/test/cases/migration/columns_test.rb @@ -225,6 +225,16 @@ module ActiveRecord assert_nil TestModel.new.contributor end + def test_change_column_to_drop_default_with_null_false + add_column "test_models", "contributor", :boolean, default: true, null: false + assert TestModel.new.contributor? + + change_column "test_models", "contributor", :boolean, default: nil, null: false + TestModel.reset_column_information + assert_not TestModel.new.contributor? + assert_nil TestModel.new.contributor + end + def test_change_column_with_new_default add_column "test_models", "administrator", :boolean, default: true assert TestModel.new.administrator? -- cgit v1.2.3 From d15b29177be06c14c8319d4726bb0e39c558faf0 Mon Sep 17 00:00:00 2001 From: Rebecca Skinner Date: Sun, 26 Feb 2017 15:47:15 +0800 Subject: Fix typo 'affect' -> 'effect' [ci skip] --- activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 26eb70d7cd..24007db8f0 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -440,7 +440,7 @@ module ActiveRecord # is no longer active, then this method will reconnect to the database. def verify!(*ignored) if ignored.size > 0 - ActiveSupport::Deprecation.warn("Passing arguments to #verify method of the connection has no affect and has been deprecated. Please remove all arguments from the #verify method call.") + 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.") end reconnect! unless active? end -- cgit v1.2.3 From 2d84a6bc74fbe9d9b97bf7d63ec6f27418d9c3a6 Mon Sep 17 00:00:00 2001 From: Nick Johnstone Date: Wed, 22 Feb 2017 20:45:48 +1300 Subject: Add Duration#before and #after as aliases for #ago and #since It's common in test cases at my job to have code like this: let(:today) { customer_start_date + 2.weeks } let(:earlier_date) { today - 5.days } With this change, we can instead write let(:today) { 2.weeks.after(customer_start_date) } let(:earlier_date) { 5.days.before(today) } Closes #27721 --- activesupport/CHANGELOG.md | 16 ++++++++++++++++ activesupport/lib/active_support/duration.rb | 2 ++ activesupport/test/core_ext/duration_test.rb | 13 +++++++++++++ 3 files changed, 31 insertions(+) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 2f08d8bc82..0614cdaabd 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,19 @@ +* Add `ActiveSupport::Duration#before` and `#after` as aliases for `#until` and `#since` + + These read more like English and require less mental gymnastics to read and write. + + Before: + + 2.weeks.since(customer_start_date) + 5.days.until(today) + + After: + + 2.weeks.after(customer_start_date) + 5.days.before(today) + + *Nick Johnstone* + * Soft-deprecated the top-level `HashWithIndifferentAccess` constant. `ActiveSupport::HashWithIndifferentAccess` should be used instead. diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 003f6203ef..70cf78519d 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -180,6 +180,7 @@ module ActiveSupport sum(1, time) end alias :from_now :since + alias :after :since # Calculates a new Time or Date that is as far in the past # as this Duration represents. @@ -187,6 +188,7 @@ module ActiveSupport sum(-1, time) end alias :until :ago + alias :before :ago def inspect #:nodoc: parts. diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index 6a275d1d5b..6facb04f1f 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -179,6 +179,19 @@ class DurationTest < ActiveSupport::TestCase Time.zone = nil end + def test_before_and_afer + t = Time.local(2000) + assert_equal t + 1, 1.second.after(t) + assert_equal t - 1, 1.second.before(t) + end + + def test_before_and_after_without_argument + Time.stub(:now, Time.local(2000)) do + assert_equal Time.now - 1.second, 1.second.before + assert_equal Time.now + 1.second, 1.second.after + end + end + def test_adding_hours_across_dst_boundary with_env_tz "CET" do assert_equal Time.local(2009, 3, 29, 0, 0, 0) + 24.hours, Time.local(2009, 3, 30, 1, 0, 0) -- cgit v1.2.3