Merge pull request #512 from TimPetricola/fix-options-access

Custom options are accessible in serializer
This commit is contained in:
Steve Klabnik 2014-08-22 16:15:41 -04:00
commit ae7959b76e
2 changed files with 17 additions and 1 deletions

View File

@ -136,8 +136,9 @@ end
@only = options[:only] ? Array(options[:only]) : nil @only = options[:only] ? Array(options[:only]) : nil
@except = options[:except] ? Array(options[:except]) : nil @except = options[:except] ? Array(options[:except]) : nil
@key_format = options[:key_format] @key_format = options[:key_format]
@context = options[:context]
end end
attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format, :context
def json_key def json_key
key = if root == true || root.nil? key = if root == true || root.nil?

View File

@ -0,0 +1,15 @@
require 'test_helper'
module ActiveModel
class Serializer
class OptionsTest < Minitest::Test
def setup
@serializer = ProfileSerializer.new(nil, context: {foo: :bar})
end
def test_custom_options_are_accessible_from_serializer
assert_equal({foo: :bar}, @serializer.context)
end
end
end
end