mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-09 08:17:58 -04:00
Actually send email on creating notifications.
This commit is contained in:
@@ -9,8 +9,14 @@ class Notification < ActiveRecord::Base
|
||||
default_scope order('created_at DESC')
|
||||
scope :unread, where(:read => false)
|
||||
|
||||
after_create :send_email
|
||||
|
||||
def self.unread_count
|
||||
self.unread.count
|
||||
end
|
||||
|
||||
def send_email
|
||||
Notifier.notify(self).deliver
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ describe NotificationsController do
|
||||
|
||||
describe "GET index" do
|
||||
it "assigns all notifications as @notifications" do
|
||||
notification = Notification.create! valid_attributes
|
||||
notification = FactoryGirl.create(:notification, :recipient_id => subject.current_member.id)
|
||||
get :index, {}
|
||||
assigns(:notifications).should eq([notification])
|
||||
end
|
||||
@@ -22,13 +22,13 @@ describe NotificationsController do
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested notification as @notification" do
|
||||
notification = Notification.create! valid_attributes
|
||||
notification = FactoryGirl.create(:notification, :recipient_id => subject.current_member.id)
|
||||
get :show, {:id => notification.to_param}
|
||||
assigns(:notification).should eq(notification)
|
||||
end
|
||||
|
||||
it "marks notifications as read" do
|
||||
notification = Notification.create! valid_attributes
|
||||
notification = FactoryGirl.create(:notification, :recipient_id => subject.current_member.id)
|
||||
get :show, {:id => notification.to_param}
|
||||
# we need to fetch it from the db again, can't test against the old one
|
||||
n = Notification.find(notification.id)
|
||||
@@ -38,14 +38,14 @@ describe NotificationsController do
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "destroys the requested notification" do
|
||||
notification = Notification.create! valid_attributes
|
||||
notification = FactoryGirl.create(:notification, :recipient_id => subject.current_member.id)
|
||||
expect {
|
||||
delete :destroy, {:id => notification.to_param}
|
||||
}.to change(Notification, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the notifications page" do
|
||||
notification = Notification.create! valid_attributes
|
||||
notification = FactoryGirl.create(:notification, :recipient_id => subject.current_member.id)
|
||||
delete :destroy, {:id => notification.to_param}
|
||||
response.should redirect_to(notifications_url)
|
||||
end
|
||||
|
||||
@@ -31,4 +31,15 @@ describe Notification do
|
||||
@who.notifications.unread_count.should eq 2
|
||||
end
|
||||
|
||||
it "sends email if asked" do
|
||||
@notification2 = FactoryGirl.create(:notification)
|
||||
@notification2.send_email
|
||||
ActionMailer::Base.deliveries.last.to.should == [@notification2.recipient.email]
|
||||
end
|
||||
|
||||
it "sends email on creation" do
|
||||
@notification2 = FactoryGirl.create(:notification)
|
||||
ActionMailer::Base.deliveries.last.to.should == [@notification2.recipient.email]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user