diff --git a/app/models/comment.rb b/app/models/comment.rb index 40d69240..c699f18a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 4ca0418f..5a14e885 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -74,7 +74,9 @@ class User < ActiveRecord::Base raise UserDisabled if user && user.is_disabled if user - user.update_attributes(email: attributes[:email]) + user.update_attributes(email: attributes[:email], + last_sign_in_at: user.current_sign_in_at, + current_sign_in_at: Time.current) else begin user = create!(username: username, email: attributes[:email]) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb new file mode 100644 index 00000000..94cb6372 --- /dev/null +++ b/spec/models/comment_spec.rb @@ -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