Skip to content

Commit

Permalink
Refactor blank_allowed
Browse files Browse the repository at this point in the history
If passed a nil in the personalisation, the Notify API will raise an
error.

The `blank_allowed` method lets developers opt-in to allow a blank
value, here 'blank' probably means `nil`.

As v2 no longer relies on the `Personalisation` class to handle
personalisations we want to remove the class, but this method still
relies on it.

We want to keep the method in-case it is used.

In v2, we really only need to know when a developer is opting in by
calling the method and then convert nil into an empty string.
  • Loading branch information
mec committed Apr 5, 2024
1 parent 38d7ad5 commit ec59317
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 98 deletions.
1 change: 0 additions & 1 deletion lib/mail/notify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require "mail/notify/version"
require "mail/notify/railtie" if defined? Rails
require "mail/notify/delivery_method"
require "mail/notify/personalisation"
require "mail/notify/mailer"
require "mail/notify/message"
require "mail/notify/mail_notify_previews_controller"
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/notify/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def view_mail(template_id, options)
# allows blank personalisation options

def blank_allowed(value)
value.presence || Personalisation::BLANK
value.to_s
end
end
end
Expand Down
30 changes: 0 additions & 30 deletions lib/mail/notify/personalisation.rb

This file was deleted.

10 changes: 8 additions & 2 deletions spec/mail/notify/mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,15 @@
end
end

context "when given a blank value" do
context "when given an empty string" do
it "returns explicitly blank personalisation" do
expect(TestMailer.new.blank_allowed("")).to be Mail::Notify::Personalisation::BLANK
expect(TestMailer.new.blank_allowed("")).to eq ""
end
end

context "when given nil" do
it "returns an empty string" do
expect(TestMailer.new.blank_allowed(nil)).to eq ""
end
end
end
Expand Down
64 changes: 0 additions & 64 deletions spec/mail/notify/personalisation_spec.rb

This file was deleted.

0 comments on commit ec59317

Please sign in to comment.