FIX: Add conditions on when to show first pm notification.

This commit is contained in:
Guo Xiang Tan 2016-11-16 14:17:47 +08:00
parent a9680e5a9e
commit 16fdcdfc00
2 changed files with 19 additions and 2 deletions

View File

@ -344,6 +344,7 @@ class User < ActiveRecord::Base
end
def read_first_notification?
return true if (trust_level > TrustLevel[0] || created_at < 1.week.ago)
notifications.order(created_at: :asc).first&.read || false
end

View File

@ -1318,7 +1318,7 @@ describe User do
end
describe '#read_first_notification?' do
let(:user) { Fabricate(:user) }
let(:user) { Fabricate(:user, trust_level: TrustLevel[0]) }
let(:notification) { Fabricate(:private_message_notification, user: user) }
let(:other_notification) { Fabricate(:private_message_notification, user: user) }
@ -1336,7 +1336,7 @@ describe User do
notification.update_attributes!(read: true)
other_notification.update_attributes!(read: false)
expect(user.read_first_notification?).to eq(true)
expect(user.reload.read_first_notification?).to eq(true)
end
end
@ -1345,6 +1345,22 @@ describe User do
expect(user.read_first_notification?).to eq(false)
end
end
describe 'when user is not trust level 0' do
it 'should return the right value' do
user.update_attributes!(trust_level: TrustLevel[1])
expect(user.read_first_notification?).to eq(true)
end
end
describe 'when user is an old user' do
it 'should return the right value' do
user.update_attributes!(created_at: 1.year.ago)
expect(user.read_first_notification?).to eq(true)
end
end
end
describe "#featured_user_badges" do