-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor adapters to implement support for array serialization
- Loading branch information
1 parent
efea975
commit 557b56a
Showing
11 changed files
with
137 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'test_helper' | ||
|
||
module ActiveModel | ||
class Serializer | ||
class Adapter | ||
class Json | ||
class Collection < Minitest::Test | ||
def setup | ||
@first_post = Post.new(id: 1, title: 'Hello!!', body: 'Hello, world!!') | ||
@second_post = Post.new(id: 2, title: 'New Post', body: 'Body') | ||
@first_post.comments = [] | ||
@second_post.comments = [] | ||
|
||
@serializer = ArraySerializer.new([@first_post, @second_post]) | ||
@adapter = ActiveModel::Serializer::Adapter::Json.new(@serializer) | ||
end | ||
|
||
def test_include_multiple_posts | ||
assert_equal([ | ||
{title: "Hello!!", body: "Hello, world!!", id: 1, comments: []}, | ||
{title: "New Post", body: "Body", id: 2, comments: []} | ||
], @adapter.serializable_hash) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'test_helper' | ||
|
||
module ActiveModel | ||
class Serializer | ||
class Adapter | ||
class JsonApi | ||
class Collection < Minitest::Test | ||
def setup | ||
@first_post = Post.new(id: 1, title: 'Hello!!', body: 'Hello, world!!') | ||
@second_post = Post.new(id: 2, title: 'New Post', body: 'Body') | ||
@first_post.comments = [] | ||
@second_post.comments = [] | ||
|
||
@serializer = ArraySerializer.new([@first_post, @second_post]) | ||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer) | ||
end | ||
|
||
def test_include_multiple_posts | ||
assert_equal([ | ||
{title: "Hello!!", body: "Hello, world!!", id: 1, links: {comments: []}}, | ||
{title: "New Post", body: "Body", id: 2, links: {comments: []}} | ||
], @adapter.serializable_hash[:posts]) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters