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

Extract email sending logic from deliver_poste_messages cron script into lib/cdo/poste.rb #31456

Merged
merged 7 commits into from Oct 29, 2019

Conversation

Hamms
Copy link
Contributor

@Hamms Hamms commented Oct 24, 2019

Description

To make it easier to write unit tests; also, add some unit tests!

Note that this change also requires that we lazily populate the MESSAGE_TEMPLATES constant: 3966745

Otherwise, circle will fail to build because this code expects the database to already be set up as soon as the file gets required, rather than not until use.

This is a follow-up to #31421, as it adds the unit tests that would have caught the error had they existed.

Reviewer Checklist:

  • Tests provide adequate coverage
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@Hamms Hamms marked this pull request as ready for review October 28, 2019 17:33
@Hamms Hamms requested a review from islemaster October 28, 2019 17:33
@islemaster islemaster added refactor Better code, no behavior change testing labels Oct 28, 2019
Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

Great call. I have a couple of implementation questions before I approve.

end
end

class Deliverer
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason not to give each class its own file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mostly a desire not to clutter up the already-large lib/cdo directory

@@ -0,0 +1,48 @@
require_relative 'test_helper'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why'd you put a test for a class in lib/cdo in shared/test instead of lib/test/cdo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, that's a much better location. I just looked for where the existing Poste tests were

def setup
@fake_smtp = FakeSmtp.new
Deliverer.any_instance.stubs(:reset_connection).returns(@fake_smtp)
@deliverer = Deliverer.new({})
Copy link
Contributor

Choose a reason for hiding this comment

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

Great clean setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for pointing me in this direction!

params: {}.to_json
}
@deliverer.send(delivery)
message = @fake_smtp.instance_variable_get(:@message)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might read better to add

attr_reader :message, :from_address, :to_address

to FakeSmtp. My only concern would be whether you think the test becomes misleading as documentation of how you'd typically use this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a comment explaining why I'm doing that

Comment on lines 31 to 33
# Sequel doesn't have a "find or create by", so we implement it manually
message = POSTE_DB[:poste_messages].where(name: "dashboard").first
message_id = message.nil? ? POSTE_DB[:poste_messages].insert({name: "dashboard"}) : message[:id]
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL! Looks like it only exists if you're using Sequel models, which we don't actually do.

@Hamms Hamms requested a review from islemaster October 29, 2019 00:29
Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

👍 Looks great!

@Hamms
Copy link
Contributor Author

Hamms commented Oct 29, 2019

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Better code, no behavior change testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants