This project is archived and is in readonly mode.
Custom RbTemplateHandler fails in test, works in dev
Reported by Gaius Centus Novus | September 28th, 2009 @ 12:48 AM
I created a custom RbTemplateHandler:
# in lib/rb_template_handler:
class RbTemplateHandler < ActionView::TemplateHandler
include ActionView::TemplateHandlers::Compilable
def compile(template)
template.source
end
end
that I load:
# in config/environment.rb:
...
ActionView::Template.register_template_handler(:rb, RbTemplateHandler)
and use:
# in app/controllers/people_controller.rb:
class PeopleController < ApplicationController
def index
@people = Person.all
respond_to do |format|
format.json
end
end
end
# in app/views/people/index.html.rb:
@people.map |person|
{ :id => person.id, :to_s => person.to_s }
end.to_json
In development mode, this works fine at first:
$ script/console development
>> app.get '/people'
=> 200
>> "[{\"id\":\"1\", \"to_s\":\"John\"},{\"id\":\"2\", \"to_s\":\"Sally\"}]"
A second call, however, fails (in a way reminiscent of #:
>> app.get '/people'
ThreadError: stopping only thread
note: use sleep to stop forever
And in test, it always fails due to a missing template:
# in test/functional/people_controller_test.rb:
class PeopleControllerTest < ActionController::TestCase
def test_get_to_index
get :index, :format => 'json'
assert_equal "[{\"to_s\":\"John\"},{\"to_s\":\"Sally\"}]", @response.body
end
end
$ rake test:functionals
1) Error:
test_get_to_index(PeopleControllerTest):
ActionView::MissingTemplate: Missing template people/index.erb in view path app/views
app/controllers/people_controller.rb:4:in `index'
/test/functional/people_controller_test.rb:6:in `test_get_to_index'
Comments and changes to this ticket
-
Gaius Centus Novus September 28th, 2009 @ 12:52 AM
- Tag changed from 2-3-stable, actionview, rack, templates to 2-3-stable, actionview, bugmash, rack, templates
Ticket #3153 also addresses the part where the second call in dev fails. It doesn't address the part where all calls in test fail.
-
Gaius Centus Novus September 28th, 2009 @ 12:52 AM
Ticket #3153 also addresses the part where the second call in dev fails. It doesn't address the part where all calls in test fail.
-
Rizwan Reza February 12th, 2010 @ 12:46 PM
- Tag changed from 2-3-stable, actionview, bugmash, rack, templates to 2-3-stable, actionview, rack, templates
-
Ryan Bigg October 14th, 2010 @ 08:12 AM
- Importance changed from to
Please confirm that this is still an issue on the latest 2-3-stable / master. If it's not then this ticket needs to be closed.
-
Santiago Pastorino February 2nd, 2011 @ 04:47 PM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:47 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>