Skip to content

Commit

Permalink
Rails 4.2 support: when sending topic reply notifications use #delive…
Browse files Browse the repository at this point in the history
…r_later if possible
  • Loading branch information
yan-hoose committed Jul 12, 2015
1 parent a33477f commit bcaed89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/forem/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ def send_notification(post_id)
# If a user cannot be found, then no-op
# This will happen if the user record has been deleted.
if subscriber.present?
SubscriptionMailer.topic_reply(post_id, subscriber.id).deliver
mail = SubscriptionMailer.topic_reply(post_id, subscriber.id)
if mail.respond_to?(:deliver_later)
mail.deliver_later
else
mail.deliver
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/models/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,18 @@
expect(Forem::SubscriptionMailer).not_to receive(:topic_reply)
subscription.send_notification(1)
end

it "should send a notification via deliver_later when method available" do
expect_any_instance_of(ActionMailer::MessageDelivery).to_not receive(:deliver)
expect_any_instance_of(ActionMailer::MessageDelivery).to receive(:deliver_later)
subscription.send_notification(1)
end

it "should send a notification via deliver when deliver_later not available" do
allow_any_instance_of(ActionMailer::MessageDelivery).to receive(:respond_to?).with(:deliver_later).and_return(false)
expect_any_instance_of(ActionMailer::MessageDelivery).to_not receive(:deliver_later)
expect_any_instance_of(ActionMailer::MessageDelivery).to receive(:deliver)
subscription.send_notification(1)
end
end
end

0 comments on commit bcaed89

Please sign in to comment.