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:
Guo Xiang Tan
2018-04-02 18:17:06 +08:00
parent d2a8f40fb0
commit 221503cd10
4 changed files with 88 additions and 8 deletions

View File

@ -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)