2017-08-09 17:17:54 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
RSpec.describe Admin::FlagsController do
|
2017-08-09 17:17:54 +08:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
2017-08-24 11:01:11 +08:00
|
|
|
let(:post_1) { Fabricate(:post) }
|
2017-08-09 17:17:54 +08:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
context '#index' do
|
2017-08-09 17:17:54 +08:00
|
|
|
it 'should return the right response when nothing is flagged' do
|
|
|
|
get '/admin/flags.json'
|
|
|
|
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-09 17:17:54 +08: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-24 11:01:11 +08:00
|
|
|
PostAction.act(user, post_1, PostActionType.types[:spam])
|
2017-08-09 17:17:54 +08:00
|
|
|
|
|
|
|
get '/admin/flags.json'
|
|
|
|
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-09 17:17:54 +08:00
|
|
|
|
|
|
|
data = ::JSON.parse(response.body)
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(data["users"].length).to eq(2)
|
|
|
|
expect(data["posts"].length).to eq(1)
|
2017-08-09 17:17:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
context '#agree' do
|
2018-08-07 08:05:43 +08: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)
|
|
|
|
|
|
|
|
post_1.reload
|
|
|
|
expect(post_1.deleted_at).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to hide spam' do
|
2017-08-09 17:17:54 +08:00
|
|
|
SiteSetting.allow_user_locale = true
|
2018-05-31 15:53:49 +08:00
|
|
|
SiteSetting.queue_jobs = false
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
|
2017-08-09 17:17:54 +08:00
|
|
|
admin.update!(locale: 'ja')
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
post "/admin/flags/agree/#{post_1.id}.json"
|
2018-05-31 15:53:49 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-09 17:17:54 +08:00
|
|
|
|
|
|
|
post_action.reload
|
|
|
|
|
|
|
|
expect(post_action.agreed_by_id).to eq(admin.id)
|
|
|
|
|
2018-06-05 15:29:17 +08:00
|
|
|
agree_post = Topic.joins(:topic_allowed_users).where('topic_allowed_users.user_id = ?', user.id).order(:id).last.posts.last
|
|
|
|
expect(agree_post.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed') })
|
2017-08-09 17:17:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|