Skip to content

Commit

Permalink
Merge pull request #1063 from bf4/poro_lint
Browse files Browse the repository at this point in the history
Lead by example: lint PORO model
  • Loading branch information
joaomdmoura committed Aug 20, 2015
2 parents e384b65 + dca286b commit fc7b9c3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/active_model/serializer/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_model_name
private

def resource
@resource
@resource or fail "'@resource' must be set as the linted object"
end

def assert_instance_of(result, name)
Expand Down
19 changes: 13 additions & 6 deletions test/fixtures/poro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ def cache_key
"#{self.class.name.downcase}/#{self.id}-#{self.updated_at.strftime("%Y%m%d%H%M%S%9N")}"
end

def cache_key_with_digest
"#{cache_key}/#{FILE_DIGEST}"
end

def updated_at
@attributes[:updated_at] ||= DateTime.now.to_time
def serializable_hash(options = nil)
@attributes
end

def read_attribute_for_serialization(name)
Expand All @@ -33,6 +29,9 @@ def id
@attributes[:id] || @attributes['id'] || object_id
end

### Helper methods, not required to be serializable
#
# Convenience for adding @attributes readers and writers
def method_missing(meth, *args)
if meth.to_s =~ /^(.*)=$/
@attributes[$1.to_sym] = args[0]
Expand All @@ -42,6 +41,14 @@ def method_missing(meth, *args)
super
end
end

def cache_key_with_digest
"#{cache_key}/#{FILE_DIGEST}"
end

def updated_at
@attributes[:updated_at] ||= DateTime.now.to_time
end
end

class Profile < Model
Expand Down
9 changes: 9 additions & 0 deletions test/poro_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'test_helper'

class PoroTest < Minitest::Test
include ActiveModel::Serializer::Lint::Tests

def setup
@resource = Model.new
end
end

0 comments on commit fc7b9c3

Please sign in to comment.