Last active
December 31, 2015 13:59
-
-
Save righi/7997188 to your computer and use it in GitHub Desktop.
ActionController::UrlGenerationError ... missing required keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
› ruby rails3_works.rb | |
Finished in 0.001542s, 648.5084 runs/s, 1297.0169 assertions/s. | |
1 runs, 2 assertions, 0 failures, 0 errors, 0 skips | |
› ruby rails4_fails.rb | |
Finished tests in 0.013107s, 76.2951 tests/s, 0.0000 assertions/s. | |
1) Error: | |
BugTest#test_routes: | |
ActionController::UrlGenerationError: No route matches {:locale=>:rose, :action=>"show", :controller=>"flowers", :id=>nil, :format=>nil} missing required keys: [:id] | |
/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/journey/formatter.rb:39:in `generate' | |
/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:601:in `generate' | |
/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:631:in `generate' | |
/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:667:in `url_for' | |
/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/routing/url_for.rb:155:in `url_for' | |
/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:234:in `call' | |
/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:274:in `block (2 levels) in define_url_helper' | |
rails4_fails.rb:47:in `test_routes' | |
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', '3.2.16' | |
gem 'minitest' | |
GEMFILE | |
system 'bundle update' | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'rails' | |
require 'action_controller/railtie' | |
class TestApp < Rails::Application | |
config.root = File.dirname(__FILE__) | |
config.session_store :cookie_store, key: 'cookie_store_key' | |
config.secret_token = '6103e0a02bd376f18cd16ab84189925f' | |
config.secret_key_base = '6103e0a02bd376f18cd16ab84189925f' | |
config.logger = Logger.new($stdout) | |
Rails.logger = config.logger | |
routes.draw do | |
scope "(:locale)", :locale => /([a-zA-Z]{2}[-_])?[a-zA-Z]{2}/ do | |
resources :flowers | |
end | |
end | |
end | |
class TestController < ActionController::Base | |
include Rails.application.routes.url_helpers | |
end | |
require 'minitest/autorun' | |
require 'rack/test' | |
class BugTest < MiniTest::Unit::TestCase | |
include Rack::Test::Methods | |
include Rails.application.routes.url_helpers | |
def test_routes | |
Rails.application.routes.default_url_options[:locale] = :en_GB | |
assert_equal "/en_GB/flowers/rose", flower_path(:rose) | |
Rails.application.routes.default_url_options[:locale] = nil | |
assert_equal "/flowers/rose", flower_path(:rose) | |
end | |
private | |
def app | |
Rails.application | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', '4.0.2' | |
gem 'minitest' | |
GEMFILE | |
system 'bundle update' | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'rails' | |
require 'action_controller/railtie' | |
class TestApp < Rails::Application | |
config.root = File.dirname(__FILE__) | |
config.session_store :cookie_store, key: 'cookie_store_key' | |
config.secret_token = '6103e0a02bd376f18cd16ab84189925f' | |
config.secret_key_base = '6103e0a02bd376f18cd16ab84189925f' | |
config.logger = Logger.new($stdout) | |
Rails.logger = config.logger | |
routes.draw do | |
scope "(:locale)", :locale => /([a-zA-Z]{2}[-_])?[a-zA-Z]{2}/ do | |
resources :flowers | |
end | |
end | |
end | |
class TestController < ActionController::Base | |
include Rails.application.routes.url_helpers | |
end | |
require 'minitest/autorun' | |
require 'rack/test' | |
class BugTest < MiniTest::Unit::TestCase | |
include Rack::Test::Methods | |
include Rails.application.routes.url_helpers | |
def test_routes | |
Rails.application.routes.default_url_options[:locale] = :en_GB | |
assert_equal "/en_GB/flowers/rose", flower_path(:rose) | |
Rails.application.routes.default_url_options[:locale] = nil | |
assert_equal "/flowers/rose", flower_path(:rose) | |
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