mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 10:17:19 +08:00
fixed a pile of notification craziness
addes some tests around post timings
This commit is contained in:
@ -108,4 +108,17 @@ describe Notification do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mark_posts_read' do
|
||||
it "marks multiple posts as read if needed" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
notifications = (1..3).map do |i|
|
||||
Notification.create!(read: false, user_id: user.id, topic_id: 2, post_number: i, data: '[]', notification_type: 1)
|
||||
end
|
||||
Notification.create!(read: true, user_id: user.id, topic_id: 2, post_number: 4, data: '[]', notification_type: 1)
|
||||
|
||||
Notification.mark_posts_read(user,2,[1,2,3,4]).should == 3
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -8,6 +8,28 @@ describe PostTiming do
|
||||
it { should validate_presence_of :post_number }
|
||||
it { should validate_presence_of :msecs }
|
||||
|
||||
describe 'process_timings' do
|
||||
|
||||
# integration test
|
||||
|
||||
it 'processes timings correctly' do
|
||||
post = Fabricate(:post)
|
||||
user2 = Fabricate(:coding_horror)
|
||||
|
||||
PostAction.act(user2, post, PostActionType.Types[:like])
|
||||
post.user.unread_notifications.should == 1
|
||||
|
||||
post.user.unread_notifications_by_type.should == {Notification.Types[:liked] => 1}
|
||||
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, 100, [[post.post_number, 100]])
|
||||
|
||||
post.user.reload
|
||||
post.user.unread_notifications_by_type.should == {}
|
||||
post.user.unread_notifications.should == 0
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'recording' do
|
||||
before do
|
||||
@post = Fabricate(:post)
|
||||
|
@ -652,9 +652,6 @@ describe User do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe '#create_for_email' do
|
||||
@ -691,4 +688,32 @@ describe User do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'update_time_read!' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it 'makes no changes if nothing is cached' do
|
||||
$redis.expects(:get).with("user-last-seen:#{user.id}").returns(nil)
|
||||
user.update_time_read!
|
||||
user.reload
|
||||
user.time_read.should == 0
|
||||
end
|
||||
|
||||
it 'makes a change if time read is below threshold' do
|
||||
$redis.expects(:get).with("user-last-seen:#{user.id}").returns(Time.now - 10.0)
|
||||
user.update_time_read!
|
||||
user.reload
|
||||
user.time_read.should == 10
|
||||
end
|
||||
|
||||
it 'makes no change if time read is above threshold' do
|
||||
t = Time.now - 1 - User::MAX_TIME_READ_DIFF
|
||||
$redis.expects(:get).with("user-last-seen:#{user.id}").returns(t)
|
||||
user.update_time_read!
|
||||
user.reload
|
||||
user.time_read.should == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user