Merge pull request #453 from jasontruluck/master

Add @options back into serializers for passing custom options
This commit is contained in:
Santiago Pastorino 2013-11-28 10:38:41 -08:00
commit c65ac37152
3 changed files with 20 additions and 2 deletions

View File

@ -20,7 +20,7 @@ module ActiveModel
@each_serializer = options[:each_serializer]
@options = options.merge(root: nil)
end
attr_accessor :object, :root, :meta_key, :meta
attr_accessor :object, :root, :meta_key, :meta, :options
def json_key
if root.nil?

View File

@ -106,8 +106,9 @@ end
@root = options.fetch(:root, self.class._root)
@meta_key = options[:meta_key] || :meta
@meta = options[@meta_key]
@options = options.reject{|k,v| [:scope, :root, :meta_key, :meta].include?(k) }
end
attr_accessor :object, :scope, :meta_key, :meta, :root
attr_accessor :object, :scope, :meta_key, :meta, :root, :options
def json_key
if root == true || root.nil?

View File

@ -0,0 +1,17 @@
require 'test_helper'
module ActiveModel
class Serializer
class OptionsTest < ActiveModel::TestCase
def setup
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
end
def test_meta
profile_serializer = ProfileSerializer.new(@profile, root: 'profile', random_option: "This is an option")
assert_equal("This is an option", profile_serializer.options[:random_option])
end
end
end
end