mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Change the way nuked users' posts are handled. Allow null in the user_id column of posts. Show these posts in the posts stream.
This commit is contained in:
@@ -216,6 +216,7 @@ describe TopicView do
|
||||
# Create the posts in a different order than the sort_order
|
||||
let!(:p5) { Fabricate(:post, topic: topic, user: coding_horror)}
|
||||
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror)}
|
||||
let!(:p6) { Fabricate(:post, topic: topic, user: Fabricate(:user), deleted_at: Time.now)}
|
||||
let!(:p4) { Fabricate(:post, topic: topic, user: coding_horror, deleted_at: Time.now)}
|
||||
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster)}
|
||||
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster)}
|
||||
@@ -224,10 +225,12 @@ describe TopicView do
|
||||
SiteSetting.stubs(:posts_per_page).returns(3)
|
||||
|
||||
# Update them to the sort order we're checking for
|
||||
[p1, p2, p3, p4, p5].each_with_index do |p, idx|
|
||||
[p1, p2, p3, p4, p5, p6].each_with_index do |p, idx|
|
||||
p.sort_order = idx + 1
|
||||
p.save
|
||||
end
|
||||
p6.user_id = nil # user got nuked
|
||||
p6.save!
|
||||
end
|
||||
|
||||
describe '#filter_posts_paged' do
|
||||
@@ -236,6 +239,7 @@ describe TopicView do
|
||||
it 'returns correct posts for all pages' do
|
||||
topic_view.filter_posts_paged(1).should == [p1, p2]
|
||||
topic_view.filter_posts_paged(2).should == [p3, p5]
|
||||
topic_view.filter_posts_paged(3).should == []
|
||||
topic_view.filter_posts_paged(100).should == []
|
||||
end
|
||||
end
|
||||
@@ -271,6 +275,13 @@ describe TopicView do
|
||||
near_view.posts.should == [p2, p3, p4]
|
||||
end
|
||||
|
||||
it "returns deleted posts by nuked users to an admin" do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.desired_post.should == p5
|
||||
near_view.posts.should == [p4, p5, p6]
|
||||
end
|
||||
|
||||
context "when 'posts per page' exceeds the number of posts" do
|
||||
before { SiteSetting.stubs(:posts_per_page).returns(100) }
|
||||
|
||||
@@ -278,6 +289,12 @@ describe TopicView do
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.posts.should == [p1, p2, p3, p5]
|
||||
end
|
||||
|
||||
it 'returns deleted posts to admins' do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.posts.should == [p1, p2, p3, p4, p5, p6]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -121,25 +121,26 @@ describe UserDestroyer do
|
||||
it "deletes the posts" do
|
||||
destroy
|
||||
post.reload.deleted_at.should_not be_nil
|
||||
post.nuked_user.should be_true
|
||||
post.user_id.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'user has deleted posts' do
|
||||
let!(:deleted_post) { Fabricate(:post, user: @user, deleted_at: 1.hour.ago) }
|
||||
it "should mark the user's deleted posts as belonging to a nuked user" do
|
||||
expect { UserDestroyer.new(@admin).destroy(@user) }.to change { User.count }.by(-1)
|
||||
deleted_post.reload.user_id.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'user has no posts' do
|
||||
context 'and destroy succeeds' do
|
||||
|
||||
let(:destroy_opts) { {} }
|
||||
subject(:destroy) { UserDestroyer.new(@admin).destroy(@user) }
|
||||
|
||||
include_examples "successfully destroy a user"
|
||||
include_examples "email block list"
|
||||
|
||||
it "should mark the user's deleted posts as belonging to a nuked user" do
|
||||
post = Fabricate(:post, user: @user, deleted_at: 1.hour.ago)
|
||||
expect { destroy }.to change { User.count }.by(-1)
|
||||
post.reload.nuked_user.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context 'and destroy fails' do
|
||||
|
||||
Reference in New Issue
Block a user