Don't store post timings that are greater than the account lifetime

This commit is contained in:
Robin Ward 2015-04-14 11:49:44 -04:00
parent a57bbd5000
commit eaf5d21c41
2 changed files with 19 additions and 1 deletions

View File

@ -65,9 +65,11 @@ class PostTiming < ActiveRecord::Base
def self.process_timings(current_user, topic_id, topic_time, timings) def self.process_timings(current_user, topic_id, topic_time, timings)
current_user.user_stat.update_time_read! current_user.user_stat.update_time_read!
account_age_msecs = ((Time.now - current_user.created_at) * 1000.0)
highest_seen = 1 highest_seen = 1
timings.each do |post_number, time| timings.each do |post_number, time|
if post_number >= 0 if post_number >= 0 && time < account_age_msecs
PostTiming.record_timing(topic_id: topic_id, PostTiming.record_timing(topic_id: topic_id,
post_number: post_number, post_number: post_number,
user_id: current_user.id, user_id: current_user.id,

View File

@ -60,6 +60,22 @@ describe PostTiming do
end end
end end
describe 'safeguard' do
it "doesn't store timings that are larger than the account lifetime" do
user = Fabricate(:user, created_at: 3.minutes.ago)
post = Fabricate(:post)
PostTiming.process_timings(user, post.topic_id, 1, [[post.post_number, 123]])
msecs = PostTiming.where(post_number: post.post_number, user_id: user.id).pluck(:msecs)[0]
expect(msecs).to eq(123)
PostTiming.process_timings(user, post.topic_id, 1, [[post.post_number, 10.minutes.to_i * 1000]])
msecs = PostTiming.where(post_number: post.post_number, user_id: user.id).pluck(:msecs)[0]
expect(msecs).to eq(123)
end
end
describe 'process_timings' do describe 'process_timings' do
# integration test # integration test