Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Fix broken module namespacing in ActiveResource when using Ruby 1.9

#5699

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.

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.

Reported by Matthijs Langenberg · September 24th, 2010 @ 10:26 PM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: none

Activity

  1. gnufied
    gnufied
    • 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.

    September 26th, 2010 @ 05:26 AM

  2. gnufied
    gnufied

    Another option would be perhaps to check for arity of the methods rather than RUBY_VERSION, but that results in somewhat more code.

    September 26th, 2010 @ 05:35 AM

  3. Matthijs Langenberg
    Matthijs Langenberg

    Updated the patch. Should apply cleanly to master now.

    September 26th, 2010 @ 07:56 PM

  4. Repository
    Repository
    • State changed from new to resolved

    (from [67a838574be000f329c0f340474bc9cec1aeca16]) Fix broken module namespacing in ActiveResource with Ruby 1.9 [#5699 Fix broken module namespacing in ActiveResource when using Ruby 1.9 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...

    September 27th, 2010 @ 10:12 PM