json provide handler invoked on html call with 2012.12.08

21 views
Skip to first unread message

Roy Wright

unread,
Dec 9, 2012, 12:31:40 AM12/9/12
to ram...@googlegroups.com
Howdy,

I ported the app I'm working on to the new release and my rspecs hit an issue.  Basically when using rspec + capybara feature scenario and do a visit() call my controller's provide :json handler is invoked with the value being the HTML generated from the view.  I expect the provide json handler not to be invoked on a visit().

Visiting the page with a browser does not invoke the provide json handler.

BTW, the rspecs were passing before the upgrade to 2012.10.08.

Curious if anyone else is seeing this.

Relevant code at:  https://gist.github.com/4243452

TIA,
Roy

Yorick Peterse

unread,
Dec 9, 2012, 2:40:46 PM12/9/12
to ram...@googlegroups.com
Roy,

What does your middleware definition look like, is it using the new
syntax? Example:

Ramaze.middleware :spec do
run Ramaze.core
end

Yorick

Roy Wright

unread,
Dec 9, 2012, 3:04:20 PM12/9/12
to ram...@googlegroups.com
Ramaze.middleware :test do |m|
m.use Rack::Session::Cookie
m.use Rack::Accept
m.run Ramaze.core
end

Here's what's weird, my spec normally tests the json API using rake-test, then tests the html via capybara/rack-test. If I remove the json tests and just run the one spec (so only capybara tests are run) then it works.
If I reverse the order so html is tests first, then json, then the html passes and the json tests fail.

I do have a monkey patch on Innate::Node.find_provide that adds support for rake-accept. I'm looking into this now. But what I'm seeing so far is that once a route is hit with a given accept type, all subsequent hits on that url will have the action wish of the first access. What I mean is say the first GET '/' accept is 'application/json', then correctly the Action :wish => :json. Now say the next request is GET '/' accept => 'text/html', then incorrectly the action :wish => :json. Almost as if the wish is being cached instead of determined each time.

FYI, I added the monkey patch to my_controller.rb in the gist: https://gist.github.com/4243452

Thank you,
Roy
> --
> You received this message because you are subscribed to the Google Groups "Ramaze" group.
> To post to this group, send email to ram...@googlegroups.com.
> To unsubscribe from this group, send email to ramaze+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ramaze?hl=en.
>

Yorick Peterse

unread,
Dec 10, 2012, 3:07:21 AM12/10/12
to ram...@googlegroups.com
Roy,

I have a feeling this issue is being caused due to the Innate
performance patch. Innate now caches actions as these do not change
during runtime but I have a feeling this doesn't take different provide
blocks into account. I'll have a chat with Michael to see if this is
actually the case and how it can be resolved.

Yorick

Roy Wright

unread,
Dec 10, 2012, 12:43:09 PM12/10/12
to ram...@googlegroups.com
I removed the action cache with the following monkey patch and my specs are working again.

module Innate
module Node
def try_resolve(path)
action = resolve(path)
action ? action_found(action) : action_missing(path)
end
end
end

I'm happy with this patch as I am using the accept header to specify type (RESTful style) instead of the Ramaze
style url extensions ('/index.json', '/index.html') which does have a one-to-one mapping for the action caching.

Thank you!
Roy

Yorick Peterse

unread,
Dec 10, 2012, 1:52:47 PM12/10/12
to ram...@googlegroups.com
Roy,

Just to clarify, it *does* work when you don't use accept-headers but
instead rely on the URL?

Yorick

Roy Wright

unread,
Dec 10, 2012, 7:38:58 PM12/10/12
to ram...@googlegroups.com
Yorick,

Yes. I just cloned a page spec and changed the tests to use url extensions (ex: '/index.json') instead of accept headers. Then I confirmed the test works with action caching (i.e., without my monkey patch).

This is as expected as the action caching is keyed to url path.

So the problem was in my domain with regard to using accept headers instead of url path extension to specify accept types.

Thank you for your help troubleshooting, the tidbit that action caching was added was much appreciated!

Roy

Yorick Peterse

unread,
Dec 11, 2012, 3:24:03 AM12/11/12
to ram...@googlegroups.com
Roy,

Glad to hear, that saves us another bug report :)

Yorick
Reply all
Reply to author
Forward
0 new messages