Add associations
This commit is contained in:
parent
746fc30b20
commit
2d5f64792f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in New Issue