test/fixtures/poro.rb in active_model_serializers-0.10.0.rc1 vs test/fixtures/poro.rb in active_model_serializers-0.10.0.rc2

- old
+ new

@@ -1,14 +1,24 @@ class Model + FILE_DIGEST = Digest::MD5.hexdigest(File.open(__FILE__).read) + + def self.model_name + @_model_name ||= ActiveModel::Name.new(self) + end + def initialize(hash={}) @attributes = hash end def cache_key "#{self.class.name.downcase}/#{self.id}-#{self.updated_at}" end + def cache_key_with_digest + "#{cache_key}/#{FILE_DIGEST}" + end + def updated_at @attributes[:updated_at] ||= DateTime.now.to_time.to_i end def read_attribute_for_serialization(name) @@ -62,19 +72,19 @@ Comment = Class.new(Model) Author = Class.new(Model) Bio = Class.new(Model) Blog = Class.new(Model) Role = Class.new(Model) -User = Class.new(Model) +User = Class.new(Model) Location = Class.new(Model) Place = Class.new(Model) module Spam; end Spam::UnrelatedLink = Class.new(Model) PostSerializer = Class.new(ActiveModel::Serializer) do - cache key:'post', expires_in: 0.1 + cache key:'post', expires_in: 0.1, skip_digest: true attributes :id, :title, :body has_many :comments belongs_to :blog belongs_to :author @@ -97,11 +107,11 @@ 'posts' end end CommentSerializer = Class.new(ActiveModel::Serializer) do - cache expires_in: 1.day + cache expires_in: 1.day, skip_digest: true attributes :id, :body belongs_to :post belongs_to :author @@ -109,20 +119,20 @@ options end end AuthorSerializer = Class.new(ActiveModel::Serializer) do - cache key:'writer' + cache key:'writer', skip_digest: true attributes :id, :name has_many :posts, embed: :ids has_many :roles, embed: :ids has_one :bio end RoleSerializer = Class.new(ActiveModel::Serializer) do - cache only: [:name] + cache only: [:name], skip_digest: true attributes :id, :name, :description, :slug def slug "#{name}-#{id}" end @@ -135,11 +145,11 @@ belongs_to :post end LocationSerializer = Class.new(ActiveModel::Serializer) do - cache only: [:place] + cache only: [:place], skip_digest: true attributes :id, :lat, :lng belongs_to :place def place @@ -152,17 +162,18 @@ has_many :locations end BioSerializer = Class.new(ActiveModel::Serializer) do - cache except: [:content] + cache except: [:content], skip_digest: true attributes :id, :content, :rating belongs_to :author end BlogSerializer = Class.new(ActiveModel::Serializer) do + cache key: 'blog' attributes :id, :name belongs_to :writer has_many :articles end @@ -176,10 +187,17 @@ AlternateBlogSerializer = Class.new(ActiveModel::Serializer) do attribute :id attribute :name, key: :title end +CustomBlogSerializer = Class.new(ActiveModel::Serializer) do + attribute :id + attribute :special_attribute + + has_many :articles +end + CommentPreviewSerializer = Class.new(ActiveModel::Serializer) do attributes :id belongs_to :post end @@ -201,6 +219,12 @@ belongs_to :author, serializer: AuthorPreviewSerializer end Spam::UnrelatedLinkSerializer = Class.new(ActiveModel::Serializer) do attributes :id +end + +RaiseErrorSerializer = Class.new(ActiveModel::Serializer) do + def json_key + raise StandardError, 'Intentional error for rescue_from test' + end end