1

I don't understand what I am doing wrong and really need some help. I am trying to just write a simple IntegrationTest for a multitenant site where each account has it's own subdomain.

I followed the instructions here for changing the host in the IntegrationTest, however when I run the test

Minitest::Assertion: Expected response to be a redirect to <http://subdomain1.example.com:3000/login> but was a redirect to <http://www.example.com:3000/>.
Expected "http://subdomain1.example.com:3000/login" to be === "http://www.example.com:3000/".
test/integration/feedback_flow_test.rb:8:in `block in <class:FeedbackFlowTest>'
Finished in 0.26594s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips

I edited my host file so that I have subdomain1.example.com and www.example.com pointing to 127.0.0.1. Is there something else that I should be doing to get this to work? Below is the code for the IntegrationTest

require 'test_helper'

class FeedbackFlowTest < ActionDispatch::IntegrationTest

  test "no token should go to the login page" do
    host! 'subdomain1.example.com:3000'
    get feedback_path
    assert_redirected_to login_url
    follow_redirect!
    assert_select '.alert-danger h3', 'You are not authorized '
  end
end
rip747
  • 9,375
  • 8
  • 36
  • 47
  • Could you please share the part of the host file that has the example sites pointing to `127.0.0.1`? – Anuj Khandelwal Jul 02 '19 at 13:52
  • Sorry everyone... Found the issue by looking at the test.log. Seems that I forgot to create a fixture for the accounts model. As such, there were no account getting created when the test would run thus causing the error. I always do `fixtures :all` in my test_helper.rb file so that it load all the fixtures for the tests. – rip747 Jul 02 '19 at 14:08

1 Answers1

0

Sorry everyone... Found the issue by looking at the test.log. Seems that I forgot to create a fixture for the accounts model. As such, there were no account getting created when the test would run thus causing the error. I always do fixtures :all in my test_helper.rb file so that it load all the fixtures for the tests.

rip747
  • 9,375
  • 8
  • 36
  • 47