diff --git a/app/mailers/scrap_notifier.rb b/app/mailers/scrap_notifier.rb new file mode 100644 index 0000000..c8da553 --- /dev/null +++ b/app/mailers/scrap_notifier.rb @@ -0,0 +1,17 @@ +class Scrap::Notifier < ActionMailer::Base + def notification(scrap) + sender, receiver = scrap.sender, scrap.receiver + @recipient = receiver.name + @sender = sender.name + @sender_link = sender.url + @scrap_content = scrap.content + @wall_url = scrap.scrap_wall_url + @environment = sender.environment.name + @url = sender.environment.top_url + mail( + to: receiver.email, + from: "#{sender.environment.name} <#{sender.environment.contact_email}>", + subject: _("[%s] You received a scrap!") % [sender.environment.name] + ) + end +end diff --git a/app/models/scrap.rb b/app/models/scrap.rb index ea57fb5..0fc1a55 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -23,7 +23,7 @@ class Scrap < ActiveRecord::Base after_create do |scrap| scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? - Scrap::Notifier.deliver_mail(scrap) if scrap.send_notification? + Scrap::Notifier.notification(scrap).deliver if scrap.send_notification? end before_validation :strip_all_html_tags @@ -49,21 +49,4 @@ class Scrap < ActiveRecord::Base sender != receiver && (is_root? ? root.receiver.receives_scrap_notification? : receiver.receives_scrap_notification?) end - class Notifier < ActionMailer::Base - def mail(scrap) - sender, receiver = scrap.sender, scrap.receiver - recipients receiver.email - - from "#{sender.environment.name} <#{sender.environment.contact_email}>" - subject _("[%s] You received a scrap!") % [sender.environment.name] - body :recipient => receiver.name, - :sender => sender.name, - :sender_link => sender.url, - :scrap_content => scrap.content, - :wall_url => scrap.scrap_wall_url, - :environment => sender.environment.name, - :url => sender.environment.top_url - end - end - end diff --git a/app/views/scrap/notifier/mail.html.erb b/app/views/scrap/notifier/mail.html.erb deleted file mode 100644 index ec88a61..0000000 --- a/app/views/scrap/notifier/mail.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -<%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> - -<%= word_wrap(_('%{sender} (%{sender_link}) has left the following scrap for you:') % { :sender => @sender, :sender_link => url_for(@sender_link) }) %> - -------------------------------------------------------------------------------- -<%= word_wrap(@scrap_content) %> -------------------------------------------------------------------------------- - -<%= _('View this scrap on the wall') %>: -<%= url_for @wall_url %> - -<%= _("Greetings,") %> - --- -<%= _('%s team.') % @environment %> -<%= url_for @url %> diff --git a/app/views/scrap/notifier/notification.html.erb b/app/views/scrap/notifier/notification.html.erb new file mode 100644 index 0000000..ec88a61 --- /dev/null +++ b/app/views/scrap/notifier/notification.html.erb @@ -0,0 +1,16 @@ +<%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> + +<%= word_wrap(_('%{sender} (%{sender_link}) has left the following scrap for you:') % { :sender => @sender, :sender_link => url_for(@sender_link) }) %> + +------------------------------------------------------------------------------- +<%= word_wrap(@scrap_content) %> +------------------------------------------------------------------------------- + +<%= _('View this scrap on the wall') %>: +<%= url_for @wall_url %> + +<%= _("Greetings,") %> + +-- +<%= _('%s team.') % @environment %> +<%= url_for @url %> diff --git a/test/unit/scrap_notifier_test.rb b/test/unit/scrap_notifier_test.rb index 39f1dc3..320051f 100644 --- a/test/unit/scrap_notifier_test.rb +++ b/test/unit/scrap_notifier_test.rb @@ -34,19 +34,19 @@ class ScrapNotifierTest < ActiveSupport::TestCase should 'display sender name in delivered mail' do Scrap.create!(:sender_id => @sender.id, :receiver_id => @receiver.id, :content => 'Hi man!') sent = ActionMailer::Base.deliveries.first - assert_match /user_scrap_sender_test/, sent.body + assert_match /user_scrap_sender_test/, sent.body.to_s end should 'display scrap content in delivered mail' do Scrap.create!(:sender_id => @sender.id, :receiver_id => @receiver.id, :content => 'Hi man!') sent = ActionMailer::Base.deliveries.first - assert_match /Hi man!/, sent.body + assert_match /Hi man!/, sent.body.to_s end should 'display receiver wall link in delivered mail' do Scrap.create!(:sender_id => @sender.id, :receiver_id => @receiver.id, :content => 'Hi man!') sent = ActionMailer::Base.deliveries.first - assert_match /\/profile\/user_scrap_receiver_test#profile-wall/, sent.body + assert_match /\/profile\/user_scrap_receiver_test#profile-wall/, sent.body.to_s end should 'not deliver mail if notify receiver and sender are the same person' do -- libgit2 0.21.2