From 1710bd464c9b22a95668c85d237800cd37486706 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Tue, 7 Sep 2021 14:00:13 +0100 Subject: [PATCH] Remove rails_upgrade conditionals Rails 5.2 is no more so we can drop the old implementation. Leave conditionals in Gemfiles for when we prep for Rails 6.1. --- Gemfile | 1 - Gemfile.lock | 1 - Gemfile.rails_next.lock | 1 - app/controllers/attachments_controller.rb | 6 +--- config/environments/development.rb | 4 +-- config/environments/production.rb | 4 --- config/environments/test.rb | 2 +- lib/user_stats.rb | 6 +--- .../admin_raw_email_controller_spec.rb | 6 +--- .../batch_downloads_controller_spec.rb | 24 ++++--------- .../public_bodies_controller_spec.rb | 6 +--- spec/controllers/api_controller_spec.rb | 12 ++----- .../attachments_controller_spec.rb | 36 ++++--------------- spec/controllers/general_controller_spec.rb | 6 +--- .../projects/downloads_controller_spec.rb | 12 ++----- spec/controllers/request_controller_spec.rb | 6 +--- spec/controllers/services_controller_spec.rb | 6 +--- spec/controllers/track_controller_spec.rb | 12 ++----- spec/integration/errors_spec.rb | 6 +--- spec/integration/search_request_spec.rb | 6 +--- 20 files changed, 30 insertions(+), 133 deletions(-) diff --git a/Gemfile b/Gemfile index 639cc60ab0..e357eedcf8 100644 --- a/Gemfile +++ b/Gemfile @@ -85,7 +85,6 @@ def rails_upgrade? end gem 'rails', rails_upgrade? ? '~> 6.0.3' : '~> 5.2.4' - gem 'nio4r', rails_upgrade? ? nil : '< 2.5.3' gem 'pg', '~> 1.2.3' diff --git a/Gemfile.lock b/Gemfile.lock index fd13505d9c..028bff4cc5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -455,7 +455,6 @@ DEPENDENCIES money (~> 6.16.0) net-ssh (~> 6.1.0) net-ssh-gateway (>= 1.1.0, < 3.0.0) - nio4r nokogiri (~> 1.12.4) oink (~> 0.10.1) open4 (~> 1.3.0) diff --git a/Gemfile.rails_next.lock b/Gemfile.rails_next.lock index 6f59cb5587..2ce4b65fa5 100644 --- a/Gemfile.rails_next.lock +++ b/Gemfile.rails_next.lock @@ -455,7 +455,6 @@ DEPENDENCIES money (~> 6.16.0) net-ssh (~> 6.1.0) net-ssh-gateway (>= 1.1.0, < 3.0.0) - nio4r nokogiri (~> 1.12.4) oink (~> 0.10.1) open4 (~> 1.3.0) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index a6c276b2dc..f272dbd6fc 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -55,11 +55,7 @@ def show_as_html } ) - html = if rails_upgrade? - @incoming_message.apply_masks(html, response.media_type) - else - @incoming_message.apply_masks(html, response.content_type) - end + html = @incoming_message.apply_masks(html, response.media_type) render html: html.html_safe end diff --git a/config/environments/development.rb b/config/environments/development.rb index 22626f43f6..f02adc133b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,9 +16,7 @@ # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true - if rails_upgrade? - config.action_controller.enable_fragment_cache_logging = true - end + config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { diff --git a/config/environments/production.rb b/config/environments/production.rb index f52e0b9595..0f684b3b75 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -24,10 +24,6 @@ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. - unless rails_upgrade? - config.assets.js_compressor = - Uglifier.new(harmony: true, mangle: false, compress: false) - end # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. diff --git a/config/environments/test.rb b/config/environments/test.rb index 3d59e32099..82d57f5f0e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -22,7 +22,7 @@ # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - config.cache_store = :null_store if rails_upgrade? + config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false diff --git a/lib/user_stats.rb b/lib/user_stats.rb index 48e0465c21..a46947dfbb 100644 --- a/lib/user_stats.rb +++ b/lib/user_stats.rb @@ -22,11 +22,7 @@ def self.list_user_domains(params={}) end sql = "#{sql} LIMIT #{params[:limit]}" if params[:limit] - if rails_upgrade? - User.connection.select_all(sql).to_a - else - User.connection.select_all(sql).to_hash - end + User.connection.select_all(sql).to_a end # Returns the number of domant users for the given domain diff --git a/spec/controllers/admin_raw_email_controller_spec.rb b/spec/controllers/admin_raw_email_controller_spec.rb index dba6efa671..d4bfb57b90 100644 --- a/spec/controllers/admin_raw_email_controller_spec.rb +++ b/spec/controllers/admin_raw_email_controller_spec.rb @@ -91,11 +91,7 @@ describe 'text version' do it 'sends the email as an RFC-822 attachment' do get :show, params: { :id => raw_email.id, :format => 'eml' } - if rails_upgrade? - expect(response.media_type).to eq('message/rfc822') - else - expect(response.content_type).to eq('message/rfc822') - end + expect(response.media_type).to eq('message/rfc822') expect(response.body).to eq(raw_email.data) end end diff --git a/spec/controllers/alaveteli_pro/batch_downloads_controller_spec.rb b/spec/controllers/alaveteli_pro/batch_downloads_controller_spec.rb index 5652875f38..6ba455bacf 100644 --- a/spec/controllers/alaveteli_pro/batch_downloads_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/batch_downloads_controller_spec.rb @@ -90,15 +90,9 @@ def show(id: '1', format: 'abc') end it 'returns content disposition' do - if rails_upgrade? - expect(response.header['Content-Disposition']).to( - eq 'attachment; filename="NAME"; filename*=UTF-8\'\'NAME' - ) - else - expect(response.header['Content-Disposition']).to( - eq 'attachment; filename="NAME"' - ) - end + expect(response.header['Content-Disposition']).to( + eq 'attachment; filename="NAME"; filename*=UTF-8\'\'NAME' + ) end it 'returns CSV content type' do @@ -129,15 +123,9 @@ def show(id: '1', format: 'abc') end it 'returns content disposition' do - if rails_upgrade? - expect(response.header['Content-Disposition']).to( - eq 'attachment; filename="NAME"; filename*=UTF-8\'\'NAME' - ) - else - expect(response.header['Content-Disposition']).to( - eq 'attachment; filename="NAME"' - ) - end + expect(response.header['Content-Disposition']).to( + eq 'attachment; filename="NAME"; filename*=UTF-8\'\'NAME' + ) end it 'returns CSV content type' do diff --git a/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb b/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb index 60b763c9e6..7c9348cd63 100644 --- a/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb @@ -24,11 +24,7 @@ it "returns json" do with_feature_enabled :alaveteli_pro do get :index, params: { query: body.name } - if rails_upgrade? - expect(response.media_type).to eq('application/json') - else - expect(response.content_type).to eq('application/json') - end + expect(response.media_type).to eq('application/json') end end diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 99ef87f264..39747b8df5 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -43,11 +43,7 @@ def _create_request 'external_user_name' => 'Bob Smith' }.to_json } - if rails_upgrade? - expect(response.media_type).to eq('application/json') - else - expect(response.content_type).to eq('application/json') - end + expect(response.media_type).to eq('application/json') ActiveSupport::JSON.decode(response.body)['id'] end @@ -73,11 +69,7 @@ def _create_request } expect(response).to be_successful - if rails_upgrade? - expect(response.media_type).to eq('application/json') - else - expect(response.content_type).to eq('application/json') - end + expect(response.media_type).to eq('application/json') response_body = ActiveSupport::JSON.decode(response.body) expect(response_body['errors']).to be_nil expect(response_body['url']).to match(/^http/) diff --git a/spec/controllers/attachments_controller_spec.rb b/spec/controllers/attachments_controller_spec.rb index d265a326aa..fdd7f285c6 100644 --- a/spec/controllers/attachments_controller_spec.rb +++ b/spec/controllers/attachments_controller_spec.rb @@ -157,11 +157,7 @@ def show(params = {}) :file_name => 'interesting.html', :skip_cache => 1 } - if rails_upgrade? - expect(response.media_type).to eq('text/html') - else - expect(response.content_type).to eq('text/html') - end + expect(response.media_type).to eq('text/html') expect(response.body).to have_content "Mouse" end @@ -179,11 +175,7 @@ def show(params = {}) :file_name => 'interesting.html', :skip_cache => 1 } - if rails_upgrade? - expect(response.media_type).to eq('text/html') - else - expect(response.content_type).to eq('text/html') - end + expect(response.media_type).to eq('text/html') expect(response.body).to have_content "Mouse" end @@ -290,11 +282,7 @@ def get_html_attachment(params = {}) type: :controller do def expect_hidden(hidden_template) - if rails_upgrade? - expect(response.media_type).to eq('text/html') - else - expect(response.content_type).to eq('text/html') - end + expect(response.media_type).to eq('text/html') expect(response).to render_template(hidden_template) expect(response.code).to eq('403') end @@ -471,11 +459,7 @@ def expect_hidden(hidden_template) file_name: 'interesting.pdf', skip_cache: 1 } - if rails_upgrade? - expect(response.media_type).to eq('application/pdf') - else - expect(response.content_type).to eq('application/pdf') - end + expect(response.media_type).to eq('application/pdf') expect(response).to be_successful end @@ -532,11 +516,7 @@ def expect_hidden(hidden_template) file_name: 'interesting.pdf', skip_cache: 1 } - if rails_upgrade? - expect(response.media_type).to eq('application/pdf') - else - expect(response.content_type).to eq('application/pdf') - end + expect(response.media_type).to eq('application/pdf') expect(response).to be_successful end @@ -550,11 +530,7 @@ def expect_hidden(hidden_template) file_name: 'interesting.pdf', skip_cache: 1 } - if rails_upgrade? - expect(response.media_type).to eq('application/pdf') - else - expect(response.content_type).to eq('application/pdf') - end + expect(response.media_type).to eq('application/pdf') expect(response).to be_successful end diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 842cc05ecd..0b235be257 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -18,11 +18,7 @@ end it 'responds as JSON' do - if rails_upgrade? - expect(response.media_type).to eq('application/json') - else - expect(response.content_type).to eq('application/json') - end + expect(response.media_type).to eq('application/json') end end end diff --git a/spec/controllers/projects/downloads_controller_spec.rb b/spec/controllers/projects/downloads_controller_spec.rb index f647b5c9f7..9c191fc8be 100644 --- a/spec/controllers/projects/downloads_controller_spec.rb +++ b/spec/controllers/projects/downloads_controller_spec.rb @@ -59,15 +59,9 @@ def show(format: 'csv') end it 'returns content disposition' do - if rails_upgrade? - expect(response.header['Content-Disposition']).to( - eq 'attachment; filename="NAME"; filename*=UTF-8\'\'NAME' - ) - else - expect(response.header['Content-Disposition']).to( - eq 'attachment; filename="NAME"' - ) - end + expect(response.header['Content-Disposition']).to( + eq 'attachment; filename="NAME"; filename*=UTF-8\'\'NAME' + ) end it 'returns CSV content type' do diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1e815674d4..8a22ab7c31 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -539,11 +539,7 @@ def make_request RSpec.describe RequestController, 'when handling prominence' do def expect_hidden(hidden_template) - if rails_upgrade? - expect(response.media_type).to eq('text/html') - else - expect(response.content_type).to eq('text/html') - end + expect(response.media_type).to eq('text/html') expect(response).to render_template(hidden_template) expect(response.code).to eq('403') end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 1fc9fb57e1..b05c8efae6 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -98,11 +98,7 @@ it 'generates plaintext output' do get :hidden_user_explanation, params: { info_request_id: info_request.id, message: 'not_foi' } - if rails_upgrade? - expect(response.media_type).to eq 'text/plain' - else - expect(response.content_type).to eq 'text/plain' - end + expect(response.media_type).to eq 'text/plain' end it 'does not HTML escape the user or site name' do diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 6297b39f01..833c9d07c9 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -97,11 +97,7 @@ :url_title => track_thing.info_request.url_title } expect(response).to render_template('track/atom_feed') - if rails_upgrade? - expect(response.media_type).to eq('application/atom+xml') - else - expect(response.content_type).to eq('application/atom+xml') - end + expect(response.media_type).to eq('application/atom+xml') # TODO: should check it is an atom.builder type being rendered, # not sure how to expect(assigns[:xapian_object].matches_estimated).to eq(3) @@ -163,11 +159,7 @@ :url_title => track_thing.info_request.url_title } expect(response).to render_template('track/atom_feed') - if rails_upgrade? - expect(response.media_type).to eq('application/atom+xml') - else - expect(response.content_type).to eq('application/atom+xml') - end + expect(response.media_type).to eq('application/atom+xml') end end diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index 1b0be9893e..2c11421c5a 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -14,11 +14,7 @@ it 'should show a full trace for general errors' do allow(InfoRequest).to receive(:find_by_url_title!).and_raise("An example error") get "/request/example" - if rails_upgrade? - expect(response.body).to match('
true) - if rails_upgrade? - expect(response.media_type).to eq('application/json') - else - expect(response.content_type).to eq('application/json') - end + expect(response.media_type).to eq('application/json') expect(response_data.size).to eql(1) expect(response_data.first[:info_request][:title]). to eq('How much public money is wasted on breeding naughty chickens?')