Skip to content

Commit

Permalink
Remove deprecated i18n scopes in Active Record
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Dec 29, 2016
1 parent f64e2eb commit 00e3973
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 55 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -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` * Allow passing extra flags to `db:structure:load` and `db:structure:dump`


Introduces `ActiveRecord::Tasks::DatabaseTasks.structure_(load|dump)_flags` to customize the Introduces `ActiveRecord::Tasks::DatabaseTasks.structure_(load|dump)_flags` to customize the
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ def handle_dependency
when :restrict_with_error when :restrict_with_error
unless empty? unless empty?
record = owner.class.human_attribute_name(reflection.name).downcase 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 owner.errors.add(:base, :'restrict_dependent_destroy.has_many', record: record)
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)
throw(:abort) throw(:abort)
end end


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ def handle_dependency
when :restrict_with_error when :restrict_with_error
if load_target if load_target
record = owner.class.human_attribute_name(reflection.name).downcase 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 owner.errors.add(:base, :'restrict_dependent_destroy.has_one', record: record)
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)
throw(:abort) throw(:abort)
end end


Expand Down
20 changes: 0 additions & 20 deletions activerecord/test/cases/associations/has_many_associations_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1582,26 +1582,6 @@ def test_restrict_with_exception
assert firm.companies.exists?(name: "child") assert firm.companies.exists?(name: "child")
end 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 def test_restrict_with_error
firm = RestrictedWithErrorFirm.create!(name: "restrict") firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.companies.create(name: "child") firm.companies.create(name: "child")
Expand Down
19 changes: 0 additions & 19 deletions activerecord/test/cases/associations/has_one_associations_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,25 +186,6 @@ def test_restrict_with_exception
assert firm.account.present? assert firm.account.present?
end 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 def test_restrict_with_error
firm = RestrictedWithErrorFirm.create!(name: "restrict") firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.create_account(credit_limit: 10) firm.create_account(credit_limit: 10)
Expand Down

0 comments on commit 00e3973

Please sign in to comment.