#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 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"
    ...
    

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

People watching this ticket

Tags

Pages