[rspec-devel] [ rspec-Bugs-12404 ] Edge Rails breaks RSpec with newer link_to syntax

noreply at rubyforge.org noreply at rubyforge.org
Sun Nov 18 22:21:18 EST 2007

Bugs item #12404, was opened at 2007-07-19 03:03
You can respond by visiting: 

Category: rails plugin
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Marcus Crafter (crafterm)
Assigned to: Nobody (None)
Summary: Edge Rails breaks RSpec with newer link_to syntax

Initial Comment:
Hi All,

Hope all is going well.

In Edge Rails you can specify link to using:

link_to('path, @model)

as opposed to:

link_to('path', model_path(@model))

in 1.2 and earlier.

The newer syntax breaks rspec though if you have any helpers or view specs that test code that uses it with mock models. The error it prints is:

undefined method `polymorphic_path' for [Dynamically generated class
for RSpec example]:#<Class:0x26814f4>

Example to reproduce:

describe ApplicationHelper do
  it "should demo edge link_to problem" do
    mock = mock_model(User, :name => test)
    link_to(mock.name, mock).should == '<a href="/users/1000">test</a>'

I've been able to fix this with the following monkey patch:

module Spec
  module Rails
    module DSL
      class EvalContext < Spec::Rails::TestCase
        def polymorphic_path(uri)

However there may be a more appropriate solution? Would be great to get this fixed, please let me know if there's anything else I can do.




Comment By: Chad Humphries (spicycode)
Date: 2007-11-18 22:21

Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/53-12404-edge-rails-breaks-rspec-with-newer-link_to-syntax#ticket-53-2


Comment By: David Chelimsky (dchelimsky)
Date: 2007-07-27 19:16

I took a look at this. The method as you've defined it would always return what is essentially the "show" path. The whole magic of polymorphic_path is that it renders a different url based on the state of the object. I think this would lead to people getting frustrated using rspec to describe helper methods like the one you are trying to deal with, with objects that are in varying states, and getting unexpected results.

With that in mind, a more robust solution *would* be to include ActionController::PolymorphicRoutes in the helper examples (that's where polymorphic_path gets defined) - but this creates a new problem, which is that polymorphic_path ends up using named routes that don't exist in scope either.

Anybody have any suggestions here?



Comment By: Marcus Crafter (crafterm)
Date: 2007-07-22 19:57

Hi David,

My apologies, I've attached a tar.bz2 archive that includes
a working example of the issue.

Please extract the polymorphic-path-example.tar.bz2, and run
the notes_helper_spec.rb spec, or simply run rake spec after
creating the test database, and you'll see the error.

I haven't included rails, or rspec with this example, in the
vendor directory, I've symlinked rails to the latest trunk
(rev 7209), and in the plugins directory rspec/rpec_on_rails
(rev 2181).

The notes_helper_spec.rb includes the fix I wrote but I'm
unsure if this is the correct solution. I'm happy to write a
patch for this for rspec itself if you're happy with it.




Comment By: David Chelimsky (dchelimsky)
Date: 2007-07-22 16:03

I'm not able to reproduce this error using the example you've provided. Please submit an example that we can get to fail running rspec's own examples. See http://rspec.rubyforge.org/community/contribute.html for more information.



You can respond by visiting: 

More information about the rspec-devel mailing list