diff --git a/app/models/user.rb b/app/models/user.rb index 7d6ca2380..71db4ee2e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index e541c1b20..aaa9f222c 100644 --- a/spec/factories.rb +++ b/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 diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index f7e62c067..e4832a263 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -11,7 +11,7 @@ feature 'Comments' do 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) diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 1bcc971f4..e16bbac98 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -4,7 +4,7 @@ module CommonActions 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