diff --git a/app/controllers/spotlight/searches_controller.rb b/app/controllers/spotlight/searches_controller.rb index 452f33595d..b2ca90a756 100644 --- a/app/controllers/spotlight/searches_controller.rb +++ b/app/controllers/spotlight/searches_controller.rb @@ -13,7 +13,7 @@ class SearchesController < Spotlight::ApplicationController def create @search.attributes = search_params - @search.query_params = params.to_unsafe_h.except(:exhibit_id, :search, *blacklisted_search_session_params).reject { |_k, v| v.blank? } + @search.query_params = params.to_unsafe_h.with_indifferent_access.except(:exhibit_id, :search, *blacklisted_search_session_params).reject { |_k, v| v.blank? } if @search.save redirect_to :back, notice: t(:'helpers.submit.search.created', model: @search.class.model_name.human.downcase) diff --git a/spec/controllers/spotlight/solr_controller_spec.rb b/spec/controllers/spotlight/solr_controller_spec.rb index 4758acf267..a7942bea57 100644 --- a/spec/controllers/spotlight/solr_controller_spec.rb +++ b/spec/controllers/spotlight/solr_controller_spec.rb @@ -29,7 +29,7 @@ doc = arr.first end - post :update, body: { a: 1 }.to_json, params: { exhibit_id: exhibit }, as: :json + post_update_with_json_body(exhibit, a: 1) expect(response).to be_successful expect(doc).to include 'a' => 1 @@ -41,7 +41,7 @@ end it 'raises an error' do - post :update, body: { a: 1 }.to_json, params: { exhibit_id: exhibit }, as: :json + post_update_with_json_body(exhibit, a: 1) expect(response.code).to eq '409' end @@ -53,7 +53,7 @@ doc = arr.first end - post :update, body: { a: 1 }.to_json, params: { exhibit_id: exhibit }, as: :json + post_update_with_json_body(exhibit, a: 1) expect(response).to be_successful expect(doc).to include exhibit.solr_data @@ -67,11 +67,19 @@ allow_any_instance_of(SolrDocument).to receive(:to_solr).and_return(b: 1) - post :update, body: { a: 1 }.to_json, params: { exhibit_id: exhibit }, as: :json + post_update_with_json_body(exhibit, a: 1) expect(response).to be_successful expect(doc).to include b: 1 end end end + + def post_update_with_json_body(exhibit, hash) + if Rails::VERSION::MAJOR >= 5 + post :update, body: hash.to_json, params: { exhibit_id: exhibit }, as: :json + else + post :update, hash.to_json, content_type: :json, exhibit_id: exhibit + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce228e4101..50766157c1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,11 +7,11 @@ Internal::Application.config.active_job.queue_adapter = :inline +require 'rails-controller-testing' if Rails::VERSION::MAJOR >= 5 require 'rspec/collection_matchers' require 'rspec/its' require 'rspec/rails' require 'rspec/active_model/mocks' -require 'rails-controller-testing' require 'capybara/poltergeist' @@ -91,8 +91,10 @@ config.after(:each, type: :feature) { Warden.test_reset! } config.include Controllers::EngineHelpers, type: :controller config.include Capybara::DSL - config.include ::Rails.application.routes.url_helpers - config.include ::Rails.application.routes.mounted_helpers + if Rails::VERSION::MAJOR >= 5 + config.include ::Rails.application.routes.url_helpers + config.include ::Rails.application.routes.mounted_helpers + end config.include Spotlight::TestFeaturesHelpers, type: :feature end diff --git a/spec/support/helpers/controller_level_helpers.rb b/spec/support/helpers/controller_level_helpers.rb index 9e5b6499a7..1806689a35 100644 --- a/spec/support/helpers/controller_level_helpers.rb +++ b/spec/support/helpers/controller_level_helpers.rb @@ -13,6 +13,12 @@ def blacklight_configuration_context def initialize_controller_helpers(helper) helper.extend ControllerLevelHelpers + initialize_routing_helpers(helper) + end + + def initialize_routing_helpers(helper) + return unless Rails::VERSION::MAJOR >= 5 + helper.class.include ::Rails.application.routes.url_helpers if ::Rails.application.routes.respond_to?(:mounted_helpers) diff --git a/spec/support/views/test_view_helpers.rb b/spec/support/views/test_view_helpers.rb index b48ce92707..4d2e3d2356 100644 --- a/spec/support/views/test_view_helpers.rb +++ b/spec/support/views/test_view_helpers.rb @@ -4,6 +4,7 @@ module TestViewHelpers included do before do + view.send(:extend, Spotlight::MainAppHelpers) view.send(:extend, Spotlight::CrudLinkHelpers) view.send(:extend, Spotlight::TitleHelper) view.send(:extend, Spotlight::NavbarHelper) diff --git a/spec/test_app_templates/Gemfile.extra b/spec/test_app_templates/Gemfile.extra index d4a54e7e51..cc2e637172 100644 --- a/spec/test_app_templates/Gemfile.extra +++ b/spec/test_app_templates/Gemfile.extra @@ -1,4 +1,4 @@ gem 'acts-as-taggable-on', github: 'mbleigh/acts-as-taggable-on' -gem 'rails-controller-testing' +gem 'rails-controller-testing', require: false gem 'friendly_id', github: 'norman/friendly_id' gem 'social-share-button', github: 'cbeer/social-share-button', branch: 'on_load'