mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 14:29:31 +00:00
Custom options are accessible in serializer (via :context)
This commit is contained in:
parent
045ba2a48c
commit
14b1df5c36
@ -116,8 +116,9 @@ end
|
||||
@only = Array(options[:only]) if options[:only]
|
||||
@except = Array(options[:except]) if options[:except]
|
||||
@key_format = options[:key_format]
|
||||
@context = options[:context]
|
||||
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
|
||||
key = if root == true || root.nil?
|
||||
|
||||
15
test/unit/active_model/serializer/options_test.rb
Normal file
15
test/unit/active_model/serializer/options_test.rb
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user