Adds polymorphic tests and documentation

This commit is contained in:
Marc Garreau
2016-03-15 12:20:00 -06:00
parent 54ddbe2851
commit 045fa9bc07
5 changed files with 114 additions and 0 deletions

View File

@@ -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
View File

@@ -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