spec/integration/formats/json_api_spec.rb in ivy-serializers-0.2.0 vs spec/integration/formats/json_api_spec.rb in ivy-serializers-0.3.0
- old
+ new
@@ -17,24 +17,22 @@
let(:resource) { post }
it { should eq({
:data => {
:type => 'post',
- :id => '1',
- :links => {}
+ :id => '1'
}
}) }
end
context 'for a resource collection' do
let(:resource) { [post] }
it { should eq({
:data => [{
:type => 'post',
- :id => '1',
- :links => {}
+ :id => '1'
}]
}) }
end
end
@@ -54,12 +52,13 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :title => 'title',
- :links => {}
+ :attributes => {
+ :title => 'title'
+ }
}
}) }
end
context 'for a resource collection' do
@@ -67,12 +66,13 @@
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :title => 'title',
- :links => {}
+ :attributes => {
+ :title => 'title'
+ }
}]
}) }
end
end
@@ -88,12 +88,13 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :headline => 'title',
- :links => {}
+ :attributes => {
+ :headline => 'title'
+ }
}
}) }
end
context 'for a resource collection' do
@@ -101,12 +102,13 @@
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :headline => 'title',
- :links => {}
+ :attributes => {
+ :headline => 'title'
+ }
}]
}) }
end
end
end
@@ -129,29 +131,43 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:author => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
}
}) }
+
+ context 'with no related resource' do
+ let(:author) { nil }
+
+ it { should eq({
+ :data => {
+ :type => 'post',
+ :id => '1',
+ :relationships => {
+ :author => nil
+ }
+ }
+ }) }
+ end
end
context 'for a resource collection' do
let(:resource) { [post] }
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:author => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
}]
}) }
end
@@ -169,29 +185,43 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:user => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
}
}) }
+
+ context 'with no related resource' do
+ let(:author) { nil }
+
+ it { should eq({
+ :data => {
+ :type => 'post',
+ :id => '1',
+ :relationships => {
+ :user => nil
+ }
+ }
+ }) }
+ end
end
context 'for a resource collection' do
let(:resource) { [post] }
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:user => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
}]
}) }
end
@@ -209,45 +239,57 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:author => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
},
:included => {
:authors => [{
:id => '1',
- :links => {},
:type => 'author'
}]
}
}) }
+
+ context 'with no related resource' do
+ let(:author) { nil }
+
+ it { should eq({
+ :data => {
+ :type => 'post',
+ :id => '1',
+ :relationships => {
+ :author => nil
+ }
+ }
+ }) }
+ end
end
context 'for a resource collection' do
let(:resource) { [post] }
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:author => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
}],
:included => {
:authors => [{
:id => '1',
- :links => {},
:type => 'author'
}]
}
}) }
end
@@ -265,29 +307,43 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:author => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
}
}) }
+
+ context 'with no related resource' do
+ let(:author) { nil }
+
+ it { should eq({
+ :data => {
+ :type => 'post',
+ :id => '1',
+ :relationships => {
+ :author => nil
+ }
+ }
+ }) }
+ end
end
context 'for a resource collection' do
let(:resource) { [post] }
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:author => {
- :linkage => {:id => '1', :type => 'author'}
+ :data => {:id => '1', :type => 'author'}
}
}
}]
}) }
end
@@ -312,13 +368,13 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:comments => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
}
}) }
end
@@ -328,13 +384,13 @@
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:comments => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
}]
}) }
end
@@ -352,13 +408,13 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:replies => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
}
}) }
end
@@ -368,13 +424,13 @@
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:replies => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
}]
}) }
end
@@ -392,22 +448,21 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:comments => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
},
:included => {
:comments => [{
:type => 'comment',
- :id => '1',
- :links => {}
+ :id => '1'
}]
}
}) }
end
@@ -416,22 +471,21 @@
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:comments => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
}],
:included => {
:comments => [{
:type => 'comment',
- :id => '1',
- :links => {}
+ :id => '1'
}]
}
}) }
end
end
@@ -448,13 +502,13 @@
it { should eq({
:data => {
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:comments => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
}
}) }
end
@@ -464,12 +518,12 @@
it { should eq({
:data => [{
:type => 'post',
:id => '1',
- :links => {
+ :relationships => {
:comments => {
- :linkage => [{:id => '1', :type => 'comment'}]
+ :data => [{:id => '1', :type => 'comment'}]
}
}
}]
}) }
end