Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/fixtures/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down