DEV: allow to have duplicate topic titles if categegory is different (#10034)

Co-authored-by: Robin Ward <robin.ward@gmail.com>

Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
Bernhard Suttner
2020-06-18 17:19:47 +02:00
committed by GitHub
parent ec794c7f29
commit e31471585a
6 changed files with 38 additions and 6 deletions

View File

@@ -255,19 +255,27 @@ describe Topic do
end
context 'topic title uniqueness' do
let!(:category1) { Fabricate(:category) }
let!(:category2) { Fabricate(:category) }
let!(:topic) { Fabricate(:topic) }
let(:new_topic) { Fabricate.build(:topic, title: topic.title) }
let!(:topic) { Fabricate(:topic, category: category1) }
let(:new_topic) { Fabricate.build(:topic, title: topic.title, category: category1) }
let(:new_topic_different_cat) { Fabricate.build(:topic, title: topic.title, category: category2) }
context "when duplicates aren't allowed" do
before do
SiteSetting.expects(:allow_duplicate_topic_titles?).returns(false)
SiteSetting.allow_duplicate_topic_titles = false
SiteSetting.allow_duplicate_topic_titles_category = false
end
it "won't allow another topic to be created with the same name" do
expect(new_topic).not_to be_valid
end
it "won't even allow another topic to be created with the same name but different category" do
expect(new_topic_different_cat).not_to be_valid
end
it "won't allow another topic with an upper case title to be created" do
new_topic.title = new_topic.title.upcase
expect(new_topic).not_to be_valid
@@ -286,7 +294,8 @@ describe Topic do
context "when duplicates are allowed" do
before do
SiteSetting.expects(:allow_duplicate_topic_titles?).returns(true)
SiteSetting.allow_duplicate_topic_titles = true
SiteSetting.allow_duplicate_topic_titles_category = false
end
it "will allow another topic to be created with the same name" do
@@ -294,6 +303,21 @@ describe Topic do
end
end
context "when duplicates are allowed if the category is different" do
before do
SiteSetting.allow_duplicate_topic_titles = false
SiteSetting.allow_duplicate_topic_titles_category = true
end
it "will allow another topic to be created with the same name but different category" do
expect(new_topic_different_cat).to be_valid
end
it "won't allow another topic to be created with the same name in same category" do
expect(new_topic).not_to be_valid
end
end
end
context 'html in title' do