test/fixtures/poro.rb in active_model_serializers-0.10.0.rc4 vs test/fixtures/poro.rb in active_model_serializers-0.10.0.rc5

- old
+ new

@@ -19,14 +19,21 @@ # required for ActiveModel::AttributeAssignment#_assign_attribute # in Rails 5 def respond_to_missing?(method_name, _include_private = false) attributes.key?(method_name.to_s.tr('=', '').to_sym) || super end +end - def cache_key_with_digest - "#{cache_key}/#{FILE_DIGEST}" - end +# see +# https://github.com/rails/rails/blob/4-2-stable/activemodel/lib/active_model/errors.rb +# The below allows you to do: +# +# model = ModelWithErrors.new +# model.validate! # => ["cannot be nil"] +# model.errors.full_messages # => ["name cannot be nil"] +class ModelWithErrors < ::ActiveModelSerializers::Model + attr_accessor :name end class Profile < Model end @@ -59,10 +66,18 @@ def cache_key "#{self.class.name.downcase}/#{self.id}" 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) PostSerializer = Class.new(ActiveModel::Serializer) do cache key: 'post', expires_in: 0.1, skip_digest: true @@ -218,9 +233,19 @@ def reviews end def maker 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