mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-21 06:24:22 -04:00
Replace blank/nil notification subjects with (no subject)
This commit is contained in:
1 parent
9d4caaa2b5
commit
aab0a438fd
3 files changed
+53
-10
No files matched your search
@@ -9,12 +9,19 @@ class Notification < ActiveRecord::Base
|
||||
default_scope order('created_at DESC')
|
||||
scope :unread, where(:read => false)
|
||||
|
||||
before_create :replace_blank_subject
|
||||
after_create :send_email
|
||||
|
||||
def self.unread_count
|
||||
self.unread.count
|
||||
end
|
||||
|
||||
def replace_blank_subject
|
||||
if self.subject.nil? or self.subject =~ /^\s*$/
|
||||
self.subject = "(no subject)"
|
||||
end
|
||||
end
|
||||
|
||||
def send_email
|
||||
if self.recipient.send_notification_email
|
||||
Notifier.notify(self).deliver
|
||||
|
||||
@@ -48,4 +48,14 @@ describe Notification do
|
||||
ActionMailer::Base.deliveries.last.to.should == [@notification2.recipient.email]
|
||||
end
|
||||
|
||||
it "replaces missing subjects with (no subject)" do
|
||||
@notification = FactoryGirl.create(:notification, :subject => nil)
|
||||
@notification.subject.should == "(no subject)"
|
||||
end
|
||||
|
||||
it "replaces whitespace-only subjects with (no subject)" do
|
||||
@notification = FactoryGirl.create(:notification, :subject => " ")
|
||||
@notification.subject.should == "(no subject)"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -4,19 +4,45 @@ describe "notifications/index" do
|
||||
before(:each) do
|
||||
@member = FactoryGirl.create(:member)
|
||||
controller.stub(:current_user) { @member }
|
||||
@notification = FactoryGirl.create(:notification, :sender => @member, :recipient => @member)
|
||||
assign(:notifications, [ @notification, @notification ])
|
||||
render
|
||||
end
|
||||
|
||||
it "renders a list of notifications" do
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "table"
|
||||
assert_select "tr>td", :text => @notification.sender.to_s, :count => 2
|
||||
assert_select "tr>td", :text => @notification.subject, :count => 2
|
||||
context "ordinary notifications" do
|
||||
before(:each) do
|
||||
@notification = FactoryGirl.create(:notification, :sender => @member,
|
||||
:recipient => @member)
|
||||
assign(:notifications, [ @notification, @notification ])
|
||||
render
|
||||
end
|
||||
|
||||
it "renders a list of notifications" do
|
||||
assert_select "table"
|
||||
assert_select "tr>td", :text => @notification.sender.to_s, :count => 2
|
||||
assert_select "tr>td", :text => @notification.subject, :count => 2
|
||||
end
|
||||
|
||||
it "links to sender's profile" do
|
||||
assert_select "a", :href => member_path(@notification.sender)
|
||||
end
|
||||
end
|
||||
|
||||
it "links to sender's profile" do
|
||||
assert_select "a", :href => member_path(@notification.sender)
|
||||
context "no subject" do
|
||||
it "shows (no subject)" do
|
||||
@notification = FactoryGirl.create(:notification,
|
||||
:sender => @member, :recipient => @member, :subject => nil)
|
||||
assign(:notifications, [@notification])
|
||||
render
|
||||
rendered.should contain "(no subject)"
|
||||
end
|
||||
end
|
||||
|
||||
context "whitespace-only subject" do
|
||||
it "shows (no subject)" do
|
||||
@notification = FactoryGirl.create(:notification,
|
||||
:sender => @member, :recipient => @member, :subject => " ")
|
||||
assign(:notifications, [@notification])
|
||||
render
|
||||
rendered.should contain "(no subject)"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user