Skip to content

Commit

Permalink
allow sender to be specified for a notification
Browse files Browse the repository at this point in the history
  • Loading branch information
jasdeepsingh committed Mar 5, 2015
1 parent 30492cc commit 8a168eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/mailboxer/notification.rb
Expand Up @@ -33,13 +33,14 @@ class Mailboxer::Notification < ActiveRecord::Base

class << self
#Sends a Notification to all the recipients
def notify_all(recipients, subject, body, obj = nil, sanitize_text = true, notification_code=nil, send_mail=true)
def notify_all(recipients, subject, body, obj = nil, sanitize_text = true, notification_code=nil, send_mail=true, sender=nil)
notification = Mailboxer::NotificationBuilder.new({
:recipients => recipients,
:subject => subject,
:body => body,
:notified_object => obj,
:notification_code => notification_code
:notification_code => notification_code,
:sender => sender
}).build

notification.deliver sanitize_text, send_mail
Expand Down
20 changes: 20 additions & 0 deletions spec/models/notification_spec.rb
Expand Up @@ -99,6 +99,26 @@
expect(notification.body).to eq "Body"
end

it "should be able to specify a sender for a notification" do

Mailboxer::Notification.notify_all(@entity1,"Subject","Body", nil, true, nil, false, @entity3)

#Check getting ALL receipts
expect(@entity1.mailbox.receipts.size).to eq 1
receipt = @entity1.mailbox.receipts.first
notification = receipt.notification
expect(notification.subject).to eq "Subject"
expect(notification.body).to eq "Body"
expect(notification.sender).to eq @entity3

#Check getting NOTIFICATION receipts only
expect(@entity1.mailbox.notifications.size).to eq 1
notification = @entity1.mailbox.notifications.first
expect(notification.subject).to eq "Subject"
expect(notification.body).to eq "Body"
expect(notification.sender).to eq @entity3
end

describe "scopes" do
let(:scope_user) { FactoryGirl.create(:user) }
let!(:notification) { scope_user.notify("Body", "Subject").notification }
Expand Down

0 comments on commit 8a168eb

Please sign in to comment.