mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
commit
62484e758c
@ -3,6 +3,7 @@ require "active_support/core_ext/string/inflections"
|
||||
require "active_support/notifications"
|
||||
require "active_model"
|
||||
require "active_model/serializer"
|
||||
require "set"
|
||||
|
||||
if defined?(Rails)
|
||||
module ActiveModel
|
||||
@ -63,6 +64,7 @@ module ActiveModel::ArraySerializerSupport
|
||||
end
|
||||
|
||||
Array.send(:include, ActiveModel::ArraySerializerSupport)
|
||||
Set.send(:include, ActiveModel::ArraySerializerSupport)
|
||||
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
ActiveRecord::Relation.send(:include, ActiveModel::ArraySerializerSupport)
|
||||
|
||||
@ -434,6 +434,22 @@ class SerializerTest < ActiveModel::TestCase
|
||||
], serializer.as_json)
|
||||
end
|
||||
|
||||
def test_sets_can_be_serialized
|
||||
post1 = Post.new(:title => "Post1", :author => "Author1", :id => 1)
|
||||
post2 = Post.new(:title => "Post2", :author => "Author2", :id => 2)
|
||||
|
||||
set = Set.new
|
||||
set << post1
|
||||
set << post2
|
||||
|
||||
serializer = set.active_model_serializer.new set, :each_serializer => CustomPostSerializer
|
||||
|
||||
assert_equal([
|
||||
{ :title => "Post1" },
|
||||
{ :title => "Post2" }
|
||||
], serializer.as_json)
|
||||
end
|
||||
|
||||
class CustomBlog < Blog
|
||||
attr_accessor :public_posts, :public_user
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user