Make Comment find_since_last_login scope robust against nil value
to fix production ArgumentError: bad value for range. Fixes #807.
This commit is contained in:
parent
55ab8a8e8f
commit
a6c89351c5
2 changed files with 15 additions and 1 deletions
|
|
@ -41,7 +41,11 @@ class Comment < ActiveRecord::Base
|
|||
}
|
||||
|
||||
scope :find_since_last_login, lambda { |user|
|
||||
where(created_at: (user.last_sign_in_at..Time.now)).order(created_at: :desc)
|
||||
if user.last_sign_in_at
|
||||
where(created_at: (user.last_sign_in_at..Time.now)).order(created_at: :desc)
|
||||
else
|
||||
none
|
||||
end
|
||||
}
|
||||
# Helper class method to look up a commentable object
|
||||
# given the commentable class name and id
|
||||
|
|
|
|||
10
spec/models/comment_spec.rb
Normal file
10
spec/models/comment_spec.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Commercial do
|
||||
|
||||
describe '.find_since_last_login' do
|
||||
it 'returns none if last_sign_in_at is nil' do
|
||||
expect(Comment.find_since_last_login(create(:user))).to eq(Comment.none)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue