Skip to content

Commit

Permalink
validates uniqueness of username 馃槶
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Sep 4, 2015
1 parent ded6568 commit 3a7a8f1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/models/user.rb
Expand Up @@ -22,6 +22,7 @@ class User < ActiveRecord::Base
has_many :comments, -> { with_hidden }

validates :username, presence: true, unless: :organization?
validates :username, uniqueness: true, unless: :organization?
validates :official_level, inclusion: {in: 0..5}
validates_format_of :email, without: OMNIAUTH_EMAIL_REGEX, on: :update

Expand Down
8 changes: 4 additions & 4 deletions spec/factories.rb
@@ -1,9 +1,9 @@
FactoryGirl.define do
factory :user do
username 'Manuela'
sequence(:email) { |n| "manuela#{n}@madrid.es" }
password 'judgmentday'
confirmed_at { Time.now }
sequence(:username) { |n| "Manuela#{n}" }
sequence(:email) { |n| "manuela#{n}@madrid.es" }
password 'judgmentday'
confirmed_at { Time.now }

trait :hidden do
hidden_at Time.now
Expand Down
2 changes: 1 addition & 1 deletion spec/features/comments_spec.rb
Expand Up @@ -11,7 +11,7 @@

expect(page).to have_css('.comment', count: 3)

comment = Comment.first
comment = Comment.last
within first('.comment') do
expect(page).to have_content comment.user.name
expect(page).to have_content time_ago_in_words(comment.created_at)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/common_actions.rb
Expand Up @@ -4,7 +4,7 @@ def sign_up(email='manuela@madrid.es', password='judgementday')
visit '/'
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_password', with: password
fill_in 'user_password_confirmation', with: password
Expand Down

0 comments on commit 3a7a8f1

Please sign in to comment.