routes.url_helpers module is not fully working with ruby 2.1.0 #13645

Closed
saks opened this Issue Jan 9, 2014 · 6 comments

Comments

Projects
None yet
4 participants

saks commented Jan 9, 2014

It works if url_helpers module was included into module or class but not works as expected if was included into singleton class of an object (at least, it doesn't define default_url_options attribute). Here is the test that shows this problems, but only with ruby 2.1.0. It works for 1.9.3 and 2.0.0.

Owner

pixeltrix commented Jan 9, 2014

This is because we overwrite singleton_class? in Ruby 2.1/Rails 4.0.2 - see 8b14a6b

I'll backport it to 4-0-stable so that it'll get fixed in 4.0.3

@ghost ghost assigned pixeltrix Jan 9, 2014

Owner

pixeltrix commented Jan 9, 2014

It's already in 4-0-stable under a different aha: c5a70cb

@pixeltrix pixeltrix closed this Jan 9, 2014

Is this suppose to work in a rails 3.2.0 app ?

Owner

pixeltrix commented Jul 15, 2014

@Davidslv the url_helpers module is meant to work in 3.2 - what are you seeing? Bear in mind that 3.2 no longer receives bug fixes, but if there's a problem I'd at least like to acknowledge here so that other people can find it.

Sorry I haven't noticed the notification.

So apparently in one of our Jobs we have the following piece of code which is causing the error

rails 3.2.17
ruby 2.1.2p95

class MyJob
  @queue = :my_job

  class << self
    include Rails.application.routes.url_helpers
  end
undefined method `default_url_options' for Class:Class
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/core_ext/class/attribute.rb:98:in `default_url_options'
vendor/gems/ruby/2.1.0/gems/actionpack-3.2.17/lib/action_dispatch/routing/url_for.rb:107:in `url_options'
vendor/gems/ruby/2.1.0/gems/actionpack-3.2.17/lib/action_dispatch/routing/url_for.rb:148:in `url_for'
vendor/gems/ruby/2.1.0/gems/actionpack-3.2.17/lib/action_dispatch/routing/route_set.rb:216:in `shareable_case_path'
app/jobs/my_job.rb:10:in `perform'
test/unit/jobs/my_job_test.rb:24:in `block (3 levels) in <class:MyJobTest>'
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/testing/assertions.rb:55:in `assert_difference'
test/unit/jobs/shareable_generator_job_test.rb:23:in `block (2 levels) in <class:MyJobTest>'
vendor/gems/ruby/2.1.0/gems/shoulda-context-1.0.0/lib/shoulda/context/context.rb:398:in `call'
vendor/gems/ruby/2.1.0/gems/shoulda-context-1.0.0/lib/shoulda/context/context.rb:398:in `block in create_test_from_should_hash'
/opt/ruby/2.1/lib/ruby/2.1.0/minitest/unit.rb:1265:in `run'
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:425:in `_run__93481615266844829__setup__1230989602901537628__callbacks'
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:405:in `__run_callback'
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:81:in `run_callbacks'
vendor/gems/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
vendor/gems/ruby/2.1.0/gems/turn-0.9.7/lib/turn/runners/minirunner.rb:91:in `block in _run_suite'
vendor/gems/ruby/2.1.0/gems/turn-0.9.7/lib/turn/runners/minirunner.rb:84:in `map'
vendor/gems/ruby/2.1.0/gems/turn-0.9.7/lib/turn/runners/minirunner.rb:84:in `_run_suite'
vendor/gems/ruby/2.1.0/gems/turn-0.9.7/lib/turn/runners/minirunner.rb:61:in `block in _run_suites'
vendor/gems/ruby/2.1.0/gems/turn-0.9.7/lib/turn/runners/minirunner.rb:61:in `map'
vendor/gems/ruby/2.1.0/gems/turn-0.9.7/lib/turn/runners/minirunner.rb:61:in `_run_suites'
/opt/ruby/2.1/lib/ruby/2.1.0/minitest/unit.rb:884:in `_run_anything'
/opt/ruby/2.1/lib/ruby/2.1.0/minitest/unit.rb:1092:in `run_tests'
/opt/ruby/2.1/lib/ruby/2.1.0/minitest/unit.rb:1079:in `block in _run'
/opt/ruby/2.1/lib/ruby/2.1.0/minitest/unit.rb:1078:in `each'
/opt/ruby/2.1/lib/ruby/2.1.0/minitest/unit.rb:1078:in `_run'
/opt/ruby/2.1/lib/ruby/2.1.0/minitest/unit.rb:1066:in `run'

errm commented May 27, 2015

Run into this in a rails 3.2 app also. I can't find a simple way to fix with a monkey patch.
I have just worked around by including Rails.application.routes.url_helpers on a normal class rather than the singleton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment