Skip to content

Commit

Permalink
Remove custom fixture method
Browse files Browse the repository at this point in the history
Rails 7.2 has one by the same name, which conflicts with ours.  We can
use the built-in file_fixture method instead.
  • Loading branch information
sandbergja committed Dec 30, 2024
1 parent 1a1d55c commit b528c41
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 46 deletions.
6 changes: 3 additions & 3 deletions spec/controllers/requests/form_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require "mail"

describe Requests::FormController, type: :controller, vcr: { cassette_name: 'form_controller', record: :none }, requests: true do
let(:valid_patron_response) { fixture('/bibdata_patron_response.json') }
let(:valid_barcode_patron_response) { fixture('/bibdata_patron_response_barcode.json') }
let(:invalid_patron_response) { fixture('/bibdata_not_found_patron_response.json') }
let(:valid_patron_response) { file_fixture('../bibdata_patron_response.json') }
let(:valid_barcode_patron_response) { file_fixture('../bibdata_patron_response_barcode.json') }
let(:invalid_patron_response) { file_fixture('../bibdata_not_found_patron_response.json') }
let(:user) { FactoryBot.create(:user) }

describe 'POST #generate' do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/email_authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe 'email form' do
let(:bibid) { '9979948663506421' }
let(:user) { FactoryBot.create(:valid_princeton_patron) }
let(:valid_patron_response) { fixture('/bibdata_patron_response.json') }
let(:valid_patron_response) { file_fixture('../bibdata_patron_response.json') }

before do
current_illiad_user_uri = "#{Requests.config[:illiad_api_base]}/ILLiadWebPlatform/Users/jstudent"
Expand Down
24 changes: 12 additions & 12 deletions spec/features/requests/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
let(:transaction_url) { "https://lib-illiad.princeton.edu/ILLiadWebPlatform/transaction" }
let(:transaction_note_url) { "https://lib-illiad.princeton.edu/ILLiadWebPlatform/transaction/1093806/notes" }

let(:valid_patron_response) { fixture('/bibdata_patron_response.json') }
let(:valid_patron_no_barcode_response) { fixture('/bibdata_patron_no_barcode_response.json') }
let(:valid_barcode_patron_response) { fixture('/bibdata_patron_response_barcode.json') }
let(:valid_patron_no_campus_response) { fixture('/bibdata_patron_response_no_campus.json') }
let(:valid_graduate_student_no_campus_response) { fixture('/bibdata_patron_response_graduate_no_campus.json') }
let(:invalid_patron_response) { fixture('/bibdata_not_found_patron_response.json') }
let(:valid_patron_response_no_ldap) { fixture('/bibdata_patron_response_no_ldap.json') }
let(:valid_patron_response) { file_fixture('../bibdata_patron_response.json') }
let(:valid_patron_no_barcode_response) { file_fixture('../bibdata_patron_no_barcode_response.json') }
let(:valid_barcode_patron_response) { file_fixture('../bibdata_patron_response_barcode.json') }
let(:valid_patron_no_campus_response) { file_fixture('../bibdata_patron_response_no_campus.json') }
let(:valid_graduate_student_no_campus_response) { file_fixture('../bibdata_patron_response_graduate_no_campus.json') }
let(:invalid_patron_response) { file_fixture('../bibdata_not_found_patron_response.json') }
let(:valid_patron_response_no_ldap) { file_fixture('../bibdata_patron_response_no_ldap.json') }

