Skip to content

Commit

Permalink
Extend Mail::Message
Browse files Browse the repository at this point in the history
We want to store the tempalte id, personalisation, reference and reply
to id options inside the `message` object, right now these are added to
the header of the message, which feels a little clunky.

Here we use the existing module to add the attributes to message so we
can set and get the values.

We also drop the `preview` method, this method hides the fact that the
impelmentation of the `preview` method is in the DeliveryMethod - on
balance the extra code to call the method seems worth the price of the
understanding where messages are being sent - to be honest, it already
feels odd that the message calls a method and passes it self - but that
might just be me?
  • Loading branch information
mec committed Apr 19, 2024
1 parent 68a76f4 commit a80a1ef
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
4 changes: 1 addition & 3 deletions lib/mail/notify/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
module Mail
module Notify
module Message
def preview
delivery_method.preview(self) if delivery_method.respond_to?(:preview)
end
attr_accessor :template_id, :personalisation, :reply_to_id, :reference
end
end
end
30 changes: 0 additions & 30 deletions spec/mail/message_spec.rb

This file was deleted.

31 changes: 31 additions & 0 deletions spec/mail/notify/message_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "spec_helper"

class FakeTestClass
include Mail::Notify::Message
end

RSpec.describe Mail::Notify::Message do
subject { FakeTestClass.new }

it "adds a template_id attribute" do
expect(subject.template_id = "template-id").to eql "template-id"
expect(subject.template_id).to eql "template-id"
end

it "adds a personalisation attribute" do
expect(subject.personalisation = {name: "Test Name"}).to eql({name: "Test Name"})
expect(subject.personalisation).to eql({name: "Test Name"})
end

it "adds the reply_to_id attribute" do
expect(subject.reply_to_id = "test-reply-to-id").to eql("test-reply-to-id")
expect(subject.reply_to_id).to eql("test-reply-to-id")
end

it "adds the reference attribute" do
expect(subject.reference = "test-reference").to eql("test-reference")
expect(subject.reference).to eql("test-reference")
end
end

0 comments on commit a80a1ef

Please sign in to comment.