mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Rename attribute with :key (0.8.x compatibility)
This commit is contained in:
5
test/fixtures/poro.rb
vendored
5
test/fixtures/poro.rb
vendored
@@ -95,3 +95,8 @@ PaginatedSerializer = Class.new(ActiveModel::Serializer::ArraySerializer) do
|
||||
'paginated'
|
||||
end
|
||||
end
|
||||
|
||||
AlternateBlogSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attribute :id
|
||||
attribute :name, key: :title
|
||||
end
|
||||
|
||||
23
test/serializers/attribute_test.rb
Normal file
23
test/serializers/attribute_test.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'test_helper'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class AttributeTest < Minitest::Test
|
||||
def setup
|
||||
@blog = Blog.new({ id: 1, name: 'AMS Hints' })
|
||||
@blog_serializer = AlternateBlogSerializer.new(@blog)
|
||||
end
|
||||
|
||||
def test_attributes_definition
|
||||
assert_equal([:id, :title],
|
||||
@blog_serializer.class._attributes)
|
||||
end
|
||||
|
||||
def test_json_serializable_hash
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(@blog_serializer)
|
||||
assert_equal({:id=>1, :title=>"AMS Hints"}, adapter.serializable_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user