let(:responses) do
{
Expand Down Expand Up @@ -106,7 +106,7 @@
end

describe 'When visiting an Alma ID as a CAS User' do
let(:good_response) { fixture('/scsb_request_item_response.json') }
let(:good_response) { file_fixture('../scsb_request_item_response.json') }
it 'Shows a ReCAP PUL item that is at "preservation and conservation" as a partner request' do
stub_illiad_patron
stub_request(:post, transaction_url)
Expand Down Expand Up @@ -149,7 +149,7 @@
.to_return(status: 200, body: "<document count='1' sent='true'></document>", headers: {})
stub_request(:post, "#{Alma.configuration.region}/almaws/v1/bibs/9994933183506421/holdings/22558528920006421/items/23558528910006421/requests?user_id=960594184")
.with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "firestone"))
.to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' })
.to_return(status: 200, body: file_fixture("../alma_hold_response.json"), headers: { 'content-type': 'application/json' })
visit "/requests/#{mms_id}"
expect(page).to have_content 'Electronic Delivery'
# some weird issue with this and capybara examining the page source shows it is there.
Expand Down Expand Up @@ -526,7 +526,7 @@
.to_return(status: 200, body: good_response, headers: {})
stub_request(:post, "#{Alma.configuration.region}/almaws/v1/bibs/99115783193506421/holdings/22534122440006421/items/23534122430006421/requests?user_id=960594184")
.with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "firestone"))
.to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' })
.to_return(status: 200, body: file_fixture("../alma_hold_response.json"), headers: { 'content-type': 'application/json' })
visit '/requests/99115783193506421?mfhd=22534122440006421'
expect(page).not_to have_content 'Item is not requestable.'
expect(page).not_to have_content 'Electronic Delivery'
Expand Down Expand Up @@ -1124,7 +1124,7 @@
expect(page).not_to have_content 'Only items available for digitization can be requested when you do not have a barcode registered with the Library. Library staff will work to try to get you access to a digital copy of the desired material.'
end

let(:good_response) { fixture('/scsb_request_item_response.json') }
let(:good_response) { file_fixture('../scsb_request_item_response.json') }
it 'disallows access to request a physical ReCAP item' do
stub_scsb_availability(bib_id: "9999443553506421", institution_id: "PUL", barcode: '32101098722844')
visit '/requests/9999443553506421?mfhd=22743365320006421'
Expand Down Expand Up @@ -1247,7 +1247,7 @@
end

context 'An Alma user that does not have a Net ID' do
let(:alma_login_response) { fixture('/alma_login_response.json') }
let(:alma_login_response) { file_fixture('../alma_login_response.json') }
let(:user) { FactoryBot.create(:valid_alma_patron) }
before do
stub_request(:get, "#{Alma.configuration.region}/almaws/v1/users/#{user.uid}?expand=fees,requests,loans")
Expand Down
2 changes: 1 addition & 1 deletion spec/features/requests/marquand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
stub_request(:post, "#{Requests.config[:scsb_base]}/requestItem/requestItem")
.to_return(status: 200, body: good_response, headers: {})
end
let(:good_response) { fixture('/scsb_request_item_response.json') }
let(:good_response) { file_fixture('../scsb_request_item_response.json') }
before do
scsb_post_stub
stub_scsb_availability(bib_id:, institution_id: "PUL", barcode: item_barcode)
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/requests/request_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# rubocop:disable RSpec/MultipleExpectations
# rubocop:disable Metrics/BlockLength
describe Requests::RequestMailer, type: :mailer, vcr: { cassette_name: 'mailer', record: :none }, requests: true do
let(:valid_patron_response) { fixture('/bibdata_patron_response.json') }
let(:valid_patron_response) { file_fixture('../bibdata_patron_response.json') }

