mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Adds polymorphic tests and documentation
This commit is contained in:
11
test/fixtures/active_record.rb
vendored
11
test/fixtures/active_record.rb
vendored
@@ -18,6 +18,17 @@ ActiveRecord::Schema.define do
|
||||
t.references :post
|
||||
t.timestamp null: false
|
||||
end
|
||||
create_table :employees, force: true do |t|
|
||||
t.string :name
|
||||
t.string :email
|
||||
t.timestamp null: false
|
||||
end
|
||||
create_table :pictures, force: true do |t|
|
||||
t.string :title
|
||||
t.string :imageable_type
|
||||
t.string :imageable_id
|
||||
t.timestamp null: false
|
||||
end
|
||||
end
|
||||
|
||||
module ARModels
|
||||
|
||||
18
test/fixtures/poro.rb
vendored
18
test/fixtures/poro.rb
vendored
@@ -72,6 +72,14 @@ Comment = Class.new(Model) do
|
||||
end
|
||||
end
|
||||
|
||||
class Employee < ActiveRecord::Base
|
||||
has_many :pictures, as: :imageable
|
||||
end
|
||||
|
||||
class Picture < ActiveRecord::Base
|
||||
belongs_to :imageable, polymorphic: true
|
||||
end
|
||||
|
||||
module Spam; end
|
||||
Spam::UnrelatedLink = Class.new(Model)
|
||||
|
||||
@@ -233,6 +241,16 @@ VirtualValueSerializer = Class.new(ActiveModel::Serializer) do
|
||||
end
|
||||
end
|
||||
|
||||
PolymorphicHasManySerializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :id, :name
|
||||
end
|
||||
|
||||
PolymorphicBelongsToSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :id, :title
|
||||
|
||||
has_one :imageable, serializer: PolymorphicHasManySerializer
|
||||
end
|
||||
|
||||
Spam::UnrelatedLinkSerializer = Class.new(ActiveModel::Serializer) do
|
||||
cache only: [:id]
|
||||
attributes :id
|
||||
|
||||
Reference in New Issue
Block a user