Commit e0fed871b6ee1027d616c8b426bf948ad1167ed2
1 parent
f02d36c9
Exists in
master
and in
29 other branches
rails3: fix scrap_notifier
Showing
5 changed files
with
37 additions
and
37 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | +class Scrap::Notifier < ActionMailer::Base | |
| 2 | + def notification(scrap) | |
| 3 | + sender, receiver = scrap.sender, scrap.receiver | |
| 4 | + @recipient = receiver.name | |
| 5 | + @sender = sender.name | |
| 6 | + @sender_link = sender.url | |
| 7 | + @scrap_content = scrap.content | |
| 8 | + @wall_url = scrap.scrap_wall_url | |
| 9 | + @environment = sender.environment.name | |
| 10 | + @url = sender.environment.top_url | |
| 11 | + mail( | |
| 12 | + to: receiver.email, | |
| 13 | + from: "#{sender.environment.name} <#{sender.environment.contact_email}>", | |
| 14 | + subject: _("[%s] You received a scrap!") % [sender.environment.name] | |
| 15 | + ) | |
| 16 | + end | |
| 17 | +end | ... | ... |
app/models/scrap.rb
| ... | ... | @@ -23,7 +23,7 @@ class Scrap < ActiveRecord::Base |
| 23 | 23 | |
| 24 | 24 | after_create do |scrap| |
| 25 | 25 | scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? |
| 26 | - Scrap::Notifier.deliver_mail(scrap) if scrap.send_notification? | |
| 26 | + Scrap::Notifier.notification(scrap).deliver if scrap.send_notification? | |
| 27 | 27 | end |
| 28 | 28 | |
| 29 | 29 | before_validation :strip_all_html_tags |
| ... | ... | @@ -49,21 +49,4 @@ class Scrap < ActiveRecord::Base |
| 49 | 49 | sender != receiver && (is_root? ? root.receiver.receives_scrap_notification? : receiver.receives_scrap_notification?) |
| 50 | 50 | end |
| 51 | 51 | |
| 52 | - class Notifier < ActionMailer::Base | |
| 53 | - def mail(scrap) | |
| 54 | - sender, receiver = scrap.sender, scrap.receiver | |
| 55 | - recipients receiver.email | |
| 56 | - | |
| 57 | - from "#{sender.environment.name} <#{sender.environment.contact_email}>" | |
| 58 | - subject _("[%s] You received a scrap!") % [sender.environment.name] | |
| 59 | - body :recipient => receiver.name, | |
| 60 | - :sender => sender.name, | |
| 61 | - :sender_link => sender.url, | |
| 62 | - :scrap_content => scrap.content, | |
| 63 | - :wall_url => scrap.scrap_wall_url, | |
| 64 | - :environment => sender.environment.name, | |
| 65 | - :url => sender.environment.top_url | |
| 66 | - end | |
| 67 | - end | |
| 68 | - | |
| 69 | 52 | end | ... | ... |
app/views/scrap/notifier/mail.html.erb
| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | -<%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> | |
| 2 | - | |
| 3 | -<%= word_wrap(_('%{sender} (%{sender_link}) has left the following scrap for you:') % { :sender => @sender, :sender_link => url_for(@sender_link) }) %> | |
| 4 | - | |
| 5 | -------------------------------------------------------------------------------- | |
| 6 | -<%= word_wrap(@scrap_content) %> | |
| 7 | -------------------------------------------------------------------------------- | |
| 8 | - | |
| 9 | -<%= _('View this scrap on the wall') %>: | |
| 10 | -<%= url_for @wall_url %> | |
| 11 | - | |
| 12 | -<%= _("Greetings,") %> | |
| 13 | - | |
| 14 | --- | |
| 15 | -<%= _('%s team.') % @environment %> | |
| 16 | -<%= url_for @url %> |
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +<%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> | |
| 2 | + | |
| 3 | +<%= word_wrap(_('%{sender} (%{sender_link}) has left the following scrap for you:') % { :sender => @sender, :sender_link => url_for(@sender_link) }) %> | |
| 4 | + | |
| 5 | +------------------------------------------------------------------------------- | |
| 6 | +<%= word_wrap(@scrap_content) %> | |
| 7 | +------------------------------------------------------------------------------- | |
| 8 | + | |
| 9 | +<%= _('View this scrap on the wall') %>: | |
| 10 | +<%= url_for @wall_url %> | |
| 11 | + | |
| 12 | +<%= _("Greetings,") %> | |
| 13 | + | |
| 14 | +-- | |
| 15 | +<%= _('%s team.') % @environment %> | |
| 16 | +<%= url_for @url %> | ... | ... |
test/unit/scrap_notifier_test.rb
| ... | ... | @@ -34,19 +34,19 @@ class ScrapNotifierTest < ActiveSupport::TestCase |
| 34 | 34 | should 'display sender name in delivered mail' do |
| 35 | 35 | Scrap.create!(:sender_id => @sender.id, :receiver_id => @receiver.id, :content => 'Hi man!') |
| 36 | 36 | sent = ActionMailer::Base.deliveries.first |
| 37 | - assert_match /user_scrap_sender_test/, sent.body | |
| 37 | + assert_match /user_scrap_sender_test/, sent.body.to_s | |
| 38 | 38 | end |
| 39 | 39 | |
| 40 | 40 | should 'display scrap content in delivered mail' do |
| 41 | 41 | Scrap.create!(:sender_id => @sender.id, :receiver_id => @receiver.id, :content => 'Hi man!') |
| 42 | 42 | sent = ActionMailer::Base.deliveries.first |
| 43 | - assert_match /Hi man!/, sent.body | |
| 43 | + assert_match /Hi man!/, sent.body.to_s | |
| 44 | 44 | end |
| 45 | 45 | |
| 46 | 46 | should 'display receiver wall link in delivered mail' do |
| 47 | 47 | Scrap.create!(:sender_id => @sender.id, :receiver_id => @receiver.id, :content => 'Hi man!') |
| 48 | 48 | sent = ActionMailer::Base.deliveries.first |
| 49 | - assert_match /\/profile\/user_scrap_receiver_test#profile-wall/, sent.body | |
| 49 | + assert_match /\/profile\/user_scrap_receiver_test#profile-wall/, sent.body.to_s | |
| 50 | 50 | end |
| 51 | 51 | |
| 52 | 52 | should 'not deliver mail if notify receiver and sender are the same person' do | ... | ... |