From 55ab8a8e8f3827b4efb9b149304256aa948701ad Mon Sep 17 00:00:00 2001 From: Christian Bruckmayer Date: Thu, 10 Mar 2016 13:42:30 +0100 Subject: [PATCH 1/2] Set sign_in attributes on iChain login Set last_sign_in_at and current_sign_in_at attributes when iChain login is enabled. #807 --- app/models/user.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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]) From a6c89351c5b6c6cafd9377a75623ec8390d3add6 Mon Sep 17 00:00:00 2001 From: Christian Bruckmayer Date: Thu, 10 Mar 2016 13:59:59 +0100 Subject: [PATCH 2/2] Make Comment find_since_last_login scope robust against nil value to fix production ArgumentError: bad value for range. Fixes #807. --- app/models/comment.rb | 6 +++++- spec/models/comment_spec.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 spec/models/comment_spec.rb 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/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