Skip to content

Commit

Permalink
rearrange test routes for WorksControllerBehavior
Browse files Browse the repository at this point in the history
the test routes need to be targeted on the `main_app` helper, since we want to
register them on the host app. the stubs here are maybe not the ideal solution,
but they seem to do the trick.
  • Loading branch information
tamsin johnson committed Jun 30, 2020
1 parent 15d2bca commit 2813624
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def after_create_response
wants.html do
# Calling `#t` in a controller context does not mark _html keys as html_safe
flash[:notice] = view_context.t('hyrax.works.create.after_create_html', application_name: view_context.application_name)

redirect_to [main_app, curation_concern]
end
wants.json { render :show, status: :created, location: polymorphic_path([main_app, curation_concern]) }
Expand Down
21 changes: 13 additions & 8 deletions spec/controllers/concerns/hyrax/works_controller_behavior_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# frozen_string_literal: true

RSpec.describe Hyrax::WorksControllerBehavior, :clean_repo, type: :controller do
let(:paths) { Rails.application.routes.url_helpers }
let(:paths) { controller.main_app }
let(:title) { ['Comet in Moominland'] }
let(:work) { FactoryBot.valkyrie_create(:hyrax_work, alternate_ids: [id], title: title) }
let(:id) { '123' }

routes { Rails.application.routes.dup }
let(:main_app_routes) do
app_routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw do # draw minimal routes for this controller mixin
mount Hyrax::Engine, at: '/'
namespaced_resources 'hyrax/test/simple_work_legacy', except: [:index]
devise_for :users
resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog'
end
end
end

before do
allow(Hyrax.config)
.to receive(:registered_curation_concern_types)
.and_return([work.model_name.name])

routes.draw do # draw minimal routes for this controller mixin
mount Hyrax::Engine, at: '/'
namespaced_resources 'hyrax/test/simple_work_legacies', except: [:index]
devise_for :users
resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog'
end
controller.main_app.instance_variable_set(:@routes, main_app_routes)
controller.main_app.instance_variable_set(:@helpers, main_app_routes.url_helpers)
end

controller(ApplicationController) do
Expand Down

0 comments on commit 2813624

Please sign in to comment.