10 May 2007

Bug in ActiveResource's HttpMock?

I'm using ActiveResource a fair bit now. It's working fairly well, even with our non-standard XML and so on. Testing it works ok with use of HttpMock (see this blog entry for a way to do it). But, I've found that HttpMock appears to have a bug in how it deals with headers, and comparing the request you're making and the known requests. If the order of the keys in the header hash differs, they will fail to compare equally, and thus fail to match. To resolve this, I've modified the HttpMock::Request#hash method. It used to look like this:

def hash
  "#{path}#{method}#{headers}".hash
end

I changed it simply to this:

def hash
  "#{path}#{method}#{headers.sort}".hash
end

I will figure out how to post a bug report on this, but wanted to post here first in case there's a different solution, or disagreement that this is a bug.


Update: I've filed a bug in Rails trac. You can find it here.


1 comments:

The Editor said...

This bug is still there! I checked the bug ticket and it seems like it got closed and reopened but as best I can tell your patch diff was never applied. I'm going to register with bugtrac and ping them...