validates uniqueness of username 😭

This commit is contained in:
Juanjo Bazán
2015-09-04 23:15:41 +02:00
parent ded656837e
commit 3a7a8f13f5
4 changed files with 7 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ class User < ActiveRecord::Base
has_many :comments, -> { with_hidden } has_many :comments, -> { with_hidden }
validates :username, presence: true, unless: :organization? validates :username, presence: true, unless: :organization?
validates :username, uniqueness: true, unless: :organization?
validates :official_level, inclusion: {in: 0..5} validates :official_level, inclusion: {in: 0..5}
validates_format_of :email, without: OMNIAUTH_EMAIL_REGEX, on: :update validates_format_of :email, without: OMNIAUTH_EMAIL_REGEX, on: :update

View File

@@ -1,6 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :user do factory :user do
username 'Manuela' sequence(:username) { |n| "Manuela#{n}" }
sequence(:email) { |n| "manuela#{n}@madrid.es" } sequence(:email) { |n| "manuela#{n}@madrid.es" }
password 'judgmentday' password 'judgmentday'
confirmed_at { Time.now } confirmed_at { Time.now }

View File

@@ -11,7 +11,7 @@ feature 'Comments' do
expect(page).to have_css('.comment', count: 3) expect(page).to have_css('.comment', count: 3)
comment = Comment.first comment = Comment.last
within first('.comment') do within first('.comment') do
expect(page).to have_content comment.user.name expect(page).to have_content comment.user.name
expect(page).to have_content time_ago_in_words(comment.created_at) expect(page).to have_content time_ago_in_words(comment.created_at)

View File

@@ -4,7 +4,7 @@ module CommonActions
visit '/' visit '/'
click_link 'Sign up' click_link 'Sign up'
fill_in 'user_username', with: 'Manuela Carmena' fill_in 'user_username', with: "Manuela Carmena #{rand(99999)}"
fill_in 'user_email', with: email fill_in 'user_email', with: email
fill_in 'user_password', with: password fill_in 'user_password', with: password
fill_in 'user_password_confirmation', with: password fill_in 'user_password_confirmation', with: password