diff --git a/app/controllers/spotlight/searches_controller.rb b/app/controllers/spotlight/searches_controller.rb index 452f33595d..c7c4b2c52f 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 = query_params if @search.save redirect_to :back, notice: t(:'helpers.submit.search.created', model: @search.class.model_name.human.downcase) @@ -103,6 +103,10 @@ def search_params ) end + def query_params + params.to_unsafe_h.with_indifferent_access.except(:exhibit_id, :search, *blacklisted_search_session_params).reject { |_k, v| v.blank? } + end + def featured_image_attributes [:display, :source, :image, :remote_image_url, :document_global_id, :image_crop_x, :image_crop_y, :image_crop_w, :image_crop_h] end diff --git a/spec/controllers/spotlight/appearances_controller_spec.rb b/spec/controllers/spotlight/appearances_controller_spec.rb index 5ad9be6683..c85d1399b2 100644 --- a/spec/controllers/spotlight/appearances_controller_spec.rb +++ b/spec/controllers/spotlight/appearances_controller_spec.rb @@ -41,15 +41,27 @@ end describe 'PATCH update' do + let(:first_nav) { exhibit.main_navigations.first } + let(:last_nav) { exhibit.main_navigations.last } it 'updates the navigation' do - first_nav = exhibit.main_navigations.first - last_nav = exhibit.main_navigations.last - patch :update, exhibit_id: exhibit, exhibit: { - main_navigations_attributes: { - 0 => { id: first_nav.id, label: 'Some Label', weight: 500 }, - 1 => { id: last_nav.id, display: false } + if Rails::VERSION::MAJOR >= 5 + patch :update, params: { + exhibit_id: exhibit, + exhibit: { + main_navigations_attributes: { + 0 => { id: first_nav.id, label: 'Some Label', weight: 500 }, + 1 => { id: last_nav.id, display: false } + } + } } - } + else + patch :update, exhibit_id: exhibit, exhibit: { + main_navigations_attributes: [ + { id: first_nav.id, label: 'Some Label', weight: 500 }, + { id: last_nav.id, display: false } + ] + } + end expect(flash[:notice]).to eq 'The exhibit was successfully updated.' expect(response).to redirect_to edit_exhibit_appearance_path(exhibit) assigns[:exhibit].tap do |saved| diff --git a/spec/controllers/spotlight/catalog_controller_spec.rb b/spec/controllers/spotlight/catalog_controller_spec.rb index 0f4bed120f..898afcf0ca 100644 --- a/spec/controllers/spotlight/catalog_controller_spec.rb +++ b/spec/controllers/spotlight/catalog_controller_spec.rb @@ -78,7 +78,7 @@ it 'shows the index when there are parameters' do expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit, q: '')) expect(controller).to receive(:add_breadcrumb).with('Search Results', search_exhibit_catalog_path(exhibit, q: 'map')) - get :index, params: { exhibit_id: exhibit, q: 'map' } + get :index, exhibit_id: exhibit, q: 'map' expect(response).to be_successful end it 'redirects to the exhibit home page when there are no parameters' do 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 c6803be6ff..71e0730b84 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 helper.class.include ::Rails.application.routes.mounted_helpers if ::Rails.application.routes.respond_to?(:mounted_helpers) end 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'