mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Don't log a claimed topic database error during tests
We now test the uniqueness validation, but also rescue a DB exception in case the controller fails this check.
This commit is contained in:
@@ -4,11 +4,14 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe ReviewableClaimedTopic, type: :model do
|
||||
|
||||
it "ensures uniqueness" do
|
||||
claimed = Fabricate(:reviewable_claimed_topic)
|
||||
expect(-> {
|
||||
ReviewableClaimedTopic.create!(topic_id: claimed.topic_id, user_id: Fabricate(:user).id)
|
||||
}).to raise_error(ActiveRecord::RecordNotUnique)
|
||||
it "respects the uniqueness constraint" do
|
||||
topic = Fabricate(:topic)
|
||||
|
||||
ct = ReviewableClaimedTopic.new(topic_id: topic.id, user_id: Fabricate(:user).id)
|
||||
expect(ct.save).to eq(true)
|
||||
|
||||
ct = ReviewableClaimedTopic.new(topic_id: topic.id, user_id: Fabricate(:user).id)
|
||||
expect(ct.save).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -33,6 +33,14 @@ describe ReviewableClaimedTopicsController do
|
||||
expect(response.code).to eq("200")
|
||||
expect(ReviewableClaimedTopic.where(user_id: moderator.id, topic_id: topic.id).exists?).to eq(true)
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user