2017-08-09 05:17:54 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
RSpec.describe Admin::FlagsController do
|
2018-11-23 08:58:04 -05:00
|
|
|
let(:user) { Fabricate(:user) }
|
2017-08-09 05:17:54 -04:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
2017-08-23 23:01:11 -04:00
|
|
|
let(:post_1) { Fabricate(:post) }
|
2018-11-23 08:58:04 -05:00
|
|
|
let(:category) { Fabricate(:category) }
|
|
|
|
let(:first_post) { Fabricate(:post, post_number: 1) }
|
2017-08-09 05:17:54 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
context '#index' do
|
2017-08-09 05:17:54 -04:00
|
|
|
it 'should return the right response when nothing is flagged' do
|
|
|
|
get '/admin/flags.json'
|
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-09 05:17:54 -04:00
|
|
|
|
|
|
|
data = ::JSON.parse(response.body)
|
|
|
|
expect(data["users"]).to eq([])
|
|
|
|
expect(data["posts"]).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return the right response' do
|
2017-08-23 23:01:11 -04:00
|
|
|
PostAction.act(user, post_1, PostActionType.types[:spam])
|
2017-08-09 05:17:54 -04:00
|
|
|
|
|
|
|
get '/admin/flags.json'
|
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-09 05:17:54 -04:00
|
|
|
|
|
|
|
data = ::JSON.parse(response.body)
|
2018-06-05 03:29:17 -04:00
|
|
|
expect(data["users"].length).to eq(2)
|
|
|
|
expect(data["posts"].length).to eq(1)
|
2017-08-09 05:17:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
context '#agree' do
|
2018-09-11 23:16:45 -04:00
|
|
|
it 'should raise a reasonable error if a flag was deferred and then someone else agreed' do
|
|
|
|
SiteSetting.queue_jobs = false
|
|
|
|
|
|
|
|
_post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
|
|
|
|
|
|
|
|
post "/admin/flags/defer/#{post_1.id}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
post "/admin/flags/agree/#{post_1.id}.json", params: { action_on_post: 'keep' }
|
|
|
|
# 409 means conflict which is what is happening here
|
|
|
|
expect(response.status).to eq(409)
|
|
|
|
error = JSON.parse(response.body)["errors"].first
|
|
|
|
expect(error).to eq(I18n.t("flags.errors.already_handled"))
|
|
|
|
end
|
|
|
|
|
2018-08-06 20:05:43 -04:00
|
|
|
it 'should be able to agree and keep content' do
|
|
|
|
SiteSetting.queue_jobs = false
|
|
|
|
|
|
|
|
post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
|
|
|
|
|
|
|
|
post "/admin/flags/agree/#{post_1.id}.json", params: { action_on_post: 'keep' }
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
post_action.reload
|
|
|
|
expect(post_action.agreed_by_id).to eq(admin.id)
|
2018-10-31 15:35:07 -04:00
|
|
|
expect(user.user_stat.reload.flags_agreed).to eq(1)
|
2018-08-06 20:05:43 -04:00
|
|
|
|
|
|
|
post_1.reload
|
|
|
|
expect(post_1.deleted_at).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to hide spam' do
|
2017-08-09 05:17:54 -04:00
|
|
|
SiteSetting.allow_user_locale = true
|
2018-05-31 03:53:49 -04:00
|
|
|
SiteSetting.queue_jobs = false
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
|
2017-08-09 05:17:54 -04:00
|
|
|
admin.update!(locale: 'ja')
|
|
|
|
|
2018-11-23 08:58:04 -05:00
|
|
|
post "/admin/flags/agree/#{post_1.id}.json", params: { action_on_post: 'delete' }
|
2018-05-31 03:53:49 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-09 05:17:54 -04:00
|
|
|
|
|
|
|
post_action.reload
|
|
|
|
|
|
|
|
expect(post_action.agreed_by_id).to eq(admin.id)
|
2018-10-31 15:35:07 -04:00
|
|
|
expect(user.user_stat.reload.flags_agreed).to eq(1)
|
2017-08-09 05:17:54 -04:00
|
|
|
|
2018-06-05 03:29:17 -04:00
|
|
|
agree_post = Topic.joins(:topic_allowed_users).where('topic_allowed_users.user_id = ?', user.id).order(:id).last.posts.last
|
2018-11-23 08:58:04 -05:00
|
|
|
expect(agree_post.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed_and_deleted') })
|
|
|
|
|
|
|
|
post_1.reload
|
|
|
|
expect(post_1.deleted_at).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not delete category topic' do
|
|
|
|
SiteSetting.queue_jobs = false
|
|
|
|
category.update_column(:topic_id, first_post.topic_id)
|
|
|
|
|
2018-11-25 13:06:34 -05:00
|
|
|
PostAction.act(user, first_post, PostActionType.types[:spam], message: 'bad')
|
2018-11-23 08:58:04 -05:00
|
|
|
|
|
|
|
post "/admin/flags/agree/#{first_post.id}.json", params: { action_on_post: 'delete' }
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
|
|
|
|
first_post.reload
|
|
|
|
expect(first_post.deleted_at).to eq(nil)
|
2017-08-09 05:17:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|