Skip to content

Commit

Permalink
Print routes available to each context
Browse files Browse the repository at this point in the history
  • Loading branch information
henrahmagix committed Jun 10, 2021
1 parent cbd5cf7 commit 5154e64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/controllers/concerns/redirect_if_requested_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module RedirectIfRequestedConcern
private

def redirect_if_requested
path_routes = _routes.named_routes.helper_names.map(&:to_s).sort.select { |r| r.end_with?('_path') }
puts "In concern method: #{path_routes.count}"
puts path_routes.map { |r| "\t#{r}" }

redirect_to url_for(redirected_from_concern: true) if params[:redirect_me] == 'yes'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
include RedirectIfRequestedConcern

def test
path_routes = _routes.named_routes.helper_names.map(&:to_s).sort.select { |r| r.end_with?('_path') }
puts "In test controller method: #{path_routes.count}"
puts path_routes.map { |r| "\t#{r}" }

render plain: 'Test controller, test method'
end
end
Expand All @@ -13,6 +17,11 @@ def test

before do
routes.draw { get 'test' => 'anonymous#test' }

path_routes = routes.named_routes.helper_names.map(&:to_s).sort.select { |r| r.end_with?('_path') }
puts "In test before hook: #{path_routes.count}"
puts path_routes.map { |r| "\t#{r}" }

get :test, params: params, session: nil
end

Expand Down
4 changes: 0 additions & 4 deletions spec/app/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
describe '#show' do
subject { response }

# controller {} # uncomment this to make all tests below fail at `get :show` with `ActionController::UrlGenerationError`

before { get :show, params: params, session: nil }

controller {} # but here is fine, after `before`

let(:params) { {} }

it { is_expected.not_to be_redirect }
Expand Down

0 comments on commit 5154e64

Please # to comment.