I have a site hosted on Heroku. For SEO purposes I am trying to use strictly my bare domain (https://example.com/).
I found this medium article suggesting to insert this code into routes.rb
match '(*any)', to: redirect(subdomain: ''), via: :all, constraints: {subdomain: 'www'}
Seems like a easy and efficient way to handle redirecting to bare domain in Rails.
However, now all my tests are failing with the message:
Expected response to be a redirect to <http://www.example.com/> but was a redirect to <http://example.com/>.
And
Expected response to be a <2XX: success>, but was a <301: Moved Permanently> redirect to <http://example.com/>
I can somewhat fix this by replacing assert_response :success
with assert_response :redirect
in my test logic for page loads.
My question is, would changing all my tests to assert_response :response
be best practice? Or is there an easier way to configure bare domain redirects in Rails 6 that does not interfere with test logic?
Example of test:
test "should get example page" do
get example_path
assert_response :success
end
Routes.rb
root to: "site#index"
get "example", to: "site#example