Deprecate the keys for association `restrict_dependent_destroy` errors in favor of new key names #20668

Merged
merged 1 commit into from Jul 21, 2015

Conversation

Projects
None yet
2 participants
@repinel
Member

repinel commented Jun 23, 2015

As suggested by #11658 (comment), it deprecates the restrict_dependent_destroy errors keys in favor of better key names.

The :'restrict_dependent_destroy.one' key should be replaced with :'restrict_dependent_destroy.has_one', and :'restrict_dependent_destroy.many' with :'restrict_dependent_destroy.has_many'.

@rafaelfranca Is this what you expected?

Closes #11658

@repinel

This comment has been minimized.

Show comment
Hide comment
@repinel

repinel Jul 10, 2015

Member

@rafaelfranca What do you think?

Member

repinel commented Jul 10, 2015

@rafaelfranca What do you think?

@repinel

This comment has been minimized.

Show comment
Hide comment
@repinel

repinel Jul 21, 2015

Member

@rafaelfranca Is this one still valid?

(sorry for the multiples pings)

Member

repinel commented Jul 21, 2015

@rafaelfranca Is this one still valid?

(sorry for the multiples pings)

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Jul 21, 2015

Member

(sorry for the multiples pings)

No problem at all. I way back in my backlog lately.

Member

rafaelfranca commented Jul 21, 2015

(sorry for the multiples pings)

No problem at all. I way back in my backlog lately.

+ assert !firm.errors.empty?
+
+ assert_equal 'message for deprecated key', firm.errors[:base].first
+ assert RestrictedWithErrorFirm.exists?(:name => 'restrict')

This comment has been minimized.

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax.

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax.

+ 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')

This comment has been minimized.

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax

+ 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')

This comment has been minimized.

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax

+
+ assert_equal 'message for deprecated key', firm.errors[:base].first
+ assert RestrictedWithErrorFirm.exists?(:name => 'restrict')
+ assert firm.companies.exists?(:name => 'child')

This comment has been minimized.

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax

@rafaelfranca

rafaelfranca Jul 21, 2015

Member

New hash syntax

Deprecate and rename the keys for association restrict_dependent_destroy
Previously `has_one` and `has_many` associations were using the
`one` and `many` keys respectively. Both of these keys have special
meaning in I18n (they are considered to be pluralizations) so by
renaming them to `has_one` and `has_many` we make the messages more
explicit and most importantly they don't clash with linguistical
systems that need to validate translation keys (and their
pluralizations).

The `:'restrict_dependent_destroy.one'` key should be replaced with
`:'restrict_dependent_destroy.has_one'`, and
`:'restrict_dependent_destroy.many'` with
`:'restrict_dependent_destroy.has_many'`.

[Roque Pinel & Christopher Dell]
@repinel

This comment has been minimized.

Show comment
Hide comment
@repinel

repinel Jul 21, 2015

Member

@rafaelfranca I fixed the hash syntax.

Member

repinel commented Jul 21, 2015

@rafaelfranca I fixed the hash syntax.

rafaelfranca added a commit that referenced this pull request Jul 21, 2015

Merge pull request #20668 from repinel/rename-restrict-dependent-dest…
…roy-i18n-key

Deprecate the keys for association `restrict_dependent_destroy` errors in favor of new key names

@rafaelfranca rafaelfranca merged commit 36ea89a into rails:master Jul 21, 2015

@repinel

This comment has been minimized.

Show comment
Hide comment
@repinel

repinel Jul 21, 2015

Member

💚 💛 💙

Member

repinel commented Jul 21, 2015

💚 💛 💙

@repinel repinel deleted the repinel:rename-restrict-dependent-destroy-i18n-key branch Jul 21, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment