Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chrismaddocks
Copy link
Contributor

No description provided.

@chrismaddocks
Copy link
Contributor Author

@@ -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
Copy link
Member

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

Copy link
Contributor Author

@chrismaddocks chrismaddocks Jan 19, 2017

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay...

Copy link
Contributor Author

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...

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. that's helpful

@gaganawhad gaganawhad changed the base branch from develop to master April 25, 2017 18:56
@chrismaddocks chrismaddocks force-pushed the feature/prevent-fb-legacy-updates branch from b524043 to c8943f6 Compare June 2, 2017 18:19
@chrismaddocks
Copy link
Contributor Author

@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 update_facebook_count method or try to update the attribute directly.

@gaganawhad
Copy link
Member

@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.

@chrismaddocks chrismaddocks requested a review from gaganawhad June 15, 2017 06:07
@chrismaddocks chrismaddocks force-pushed the feature/prevent-fb-legacy-updates branch from c8943f6 to 8e6fdbd Compare June 15, 2017 06:08
@chrismaddocks
Copy link
Contributor Author

chrismaddocks commented Jun 15, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants