-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
Hey, I've been wracking my head trying to figure this one out and I've hit a wall. Ever since upgrading our app to Rails 3.1 and RSpec 2.7, the URL helpers are broken in view specs. Example backtrace:
ActionView::Template::Error: undefined method `account_path' for #<#<Class:0x007fa5f444da30>:0x007fa5dd262318>
/Users/tmorgan/Development/recurly/app/app/views/transactions/_side_account_info.html.erb:5:in `_app_views_transactions__side_account_info_html_erb___4285474219857912422_70175171766660'
/Users/tmorgan/.rvm/gems/ruby-1.9.2-p290@recurly-app/gems/actionpack-3.1.3/lib/action_view/template.rb:171:in `block in render'
/Users/tmorgan/.rvm/gems/ruby-1.9.2-p290@recurly-app/gems/activesupport-3.1.3/lib/active_support/notifications.rb:53:in `block in instrument'
/Users/tmorgan/.rvm/gems/ruby-1.9.2-p290@recurly-app/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/tmorgan/.rvm/gems/ruby-1.9.2-p290@recurly-app/gems/activesupport-3.1.3/lib/active_support/notifications.rb:53:in `instrument'
[...]
Obviously, account_path
is a valid auto-generated URL method. Errors of this type are raised for all views that make calls to URL-generating methods.
If I modify my ApplicationHelper
to include Rails.application.routes.url_helpers
(which of course I shouldn't have to do), then the method becomes defined, but its call to url_for
raises an error:
In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers`
Here's an example of one such view spec; pretty straightforward:
describe "/transactions/show.html.erb" do
before(:each) do
@transaction = FactoryGirl.create(:payment)
@account = @transaction.account
end
it "displays the transaction details" do
controller.request.path_parameters[:id] = @transaction.uuid
render
view.content_for(:wide_aside).should include("XXXX-#{@transaction.credit_card_last_four}")
view.content_for(:wide_aside).should include("Success")
view.content_for(:wide_aside).should include(@transaction.ip_address)
end
end