FIX: allow destination categories to be set if not at first

This commit is contained in:
Robin Ward
2018-03-23 11:33:02 -04:00
parent 38af67eb73
commit 5f19ad9507
2 changed files with 26 additions and 13 deletions

View File

@ -465,31 +465,40 @@ RSpec.describe TopicsController do
end
describe "#update_shared_draft" do
let(:category) { Fabricate(:category) }
let(:other_cat) { Fabricate(:category) }
let(:category) { Fabricate(:category) }
let(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
let!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
let(:moderator) { Fabricate(:moderator) }
context "anonymous" do
it "doesn't allow staff to update the shared draft" do
put "/t/#{topic.id}/shared-draft.json", params: { category_id: other_cat.id }
expect(response.code.to_i).to eq(403)
topic.reload
expect(topic.shared_draft.category_id).to eq(category.id)
end
end
context "as a moderator" do
let(:moderator) { Fabricate(:moderator) }
before do
sign_in(moderator)
end
it "allows staff to update the category id" do
put "/t/#{topic.id}/shared-draft.json", params: { category_id: other_cat.id }
expect(response).to be_success
topic.reload
expect(topic.shared_draft.category_id).to eq(other_cat.id)
context "with a shared draft" do
let!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
it "allows staff to update the category id" do
put "/t/#{topic.id}/shared-draft.json", params: { category_id: other_cat.id }
expect(response).to be_success
topic.reload
expect(topic.shared_draft.category_id).to eq(other_cat.id)
end
end
context "without a shared draft" do
it "allows staff to update the category id" do
put "/t/#{topic.id}/shared-draft.json", params: { category_id: other_cat.id }
expect(response).to be_success
topic.reload
expect(topic.shared_draft.category_id).to eq(other_cat.id)
end
end
end
end