Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Created August 11, 2016 19:09
Show Gist options
  • Save davidcornu/23ca66e62f34add9bbd4aea49a4eefaf to your computer and use it in GitHub Desktop.
Save davidcornu/23ca66e62f34add9bbd4aea49a4eefaf to your computer and use it in GitHub Desktop.
❯ ruby route_defaults_test_case.rb
Fetching git://github.com/rails/rails.git
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Resolving dependencies...
Using rake 11.2.2
Using concurrent-ruby 1.0.2
Using i18n 0.7.0
Using minitest 5.9.0
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using pkg-config 1.1.7
Using rack 2.0.1
Using nio4r 1.2.1
Using websocket-extensions 0.1.2
Using mime-types-data 3.2016.0521
Using arel 7.1.1
Using bundler 1.12.5
Using byebug 9.0.5
Using coderay 1.1.1
Using method_source 0.8.2
Using slop 3.6.0
Using thor 0.19.1
Using tzinfo 1.2.2
Using nokogiri 1.6.8
Using rack-test 0.6.3
Using sprockets 3.7.0
Using websocket-driver 0.6.4
Using mime-types 3.1
Using pry 0.10.4
Using activesupport 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using loofah 2.0.3
Using mail 2.6.4
Using pry-byebug 3.4.0
Using rails-dom-testing 2.0.1
Using globalid 0.3.7
Using activemodel 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using rails-html-sanitizer 1.0.3
Using activejob 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using activerecord 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using actionview 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using actionpack 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using actioncable 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using actionmailer 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using railties 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Using sprockets-rails 3.1.1
Using rails 5.1.0.alpha from git://github.com/rails/rails.git (at master@4394e90)
Run options: --seed 40092
# Running:
.E
Finished in 0.001380s, 1449.7828 runs/s, 724.8914 assertions/s.
1) Error:
BugTest#test_url_for_uses_default_category:
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"tests"}
/Users/davidcornu/.gem/ruby/2.3.1/bundler/gems/rails-4394e9075189/actionpack/lib/action_dispatch/journey/formatter.rb:50:in `generate'
/Users/davidcornu/.gem/ruby/2.3.1/bundler/gems/rails-4394e9075189/actionpack/lib/action_dispatch/routing/route_set.rb:629:in `generate'
/Users/davidcornu/.gem/ruby/2.3.1/bundler/gems/rails-4394e9075189/actionpack/lib/action_dispatch/routing/route_set.rb:660:in `generate'
/Users/davidcornu/.gem/ruby/2.3.1/bundler/gems/rails-4394e9075189/actionpack/lib/action_dispatch/routing/route_set.rb:707:in `url_for'
route_defaults_test_case.rb:49:in `test_url_for_uses_default_category'
2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
gem "pry-byebug"
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
resources :tests, path: "/tests/:category", defaults: { category: "unit" }
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render plain: "Home"
end
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_url_helper_uses_default_category
assert_equal "/tests/unit", app.routes.url_helpers.tests_path
end
def test_url_for_uses_default_category
assert_equal "/tests/unit", app.routes.url_for(controller: 'tests', action: 'index', only_path: true)
end
private
def app
Rails.application
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment