Skip to content

Commit 3810178

Browse files
committed
Add Rails 8.1 compatibility tests for relationship routes
Tests to verify Issue JSONAPI-Resources#1479 is fixed: - Rails 8.1 changed ActionDispatch::Routing::Mapper::Resources::Resource#initialize to require keyword arguments - These tests verify that jsonapi_resources generates relationship routes correctly - Tests include has_many and polymorphic belongs_to relationships - Confirms automatic jsonapi_relationships call works in Rails 8.1+ All 37 route tests pass on Rails 8.1.2
1 parent b9de02d commit 3810178

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

test/integration/routes/routes_test.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,45 @@ def test_routing_primary_key_jsonapi_resources
243243

244244
# Test that non-acts-as-set to_many relationship update route is not created
245245

246+
# Rails 8.1 compatibility tests (Issue #1479)
247+
# These tests verify that jsonapi_resources generates relationship routes correctly
248+
# in Rails 8.1+, where ActionDispatch::Routing::Mapper::Resources::Resource#initialize
249+
# changed to require keyword arguments.
250+
251+
def test_routing_articles_show
252+
assert_routing({path: '/articles/1', method: :get},
253+
{action: 'show', controller: 'articles', id: '1'})
254+
end
255+
256+
def test_routing_articles_relationship_comments_show
257+
# Tests that has_many relationship routes are automatically generated
258+
# when using jsonapi_resources without an explicit block
259+
assert_routing({path: '/articles/1/relationships/article_comments', method: :get},
260+
{controller: 'articles', action: 'show_relationship', article_id: '1', relationship: 'article_comments'})
261+
end
262+
263+
def test_routing_articles_relationship_comments_create
264+
# Tests to_many relationship creation route
265+
assert_routing({path: '/articles/1/relationships/article_comments', method: :post},
266+
{controller: 'articles', action: 'create_relationship', article_id: '1', relationship: 'article_comments'})
267+
end
268+
269+
def test_routing_articles_relationship_comments_update
270+
# Tests to_many relationship update route
271+
assert_routing({path: '/articles/1/relationships/article_comments', method: :patch},
272+
{controller: 'articles', action: 'update_relationship', article_id: '1', relationship: 'article_comments'})
273+
end
274+
275+
def test_routing_articles_relationship_comments_destroy
276+
# Tests to_many relationship deletion route
277+
assert_routing({path: '/articles/1/relationships/article_comments', method: :delete},
278+
{controller: 'articles', action: 'destroy_relationship', article_id: '1', relationship: 'article_comments'})
279+
end
280+
281+
def test_routing_article_comments_relationship_commentable_show
282+
# Tests polymorphic belongs_to relationship route
283+
assert_routing({path: '/article_comments/1/relationships/commentable', method: :get},
284+
{controller: 'article_comments', action: 'show_relationship', article_comment_id: '1', relationship: 'commentable'})
285+
end
286+
246287
end

0 commit comments

Comments
 (0)