Skip to content

Commit

Permalink
Add more EtdHelper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-dce committed Mar 13, 2023
1 parent 6fb92a6 commit 043fecf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/helpers/etd_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def school_determined_departments(f)

def department_determined_subfields(f)
# a 'new' state, nothing is selected and disable subfields
if @curation_concern.new_record? || curation_concern['subfield'].empty?
if @curation_concern.new_record? || @curation_concern['subfield'].empty?

f.input :subfield, subfield_form_opts(disabled: true)

Expand Down
19 changes: 1 addition & 18 deletions spec/factories/etd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@
abstract { [] << FFaker::Lorem.paragraph }
end

factory :eun_etd do
title { ['China and its Minority Population'] }
creator { ['Eun, Dongwon'] }
keyword { ['China', 'Minority Population'] }
degree { ['MS'] }
department { ['Religion'] }
school { ['Laney Graduate School'] }
subfield { ['Ethics and Society'] }
submitting_type { ["Honors Thesis"] }
research_field { ['Religion, General'] }

after(:build) do |etd, evaluator|
etd.committee_chair.build(FactoryBot.attributes_for(:committee_member))
etd.committee_members.build(FactoryBot.attributes_for_list(:committee_member, 3))
end
end

factory :ateer_etd do
creator { ['Teer, Drew'] }
depositor do
Expand All @@ -48,7 +31,7 @@
AdminSet.where(title: 'Laney Graduate School').first
end
department { ['Psychology'] }
subfield { [] }
subfield { ['Clinical Psychology'] }
degree { ['MA'] }
language { ['English'] }
graduation_date { "Spring 1986" }
Expand Down
64 changes: 45 additions & 19 deletions spec/helpers/etd_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,56 @@
require 'rails_helper'

RSpec.describe EtdHelper, type: :helper do
let(:etd) { FactoryBot.build(:sample_data) }
let(:etd) { FactoryBot.build(:ateer_etd) }
let(:form) { double }
before { helper.instance_variable_set(:@curation_concern, etd) }

example "#department_form_opts" do
helper.instance_variable_set(:@curation_concern, etd)
form = double(form)
allow(form).to receive(:input)
helper.school_determined_departments(form)
expect(form).to have_received(:input).with(:department, hash_including(input_html: hash_including("data-option-url" => "/authorities/terms/local/:etd_school:")))
describe "#department_form_opts" do
example "for new ETDs" do
allow(etd).to receive(:new_record?).and_return true
allow(form).to receive(:input)
helper.school_determined_departments(form)
expect(form).to have_received(:input).with(:department, hash_including(required: true))
end
example "for saved ETDs" do
allow(etd).to receive(:new_record?).and_return false
allow(form).to receive(:input)
helper.school_determined_departments(form)
expect(form).to have_received(:input).with(:department, hash_including(selected: "Psychology", collection: kind_of(Array)))
end
end

example "#department_determined_subfields" do
helper.instance_variable_set(:@curation_concern, etd)
form = double(form)
allow(form).to receive(:input)
helper.department_determined_subfields(form)
expect(form).to have_received(:input).with(:subfield, hash_including(input_html: hash_including("data-option-url" => "/authorities/terms/local/:etd_department:")))
describe "#department_determined_subfields" do
example "for new ETDs" do
allow(etd).to receive(:new_record?).and_return true
allow(form).to receive(:input)
helper.department_determined_subfields(form)
expect(form).to have_received(:input).with(:subfield, hash_including(label: "Sub Field"))
end
example "for saved ETDs" do
allow(etd).to receive(:new_record?).and_return false
allow(form).to receive(:input)
helper.department_determined_subfields(form)
expect(form).to have_received(:input).with(:subfield, hash_including(selected: "Clinical Psychology", collection: kind_of(Array)))
end
end

example "#partnering_agency" do
helper.instance_variable_set(:@curation_concern, etd)
form = double(form)
allow(form).to receive(:input)
helper.partnering_agency(form)
expect(form).to have_received(:input).with(:partnering_agency, hash_including(collection: kind_of(Array)))
describe "#partnering_agency" do
example "for new ETDs" do
allow(etd).to receive(:new_record?).and_return true
form = double(form)
allow(form).to receive(:input)
helper.partnering_agency(form)
expect(form).to have_received(:input).with(:partnering_agency, hash_including(collection: kind_of(Array)))
end
example "for saved ETDs" do
allow(etd).to receive(:new_record?).and_return false
etd.partnering_agency = ['CDC']
form = double(form)
allow(form).to receive(:input)
helper.partnering_agency(form)
expect(form).to have_received(:input).with(:partnering_agency, hash_including(selected: 'CDC'))
end
end

example "#post_graduation_email" do
Expand Down

0 comments on commit 043fecf

Please sign in to comment.