From c207b4bb330463c39c202d1c66e2447b55332093 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 8 Jun 2017 15:22:01 +0200 Subject: Fix db:seed - only run some validations when the field was changed (#3592) * Fix db:seed - only run some validations when the field was changed * Add tests --- spec/models/account_spec.rb | 6 ++++++ spec/models/user_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'spec/models') diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index ab4de9aa1..73ae34f8e 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -387,6 +387,12 @@ RSpec.describe Account, type: :model do expect(account).to model_have_error_on_field(:username) end + it 'is valid when username is reserved but record has already been created' do + account = Fabricate.build(:account, username: 'support') + account.save(validate: false) + expect(account.valid?).to be true + end + context 'when is local' do it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do account = Fabricate.build(:account, username: 'the-doctor') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 13a60f668..a6df3fb26 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -34,6 +34,12 @@ RSpec.describe User, type: :model do expect(user).to model_have_error_on_field(:email) end + it 'is valid with an invalid e-mail that has already been saved' do + user = Fabricate.build(:user, email: 'invalid-email') + user.save(validate: false) + expect(user.valid?).to be true + end + it 'cleans out empty string from languages' do user = Fabricate.build(:user, filtered_languages: ['']) user.valid? -- cgit