From b18439a1e217ebd8172f2e3bde57e951983e3309 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 8 Nov 2016 17:00:44 +0800 Subject: [PATCH] Fix build. --- app/models/user.rb | 2 +- spec/models/user_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 062bc473635..3de3020d17e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -344,7 +344,7 @@ class User < ActiveRecord::Base end def read_first_notification? - notifications.order(created_at: :asc).first.read + notifications.order(created_at: :asc).first&.read || false end def publish_notifications_state diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8e8218110cc..cddc4b50a89 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1336,5 +1336,11 @@ describe User do expect(user.read_first_notification?).to eq(true) end end + + describe 'when user does not have any notifications' do + it 'should return the right value' do + expect(user.read_first_notification?).to eq(false) + end + end end end