let(:user_info) do
stub_request(:get, "#{Requests.config[:bibdata_base]}/patron/foo?ldap=true").to_return(status: 200, body: valid_patron_response, headers: {})
Expand Down
2 changes: 1 addition & 1 deletion spec/models/concerns/requests/scsb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:patron) do
Requests::Patron.new(user:, patron_hash: valid_patron)
end
let(:scsb_no_format) { fixture('/SCSB-7935196.json') }
let(:scsb_no_format) { file_fixture('../SCSB-7935196.json') }
let(:location_code) { 'scsbnypl' }
let(:params) do
{
Expand Down
2 changes: 1 addition & 1 deletion spec/models/requests/alma_patron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RSpec.describe Requests::AlmaPatron, requests: true, patrons: true do
context 'with a call to Alma' do
let(:uid) { 'BC123456789' }
let(:patron_with_multiple_barcodes) { fixture('/BC123456789.json') }
let(:patron_with_multiple_barcodes) { file_fixture('../BC123456789.json') }
let(:alma_stub) do
stub_request(:get, "https://api-na.hosted.exlibrisgroup.com/almaws/v1/users/#{uid}?expand=fees,requests,loans")
.to_return(status: 200, body: patron_with_multiple_barcodes, headers: { "Content-Type" => "application/json" })
Expand Down
2 changes: 1 addition & 1 deletion spec/models/requests/form_no_vcr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
stub_request(:get, "https://catalog.princeton.edu/catalog/#{document_id}/raw")
.to_return(status: 200, body: catalog_raw_fixture)
stub_request(:get, "#{Requests.config[:bibdata_base]}/locations/holding_locations/eastasian$cjk.json")
.to_return(status: 200, body: fixture('/bibdata/eastasian_cjk_holding_locations.json'))
.to_return(status: 200, body: file_fixture('../bibdata/eastasian_cjk_holding_locations.json'))
stub_request(:get, "#{Requests.config[:bibdata_base]}/bibliographic/#{params[:system_id]}/holdings/#{params[:mfhd]}/availability.json").to_timeout
stub_delivery_locations
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/requests/full_patron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

context 'with a patron' do
let(:patron) { described_class.new(user:) }
let(:valid_patron_response) { fixture('/bibdata_patron_response.json') }
let(:valid_patron_response) { file_fixture('../bibdata_patron_response.json') }
let(:bibdata_mock) do
stub_request(:get, "#{Requests.config[:bibdata_base]}/patron/abc123?ldap=true")
.to_return(status: 200, body: valid_patron_response, headers: {})
Expand Down
8 changes: 4 additions & 4 deletions spec/models/requests/patron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
instance_double(User, guest?: guest?, uid:, alma_provider?: false, provider:, valid?: true)
end
let(:bibdata_uri) { Requests.config[:bibdata_base] }
let(:valid_patron_response) { fixture('/bibdata_patron_response.json') }
let(:valid_barcode_patron_response) { fixture('/bibdata_patron_response_barcode.json') }
let(:invalid_patron_response) { fixture('/bibdata_not_found_patron_response.json') }
let(:valid_patron_response) { file_fixture('../bibdata_patron_response.json') }
let(:valid_barcode_patron_response) { file_fixture('../bibdata_patron_response_barcode.json') }
let(:invalid_patron_response) { file_fixture('../bibdata_not_found_patron_response.json') }

context 'when the user is provided from Alma' do
let(:uid) { 'BC123456789' }
let(:user) do
instance_double(User, guest?: guest?, uid:, alma_provider?: true, provider:)
end
let(:patron_with_multiple_barcodes) { fixture('/BC123456789.json') }
let(:patron_with_multiple_barcodes) { file_fixture('../BC123456789.json') }

before do
stub_request(:get, "https://api-na.hosted.exlibrisgroup.com/almaws/v1/users/#{uid}?expand=fees,requests,loans")
Expand Down
2 changes: 1 addition & 1 deletion spec/models/requests/router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Requests::Patron.new(user:, patron_hash: valid_patron)
end

let(:scsb_single_holding_item) { fixture('/SCSB-2635660.json') }
let(:scsb_single_holding_item) { file_fixture('../SCSB-2635660.json') }
let(:location_code) { 'scsbcul' }
let(:params) do
{
Expand Down
6 changes: 3 additions & 3 deletions spec/models/requests/submissions/hold_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@

let(:responses) do
{
error: fixture("alma_hold_error_response.json"),
error_malformed: fixture("alma_hold_error_no_library_response.json"),
success: fixture("alma_hold_response.json")
error: file_fixture("../alma_hold_error_response.json"),
error_malformed: file_fixture("../alma_hold_error_no_library_response.json"),
success: file_fixture("../alma_hold_response.json")
}
end

Expand Down
20 changes: 10 additions & 10 deletions spec/models/requests/submissions/recap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@

let(:recap_request) { described_class.new(submission) }
let(:recap_edd_request) { described_class.new(submission, service_type: 'recap_edd') }
let(:good_request) { fixture('/scsb_find_request.json') }
let(:good_response) { fixture('/scsb_request_item_response.json') }
let(:bad_response) { fixture('/scsb_request_item_response_errors.json') }
let(:good_request) { file_fixture('../scsb_find_request.json') }
let(:good_response) { file_fixture('../scsb_request_item_response.json') }
let(:bad_response) { file_fixture('../scsb_request_item_response_errors.json') }

describe 'All ReCAP Requests' do
it "captures recap errors when the request is unsuccessful or malformed." do
Expand Down Expand Up @@ -125,7 +125,7 @@
.to_return(status: 200, body: good_response, headers: {})
stub_request(:post, alma_url)
.with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "firestone"))
.to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' })
.to_return(status: 200, body: file_fixture("../alma_hold_response.json"), headers: { 'content-type': 'application/json' })
expect { recap_request.handle }.to change { ActionMailer::Base.deliveries.count }.by(0)
expect(recap_request.submitted.size).to eq(1)
expect(recap_request.errors.size).to eq(0)
Expand All @@ -138,7 +138,7 @@
.to_return(status: 200, body: good_response, headers: {})
stub_request(:post, alma_url)
.with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "firestone"))
.to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' })
.to_return(status: 200, body: file_fixture("../alma_hold_response.json"), headers: { 'content-type': 'application/json' })
expect { recap_edd_request.handle }.to change { ActionMailer::Base.deliveries.count }.by(0)
expect(recap_edd_request.submitted.size).to eq(1)
expect(recap_edd_request.errors.size).to eq(0)
Expand All @@ -151,7 +151,7 @@
.to_return(status: 200, body: good_response, headers: {})
stub_request(:post, alma_url)
.with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "firestone"))
.to_return(status: 400, body: fixture("alma_hold_error_no_library_response.json"), headers: { 'content-type': 'application/json' })
.to_return(status: 400, body: file_fixture("../alma_hold_error_no_library_response.json"), headers: { 'content-type': 'application/json' })
expect do
recap_request.handle
perform_enqueued_jobs
Expand Down Expand Up @@ -287,19 +287,19 @@
end

