Skip to content

Commit

Permalink
Merge pull request #39320 from trevorrjohn/i18n_key
Browse files Browse the repository at this point in the history
Set i18n_key defined on class or default to name
  • Loading branch information
rafaelfranca committed Sep 23, 2020
2 parents fc2a1ed + 6fba3c3 commit 20423ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/naming.rb
Expand Up @@ -8,7 +8,7 @@ module ActiveModel
class Name
include Comparable

attr_reader :singular, :plural, :element, :collection,
attr_accessor :singular, :plural, :element, :collection,
:singular_route_key, :route_key, :param_key, :i18n_key,
:name

Expand Down
26 changes: 26 additions & 0 deletions activemodel/test/cases/naming_test.rb
Expand Up @@ -280,3 +280,29 @@ def test_model_name
assert_equal Blog::Post.model_name, Blog::Post.new.model_name
end
end

class OverridingAccessorsTest < ActiveModel::TestCase
def test_overriding_accessors_keys
model_name = ActiveModel::Name.new(Post::TrackBack).tap do |name|
name.singular = :singular
name.plural = :plural
name.element = :element
name.collection = :collection
name.singular_route_key = :singular_route_key
name.route_key = :route_key
name.param_key = :param_key
name.i18n_key = :i18n_key
name.name = :name
end

assert_equal :singular, model_name.singular
assert_equal :plural, model_name.plural
assert_equal :element, model_name.element
assert_equal :collection, model_name.collection
assert_equal :singular_route_key, model_name.singular_route_key
assert_equal :route_key, model_name.route_key
assert_equal :param_key, model_name.param_key
assert_equal :i18n_key, model_name.i18n_key
assert_equal :name, model_name.name
end
end

0 comments on commit 20423ef

Please sign in to comment.