test/unit/serializer/serializer_test.rb in jsonapi-resources-0.5.9 vs test/unit/serializer/serializer_test.rb in jsonapi-resources-0.6.0
- old
+ new
@@ -21,11 +21,11 @@
def test_serializer
serialized = JSONAPI::ResourceSerializer.new(
PostResource,
- base_url: 'http://example.com').serialize_to_hash(PostResource.new(@post)
+ base_url: 'http://example.com').serialize_to_hash(PostResource.new(@post, nil)
)
assert_hash_equals(
{
data: {
@@ -116,11 +116,11 @@
}
}
},
JSONAPI::ResourceSerializer.new(Api::V1::PostResource,
base_url: 'http://example.com').serialize_to_hash(
- Api::V1::PostResource.new(@post))
+ Api::V1::PostResource.new(@post, nil))
)
end
def test_serializer_limited_fieldset
@@ -144,19 +144,19 @@
}
}
}
},
JSONAPI::ResourceSerializer.new(PostResource,
- fields: {posts: [:id, :title, :author]}).serialize_to_hash(PostResource.new(@post))
+ fields: {posts: [:id, :title, :author]}).serialize_to_hash(PostResource.new(@post, nil))
)
end
def test_serializer_include
serialized = JSONAPI::ResourceSerializer.new(
PostResource,
include: ['author']
- ).serialize_to_hash(PostResource.new(@post))
+ ).serialize_to_hash(PostResource.new(@post, nil))
assert_hash_equals(
{
data: {
type: 'posts',
@@ -254,11 +254,11 @@
def test_serializer_key_format
serialized = JSONAPI::ResourceSerializer.new(
PostResource,
include: ['author'],
key_formatter: UnderscoredKeyFormatter
- ).serialize_to_hash(PostResource.new(@post))
+ ).serialize_to_hash(PostResource.new(@post, nil))
assert_hash_equals(
{
data: {
type: 'posts',
@@ -523,19 +523,19 @@
}
}
]
},
JSONAPI::ResourceSerializer.new(PostResource,
- include: ['comments', 'comments.tags']).serialize_to_hash(PostResource.new(@post))
+ include: ['comments', 'comments.tags']).serialize_to_hash(PostResource.new(@post, nil))
)
end
def test_serializer_different_foreign_key
serialized = JSONAPI::ResourceSerializer.new(
PersonResource,
include: ['comments']
- ).serialize_to_hash(PersonResource.new(@fred))
+ ).serialize_to_hash(PersonResource.new(@fred, nil))
assert_hash_equals(
{
data: {
type: 'people',
@@ -654,11 +654,11 @@
def test_serializer_array_of_resources_always_include_to_one_linkage_data
posts = []
Post.find(1, 2).each do |post|
- posts.push PostResource.new(post)
+ posts.push PostResource.new(post, nil)
end
JSONAPI.configuration.always_include_to_one_linkage_data = true
assert_hash_equals(
@@ -970,11 +970,11 @@
def test_serializer_array_of_resources
posts = []
Post.find(1, 2).each do |post|
- posts.push PostResource.new(post)
+ posts.push PostResource.new(post, nil)
end
assert_hash_equals(
{
data: [
@@ -1245,11 +1245,11 @@
def test_serializer_array_of_resources_limited_fields
posts = []
Post.find(1, 2).each do |post|
- posts.push PostResource.new(post)
+ posts.push PostResource.new(post, nil)
end
assert_hash_equals(
{
data: [
@@ -1474,17 +1474,17 @@
]
},
JSONAPI::ResourceSerializer.new(ExpenseEntryResource,
include: ['iso_currency', 'employee'],
fields: {people: [:id, :name, :email, :date_joined]}).serialize_to_hash(
- ExpenseEntryResource.new(@expense_entry))
+ ExpenseEntryResource.new(@expense_entry, nil))
)
end
def test_serializer_empty_links_null_and_array
planet_hash = JSONAPI::ResourceSerializer.new(PlanetResource).serialize_to_hash(
- PlanetResource.new(Planet.find(8)))
+ PlanetResource.new(Planet.find(8), nil))
assert_hash_equals(
{
data: {
type: 'planets',
@@ -1521,11 +1521,11 @@
end
def test_serializer_include_with_empty_links_null_and_array
planets = []
Planet.find(7, 8).each do |planet|
- planets.push PlanetResource.new(planet)
+ planets.push PlanetResource.new(planet, nil)
end
planet_hash = JSONAPI::ResourceSerializer.new(PlanetResource,
include: ['planet_type'],
fields: { planet_types: [:id, :name] }).serialize_to_hash(planets)
@@ -1617,11 +1617,11 @@
def test_serializer_booleans
original_config = JSONAPI.configuration.dup
JSONAPI.configuration.json_key_format = :underscored_key
- preferences = PreferencesResource.new(Preferences.find(1))
+ preferences = PreferencesResource.new(Preferences.find(1), nil)
assert_hash_equals(
{
data: {
type: 'preferences',
@@ -1656,11 +1656,11 @@
def test_serializer_data_types
original_config = JSONAPI.configuration.dup
JSONAPI.configuration.json_key_format = :underscored_key
- facts = FactResource.new(Fact.find(1))
+ facts = FactResource.new(Fact.find(1), nil)
assert_hash_equals(
{
data: {
type: 'facts',
@@ -1689,10 +1689,10 @@
def test_serializer_to_one
serialized = JSONAPI::ResourceSerializer.new(
Api::V5::AuthorResource,
include: ['author_detail']
- ).serialize_to_hash(Api::V5::AuthorResource.new(Person.find(1)))
+ ).serialize_to_hash(Api::V5::AuthorResource.new(Person.find(1), nil))
assert_hash_equals(
{
data: {
type: 'authors',