Found bug, wrote patch. Need help with failing test.

There is a bug in the AbstractRequest getter/setter combo for the format. It was introduced in changeset 7479 a couple of months ago. It has escaped detection so far because the "respond_to |format|" circumvents it. The bug is trivial to understand and fix.

Understanding: Assuming the request format (from Accept header) is initially not XML, this works as expected:

  request.format = :xml   request.format.xml? => true

...but this does not:

  request.format.xml? => false   request.format = :xml   request.format.xml? => false

The problem is that the getter caches the answer the first time it is invoked and subsequent changes with the setter don't update the cache. The fix is trivial (see my ticket http://dev.rubyonrails.org/ticket/10889).

But I am having a tough time writing a failing test. It seems as though TestRequest does not implement the getter/setter the same way as AbstractRequest. I've looked at mime_responds_test, and while it is easy enough to replicate the bug there, it seems like it is out of place as all the tests there are round trip tests. The obvious place is request_test, but I can't get the @request instance variable to behave like the real thing -it doesn't implement the setter the same way as the request.

I would greatly appreciate it if someone could point me towards a testing mechanism.

-Chris

But I am having a tough time writing a failing test. It seems as though TestRequest does not implement the getter/setter the same way as AbstractRequest. I've looked at mime_responds_test, and while it is easy enough to replicate the bug there, it seems like it is out of place as all the tests there are round trip tests. The obvious place is request_test, but I can't get the @request instance variable to behave like the real thing -it doesn't implement the setter the same way as the request.

I would greatly appreciate it if someone could point me towards a testing mechanism.

Hey Chris,

Sorry that it took a while to get back to you, jump into #rails-contrib and ask some of the folks hanging out in there. If we need to rejig the tests for that functionality, I'm sure we can hash it out pretty quickly.

Thanks Michael. I did just that and Ben Scofield pointed me in the right direction.

Can I get a +1?

-Chris