-
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.
Adds support for top-level links to JsonApi adapter
http://jsonapi.org/format/#document-top-level fix failing tests support for top-level links limited to jsonapi adapter
- Loading branch information
Showing
9 changed files
with
122 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ test/version_tmp | |
tmp | ||
*.swp | ||
.ruby-version | ||
tags |
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
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,62 @@ | ||
require 'test_helper' | ||
|
||
module ActiveModel | ||
class Serializer | ||
class LinksTest < Minitest::Test | ||
def setup | ||
ActionController::Base.cache_store.clear | ||
@blog = Blog.new(id: 1, | ||
name: 'AMS Hints', | ||
writer: Author.new(id: 2, name: "Steve"), | ||
articles: [Post.new(id: 3, title: "AMS")]) | ||
end | ||
|
||
def test_links_is_present_with_root | ||
serializer = AlternateBlogSerializer.new(@blog, :links => {:self => "/blogs/1"}) | ||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer) | ||
expected = { | ||
data: { | ||
id: "1", | ||
type: "blogs", | ||
attributes: { | ||
title: "AMS Hints" | ||
} | ||
}, | ||
links: { | ||
self: "/blogs/1" | ||
} | ||
} | ||
assert_equal expected, adapter.as_json | ||
end | ||
|
||
def test_links_is_not_present_when_not_declared | ||
serializer = AlternateBlogSerializer.new(@blog) | ||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer) | ||
expected = { | ||
data: { | ||
id: "1", | ||
type: "blogs", | ||
attributes: { | ||
title: "AMS Hints" | ||
} | ||
} | ||
} | ||
assert_equal expected, adapter.as_json | ||
end | ||
|
||
def test_links_is_not_present_on_flattenjson_adapter | ||
serializer = AlternateBlogSerializer.new(@blog, :links => {:self => "/blogs/1"}) | ||
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(serializer) | ||
expected = {:id=>1, :title=>"AMS Hints"} | ||
assert_equal expected, adapter.as_json | ||
end | ||
|
||
def test_links_is_not_present_on_json_adapter | ||
serializer = AlternateBlogSerializer.new(@blog, :links => {:self => "/blogs/1"}) | ||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer) | ||
expected = {:blog=>{:id=>1, :title=>"AMS Hints"}} | ||
assert_equal expected, adapter.as_json | ||
end | ||
end | ||
end | ||
end |