From 228dfdd609fcd8939419bd57c6ab511a2e7081de Mon Sep 17 00:00:00 2001 From: Lori Bailey <44073106+elceebee@users.noreply.github.com> Date: Thu, 30 May 2024 14:14:52 +0100 Subject: [PATCH] Unit test for interview process form --- .../course_interview_process_form_spec.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/forms/publish/course_interview_process_form_spec.rb diff --git a/spec/forms/publish/course_interview_process_form_spec.rb b/spec/forms/publish/course_interview_process_form_spec.rb new file mode 100644 index 0000000000..513d894b1a --- /dev/null +++ b/spec/forms/publish/course_interview_process_form_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Publish::CourseInterviewProcessForm, type: :model do + describe 'validations' do + it 'validates length' do + course = create(:course) + enrichment = course.enrichments.find_or_initialize_draft + valid_interview_process = Faker::Lorem.sentence(word_count: 249) + invalid_interview_process = Faker::Lorem.sentence(word_count: 251) + + expect(described_class.new(enrichment, params: { interview_process: valid_interview_process }).valid?).to be true + expect(described_class.new(enrichment, params: { interview_process: nil }).valid?).to be true + expect(described_class.new(enrichment, params: { interview_process: invalid_interview_process }).valid?).to be false + end + end + + describe '#save!' do + it 'saves valid interview_process values' do + course = create(:course) + enrichment = course.enrichments.find_or_initialize_draft + + [nil, 'some value'].each do |value| + described_class.new(enrichment, params: { interview_process: value }).save! + expect(enrichment.reload.interview_process).to eq value + end + end + end +end