mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Adjusts JsonApi adapter to serialize attributes in a nested attributes hash
This commit is contained in:
@@ -42,8 +42,10 @@ module ActiveModel
|
||||
expected = [{
|
||||
id: "42",
|
||||
type: "posts",
|
||||
title: 'New Post',
|
||||
body: 'Body',
|
||||
attributes: {
|
||||
title: 'New Post',
|
||||
body: 'Body',
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -58,7 +60,9 @@ module ActiveModel
|
||||
expected = [{
|
||||
id: "42",
|
||||
type: "posts",
|
||||
title: 'New Post',
|
||||
attributes: {
|
||||
title: 'New Post'
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -110,7 +114,9 @@ module ActiveModel
|
||||
{
|
||||
id: "1",
|
||||
type: "authors",
|
||||
name: "Steve K.",
|
||||
attributes: {
|
||||
name: "Steve K."
|
||||
},
|
||||
links: {
|
||||
posts: { linkage: [] },
|
||||
roles: { linkage: [] },
|
||||
@@ -119,8 +125,10 @@ module ActiveModel
|
||||
},{
|
||||
id: "42",
|
||||
type: "posts",
|
||||
title: "New Post",
|
||||
body: "Body",
|
||||
attributes: {
|
||||
title: "New Post",
|
||||
body: "Body"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -129,8 +137,10 @@ module ActiveModel
|
||||
}, {
|
||||
id: "43",
|
||||
type: "posts",
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!",
|
||||
attributes: {
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
|
||||
@@ -29,8 +29,10 @@ module ActiveModel
|
||||
{
|
||||
id: "1",
|
||||
type: "posts",
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!",
|
||||
attributes: {
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -40,8 +42,10 @@ module ActiveModel
|
||||
{
|
||||
id: "2",
|
||||
type: "posts",
|
||||
title: "New Post",
|
||||
body: "Body",
|
||||
attributes: {
|
||||
title: "New Post",
|
||||
body: "Body"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -60,7 +64,9 @@ module ActiveModel
|
||||
{
|
||||
id: "1",
|
||||
type: "posts",
|
||||
title: "Hello!!",
|
||||
attributes: {
|
||||
title: "Hello!!"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -70,7 +76,9 @@ module ActiveModel
|
||||
{
|
||||
id: "2",
|
||||
type: "posts",
|
||||
title: "New Post",
|
||||
attributes: {
|
||||
title: "New Post"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
|
||||
@@ -43,7 +43,9 @@ module ActiveModel
|
||||
expected = [{
|
||||
id: "1",
|
||||
type: "comments",
|
||||
body: 'ZOMG A COMMENT',
|
||||
attributes: {
|
||||
body: 'ZOMG A COMMENT'
|
||||
},
|
||||
links: {
|
||||
post: { linkage: { type: "posts", id: "1" } },
|
||||
author: { linkage: nil }
|
||||
@@ -51,7 +53,9 @@ module ActiveModel
|
||||
}, {
|
||||
id: "2",
|
||||
type: "comments",
|
||||
body: 'ZOMG ANOTHER COMMENT',
|
||||
attributes: {
|
||||
body: 'ZOMG ANOTHER COMMENT'
|
||||
},
|
||||
links: {
|
||||
post: { linkage: { type: "posts", id: "1" } },
|
||||
author: { linkage: nil }
|
||||
|
||||
@@ -41,9 +41,11 @@ module ActiveModel
|
||||
expected = [
|
||||
{
|
||||
id: "43",
|
||||
rating: nil,
|
||||
type: "bios",
|
||||
content:"AMS Contributor",
|
||||
attributes: {
|
||||
content:"AMS Contributor",
|
||||
rating: nil
|
||||
},
|
||||
links: {
|
||||
author: { linkage: { type: "authors", id: "1" } }
|
||||
}
|
||||
|
||||
@@ -54,9 +54,11 @@ module ActiveModel
|
||||
data: [
|
||||
{
|
||||
id: "10",
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!",
|
||||
type: "posts",
|
||||
attributes: {
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -65,9 +67,11 @@ module ActiveModel
|
||||
},
|
||||
{
|
||||
id: "20",
|
||||
title: "New Post",
|
||||
body: "Body",
|
||||
type: "posts",
|
||||
attributes: {
|
||||
title: "New Post",
|
||||
body: "Body"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -78,24 +82,30 @@ module ActiveModel
|
||||
included: [
|
||||
{
|
||||
id: "1",
|
||||
body: "ZOMG A COMMENT",
|
||||
type: "comments",
|
||||
attributes: {
|
||||
body: "ZOMG A COMMENT"
|
||||
},
|
||||
links: {
|
||||
post: { linkage: { type: "posts", id: "10" } },
|
||||
author: { linkage: nil }
|
||||
}
|
||||
}, {
|
||||
id: "2",
|
||||
body: "ZOMG ANOTHER COMMENT",
|
||||
type: "comments",
|
||||
attributes: {
|
||||
body: "ZOMG ANOTHER COMMENT",
|
||||
},
|
||||
links: {
|
||||
post: { linkage: { type: "posts", id: "10" } },
|
||||
author: { linkage: nil }
|
||||
}
|
||||
}, {
|
||||
id: "1",
|
||||
name: "Steve K.",
|
||||
type: "authors",
|
||||
attributes: {
|
||||
name: "Steve K."
|
||||
},
|
||||
links: {
|
||||
posts: { linkage: [ { type: "posts", id: "10" }, { type: "posts", id: "30" } ] },
|
||||
roles: { linkage: [] },
|
||||
@@ -103,16 +113,20 @@ module ActiveModel
|
||||
}
|
||||
}, {
|
||||
id: "1",
|
||||
rating: nil,
|
||||
type: "bios",
|
||||
content: "AMS Contributor",
|
||||
attributes: {
|
||||
content: "AMS Contributor",
|
||||
rating: nil
|
||||
},
|
||||
links: {
|
||||
author: { linkage: { type: "authors", id: "1" } }
|
||||
}
|
||||
}, {
|
||||
id: "2",
|
||||
name: "Tenderlove",
|
||||
type: "authors",
|
||||
attributes: {
|
||||
name: "Tenderlove"
|
||||
},
|
||||
links: {
|
||||
posts: { linkage: [ { type: "posts", id:"20" } ] },
|
||||
roles: { linkage: [] },
|
||||
@@ -120,9 +134,11 @@ module ActiveModel
|
||||
}
|
||||
}, {
|
||||
id: "2",
|
||||
rating: nil,
|
||||
type: "bios",
|
||||
content: "Rails Contributor",
|
||||
attributes: {
|
||||
rating: nil,
|
||||
content: "Rails Contributor",
|
||||
},
|
||||
links: {
|
||||
author: { linkage: { type: "authors", id: "2" } }
|
||||
}
|
||||
@@ -148,7 +164,9 @@ module ActiveModel
|
||||
{
|
||||
id: "1",
|
||||
type: "authors",
|
||||
name: "Steve K.",
|
||||
attributes: {
|
||||
name: "Steve K."
|
||||
},
|
||||
links: {
|
||||
posts: { linkage: [ { type: "posts", id: "10"}, { type: "posts", id: "30" }] },
|
||||
roles: { linkage: [] },
|
||||
@@ -157,8 +175,10 @@ module ActiveModel
|
||||
}, {
|
||||
id: "10",
|
||||
type: "posts",
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!",
|
||||
attributes: {
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [ { type: "comments", id: "1"}, { type: "comments", id: "2" }] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -167,8 +187,10 @@ module ActiveModel
|
||||
}, {
|
||||
id: "30",
|
||||
type: "posts",
|
||||
title: "Yet Another Post",
|
||||
body: "Body",
|
||||
attributes: {
|
||||
title: "Yet Another Post",
|
||||
body: "Body"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [] },
|
||||
blog: { linkage: { type: "blogs", id: "999" } },
|
||||
@@ -208,9 +230,11 @@ module ActiveModel
|
||||
expected = [
|
||||
{
|
||||
id: "10",
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!",
|
||||
type: "posts",
|
||||
attributes: {
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!"
|
||||
},
|
||||
links: {
|
||||
comments: {
|
||||
linkage: [{type: "comments", id: "1"}, {type: "comments", id: "2"}]
|
||||
@@ -239,9 +263,11 @@ module ActiveModel
|
||||
expected = {
|
||||
data: {
|
||||
id: "10",
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!",
|
||||
type: "posts",
|
||||
attributes: {
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!"
|
||||
},
|
||||
links: {
|
||||
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
|
||||
author: { linkage: nil }
|
||||
|
||||
Reference in New Issue
Block a user