Alias_method_chain stack level too deep in Rake test only

I have an odd error. I have the following module:

module ActionController
module SslSupport

def self.included(base)
  raise "#{base} does not define url_for" unless

base.method_defined?(:url_for)
unless base.respond_to?(:url_for_without_ssl_supprt)
base.send :include, InstanceMethods
base.send :alias_method_chain, :url_for, :ssl_support
end
end

module InstanceMethods

  def url_for_with_ssl_support(options)
    new_options = options.dup

    if options.kind_of?(Hash)
      new_options.merge!({ :only_path => false }) if request.ssl?

^ url_ssl?(new_options)
if url_ssl?(new_options)
new_options.merge!({ :protocol => ‘https’ })
if [‘development’].include?(ENV[‘RAILS_ENV’])
new_options.merge!({ :port => 3001, :host =>
request.host })
end
end
new_options.delete(:ssl)
end

    url_for_without_ssl_support(new_options)
  end

  private

  def url_ssl?(options)
    case options
    when Hash
      protocol = options[:protocol] || 'http://'
      return options[:ssl] || protocol =~ /^https/
    when String
      return options =~ /^https/
    else
      return self.class.method_defined?(:request) ? request.ssl? :

false
end
end

end

end
end

It is included in app/controllers/application.rb and in
ActionView::Base. If I run

ruby test/functional/people_controller_test.rb or ruby test/functional/
account_controller_test.rb, everything runs fine. If I run rake
test:functionals, however, I get a “stack level too deep” within
url_for within those two test classes.

Example output:

test_spec {The Account controller A guest (in general)} 001
[should be able to view the sign-up page](The Account controller
A guest (in general)):
ActionView::TemplateError: stack level too deep
On line #8 of app/views/account/start.rhtml

5: <h1>Create a free account in three steps:</h1>
6:
7: <ol>
8:  <li>a.&nbsp;<%= link_to 'Choose', :action => 'choose' %></li>
9:  <li>b.&nbsp;Create</li>
10:         <li>c.&nbsp;Customize</li>
11: </ol>
lib/action_controller/ssl_support.rb:36:in `url_ssl?'
lib/action_controller/ssl_support.rb:19:in

url_for_without_ssl_support' lib/action_controller/ssl_support.rb:28:inurl_for’
vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:
70:in send' vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb: 70:inurl_for_without_ssl_support’
lib/action_controller/ssl_support.rb:28:in url_for' vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb: 136:inlink_to’

I figured that my self.included(base) would guard against this, but it
doesn’t seem to work. Any thoughts?

-Gaius

I suppose I meant ‘method_defined?’ instead of ‘respond_to?’ but that
doesn’t change the problem.

-Gaius

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs