#140 open
Zach Dennis

current_url should be fully qualified

Reported by Zach Dennis | January 22nd, 2009 @ 12:00 AM | in 0.4.2

current_url is currently set to the request URl in Webrat::Session#request_page. This is misleading and it causes issues when working with subdomains (and redirecting). A browser is smart enough to take a relative path and expand it to an absolute url based on the current host.

The below patch makes Webrat act more like a browser, and it will fully qualify the current_url at all times (which seems least surprising for a method of that name).

See: http://github.com/zdennis/webrat...

Comments and changes to this ticket

  • Zach Dennis

    Zach Dennis January 22nd, 2009 @ 12:02 AM

    Forgot to add, Webrat still successfully redirects w/o this patch, but this makes #current_url return the actual correct URL, and when working with subdomains it comes in very handy to be able to access the real absolute url.

  • Bryan Helmkamp

    Bryan Helmkamp January 25th, 2009 @ 04:58 PM

    • Milestone set to 0.4.1
  • Bryan Helmkamp

    Bryan Helmkamp February 8th, 2009 @ 11:23 PM

    • Milestone changed from 0.4.1 to 0.4.2
  • gaffo

    gaffo May 7th, 2009 @ 03:14 PM

    • State changed from “new” to “open”

    Not sure if this is done or not. Need to verify.

  • gaffo

    gaffo May 7th, 2009 @ 03:14 PM

    • Tag changed from patch to patch, verify
  • Henrik Nyh
  • hedgehog

    hedgehog January 20th, 2010 @ 10:19 PM

    still an issue in webrat 0.6.0

    The following step fails because path_to returns a fully qualified path, as it must in this usecase.

    Then /^(?:|I )should be on (.+)$/ do |page_name|
      current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
      if defined?(Spec::Matchers) || defined?(Spec::Rails::Matchers)
        current_path.should == path_to(page_name)
      else
        assert_equal path_to(page_name), current_path
      end
    end
    
  • hedgehog

    hedgehog January 20th, 2010 @ 10:41 PM

    I had no success with the workaround:
    http://stackoverflow.com/questions/1137965/cucumber-defaulturloptio...

    Instead you have to relax and invert your spec:

    Then /^(?:|I )should be on (.+)$/ do |page_name|
      current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
      if defined?(Spec::Matchers) || defined?(Spec::Rails::Matchers)
    
    
     path_to(page_name).should contain(current_path)
    
    
    
    
    else
     assert_equal path_to(page_name), current_path
    
    
    
    
    end end

    The stack I am using for this is
    cucumber 0.6.1
    webrat 0.6.0
    mechainize 0.9.3
    nanoc3 3.0.6

    The pages are served on http://localhost:3000/ by:

    nanoc3 aco --server=thin
    

    PS not sure why lighhouse is now choking on the step definition code...

  • hedgehog

    hedgehog January 30th, 2010 @ 10:15 PM

    Current_url is raiing a problem in the course of using click_link in a Cucumber+Mechanize step.

    In /home/hedge/.rvm/gems/ruby-1.9.1-p378/gems/webrat-0.7.0/lib/webrat/core/elements/link.rb


    def absolute_href
    if href =~ /^\?/

    {mkd-extraction-94c2d85d1d05e2f0058f5d48b5feebd5}

    elsif href !~ %r{^https?://} && (href !~ /^\//)

    {mkd-extraction-baef91455759ba89b65564866458a6bd}

    else ...

    However

    (rdb:1) pp @session.current_url "http://localhost:3000/index.html" (rdb:1) pp href "spec_resources/"

    Which means that a click_link("Resources") step fails with a 404 because:

    http://localhost:3000/index.html/spec_resources/

    does not exist.

    FYI the URL http://localhost:3000/index.html is the result of the step:

    Given I go to "nanoc's localhost Home page"

    Where


    def path_to(page_name)

    {mkd-extraction-d12432ba6bcbff90b64aa0b207aaf83f}

    ...

  • hedgehog

    hedgehog January 30th, 2010 @ 10:21 PM

    current_url is raising a problem in the course of using click_link in a Cucumber+Mechanize step.

    In /home/hedge/.rvm/gems/ruby-1.9.1-p378/gems/webrat-0.7.0/lib/webrat/core/elements/link.rb

    def absolute_href
      if href =~ /^\?/
        "#{@session.current_url}#{href}"
      elsif href !~ %r{^https?://} && (href !~ /^\//)
        "#{@session.current_url}/#{href}"
      else
    ...
    

    However

    (rdb:1) pp @session.current_url
    "http://localhost:3000/index.html"
    (rdb:1) pp href
    "spec_resources/"
    

    Which means that a click_link("Resources") step fails with a 404 because:
    http://localhost:3000/index.html/spec_resources/ does not exist.

    FYI the URL http://localhost:3000/index.html is the result of the step:

    Given I go to "nanoc's localhost Home page"

    Where

      def path_to(page_name)
        case page_name
        when /nanoc's localhost Home page/
          @url_root = "http://localhost:3000"
          @url="#{@url_root}/index.html"
    ...
    
  • Aleks Shamles

    Aleks Shamles March 5th, 2021 @ 09:55 AM

    Je ne pense pas que la vieillesse soit un obstacle majeur. On peut dire que l'achat d'un ici est un excellent choix pour les personnes qui peuvent lutter contre leurs problèmes non seulement par des mots. Après ce remède, votre femme sera très surprise!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

Tags

Pages