2019-05-08 10:20:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ReviewableClaimedTopicsController do
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
|
|
|
|
|
|
|
describe '#create' do
|
2019-05-10 06:59:31 -04:00
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
2019-05-08 10:20:51 -04:00
|
|
|
let(:params) do
|
|
|
|
{ reviewable_claimed_topic: { topic_id: topic.id } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "requires you to be logged in" do
|
|
|
|
post "/reviewable_claimed_topics.json", params: params
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(moderator)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "will raise an error if you can't claim the topic" do
|
|
|
|
post "/reviewable_claimed_topics.json", params: params
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "will return 200 if the user can claim the topic" do
|
|
|
|
SiteSetting.reviewable_claiming = 'optional'
|
|
|
|
post "/reviewable_claimed_topics.json", params: params
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
expect(ReviewableClaimedTopic.where(user_id: moderator.id, topic_id: topic.id).exists?).to eq(true)
|
|
|
|
end
|
2020-01-09 12:32:05 -05:00
|
|
|
|
|
|
|
it "won't an error if you claim twice" do
|
|
|
|
SiteSetting.reviewable_claiming = 'optional'
|
|
|
|
post "/reviewable_claimed_topics.json", params: params
|
|
|
|
expect(ReviewableClaimedTopic.where(user_id: moderator.id, topic_id: topic.id).exists?).to eq(true)
|
|
|
|
post "/reviewable_claimed_topics.json", params: params
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
end
|
2019-05-08 10:20:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
2019-05-10 06:59:31 -04:00
|
|
|
fab!(:claimed) { Fabricate(:reviewable_claimed_topic) }
|
2019-05-08 10:20:51 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(moderator)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "404s for a missing topic" do
|
|
|
|
delete "/reviewable_claimed_topics/111111111.json"
|
|
|
|
expect(response.code).to eq("404")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "403s when you can't claim the topic" do
|
|
|
|
delete "/reviewable_claimed_topics/#{claimed.topic_id}.json"
|
|
|
|
expect(response.code).to eq("403")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works when the feature is enabled" do
|
|
|
|
SiteSetting.reviewable_claiming = 'optional'
|
|
|
|
delete "/reviewable_claimed_topics/#{claimed.topic_id}.json"
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
expect(ReviewableClaimedTopic.where(topic_id: claimed.topic_id).exists?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|