Skip to content

Commit

Permalink
Remove rails_upgrade conditionals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gbp committed Sep 7, 2021
1 parent 47a6376 commit 1710bd4
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 133 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion Gemfile.rails_next.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/attachments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 0 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions lib/user_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions spec/controllers/admin_raw_email_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 6 additions & 18 deletions spec/controllers/alaveteli_pro/batch_downloads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 2 additions & 10 deletions spec/controllers/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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/)
Expand Down
36 changes: 6 additions & 30 deletions spec/controllers/attachments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 1 addition & 5 deletions spec/controllers/general_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions spec/controllers/projects/downloads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions spec/controllers/request_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions spec/controllers/services_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions spec/controllers/track_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
6 changes: 1 addition & 5 deletions spec/integration/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div id="traces-0"')
else
expect(response.body).to match('<div id="traces"')
end
expect(response.body).to match('<div id="traces-0"')
expect(response.body).to match('An example error')
end

Expand Down
6 changes: 1 addition & 5 deletions spec/integration/search_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@
get '/feed/search/chicken.json'
response_data = JSON.parse(response.body, :symbolize_names => 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?')
Expand Down

0 comments on commit 1710bd4

Please sign in to comment.