Allow to pass context around serializers

This commit is contained in:
Santiago Pastorino
2014-01-03 20:52:32 -02:00
parent 9bb32331f4
commit 8bd2542ed2
4 changed files with 44 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
require 'test_helper'
module ActiveModel
class ArraySerializer
class ContextTest < ActiveModel::TestCase
def test_context_using_a_hash
serializer = ArraySerializer.new(nil, context: { a: 1, b: 2 })
assert_equal(1, serializer.context[:a])
assert_equal(2, serializer.context[:b])
end
def test_context_using_an_object
serializer = ArraySerializer.new(nil, context: Struct.new(:a, :b).new(1, 2))
assert_equal(1, serializer.context.a)
assert_equal(2, serializer.context.b)
end
end
end
end

View File

@@ -0,0 +1,19 @@
require 'test_helper'
module ActiveModel
class Serializer
class ContextTest < ActiveModel::TestCase
def test_context_using_a_hash
serializer = UserSerializer.new(nil, context: { a: 1, b: 2 })
assert_equal(1, serializer.context[:a])
assert_equal(2, serializer.context[:b])
end
def test_context_using_an_object
serializer = UserSerializer.new(nil, context: Struct.new(:a, :b).new(1, 2))
assert_equal(1, serializer.context.a)
assert_equal(2, serializer.context.b)
end
end
end
end