Permalink
Browse files

Remove deprecated i18n scopes in Active Record

  • Loading branch information...
rafaelfranca committed Nov 29, 2016
1 parent f64e2eb commit 00e3973a31181decc1b1574bf78bfa0226f0f04b
@@ -1,3 +1,8 @@
* Remove deprecated `activerecord.errors.messages.restrict_dependent_destroy.one` and
`activerecord.errors.messages.restrict_dependent_destroy.many` i18n scopes.
*Rafael Mendonça França*
* Allow passing extra flags to `db:structure:load` and `db:structure:dump`
Introduces `ActiveRecord::Tasks::DatabaseTasks.structure_(load|dump)_flags` to customize the
@@ -16,14 +16,7 @@ def handle_dependency
when :restrict_with_error
unless empty?
record = owner.class.human_attribute_name(reflection.name).downcase
message = owner.errors.generate_message(:base, :'restrict_dependent_destroy.many', record: record, raise: true) rescue nil
if message
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
The error key `:'restrict_dependent_destroy.many'` has been deprecated and will be removed in Rails 5.1.
Please use `:'restrict_dependent_destroy.has_many'` instead.
MESSAGE
end
owner.errors.add(:base, message || :'restrict_dependent_destroy.has_many', record: record)
owner.errors.add(:base, :'restrict_dependent_destroy.has_many', record: record)
throw(:abort)
end
@@ -12,14 +12,7 @@ def handle_dependency
when :restrict_with_error
if load_target
record = owner.class.human_attribute_name(reflection.name).downcase
message = owner.errors.generate_message(:base, :'restrict_dependent_destroy.one', record: record, raise: true) rescue nil
if message
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
The error key `:'restrict_dependent_destroy.one'` has been deprecated and will be removed in Rails 5.1.
Please use `:'restrict_dependent_destroy.has_one'` instead.
MESSAGE
end
owner.errors.add(:base, message || :'restrict_dependent_destroy.has_one', record: record)
owner.errors.add(:base, :'restrict_dependent_destroy.has_one', record: record)
throw(:abort)
end
@@ -1582,26 +1582,6 @@ def test_restrict_with_exception
assert firm.companies.exists?(name: "child")
end
def test_restrict_with_error_is_deprecated_using_key_many
I18n.backend = I18n::Backend::Simple.new
I18n.backend.store_translations :en, activerecord: { errors: { messages: { restrict_dependent_destroy: { many: "message for deprecated key" } } } }
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.companies.create(name: "child")
assert !firm.companies.empty?
assert_deprecated { firm.destroy }
assert !firm.errors.empty?
assert_equal "message for deprecated key", firm.errors[:base].first
assert RestrictedWithErrorFirm.exists?(name: "restrict")
assert firm.companies.exists?(name: "child")
ensure
I18n.backend.reload!
end
def test_restrict_with_error
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.companies.create(name: "child")
@@ -186,25 +186,6 @@ def test_restrict_with_exception
assert firm.account.present?
end
def test_restrict_with_error_is_deprecated_using_key_one
I18n.backend = I18n::Backend::Simple.new
I18n.backend.store_translations :en, activerecord: { errors: { messages: { restrict_dependent_destroy: { one: "message for deprecated key" } } } }
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.create_account(credit_limit: 10)
assert_not_nil firm.account
assert_deprecated { firm.destroy }
assert !firm.errors.empty?
assert_equal "message for deprecated key", firm.errors[:base].first
assert RestrictedWithErrorFirm.exists?(name: "restrict")
assert firm.account.present?
ensure
I18n.backend.reload!
end
def test_restrict_with_error
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.create_account(credit_limit: 10)

0 comments on commit 00e3973

Please sign in to comment.