kshnurov / mandrill_dm

A basic Mandrill delivery method for Rails.
MIT License
46 stars 45 forks source link

Expose sent emails #36

Closed p55 closed 8 years ago

p55 commented 8 years ago

MandrillDm.DeliveryMethod.deliveries returns sent emails. This allows to test if your code properly changed deliveries size (similar to ApplicationMailer.deliveries.size and ApplicationMailer.deliveries.last)

kshnurov commented 8 years ago

@p55 tests are failing.

deliveries is used only for testing (deliveries - Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test.), why would you need it here? You should check Mandrill's @response directly.

p55 commented 8 years ago

@kshnurov specs fixed. Yes - I know that deliveries are used only for testing and that is my point. For example, you have in your app some code that sends emails

MandrillDm::DeliveryMethod.new.deliver!(mail).each do |response|
  # do something with response {:email=>"recipient.email@example.com", :status=>"sent", :reject_reason=>"hard-bounce", :_id=>"abc123abc123abc123abc123abc123"}
end

and you want test your code for example

scenario "user sends email with attachments and some name" do
  expect do
    visit "/some/path"
    fill_in "Subject", with: "Foo"
    attach_file "Attachment", "/some/path.txt"
    click_button "Go for it"
  end.to change {MandrillDm.DeliveryMethod.deliveries.size}.from(0).to(1)
  expect(MandrillDm.DeliveryMethod.deliveries.last.subject).to eq("Foo")
  expect(MandrillDm.DeliveryMethod.deliveries.last.attachments.size).to eq(1)
end

I don't want to test mandril response (which in fact returns an array of hashes without email details), but messages that have been sent to mandrill api (which are instances of ActionMailer::MessageDelivery).

kshnurov commented 8 years ago

@p55 this has absolutely nothing to do with this gem, use default ActionMailer's delivery_method :test and you'll get the same result.

p55 commented 8 years ago

ActionMailer has nothing to do when sending emails via mandrill api (which is just a POST request on mandrill 'messages/send' api endpoint)

kshnurov commented 8 years ago

@p55 so does your tests, they have nothing to do with Mandrill. If you want to test Madrill's response - look into @response.