Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve "Missing host to link to! Please provide the :host parameter"? (RoR)

I'm following the RoR Tutorial and I'm stuck at Listing 9.15

I getting the following error after running 'bundle exec rspec spec/' :

1) Authentication authorization as wrong user submitting a PATCH request to the Users#update action 
     Failure/Error: specify { expect(response).to redirect_to(root_url) }
     ArgumentError:
       Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
     # ./spec/features/authentication_pages_spec.rb:79:in `block (5 levels) in <top (required)>'

My Authentication test code is:

require 'spec_helper'

describe "Authentication", type: :request do

  subject { page }


  describe "signin page" do
    before { visit signin_path }

    it { should have_content('Sign in') }
    it { should have_title('Sign in') }
  end

  describe "signin" do
    before { visit signin_path }

    describe "with invalid information" do
      before { click_button "Sign in" }

      it { should have_title('Sign in') }
      it { should have_selector('div.alert.alert-error', text: 'Invalid') }

      describe "after visiting another page" do
        before { click_link "Home" }
        it { should_not have_selector('div.alert.alert-error') }
      end

    end

    describe "with valid information" do
      let(:user) { FactoryGirl.create(:user) }
      before { sign_in user }

      #it { should have_title(user.name) }
      it { should have_link('Profile',     href: user_path(user)) }
      it { should have_link('Settings',    href: edit_user_path(user)) }
      it { should have_link('Sign out',    href: signout_path) }
      it { should_not have_link('Sign in', href: signin_path) }

      describe "followed by signout" do
        before { click_link "Sign out" }
        it { should have_link('Sign in') }
      end
    end
  end

  describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) { FactoryGirl.create(:user) }

      describe "in the Users controller" do

        describe "visiting the edit page" do
          before { visit edit_user_path(user) }
          it { should have_title('Sign in') }
        end

        describe "submitting to the update action" do
          before { patch user_path(user) }
          specify { expect(response).to redirect_to(signin_path) }
        end
      end
    end

    describe "as wrong user" do
      let(:user) { FactoryGirl.create(:user) }
      let(:wrong_user) { FactoryGirl.create(:user, email: "[email protected]") }
      before { sign_in user, no_capybara: true }

      describe "visiting Users#edit page" do
        before { visit edit_user_path(wrong_user) }
        #it { should_not have_title(full_title('Edit user')) }
      end

      describe "submitting a PATCH request to the Users#update action" do
        before { patch user_path(wrong_user) }
        specify { expect(response).to redirect_to(root_url) }
      end
    end

  end
end

I don't know how to resolve this issue so the test passes. How do I resolve it? Could someone explain what's going wrong? (According to the tutorial the test should be passing).

like image 213
Sheldon Avatar asked Aug 25 '13 20:08

Sheldon


People also ask

Why is resolving host not working on my browser?

Resolving host is not a browser specific process but somewhat depends on browser’s settings. Other browsers may show connecting, looking up, etc, still worth to try Mozilla Firefox. I did all of this, and I’m still having Resolving Host issues. Check with your ISP if the problem persists, public DNS / proxy / VPN should ideally work.

How to fix “resolving host” message in browser status bar?

After changing the DNS servers, close all browser windows and reopen the browser. Now try opening your website which should open fast without showing any “Resolving host” message in the status bar. All sites should be loaded comparatively faster than before and you can open the sites properly in Firefox, Safari, Edge and Internet explorer also.

How to resolve “resolving proxy” error in chrome?

If you see a “Resolving proxy” message in the status bar it might be due to your LAN settings. As explained in the option 4, open Chrome’s settings and click on the “Show advanced settings…” link. Navigate to “Network” section and click on “Change proxy settings…” button.

How to resolve host issue?

This resolution happens through Domain Name System known popularly as DNS. The technical reason for resolving host issue is that the DNS servers configured by your Internet Service Provider (ISP) takes long time to find a mapping IP address for the URL you have entered. This is probably due to change in ISP or change in DNS settings by your ISP.


2 Answers

In the end I just used:

root_path

instead of:

root_url
like image 24
Sheldon Avatar answered Sep 22 '22 05:09

Sheldon


The problem may be that you have not defined default_host for test environment. Define default_host inside config/environments/test.rb like this:

config.action_mailer.default_url_options = {:host => "localhost:3000"}
like image 129
Aman Garg Avatar answered Sep 22 '22 05:09

Aman Garg