diff --git a/app/mailers/form_mailer.rb b/app/mailers/form_mailer.rb index 0ec3671..0b5ddcc 100644 --- a/app/mailers/form_mailer.rb +++ b/app/mailers/form_mailer.rb @@ -106,8 +106,8 @@ def confirm_fixopac_email(user, bib, values) def confirm_illiad_email(user, bib, txnumber, values) userinfo = user.data - @to = userinfo['emailAddr'] - @from = '' + # use email from form if userinfo doesn't have an address + @to = userinfo['emailAddr'] || values['email'] @subject = 'Request Confirmation' @name = "#{userinfo['first_name']} #{userinfo['last_name']}" diff --git a/app/services/illiad.rb b/app/services/illiad.rb index 641ebc3..2593a06 100644 --- a/app/services/illiad.rb +++ b/app/services/illiad.rb @@ -1,6 +1,6 @@ class Illiad - @illoffices = Hash.new() { 'Van Pelt Library' } + @illoffices = Hash.new { 'Van Pelt Library' } @illoffices['BIOMED'] = 'Biomedical Library' @illoffices['DENTAL'] = 'Dental Medicine Library' @illoffices['VET'] = 'Veterinary Medicine Library' @@ -86,8 +86,7 @@ def self.getBibData(params) bib_data['pages'] = 'none specified' if bib_data['pages'].empty? - return bib_data - + bib_data end # queries DB @@ -137,7 +136,7 @@ def self.getIlliadUserInfo(user, params) db.close - return userinfo + userinfo end # no DB @@ -188,7 +187,7 @@ def self.getILLOffice(userinfo) end end - return office || 'VPL' + office || 'VPL' end # queries DB @@ -204,7 +203,7 @@ def self.addIlliadUser(user) unless unescaped_username raise ArgumentError, "addIlliadUser called with no username available! user_info: #{userinfo}" end - + username = db.escape unescaped_username # throws exception if #escape is sent nil query = %Q{INSERT INTO #{tablename} @@ -321,8 +320,8 @@ def self.submit(user, bib_data, params) PhotoArticleTitle: bib_data['chaptitle'], NotWantedAfter: '12/31/2010', Notes: bib_data['comments'], - CitedIn: bib_data['sid'], - SubmitButton: 'Submit Request'} + CitedIn: bib_data['sid'], + SubmitButton: 'Submit Request'} else illiadreqtype = 'ArticleRequest' illiadreqtype = 'BookChapterRequest' unless bib_data['requesttype'].index('chapter').nil? @@ -343,8 +342,8 @@ def self.submit(user, bib_data, params) PhotoArticleTitle: bib_data['article'], NotWantedAfter: '12/31/2010', Notes: bib_data['comments'], - CitedIn: bib_data['sid'], - SubmitButton: 'Submit Request'} + CitedIn: bib_data['sid'], + SubmitButton: 'Submit Request'} end begin @@ -356,7 +355,7 @@ def self.submit(user, bib_data, params) "Failed to get txnumber on Illiad submission. Illiad response: #{res}. Original exception: #{e.message}" end - return txnumber + txnumber end end diff --git a/spec/features/forms_spec.rb b/spec/features/forms_spec.rb index 326ebae..718c76a 100644 --- a/spec/features/forms_spec.rb +++ b/spec/features/forms_spec.rb @@ -1,6 +1,13 @@ require 'rails_helper' RSpec.feature 'Form rendering and submission', type: :feature do + before do + # Mock Illiad interactions + allow(Illiad).to receive(:getIlliadUserInfo).and_return nil + allow(Illiad).to receive(:addIlliadUser).and_return nil + allow(Illiad).to receive(:updateIlliadUser).and_return nil + allow(Illiad).to receive(:submit).and_return 'test_tx_number' + end let(:book_params) do { rfe_dat: '729064964', @@ -31,6 +38,21 @@ expect(page).to have_field 'Journal/Book Title', with: 'Phenomenology of perception /' expect(page).to have_field 'ISBN/ISSN', with: '0415834333' end + scenario 'upon submission, sends and email and renders confirmation' do + visit form_path({ id: 'ill', requesttype: 'ScanDelivery' }.merge(book_params)) + # fill in required fields even though they are only required by JS + test_email = 'test@upenn.edu' + fill_in 'Email', with: test_email + fill_in 'Article/Chapter Title', with: 'Other Selves and the Human World' + fill_in 'Issue Date', with: '1945' + click_on 'Submit Request' + expect(ActionMailer::Base.deliveries.length).to eq 1 + mail = ActionMailer::Base.deliveries.first + expect(mail.subject).to eq 'Request Confirmation' + expect(mail.to).to eq [test_email] + expect(page.current_path).to eq form_path(id: 'ill') + expect(page).to have_text 'Your request has been submitted' + end end context 'for cataloging errors' do let(:cataloging_params) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66..4a20410 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -93,4 +93,10 @@ # as the one that triggered the failure. Kernel.srand config.seed =end + + # Clear email queue before each test + config.before(:each) do + ActionMailer::Base.deliveries.clear + end + end