Problems Using Subdomains with Cucumber / Capybara

I have successfully added the ability to use dynamic subdomains in my application. The problem is that when I run the Cucumber tests, I get the following error when my application runs redirect_to, which contains a subdomain:

features/step_definitions/web_steps.rb:27
the scheme http does not accept registry part: test_url.example.com (or bad hostname?)

I have a registration controller action that creates the user and the selected account and redirects the user to the exit method with the specified subdomain based on what the user has selected as the subdomain in the registration form. Here is the code for the redirect action that occurs after creating and saving user models and accounts:

redirect_to :controller => "sessions", :action => "destroy", :subdomain => @account.site_address

Here are my rails 3 routes:

constraints(Subdomain) do
  resources :sessions
  match 'login', :to => 'sessions#new', :as => :login
  match 'logout', :to => 'sessions#destroy', :as => :logout
  match '/' => 'accounts#show'
end

Here is the code that I still have for the Subdomain class, which is specified in the restriction above:

class Subdomain
  def self.matches?(request)
    request.subdomain.present? && request.subdomain != "www"
  end
end

UrlHelper ApplicationController:

class ApplicationController < ActionController::Base
  include UrlHelper
  protect_from_forgery
end

UrlHelper:

module UrlHelper
  def with_subdomain(subdomain)
    subdomain = (subdomain || "")
    subdomain += "." unless subdomain.empty?
    [subdomain, request.domain, request.port_string].join
  end

  def url_for(options = nil)
    if options.kind_of?(Hash) && options.has_key?(:subdomain)
      options[:host] = with_subdomain(options.delete(:subdomain))
    end
    super
  end
end

. , . , redirect_to , .

gem:

require 'subdomain'

SomeApp::Application.routes.draw do

  resources :accounts, :only => [:new, :create]
  match 'signup', :to => 'accounts#new'

  constraints(Subdomain) do
    resources :sessions
    match 'login', :to => 'sessions#new', :as => :login
    match 'logout', :to => 'sessions#destroy', :as => :logout

    match '/' => 'accounts#show'
  end
end

, ? , , , (, , ).

+3
1

. Capybara ( Cucumber), :

    # user creates an account that will have a new subdomain
    click_button "Get Started"  
    host! "testyco.myapp.com"

    # user is now visiting app on new subdomain
    visit "/register/get_started/" + Resetkey.first.resetkey
    assert_contain("Get Started Guide")

! , .

EDIT: , webrat, capybara ( , webrat .) capybara, (capybara ) :

 visit "http://testyco.myapp.com/register"

EDIT: . , URL- .

        host! "test.hiringthing.com"
        Capybara.app_host = "http://test.hiringthing.com"

.

+1

Source: https://habr.com/ru/post/1771618/


All Articles