Skip to content

Commit

Permalink
Inject a new spec module to make routes used in rspec behave like tho…
Browse files Browse the repository at this point in the history
…se used in the app
  • Loading branch information
cbeer committed Apr 18, 2019
1 parent 9dbe9fd commit d2dc69f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/jobs/send_publish_state_change_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def message_text(exhibit:, published:)

def exhibit_url(exhibit)
url_helpers = Spotlight::Engine.routes.url_helpers
url_helpers.exhibit_url(exhibit, host: Settings.action_mailer.default_url_options.host)
url_helpers.exhibit_url(exhibit, locale: nil, host: Settings.action_mailer.default_url_options.host)
end
end
6 changes: 6 additions & 0 deletions app/services/upload_solr_document_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ def add_file_versions(solr_hash)

solr_hash[:thumbnail_square_url_ssm] = riiif.image_path(resource.upload_id, region: 'square', size: '100,100')
end

# Override upstream to add an empty locale
def add_manifest_path(solr_hash)
path = spotlight_routes.manifest_exhibit_solr_document_path(exhibit, resource.compound_id, locale: nil)
solr_hash[Spotlight::Engine.config.iiif_manifest_field] = path
end
end
8 changes: 4 additions & 4 deletions spec/controllers/bibliography_resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
it 'goes to the exhibit' do
post :create, params: { exhibit_id: exhibit.id, resource: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit)
expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand All @@ -37,7 +37,7 @@
it 'goes to the exhibit' do
post :create, params: { exhibit_id: exhibit.id, resource: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit)
expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand All @@ -52,7 +52,7 @@
it 'goes to the exhibit' do
patch :update, params: { exhibit_id: exhibit.id, resource: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit)
expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand All @@ -65,7 +65,7 @@
it 'goes to the exhibit' do
patch :update, params: { exhibit_id: exhibit.id, resource: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit)
expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/dor_harvester_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
it 'goes to the exhibit' do
post :create, params: { exhibit_id: exhibit.id, dor_harvester: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit)
expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand All @@ -35,7 +35,7 @@
it 'goes to the exhibit' do
post :create, params: { exhibit_id: exhibit.id, dor_harvester: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit)
expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand All @@ -50,7 +50,7 @@
it 'goes to the exhibit' do
patch :update, params: { exhibit_id: exhibit.id, dor_harvester: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.admin_exhibit_catalog_path(exhibit)
expect(response).to redirect_to spotlight.admin_exhibit_catalog_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand All @@ -63,7 +63,7 @@
it 'goes to the exhibit' do
patch :update, params: { exhibit_id: exhibit.id, dor_harvester: attributes }

expect(response).to redirect_to Spotlight::Engine.routes.url_helpers.new_exhibit_resource_path(exhibit)
expect(response).to redirect_to spotlight.new_exhibit_resource_path(exhibit)

expect(resource).to have_received(:update)
expect(resource).to have_received(:save_and_index)
Expand Down
4 changes: 4 additions & 0 deletions spec/helpers/catalog_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require 'rails_helper'

describe CatalogHelper, type: :helper do
before do
controller.extend OptionalLocaleRouteParamInjection
end

describe '#has_thumbnail?' do
context 'for references' do
let(:document) { SolrDocument.new(format_main_ssim: ['Reference']) }
Expand Down
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@

config.include FactoryBot::Syntax::Methods
config.include RequestSpecHelper
config.include ::Rails.application.routes.url_helpers, type: :controller
config.include ::Rails.application.routes.mounted_helpers, type: :controller
config.include OptionalLocaleRouteParamInjection

config.before do
DatabaseCleaner.strategy = if Capybara.current_driver == :rack_test
Expand Down
9 changes: 9 additions & 0 deletions spec/support/optional_locale_route_param_injection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# This makes routes in rspec behave like routes in
# the application as run.
module OptionalLocaleRouteParamInjection
def url_options
default_url_options.merge(locale: nil)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let(:current_exhibit) { create(:exhibit) }

before do
view.extend OptionalLocaleRouteParamInjection
assign(:document, document)
end

Expand Down

0 comments on commit d2dc69f

Please sign in to comment.