mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #1063 from bf4/poro_lint
Lead by example: lint PORO model
This commit is contained in:
commit
fc7b9c3c14
@ -106,7 +106,7 @@ module ActiveModel::Serializer::Lint
|
|||||||
private
|
private
|
||||||
|
|
||||||
def resource
|
def resource
|
||||||
@resource
|
@resource or fail "'@resource' must be set as the linted object"
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_instance_of(result, name)
|
def assert_instance_of(result, name)
|
||||||
|
|||||||
19
test/fixtures/poro.rb
vendored
19
test/fixtures/poro.rb
vendored
@ -13,12 +13,8 @@ class Model
|
|||||||
"#{self.class.name.downcase}/#{self.id}-#{self.updated_at.strftime("%Y%m%d%H%M%S%9N")}"
|
"#{self.class.name.downcase}/#{self.id}-#{self.updated_at.strftime("%Y%m%d%H%M%S%9N")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_key_with_digest
|
def serializable_hash(options = nil)
|
||||||
"#{cache_key}/#{FILE_DIGEST}"
|
@attributes
|
||||||
end
|
|
||||||
|
|
||||||
def updated_at
|
|
||||||
@attributes[:updated_at] ||= DateTime.now.to_time
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_attribute_for_serialization(name)
|
def read_attribute_for_serialization(name)
|
||||||
@ -33,6 +29,9 @@ class Model
|
|||||||
@attributes[:id] || @attributes['id'] || object_id
|
@attributes[:id] || @attributes['id'] || object_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
### Helper methods, not required to be serializable
|
||||||
|
#
|
||||||
|
# Convenience for adding @attributes readers and writers
|
||||||
def method_missing(meth, *args)
|
def method_missing(meth, *args)
|
||||||
if meth.to_s =~ /^(.*)=$/
|
if meth.to_s =~ /^(.*)=$/
|
||||||
@attributes[$1.to_sym] = args[0]
|
@attributes[$1.to_sym] = args[0]
|
||||||
@ -42,6 +41,14 @@ class Model
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cache_key_with_digest
|
||||||
|
"#{cache_key}/#{FILE_DIGEST}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def updated_at
|
||||||
|
@attributes[:updated_at] ||= DateTime.now.to_time
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Profile < Model
|
class Profile < Model
|
||||||
|
|||||||
9
test/poro_test.rb
Normal file
9
test/poro_test.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class PoroTest < Minitest::Test
|
||||||
|
include ActiveModel::Serializer::Lint::Tests
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@resource = Model.new
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user