Skip to content

Commit

Permalink
Begin fixing compatibility with Rails 4 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jul 29, 2016
1 parent dd5163b commit 8b4e470
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spotlight/searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions spec/controllers/spotlight/solr_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
8 changes: 5 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

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

Expand Down
6 changes: 6 additions & 0 deletions spec/support/helpers/controller_level_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/support/views/test_view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 8b4e470

Please sign in to comment.