collapse some db tests

ensure deleted topics do not show up in user stream
This commit is contained in:
Sam 2013-04-10 12:50:00 +10:00
parent e8a6626e6a
commit 9b487953c4
2 changed files with 17 additions and 14 deletions

View file

@ -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

View file

@ -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