mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FIX: Add server side uniqueness validations for Group#name
and User#username
.
https://meta.discourse.org/t/groups-can-be-given-same-name-as-existing-username/74010
This commit is contained in:
@ -5,6 +5,32 @@ describe Group do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
context 'validations' do
|
||||
describe '#username' do
|
||||
context 'when a user with a similar name exists' do
|
||||
it 'should not be valid' do
|
||||
new_group = Fabricate.build(:group, name: admin.username.upcase)
|
||||
|
||||
expect(new_group).to_not be_valid
|
||||
|
||||
expect(new_group.errors.full_messages.first)
|
||||
.to include(I18n.t("activerecord.errors.messages.taken"))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a group with a similar name exists' do
|
||||
it 'should not be valid' do
|
||||
new_group = Fabricate.build(:group, name: group.name.upcase)
|
||||
|
||||
expect(new_group).to_not be_valid
|
||||
|
||||
expect(new_group.errors.full_messages.first)
|
||||
.to include(I18n.t("activerecord.errors.messages.taken"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#posts_for" do
|
||||
it "returns the post in the group" do
|
||||
p = Fabricate(:post)
|
||||
|
Reference in New Issue
Block a user