mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:42:45 +08:00
FIX: don't allow same category name with different case
This commit is contained in:
parent
d1f6c31382
commit
e40e9351f6
|
@ -23,7 +23,10 @@ class Category < ActiveRecord::Base
|
|||
has_many :groups, through: :category_groups
|
||||
|
||||
validates :user_id, presence: true
|
||||
validates :name, presence: true, uniqueness: { scope: :parent_category_id }, length: { in: 1..50 }
|
||||
validates :name, if: Proc.new { |c| c.new_record? || c.name_changed? },
|
||||
presence: true,
|
||||
uniqueness: { scope: :parent_category_id, case_sensitive: false },
|
||||
length: { in: 1..50 }
|
||||
validate :parent_category_validator
|
||||
|
||||
before_validation :ensure_slug
|
||||
|
|
|
@ -48,7 +48,7 @@ class Topic < ActiveRecord::Base
|
|||
rate_limit :limit_topics_per_day
|
||||
rate_limit :limit_private_messages_per_day
|
||||
|
||||
validates :title, :if => Proc.new { |t| t.title_changed? },
|
||||
validates :title, :if => Proc.new { |t| t.new_record? || t.title_changed? },
|
||||
:presence => true,
|
||||
:topic_title_length => true,
|
||||
:quality_title => { :unless => :private_message? },
|
||||
|
|
|
@ -12,6 +12,13 @@ describe Category do
|
|||
should validate_uniqueness_of(:name).scoped_to(:parent_category_id)
|
||||
end
|
||||
|
||||
it 'validates uniqueness in case insensitive way' do
|
||||
Fabricate(:category, name: "Cats")
|
||||
c = Fabricate.build(:category, name: "cats")
|
||||
c.should_not be_valid
|
||||
c.errors[:name].should be_present
|
||||
end
|
||||
|
||||
it { should belong_to :topic }
|
||||
it { should belong_to :user }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user