|
196 | 196 | end |
197 | 197 | end |
198 | 198 |
|
| 199 | + context '.reject_bulk' do |
| 200 | + let(:reject_me) { Fabricate(:user) } |
| 201 | + let(:reject_me_too) { Fabricate(:user) } |
| 202 | + |
| 203 | + it 'does nothing without users' do |
| 204 | + UserDestroyer.any_instance.expects(:destroy).never |
| 205 | + xhr :delete, :reject_bulk |
| 206 | + end |
| 207 | + |
| 208 | + it "won't delete users if not allowed" do |
| 209 | + Guardian.any_instance.stubs(:can_delete_user?).returns(false) |
| 210 | + UserDestroyer.any_instance.expects(:destroy).never |
| 211 | + xhr :delete, :reject_bulk, users: [reject_me.id] |
| 212 | + end |
| 213 | + |
| 214 | + it "reports successes" do |
| 215 | + Guardian.any_instance.stubs(:can_delete_user?).returns(true) |
| 216 | + UserDestroyer.any_instance.stubs(:destroy).returns(true) |
| 217 | + xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id] |
| 218 | + response.should be_success |
| 219 | + json = ::JSON.parse(response.body) |
| 220 | + json['success'].to_i.should == 2 |
| 221 | + json['failed'].to_i.should == 0 |
| 222 | + end |
| 223 | + |
| 224 | + context 'failures' do |
| 225 | + before do |
| 226 | + Guardian.any_instance.stubs(:can_delete_user?).returns(true) |
| 227 | + end |
| 228 | + |
| 229 | + it 'can handle some successes and some failures' do |
| 230 | + UserDestroyer.any_instance.stubs(:destroy).with(reject_me, anything).returns(false) |
| 231 | + UserDestroyer.any_instance.stubs(:destroy).with(reject_me_too, anything).returns(true) |
| 232 | + xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id] |
| 233 | + response.should be_success |
| 234 | + json = ::JSON.parse(response.body) |
| 235 | + json['success'].to_i.should == 1 |
| 236 | + json['failed'].to_i.should == 1 |
| 237 | + end |
| 238 | + |
| 239 | + it 'reports failure due to a user still having posts' do |
| 240 | + UserDestroyer.any_instance.expects(:destroy).with(reject_me, anything).raises(UserDestroyer::PostsExistError) |
| 241 | + xhr :delete, :reject_bulk, users: [reject_me.id] |
| 242 | + response.should be_success |
| 243 | + json = ::JSON.parse(response.body) |
| 244 | + json['success'].to_i.should == 0 |
| 245 | + json['failed'].to_i.should == 1 |
| 246 | + end |
| 247 | + end |
| 248 | + end |
| 249 | + |
199 | 250 | context '.destroy' do |
200 | 251 | before do |
201 | 252 | @delete_me = Fabricate(:user) |
|
0 commit comments