From 769d86fe0cbb29996bd7b46dc5e6cb65649f8f93 Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Thu, 21 Nov 2019 16:20:32 -0500 Subject: [PATCH] use response.media_type instead of .content_type in tests Preparing for Rails6. In Rails6, response.content_type includes entire content type header, like 'application/n-triples; charset=utf-8' when previously it was just application/n-triples, which is what tests are expecting. This is only a change to test code, not actual code under test, to make tests test the right thing under a future Rails 6.0. https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#actiondispatch-response-content-type-now-returned-content-type-header-as-it-is https://github.com/samvera/questioning_authority/pull/291 https://circleci.com/gh/samvera/questioning_authority/1295 --- .../linked_data_terms_controller_spec.rb | 22 +++++++++---------- spec/controllers/terms_controller_spec.rb | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/controllers/linked_data_terms_controller_spec.rb b/spec/controllers/linked_data_terms_controller_spec.rb index 8b18d583..0286c317 100644 --- a/spec/controllers/linked_data_terms_controller_spec.rb +++ b/spec/controllers/linked_data_terms_controller_spec.rb @@ -403,14 +403,14 @@ it 'succeeds and defaults to json content type' do get :show, params: { id: '530369', vocab: 'OCLC_FAST' } expect(response).to be_successful - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end context 'and it was requested as json' do it 'succeeds and returns term data as json content type' do get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'json' } expect(response).to be_successful - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end end @@ -418,7 +418,7 @@ it 'succeeds and returns term data as jsonld content type' do get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'jsonld' } expect(response).to be_successful - expect(response.content_type).to eq 'application/ld+json' + expect(response.media_type).to eq 'application/ld+json' expect(JSON.parse(response.body).keys).to match_array ["@context", "@graph"] end end @@ -427,7 +427,7 @@ it 'succeeds and returns term data as n3 content type' do get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'n3' } expect(response).to be_successful - expect(response.content_type).to eq 'text/n3' + expect(response.media_type).to eq 'text/n3' expect(response.body).to start_with "@prefix" end end @@ -436,7 +436,7 @@ it 'succeeds and returns term data as ntriples content type' do get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'ntriples' } expect(response).to be_successful - expect(response.content_type).to eq 'application/n-triples' + expect(response.media_type).to eq 'application/n-triples' expect(response.body).to include(' "Cornell University"') end end @@ -476,7 +476,7 @@ it 'succeeds and defaults to json content type' do get :show, params: { id: 'sh 85118553', vocab: 'LOC', subauthority: 'subjects' } expect(response).to be_successful - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end end end @@ -578,14 +578,14 @@ it 'succeeds and defaults to json content type' do get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' } expect(response).to be_successful - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end context 'and it was requested as json' do it 'succeeds and returns term data as json content type' do get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'json' } expect(response).to be_successful - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end end @@ -593,7 +593,7 @@ it 'succeeds and returns term data as jsonld content type' do get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'jsonld' } expect(response).to be_successful - expect(response.content_type).to eq 'application/ld+json' + expect(response.media_type).to eq 'application/ld+json' expect(JSON.parse(response.body).keys).to match_array ["@context", "@graph"] end end @@ -602,7 +602,7 @@ it 'succeeds and returns term data as n3 content type' do get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'n3' } expect(response).to be_successful - expect(response.content_type).to eq 'text/n3' + expect(response.media_type).to eq 'text/n3' expect(response.body).to start_with "@prefix" end end @@ -611,7 +611,7 @@ it 'succeeds and returns term data as ntriples content type' do get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'ntriples' } expect(response).to be_successful - expect(response.content_type).to eq 'application/n-triples' + expect(response.media_type).to eq 'application/n-triples' expect(response.body).to include(' "Cornell University"') end end diff --git a/spec/controllers/terms_controller_spec.rb b/spec/controllers/terms_controller_spec.rb index 2f2a4b04..ee2a5729 100644 --- a/spec/controllers/terms_controller_spec.rb +++ b/spec/controllers/terms_controller_spec.rb @@ -236,7 +236,7 @@ def search(_arg1, _arg2) it 'Access-Control-Allow-Origin is not present' do get :show, params: { vocab: "discogs", subauthority: "release", id: "3380671", format: 'n3' } expect(response).to be_successful - expect(response.content_type).to eq 'text/n3' + expect(response.media_type).to eq 'text/n3' expect(response.body).to start_with "@prefix" end end @@ -248,7 +248,7 @@ def search(_arg1, _arg2) it 'Access-Control-Allow-Origin is not present' do get :show, params: { vocab: "discogs", subauthority: "release", id: "3380671", format: 'ntriples' } expect(response).to be_successful - expect(response.content_type).to eq 'application/n-triples' + expect(response.media_type).to eq 'application/n-triples' expect(response.body).to include('_:agentn1 "Dexter Gordon"') end end