Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need support for subclasses #7

Open
bloudermilk opened this issue Mar 10, 2010 · 1 comment
Open

Need support for subclasses #7

bloudermilk opened this issue Mar 10, 2010 · 1 comment

Comments

@bloudermilk
Copy link

I am currently developing a service that acts as a middle-man for two other services. On either side, we have Foo model and the middle transports them across. We accomplished the same-name model problem in our middle man by subclassing our ActiveResource models like so:

module LeftSide::Foo
  class Foo < ActiveResource::Base
    self.site = CONFIG['api']['left_side_url']
  end
end
module RightSide::Foo
  class Foo < ActiveResource::Base
    self.site = CONFIG['api']['right_side_url']
  end
end

Currently I am getting the error:

HANDLER ERROR: Undefined prefix RightSide found
/usr/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:389:in `pull'
/usr/local/lib/ruby/1.8/set.rb:195:in `each'
/usr/local/lib/ruby/1.8/set.rb:195:in `each_key'
/usr/local/lib/ruby/1.8/set.rb:195:in `each'

When trying to execute this code in my steps:

Dupe.create "RightSide::Foo", :a_value => '1234'
Dupe.find('RightSide::Foo') {|b| a_value == '1234'}

The other issue we'll have is the fact that API calls are reduced down to the path. In both my LeftSide and RightSide API's, the routes are the same. I haven't had a chance to test conflicts between model URLs yet, but I have a feeling this is going to fail.

@moonmaster9000
Copy link
Owner

hi bloudermilk. thanks for using dupe. i think the problem stems from trying to call the duped resource "RightSide::Foo". when you dupe a resource, it essentially creates a glorified hash, and eventually a to_xml will be run on the hash, with the root node set to the name of the resource. so in this case, it sounds like it's setting the root node to RightSide::Foo, which is essentially a namespaced XML node, which i think is probably why REXML is complaining. the solution: call your resource "right_side_foo", or even just "foo". if during some tests, your testing the left side foo, then during that test, create mocked resources named "foo", and then create the intercept mocks to respond to that particular url. same for the right side foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants