-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lead by example: lint PORO model #1063
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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] | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should really be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind keeping it 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't change it in this PR. :) OT: In 1.8 and 1.9 I think DateTime was much slower than Time. Now, I think avoiding DateTime is mostly about it being the wrong tool and being weird with timezones sometimes... |
||
end | ||
end | ||
|
||
class Profile < Model | ||
|
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, this method was missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