Merge pull request #651 from gauthier-delacroix/Plural-default-root

Add plural_default_root config option
This commit is contained in:
Steve Klabnik 2014-09-20 17:44:58 -04:00
commit da81c97e59
2 changed files with 7 additions and 1 deletions

View File

@ -72,7 +72,10 @@ end
alias root= _root=
def root_name
name.demodulize.underscore.sub(/_serializer$/, '') if name
if name
root_name = name.demodulize.underscore.sub(/_serializer$/, '')
CONFIG.plural_default_root ? root_name.pluralize : root_name
end
end
def attributes(*attrs)

View File

@ -78,6 +78,9 @@ module ActiveModel
assert !association.embed_objects?
assert association.embed_in_root
assert_equal :lower_camel, association.key_format
assert_equal 'post', PostSerializer.root_name
CONFIG.plural_default_root = true
assert_equal 'posts', PostSerializer.root_name
ensure
PostSerializer._associations[:comments] = old_association
CONFIG.clear