2009-12-24 73 views
0

我在我的項目中添加了Subdomain-fu。在ApplicationController中我有before_filter,它檢查url並將app.com重定向到www.app.com,www.subdomain.app.com到subdomain.app.com並檢查帳戶是否存在(如果不存在,則重定向到home):添加Subdomain-fu和重定向功能後,黃瓜/ webrat測試失敗

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 

上面的代碼相當不錯。但添加此片段後,我的黃瓜測試,例如。這一個:

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

成了失敗,錯誤:

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!"' 

如果我評論這個的before_filter一切正常。 有人知道爲什麼嗎?

回答

0

我可以弄清楚Webrat非常喜歡域名「example.com」,並且模仿它的所有步驟。

所以,如果你不使用子域名,你可以在你的步驟寫:

Before do 
    host! "example.com" 
end 

和所有重定向應該工作(我不檢查)。 隨着子域福,它甚至更加esier。所有你應該做的 - 正確地配置您的子夫配置文件:

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

,並重定向工作測試,沒有任何主機! 「example.com」