Improve code
This commit is contained in:
parent
df0e458c00
commit
27a6c17f1f
|
@ -40,7 +40,7 @@ class Account < ApplicationRecord
|
|||
|
||||
before_create :generate_guest_token
|
||||
|
||||
validates :person_id, allow_nil: true, uniqueness: true
|
||||
validates :person, allow_nil: true, uniqueness: true
|
||||
|
||||
validates :username,
|
||||
presence: true,
|
||||
|
|
|
@ -4,5 +4,5 @@ class AccountTelegramContact < ApplicationRecord
|
|||
belongs_to :account
|
||||
belongs_to :telegram_chat
|
||||
|
||||
validates :telegram_chat_id, uniqueness: true
|
||||
validates :telegram_chat, uniqueness: true
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ class MembershipApp < ApplicationRecord
|
|||
validates :date_of_birth, presence: true
|
||||
validates :phone_number, presence: true
|
||||
|
||||
validates :account_id, uniqueness: true
|
||||
validates :account, uniqueness: true
|
||||
|
||||
before_validation do
|
||||
email&.strip!
|
||||
|
|
|
@ -4,7 +4,7 @@ class PassportConfirmation < ApplicationRecord
|
|||
belongs_to :passport
|
||||
belongs_to :account
|
||||
|
||||
validates :account_id, uniqueness: { scope: :passport_id }
|
||||
validates :account, uniqueness: { scope: :passport_id }
|
||||
|
||||
validate :passport_can_have_confirmations
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@ class RegionalOffice < ApplicationRecord
|
|||
|
||||
has_many :people, dependent: :restrict_with_exception
|
||||
|
||||
validates :country_state_id, uniqueness: true
|
||||
validates :country_state, uniqueness: true
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ class User < ApplicationRecord
|
|||
|
||||
has_many :user_omniauths, dependent: :restrict_with_exception
|
||||
|
||||
validates :account_id, uniqueness: true
|
||||
validates :account, uniqueness: true
|
||||
|
||||
before_validation do
|
||||
self.account ||= Account.new
|
||||
|
|
|
@ -30,7 +30,7 @@ RSpec.describe MembershipApp do
|
|||
it { is_expected.not_to validate_presence_of :organization_membership }
|
||||
it { is_expected.not_to validate_presence_of :comment }
|
||||
|
||||
it { is_expected.to validate_uniqueness_of :account_id }
|
||||
it { is_expected.to validate_uniqueness_of :account }
|
||||
|
||||
describe '#email' do
|
||||
def allow_value(*)
|
||||
|
|
|
@ -12,7 +12,7 @@ RSpec.describe PassportConfirmation do
|
|||
it { is_expected.to validate_presence_of(:account).with_message(:required) }
|
||||
|
||||
it do
|
||||
is_expected.to validate_uniqueness_of(:account_id).scoped_to(:passport_id)
|
||||
is_expected.to validate_uniqueness_of(:account).scoped_to(:passport_id)
|
||||
end
|
||||
|
||||
it { is_expected.not_to allow_value(create(:empty_passport)).for :passport }
|
||||
|
|
|
@ -17,5 +17,5 @@ RSpec.describe RegionalOffice do
|
|||
.with_message(:required)
|
||||
end
|
||||
|
||||
it { is_expected.to validate_uniqueness_of :country_state_id }
|
||||
it { is_expected.to validate_uniqueness_of :country_state }
|
||||
end
|
||||
|
|
|
@ -7,5 +7,5 @@ RSpec.describe User do
|
|||
|
||||
it { is_expected.to belong_to(:account).required(false) }
|
||||
|
||||
it { is_expected.to validate_uniqueness_of :account_id }
|
||||
it { is_expected.to validate_uniqueness_of :account }
|
||||
end
|
||||
|
|
Reference in New Issue