-
Notifications
You must be signed in to change notification settings - Fork 0
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
Prevent updates to Facebook count on non-canonical locations #42
base: master
Are you sure you want to change the base?
Conversation
@@ -7,13 +7,26 @@ module Facebook | |||
included do | |||
store_accessor :document, :facebook_count, :facebook_count_updated_at | |||
|
|||
before_validation :prevent_update_of_legacy_location, on: :update |
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.
@chrismaddocks what if, instead of all this, we redefined #facebook_count=
to include a check for canonical?
before setting the value? (And if not canonical, return some sort of warning.) Something like,
def facebook_count=(facebook_count)
if canonical?
super
else
'Cannot update the facebook count of a noncanonical location.'
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.
@benhutton The issue then is that facebook_count_updated_at
will be updated even though facebook_count
is not: https://github.com/desiringgod/wakes/blob/develop/app/services/wakes/facebook_count_updater_service.rb#L14.
While we could code around that, that smells like we want the transaction to fail, not the individual attribute (especially since we can't predict how future developers will try to set the attribute). Doesn't validating on save feel more aligned with ActiveModel, too?
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.
okay...
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.
@benhutton You sound like you still have some hesitation. Let's talk...
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.
no. my ellipsis was merely to indicate that I was moving my questioning to the throw :abort
line
protected | ||
|
||
def prevent_update_of_legacy_location | ||
throw :abort if facebook_count_will_change? && !canonical |
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.
@chrismaddocks tell me more about throw :abort
. Is that a standard / documented way of doing this?
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.
@benhutton Yes, this is the Rails 5 way of halting the callback chain when a validation fails (returning false
no longer works).
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.
gotcha. that's helpful
b524043
to
c8943f6
Compare
@gaganawhad I had submitted this several months ago, but looks like I never merged it. I see you solved a related problem in #49. What do you think of the refactor in 8c6e430? The advantage of doing it with filters is that bad updates will be caught whether they use your |
@chrismaddocks I like the refactor. One point that's not really related with your refactor is, I wonder if we want to keep a possibility of allowing updates for decreasing counts when we are forcing a decreasing count for error correction. We have had to do that a few times in the past. May be something we don't need to really bother about in code. |
c8943f6
to
8e6fdbd
Compare
@gaganawhad One more commit (8e6fdbd) needed here to get the specs to pass, which may be a smell for the way we are trying to do atomic updates here. Maybe you have another idea here? I've also assigned you as a reviewer. Also, the tests will fail until #55 is merged. |
No description provided.