Skip to content

Commit

Permalink
update specs for rails 5
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Aug 5, 2016
1 parent fab840a commit 8a692c2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 11 deletions.
23 changes: 17 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
cache: bundler
language: ruby
sudo: false

notifications:
email: false

rvm:
- 2.2.5
- 2.3.1

matrix:
include:
- rvm: 2.3.1
env: "RAILS_VERSION=4.2.6"
- rvm: 2.2.5
env: "RAILS_VERSION=5.0.0"

jdk:
- oraclejdk8
before_install:
- gem install bundler

env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- "RAILS_VERSION=5.0.0"

global_env:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true

jdk: oraclejdk8
4 changes: 2 additions & 2 deletions geoblacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'blacklight', '~> 6.3'
spec.add_dependency 'leaflet-rails', '~> 0.7.3'
spec.add_dependency 'font-awesome-rails'
spec.add_dependency 'config', '~> 1.2.1'
spec.add_dependency 'config'
spec.add_dependency 'faraday'
spec.add_dependency 'coderay'
spec.add_dependency 'geoblacklight-icons', '>= 0.2'
Expand All @@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec-rails', '~> 3.1'
spec.add_development_dependency 'engine_cart', '~> 0.10'
spec.add_development_dependency 'capybara', '>= 2.5.0'
spec.add_development_dependency 'poltergeist', '>= 1.5.0'
spec.add_development_dependency 'poltergeist'
spec.add_development_dependency 'factory_girl_rails'
spec.add_development_dependency 'database_cleaner', '~> 1.3'
end
3 changes: 2 additions & 1 deletion lib/geoblacklight/view_helper_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def render_search_to_s_bbox(params)

def render_constraints_filters(localized_params = params)
content = super(localized_params)
localized_params = localized_params.to_unsafe_h unless localized_params.is_a?(Hash)

if localized_params.to_h[:bbox]
if localized_params[:bbox]
path = search_action_path(remove_spatial_filter_group(:bbox, localized_params))
content << render_constraint_element('Bounding Box', localized_params[:bbox], remove: path)
end
Expand Down
10 changes: 8 additions & 2 deletions spec/controllers/download_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
end
describe 'public file' do
it 'initiates download' do
expect(controller).to receive(:render)
allow(controller).to receive(:render) # Needed for testing with Rails 4
expect(controller).to receive(:send_file)
get :file, params: { id: 'mit-us-ma-e25zcta5dct-2000-shapefile', format: 'zip' }
expect(response.status).to eq 200
end
end
end
Expand All @@ -25,7 +24,14 @@
end
end
describe 'public file' do
let(:shapefile_download) { instance_double(Geoblacklight::ShapefileDownload) }

before do
allow(Geoblacklight::ShapefileDownload).to receive(:new).and_return(shapefile_download)
end

it 'initiates download creation' do
allow(shapefile_download).to receive(:get).and_return('success')
get :show, params: { id: 'mit-us-ma-e25zcta5dct-2000', type: 'shapefile' }
expect(response.status).to eq 200
end
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
config.after do
DatabaseCleaner.clean
end
if Rails::VERSION::MAJOR >= 5
config.include ::Rails.application.routes.url_helpers
config.include ::Rails.application.routes.mounted_helpers
else
config.include BackportTestHelpers, type: :controller
end

config.include Devise::Test::ControllerHelpers, type: :controller
end
45 changes: 45 additions & 0 deletions spec/support/backport_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Backport the Rails 5 controller test methods to Rails 4
module BackportTestHelpers
def delete(*args)
(action, rest) = *args
rest ||= {}

@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if rest[:xhr]

super(action, rest[:params])
end

def get(*args)
(action, rest) = *args
rest ||= {}
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if rest[:xhr]
super(action, rest[:params])
end

def post(*args)
(action, rest) = *args
rest ||= {}
body = rest[:body]
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if rest[:xhr]

if body
super(action, body, rest.except(:params).merge(rest[:params]))
else
super(action, rest[:params])
end
end

def put(*args)
(action, rest) = *args
rest ||= {}
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if rest[:xhr]
super(action, rest[:params])
end

def patch(*args)
(action, rest) = *args
rest ||= {}
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if rest[:xhr]
super(action, rest[:params])
end
end

0 comments on commit 8a692c2

Please sign in to comment.