This project is archived and is in readonly mode.
Fix broken module namespacing in ActiveResource when using Ruby 1.9
Reported by Matthijs Langenberg | September 24th, 2010 @ 10:26 PM
Following namespacing use case is broken when using Ruby 1.9:
class Author < ActiveRecord::Base
end
module Api
class Book < ActiveResouce::Base
end
end
Let's say XML contains
<book><author><name>John</name></author>....
Api::Book.first.author.class.to_s #=>
Ruby 1.8.7: "Api::Book::Author" (namespaced, correct),
Ruby 1.9: "Author" (toplevel, broken)
This is caused by differences in the implementation of
mod.const_get? and mod.const_defined? between Ruby 1.8 and
1.9.
- http://railsapi.com/doc/ruby-v1.8/classes/Module.html#M000994
- http://railsapi.com/doc/ruby-v1.9.2/classes/Module.html#M001257
Also, see http://eigenclass.org/hiki/Changes+in+Ruby+1.9#l33 for more background information.
This patch fixes this by passing the 2nd inherit
argument as false
for mod.const_get? and
mod.const_defined? when trying to lookup an existing resource, in
the case of Ruby 1.9.
Comments and changes to this ticket
-
gnufied September 26th, 2010 @ 05:26 AM
- Assigned user set to José Valim
Verified. The problem does exists and patch does fixes it. But the patch can't be applied cleanly to master, hence please create and submit a new patch.
I have the updated patch, but I will have rather original submitter submitting it again.
-
gnufied September 26th, 2010 @ 05:35 AM
Another option would be perhaps to check for arity of the methods rather than
RUBY_VERSION
, but that results in somewhat more code. -
Matthijs Langenberg September 26th, 2010 @ 07:56 PM
Updated the patch. Should apply cleanly to master now.
-
Repository September 27th, 2010 @ 10:12 PM
- State changed from new to resolved
(from [67a838574be000f329c0f340474bc9cec1aeca16]) Fix broken module namespacing in ActiveResource with Ruby 1.9 [#5699 state:resolved]
Following namespace use case was broken with Ruby 1.9:
class Author < ActiveRecord::Base
...
end
module Api
class Book < ActiveResouce::Base end
end
Let's say XML contains John....
Api::Book.first.author.class.to_s #=>
Ruby 1.8.7: "Api::Book::Author" (namespaced, correct), Ruby 1.9: "Author" (toplevel, broken)
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/67a838574be000f329c0f340474bc9...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 5699 Fix broken module namespacing in ActiveResource when using Ruby 1.9 (from [67a838574be000f329c0f340474bc9cec1aeca16]) Fix bro...