Forum: Ruby on Rails scope problems testing a helper method that calls link_to()

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Rick B. (Guest)
on 2006-02-07 23:00
(Received via mailing list)
We've been having problems writing functional tests for helper methods
that rely on ActionView methods.  Here's a specific example.

In application_helper.rb I've got a method called 'party_link()ยจ:

  def party_link(party)
    link_to party.full_name, { :controller => 'contacts',
                               :action => 'view',
                               :category => party.category_name,
                               :id => },
            :class => 'a2'

It takes a Party object (person, organization...) and returns an HTML
link to
that party's contact page.  Simple enough.  And it appears to work well
from the browser.

We want to test it, though, so we want to write a functional test that
fixture Party data at it and ensure that it returns reasonable links,
for some
value of reasonable.

Since it's not in a particular controller's helper file (since it will
be used
by many controllers), we will create a trivial controller for use in
The problem we run into is that we can't seem to get the ActionView
required to run party_link() visible while testing.  Here's the

require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/../../app/controllers/application'
require File.dirname(__FILE__) + '/../../app/helpers/application_helper'
require 'action_view'

module LoginSystem
  def unprotected?() true; end # drop login protection for this test

# dummy controller to drive helper tests
class HelperController < ActionController::Base
  include ApplicationHelper
  include ActionView

class HelperControllerTest < Test::Unit::TestCase
  fixtures :party

  include ApplicationHelper

  def setup
    @controller =
    @request    =
    @response   =

  # Test party_link function passing staff
  def test_party_link_staff
    link_data = @controller.party_link(party(:twburges))

Note that we're not even getting to an assert_* in
because, well, we tried, and we just get an error, so we culled the
from the code I'm sending (so as not to confuse the issue).

  1) Error:
NoMethodError: undefined method `link_to' for
    ./test/functional/bad_test.rb:30:in `test_party_link_staff'

Currently we're stubbing link_to() and checking that it gets called,
which is
The Wrong Way to fix the problem.  We can 'include' ActionView,
ActionView::Helpers, ActionView::Helpers::UrlHelper and get past link_to
I think url_for) but end up blowing on tag_options (IIRC).  Seems like
must be a simpler and more straightforward way to do this, that I'm sure
missed in Rails 101.

Any suggestions?
--    MUPRN: 591
                       |  At present, one of
   random email haiku  |  the machines shows all the
                       |  detail from reboots.
This topic is locked and can not be replied to.