mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user