diff --git a/test/unit/creation_test.rb b/test/unit/creation_test.rb index abcf78cd..6459b41e 100644 --- a/test/unit/creation_test.rb +++ b/test/unit/creation_test.rb @@ -272,42 +272,4 @@ def test_callbacks_on_update callback_test = CallbackTest.create({foo: 1, bar: 1}) assert_equal 100, callback_test.bar end - - def test_create_with_relationships_in_payload - stub_request(:post, 'http://example.com/articles') - .with(headers: {content_type: 'application/vnd.api+json', accept: 'application/vnd.api+json'}, body: { - data: { - type: 'articles', - attributes: { - title: 'Rails is Omakase' - }, - relationships: { - comments: { - data: [ - { - id: '2', - type: 'comments' - } - ] - } - } - } - }.to_json) - .to_return(headers: {content_type: 'application/vnd.api+json'}, body: { - data: { - type: 'articles', - id: '1', - attributes: { - title: 'Rails is Omakase' - } - } - }.to_json) - - article = Article.new(title: 'Rails is Omakase', relationships: {comments: [Comment.new(id: 2)]}) - - assert article.save - assert article.persisted? - assert_equal "1", article.id - end - end diff --git a/test/unit/creation_with_relation_test.rb b/test/unit/creation_with_relation_test.rb new file mode 100644 index 00000000..b3e324de --- /dev/null +++ b/test/unit/creation_with_relation_test.rb @@ -0,0 +1,40 @@ +require 'test_helper' + +class CreationWithRelationTest < MiniTest::Test + def test_create_with_relationships_in_payload + stub_request(:post, 'http://example.com/articles') + .with(headers: {content_type: 'application/vnd.api+json', accept: 'application/vnd.api+json'}, body: { + data: { + type: 'articles', + attributes: { + title: 'Rails is Omakase' + }, + relationships: { + comments: { + data: [ + { + id: '2', + type: 'comments' + } + ] + } + } + } + }.to_json) + .to_return(headers: {content_type: 'application/vnd.api+json'}, body: { + data: { + type: 'articles', + id: '1', + attributes: { + title: 'Rails is Omakase' + } + } + }.to_json) + + article = Article.new(title: 'Rails is Omakase', relationships: {comments: [Comment.new(id: 2)]}) + + assert article.save + assert article.persisted? + assert_equal "1", article.id + end +end