let(:recap_request) { described_class.new(submission) }
let(:good_request) { fixture('/scsb_find_request.json') }
let(:good_response) { fixture('/scsb_request_item_response.json') }
let(:good_request) { file_fixture('../scsb_find_request.json') }
let(:good_response) { file_fixture('../scsb_request_item_response.json') }

describe 'All ReCAP Requests' do
it "captures successful request submissions." do
stub_request(:post, scsb_url)
.to_return(status: 200, body: good_response, headers: {})
stub_request(:post, alma_url)
.with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "firestone"))
.to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' })
.to_return(status: 200, body: file_fixture("../alma_hold_response.json"), headers: { 'content-type': 'application/json' })
stub_request(:post, alma2_url)
.with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "mudd"))
.to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' })
.to_return(status: 200, body: file_fixture("../alma_hold_response.json"), headers: { 'content-type': 'application/json' })
expect { recap_request.handle }.to change { ActionMailer::Base.deliveries.count }.by(0)
expect(recap_request.submitted.size).to eq(2)
expect(recap_request.errors.size).to eq(0)
Expand Down
4 changes: 0 additions & 4 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@
config.after { Rails.cache.clear }
end

def fixture(file)
File.open(File.join(File.dirname(__FILE__), 'fixtures', file), 'rb')
end

def wait_for_ajax
counter = 0
while page.execute_script('return $.active').to_i > 0
Expand Down
2 changes: 1 addition & 1 deletion spec/support/stub_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def stub_alma_hold(id, mfhd, item_id, patron_id, status: 200, fixture_name: "alm
stub_url = "#{Alma.configuration.region}/almaws/v1/bibs/#{id}/holdings/#{mfhd}/items/#{item_id}/requests?user_id=#{patron_id}"
stub_request(:post, stub_url)
.to_return(status:,
body: fixture(fixture_name),
body: file_fixture("../#{fixture_name}"),
headers: { 'content-type': 'application/json' })
end
# rubocop:enable Metrics/ParameterLists
Expand Down
2 changes: 1 addition & 1 deletion spec/views/feedback/feedback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

context 'Princeton Community User has signed in' do
let(:user) { FactoryBot.create(:valid_princeton_patron) }
let(:valid_patron_response) { fixture('/bibdata_patron_response.json') }
let(:valid_patron_response) { file_fixture('../bibdata_patron_response.json') }

it 'Populates Email Field' do
stub_request(:get, "#{Requests.config['bibdata_base']}/patron/#{user.uid}")
Expand Down

0 comments on commit b528c41

Please sign in to comment.