Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Eagerload active_support/json/encoding in active_support/core_ext/object/to_json #12203
This is related to #12106. (The root cause for that ticket is that json/add defines Regexp#to_json among others, but here I'll reproduce the problem without json/add.)
>> require 'active_support/core_ext' => true >> //.as_json NoMethodError: undefined method `as_json' for //:Regexp from (irb):3 from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>' >> //.to_json => "\"(?-mix:)\"" >> //.as_json => "(?-mix:)"
>> require 'active_support/core_ext' => true >> //.as_json => "(?-mix:)"
When someone require 'active_support/core_ext', the expectation is that it would add certain methods to the core classes NOW. The previous behaviour causes additional methods to be loaded the first time you call
Any way to test this?
I was thinking really hard about this and I couldn't come up with any good ideas, any hints? :P
I have some ideas that might work when the test file is run in isolation, but I'm not sure if there are any good ways to test this as part of the suite without relying the order the tests are run/loaded.
Sorry @jeremy, I changed my mind again – the final solution I proposed in the inline notes seems like the safest and cleanest solution to fix this, and on second thought the distinction between
With this change, chance of regressing on this same issue seems pretty slim, so I removed the test.
If we want to backport this (I think the bug might be worth fixing in other branches), we can probably just do the same thing minus the deprecation warning. I just didn't feel too good about silencing the circular require warning as I'm unsure of the impact.
This should be ready for merge barring any extra feedback