Skip to content

Improve logic in Idv::UspsMail#mail_spammed?#1460

Merged
monfresh merged 1 commit intomasterfrom
mb-usps-mail-events
Jun 2, 2017
Merged

Improve logic in Idv::UspsMail#mail_spammed?#1460
monfresh merged 1 commit intomasterfrom
mb-usps-mail-events

Conversation

@monfresh
Copy link
Contributor

Why: If the max_mail_events Figaro key is not set on the server,
or if it's set to zero, and if the user has not requested any letters,
max_events? will return true, which will then cause
updated_within_last_month? to throw a NoMethod error because it can't
call update_at on a nil object.

How:

  • Return false early in mail_spammed? if the user has not requested
    any letters.
  • Add max_mail_events and max_mail_events_window_in_days to the list
    of required Figaro keys.
  • Set max_mail_events to 2 in the test environment to avoid creating
    more entries in the DB than is necessary.
  • Use #size instead of #count for performance reasons.

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

Looks like some spec failures in the controller, but other than that LGTM! Thanks for following up!

rspec ./spec/controllers/verify/review_controller_spec.rb:197 # Verify::ReviewController#new user has not requested too much mail does not display a success message
rspec ./spec/controllers/verify/review_controller_spec.rb:205 # Verify::ReviewController#new user has not requested too much mail displays a helpful error message

**Why**: If the `max_mail_events` Figaro key is not set on the server,
or if it's set to zero, and if the user has not requested any letters,
`max_events?` will return `true`, which will then cause
`updated_within_last_month?` to throw a NoMethod error because it can't
call `update_at` on a nil object.

**How**:
- Return `false` early in `mail_spammed?` if the user has not requested
any letters.
- Add `max_mail_events` and `max_mail_events_window_in_days` to the list
of required Figaro keys.
- Set `max_mail_events` to 2 in the test environment to avoid creating
more entries in the DB than is necessary.
- Use `#size` instead of `#count` for performance reasons.
@monfresh monfresh force-pushed the mb-usps-mail-events branch from d4591b3 to cf9bc35 Compare May 31, 2017 15:14
@monfresh monfresh merged commit 2d9d7fc into master Jun 2, 2017
@monfresh monfresh deleted the mb-usps-mail-events branch June 2, 2017 19:54
zachmargolis added a commit that referenced this pull request Jun 7, 2017
…c-2017-06-12

Adds pull request #1460 to release candidate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants