diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb index 6126cca0..0922c7dd 100644 --- a/test/fixtures/active_record.rb +++ b/test/fixtures/active_record.rb @@ -429,6 +429,18 @@ t.integer :version t.timestamps null: false end + + # Tables for testing Issue #1473: Polymorphic has_many with foreign_key_on: :related + create_table :articles, force: true do |t| + t.string :title + t.timestamps null: false + end + + create_table :article_comments, force: true do |t| + t.text :content + t.references :commentable, polymorphic: true, index: true + t.timestamps null: false + end end ### MODELS @@ -868,6 +880,15 @@ class ListItem < ActiveRecord::Base belongs_to :list, inverse_of: :items end +# Models for testing Issue #1473: Polymorphic has_many with foreign_key_on: :related +class Article < ActiveRecord::Base + has_many :article_comments, as: :commentable +end + +class ArticleComment < ActiveRecord::Base + belongs_to :commentable, polymorphic: true +end + ### CONTROLLERS class SessionsController < ActionController::Base include JSONAPI::ActsAsResourceController @@ -1230,6 +1251,13 @@ class IndicatorsController < JSONAPI::ResourceController class RobotsController < JSONAPI::ResourceController end +# Controllers for testing Issue #1473 +class ArticlesController < JSONAPI::ResourceController +end + +class ArticleCommentsController < JSONAPI::ResourceController +end + ### RESOURCES class BaseResource < JSONAPI::Resource abstract @@ -2691,6 +2719,17 @@ class RobotResource < ::JSONAPI::Resource end end +# Resources for testing Issue #1473: Polymorphic has_many with foreign_key_on: :related +class ArticleResource < JSONAPI::Resource + attribute :title + has_many :article_comments, foreign_key_on: :related +end + +class ArticleCommentResource < JSONAPI::Resource + attribute :content + has_one :commentable, polymorphic: true +end + # Models and Resources for testing Issue #1467: ActiveModel-based resources # ActiveModel class without ActiveRecord class SimpleModel diff --git a/test/test_helper.rb b/test/test_helper.rb index 964ef224..191e181b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -340,6 +340,10 @@ class CatResource < JSONAPI::Resource jsonapi_resources :employees jsonapi_resources :robots + # Routes for testing Issue #1473 + jsonapi_resources :articles + jsonapi_resources :article_comments + jsonapi_resources :lists jsonapi_resources :list_items