Skip to content

Commit

Permalink
Fix suitability record factory
Browse files Browse the repository at this point in the history
This fixes issues with the factories related to suitability records.
  • Loading branch information
thomasleese committed Jul 17, 2024
1 parent c95ec60 commit dc364f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/models/suitability_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# fk_rails_... (created_by_id => staff.id)
#
class SuitabilityRecord < ApplicationRecord
belongs_to :created_by, class_name: "Staff"
has_and_belongs_to_many :application_forms
has_many :emails, class_name: "SuitabilityRecord::Email"
has_many :names, class_name: "SuitabilityRecord::Name"
Expand All @@ -39,6 +40,8 @@ def archived?
class Email < ApplicationRecord
self.table_name = "suitability_record_emails"

belongs_to :suitability_record

validates :value, presence: true
validates :canonical, presence: true

Expand All @@ -51,6 +54,8 @@ def value=(value)
class Name < ApplicationRecord
self.table_name = "suitability_record_names"

belongs_to :suitability_record

validates :value, presence: true
end
end
12 changes: 7 additions & 5 deletions spec/factories/suitability_records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#
FactoryBot.define do
factory :suitability_record do
association :created_by, factory: :staff

note { Faker::Lorem.sentence }

trait :archived do
Expand All @@ -32,16 +34,16 @@
end
end

factory :suitability_record_email do
factory :suitability_record_email, class: SuitabilityRecord::Email do
association :suitability_record

value { Faker::Name.name }
value { Faker::Internet.email }
canonical { EmailAddress.canonical(value) }
end

factory :suitability_record_name do
factory :suitability_record_name, class: SuitabilityRecord::Name do
association :suitability_record

value { Faker::Internet.email }
canonical { EmailAddress.canonical(value) }
value { Faker::Name.name }
end
end

0 comments on commit dc364f8

Please sign in to comment.