views:

422

answers:

1

I added Subdomain-fu in my project. In ApplicationController I have before_filter which checks url and redirects app.com to www.app.com, www.subdomain.app.com to subdomain.app.com and checks account existence (redirects to home if not exists):

    before_filter :check_uri 

    def check_uri
      if !subdomain?
        redirect_to http_protocol + "www." + current_host + request.request_uri if !/^www\./.match(current_host)
      elsif /^www\./.match(current_host)
        redirect_to http_protocol + current_host.gsub(/^www\./, '') + request.request_uri
      elsif !account_subdomain?
        redirect_to http_protocol + "www" + current_host.gsub(account_subdomain, '')
      end
    end

Code above works pretty nice. But after adding this snippet my Cucumber tests, for ex. this one:

  Scenario: Successful sign up
    Given I am an anonymous user
    And an Accept Language header
    And I am on the home page
    When I follow "Join now!"
    And ...

became fail with error:

Webrat::NotFoundError: Could not find link with text or title or id "Join now!"
(eval):2:in `/^I follow "([^\"]*)"$/'
features/manage_users.feature:10:in `When I follow "Join now!"'

If I comment this before_filter everything works well. Does anybody know why?

A: 

I could figure out that Webrat loves domain "example.com" very deeply and emulates all step with it.

So if you don't use subdomains, you can write in your steps:

Before do
  host! "example.com"
end

and all your redirections should work (I don't check). With Subdomain-fu it's even esier. Everything what you should do - to configure your subdomain-fu config file properly:

SubdomainFu.tld_sizes = {:development => 0,
                         :test => 1, # not 0, even if you use *.localhost in development
                         :production => 1}

and tests with redirection work without any host! "example.com".

Voldy