From 9b487953c44874864fe56c21359cc9a463ce8f34 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 10 Apr 2013 12:50:00 +1000 Subject: [PATCH] collapse some db tests ensure deleted topics do not show up in user stream --- app/models/user_action.rb | 6 +++++- spec/models/user_action_spec.rb | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/models/user_action.rb b/app/models/user_action.rb index a7278a48a..17813b942 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -50,6 +50,10 @@ class UserAction < ActiveRecord::Base results = results.where("action_type <> ?", BOOKMARK) end + unless guardian.can_see_deleted_posts? + results = results.where('topics.deleted_at IS NULL') + end + results = results.to_a results.sort! { |a,b| ORDER[a.action_type] <=> ORDER[b.action_type] } @@ -97,7 +101,7 @@ JOIN users pu on pu.id = COALESCE(p.user_id, t.user_id) ") unless guardian.can_see_deleted_posts? - builder.where("p.deleted_at is null and p2.deleted_at is null") + builder.where("p.deleted_at is null and p2.deleted_at is null and t.deleted_at is null") end unless guardian.user && guardian.user.id == user_id diff --git a/spec/models/user_action_spec.rb b/spec/models/user_action_spec.rb index e79f8a6df..05bbfb9cf 100644 --- a/spec/models/user_action_spec.rb +++ b/spec/models/user_action_spec.rb @@ -43,25 +43,19 @@ describe UserAction do UserAction.stats(user.id, Guardian.new(user)) end - it 'should include non private message events' do + it 'include correct events' do mystats.map{|r| r["action_type"].to_i}.should include(UserAction::NEW_TOPIC) - end - - it 'should exclude private messages for non owners' do UserAction.stats(user.id,Guardian.new).map{|r| r["action_type"].to_i}.should_not include(UserAction::NEW_PRIVATE_MESSAGE) - end - - it 'should not include got private messages for owners' do UserAction.stats(user.id,Guardian.new).map{|r| r["action_type"].to_i}.should_not include(UserAction::GOT_PRIVATE_MESSAGE) - end - - it 'should include private messages for owners' do mystats.map{|r| r["action_type"].to_i}.should include(UserAction::NEW_PRIVATE_MESSAGE) - end - - it 'should include got private messages for owners' do mystats.map{|r| r["action_type"].to_i}.should include(UserAction::GOT_PRIVATE_MESSAGE) end + + it 'should not include new topic when topic is deleted' do + public_topic.destroy + mystats.map{|r| r["action_type"].to_i}.should_not include(UserAction::NEW_TOPIC) + end + end describe 'stream' do @@ -70,6 +64,11 @@ describe UserAction do UserAction.stream(user_id: user.id, guardian: Guardian.new).count.should == 1 end + it 'should include no items for non owner when topic deleted' do + public_topic.destroy + UserAction.stream(user_id: user.id, guardian: Guardian.new).count.should == 0 + end + it 'should have bookmarks and pms for owners' do UserAction.stream(user_id: user.id, guardian: user.guardian).count.should == 4 end