Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Custom RbTemplateHandler fails in test, works in dev

#3287

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'

Reported by Gaius Centus Novus · September 28th, 2009 @ 12:48 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Gaius Centus Novus
    Gaius Centus Novus
    • 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.

    September 28th, 2009 @ 12:52 AM

  2. Gaius Centus Novus
    Gaius Centus Novus

    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.

    September 28th, 2009 @ 12:52 AM

  3. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2-3-stable, actionview, bugmash, rack, templates to 2-3-stable, actionview, rack, templates

    February 12th, 2010 @ 12:46 PM

  4. Ryan Bigg
    Ryan Bigg
    • 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.

    October 14th, 2010 @ 08:12 AM

  5. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:31 AM

  6. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:47 PM

  7. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:47 PM