2018-06-05 00:43:05 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
require_dependency 'queued_posts_controller'
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
# NOTE: This controller only exists for backwards compatibility
|
2018-06-05 00:43:05 -04:00
|
|
|
describe QueuedPostsController do
|
|
|
|
context 'without authentication' do
|
|
|
|
it 'fails' do
|
|
|
|
get "/queued-posts.json"
|
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as a regular user' do
|
|
|
|
before { sign_in(Fabricate(:user)) }
|
|
|
|
|
|
|
|
it 'fails' do
|
|
|
|
get "/queued-posts.json"
|
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as an admin' do
|
|
|
|
before { sign_in(Fabricate(:moderator)) }
|
|
|
|
|
|
|
|
it 'returns the queued posts' do
|
|
|
|
get "/queued-posts.json"
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-05 00:43:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
|
|
|
before { sign_in(Fabricate(:moderator)) }
|
2019-01-03 12:03:01 -05:00
|
|
|
let(:qp) { Fabricate(:reviewable_queued_post) }
|
2018-06-05 00:43:05 -04:00
|
|
|
|
|
|
|
context 'not found' do
|
|
|
|
it 'returns json error' do
|
|
|
|
qp.destroy!
|
|
|
|
|
|
|
|
put "/queued_posts/#{qp.id}.json", params: {
|
|
|
|
queued_post: { state: 'approved' }
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(response.status).to eq(404)
|
2018-06-05 00:43:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'approved' do
|
|
|
|
it 'updates the post to approved' do
|
|
|
|
|
|
|
|
put "/queued_posts/#{qp.id}.json", params: {
|
|
|
|
queued_post: { state: 'approved' }
|
|
|
|
}
|
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2019-01-03 12:03:01 -05:00
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
qp_json = json['queued_posts']
|
2018-06-05 00:43:05 -04:00
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(qp_json['state']).to eq(2)
|
2018-06-05 00:43:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'rejected' do
|
|
|
|
it 'updates the post to rejected' do
|
|
|
|
|
|
|
|
put "/queued_posts/#{qp.id}.json", params: {
|
|
|
|
queued_post: { state: 'rejected' }
|
|
|
|
}
|
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-05 00:43:05 -04:00
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
qp_json = json['queued_posts']
|
|
|
|
expect(qp_json['state']).to eq(3)
|
2018-06-05 00:43:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'editing content' do
|
|
|
|
let(:changes) do
|
|
|
|
{
|
|
|
|
raw: 'new raw',
|
|
|
|
title: 'new title',
|
|
|
|
category_id: 10,
|
|
|
|
tags: ['new_tag']
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is a topic' do
|
2019-01-03 12:03:01 -05:00
|
|
|
let(:queued_topic) { Fabricate(:reviewable_queued_post_topic,) }
|
2018-06-05 00:43:05 -04:00
|
|
|
|
|
|
|
it 'updates the topic attributes' do
|
|
|
|
put "/queued_posts/#{queued_topic.id}.json", params: {
|
|
|
|
queued_post: changes
|
|
|
|
}
|
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-05 00:43:05 -04:00
|
|
|
queued_topic.reload
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(queued_topic.payload['raw']).to eq(changes[:raw])
|
|
|
|
expect(queued_topic.payload['title']).to eq(changes[:title])
|
|
|
|
expect(queued_topic.category_id).to eq(changes[:category_id])
|
|
|
|
expect(queued_topic.payload['tags']).to eq(changes[:tags])
|
2018-06-05 00:43:05 -04:00
|
|
|
end
|
2018-06-26 07:29:33 -04:00
|
|
|
|
|
|
|
it 'removes tags if not present' do
|
2019-01-03 12:03:01 -05:00
|
|
|
queued_topic.payload[:tags] = ['another-tag']
|
2018-06-26 07:29:33 -04:00
|
|
|
queued_topic.save!
|
|
|
|
|
|
|
|
put "/queued_posts/#{queued_topic.id}.json", params: {
|
|
|
|
queued_post: changes.except(:tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
queued_topic.reload
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(queued_topic.payload['raw']).to eq(changes[:raw])
|
|
|
|
expect(queued_topic.payload['title']).to eq(changes[:title])
|
|
|
|
expect(queued_topic.category_id).to eq(changes[:category_id])
|
|
|
|
expect(queued_topic.payload['tags']).to be_nil
|
2018-06-26 07:29:33 -04:00
|
|
|
end
|
2018-06-05 00:43:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is a reply' do
|
2019-01-03 12:03:01 -05:00
|
|
|
let(:queued_reply) { Fabricate(:reviewable_queued_post) }
|
2018-06-05 00:43:05 -04:00
|
|
|
|
|
|
|
it 'updates the reply attributes' do
|
|
|
|
put "/queued_posts/#{queued_reply.id}.json", params: {
|
|
|
|
queued_post: changes
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
original_category = queued_reply.category_id
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-05 00:43:05 -04:00
|
|
|
queued_reply.reload
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(queued_reply.payload['raw']).to eq(changes[:raw])
|
|
|
|
expect(queued_reply.payload['title']).to be_nil
|
|
|
|
expect(queued_reply.category_id).to eq(original_category)
|
|
|
|
expect(queued_reply.payload['tags']).to be_nil
|
2018-06-05 00:43:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|