1
0
Fork 0

Add associations

This commit is contained in:
Alex Kotov 2018-12-07 04:00:15 +05:00
parent 746fc30b20
commit 2d5f64792f
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
4 changed files with 8 additions and 0 deletions

View File

@ -4,6 +4,8 @@ class MembershipApp < ApplicationRecord
belongs_to :account, inverse_of: :own_membership_apps
belongs_to :country_state, optional: true
has_one :regional_office, through: :country_state
validates :email, presence: true, format: Devise.email_regexp
validates :first_name, presence: true

View File

@ -3,5 +3,7 @@
class RegionalOffice < ApplicationRecord
belongs_to :country_state
has_many :membership_apps, through: :country_state
validates :country_state_id, uniqueness: true
end

View File

@ -8,6 +8,8 @@ RSpec.describe MembershipApp do
it { is_expected.to belong_to(:account).inverse_of(:own_membership_apps) }
it { is_expected.to belong_to(:country_state).optional }
it { is_expected.to have_one(:regional_office).through(:country_state) }
it { is_expected.to validate_presence_of(:account).with_message(:required) }
it { is_expected.not_to validate_presence_of :country_state }
it { is_expected.to validate_presence_of :first_name }

View File

@ -7,6 +7,8 @@ RSpec.describe RegionalOffice do
it { is_expected.to belong_to :country_state }
it { is_expected.to have_many(:membership_apps).through(:country_state) }
it do
is_expected.to \
validate_presence_of(:country_state)