adds polymorphic option to association definition which includes association type in serializer

regen gemlock

regen gemlock

better variable naming

rubocop fixes

adds to changelog

adds empty relationship and has_many polymorph tests

indent

test cleaning

-rubocop

rubocop

rubocop

rubocop

changelog

remove silly .DS

fix roque failure

fix
This commit is contained in:
cgmckeever
2016-05-15 13:19:37 -05:00
parent 6c321cd862
commit bbed12864d
6 changed files with 159 additions and 14 deletions

View File

@@ -24,6 +24,16 @@ ActiveRecord::Schema.define do
t.string :email
t.timestamp null: false
end
create_table :object_tags, force: true do |t|
t.string :poly_tag_id
t.string :taggable_type
t.string :taggable_id
t.timestamp null: false
end
create_table :poly_tags, force: true do |t|
t.string :phrase
t.timestamp null: false
end
create_table :pictures, force: true do |t|
t.string :title
t.string :imageable_type

29
test/fixtures/poro.rb vendored
View File

@@ -70,10 +70,21 @@ end
class Employee < ActiveRecord::Base
has_many :pictures, as: :imageable
has_many :object_tags, as: :taggable
end
class ObjectTag < ActiveRecord::Base
belongs_to :poly_tag
belongs_to :taggable, polymorphic: true
end
class Picture < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
has_many :object_tags, as: :taggable
end
class PolyTag < ActiveRecord::Base
has_many :object_tags
end
module Spam; end
@@ -245,7 +256,23 @@ end
PolymorphicBelongsToSerializer = Class.new(ActiveModel::Serializer) do
attributes :id, :title
has_one :imageable, serializer: PolymorphicHasManySerializer
has_one :imageable, serializer: PolymorphicHasManySerializer, polymorphic: true
end
PolymorphicSimpleSerializer = Class.new(ActiveModel::Serializer) do
attributes :id
end
PolymorphicObjectTagSerializer = Class.new(ActiveModel::Serializer) do
attributes :id
has_many :taggable, serializer: PolymorphicSimpleSerializer, polymorphic: true
end
PolymorphicTagSerializer = Class.new(ActiveModel::Serializer) do
attributes :id, :phrase
has_many :object_tags, serializer: PolymorphicObjectTagSerializer
end
Spam::UnrelatedLinkSerializer = Class.new(ActiveModel::Serializer) do