Allow changing ownwership of posts by admins

This commit is contained in:
riking
2014-03-27 18:28:14 -07:00
parent 7a843d2ac2
commit 1540a3d5e5
22 changed files with 308 additions and 20 deletions

View File

@ -195,6 +195,73 @@ describe TopicsController do
end
context 'change_post_owners' do
it 'needs you to be logged in' do
lambda { xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3] }.should raise_error(Discourse::NotLoggedIn)
end
describe 'forbidden to moderators' do
let!(:moderator) { log_in(:moderator) }
it 'correctly denies' do
xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3]
response.should be_forbidden
end
end
describe 'forbidden to elders' do
let!(:elder) { log_in(:elder) }
it 'correctly denies' do
xhr :post, :change_post_owners, topic_id: 111, username: 'user_a', post_ids: [1,2,3]
response.should be_forbidden
end
end
describe 'changing ownership' do
let!(:editor) { log_in(:admin) }
let(:topic) { Fabricate(:topic) }
let(:user_a) { Fabricate(:user) }
let(:p1) { Fabricate(:post, topic_id: topic.id) }
it "raises an error with a parameter missing" do
lambda { xhr :post, :change_post_owners, topic_id: 111, post_ids: [1,2,3] }.should raise_error(ActionController::ParameterMissing)
lambda { xhr :post, :change_post_owners, topic_id: 111, username: 'user_a' }.should raise_error(ActionController::ParameterMissing)
end
it "calls PostRevisor" do
PostRevisor.any_instance.expects(:revise!)
xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id]
response.should be_success
end
it "changes the user" do
old_user = p1.user
xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id]
p1.reload
old_user.should_not == p1.user
end
# Make sure that p1.reload isn't changing the user for us
it "is not an artifact of the framework" do
old_user = p1.user
# xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id]
p1.reload
p1.user.should_not == nil
old_user.should == p1.user
end
let(:p2) { Fabricate(:post, topic_id: topic.id) }
it "changes multiple posts" do
xhr :post, :change_post_owners, topic_id: topic.id, username: user_a.username_lower, post_ids: [p1.id, p2.id]
p1.reload
p2.reload
p1.user.should_not == nil
p1.user.should == p2.user
end
end
end
context 'similar_to' do
let(:title) { 'this title is long enough to search for' }