2017-08-09 05:17:54 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
RSpec.describe Admin::FlagsController do
|
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) }
|
2017-08-09 05:17:54 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
data = ::JSON.parse(response.body)
|
|
|
|
data["users"].length == 2
|
|
|
|
data["posts"].length == 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
context '#agree' do
|
2017-08-09 05:17:54 -04:00
|
|
|
it 'should work' do
|
|
|
|
SiteSetting.allow_user_locale = true
|
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')
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
post "/admin/flags/agree/#{post_1.id}.json"
|
2017-08-09 05:17:54 -04:00
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
post_action.reload
|
|
|
|
|
|
|
|
expect(post_action.agreed_by_id).to eq(admin.id)
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
post_1 = Post.offset(1).last
|
2017-08-09 05:17:54 -04:00
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
expect(post_1.raw).to eq(I18n.with_locale(:en) { I18n.t('flags_dispositions.agreed') })
|
2017-08-09 05:17:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|