jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

Respect Rails relative_url_root option when app is deployed in sub directory #131

Closed kowal closed 10 years ago

kowal commented 10 years ago

When Rails application is deployed in sub-directory, application root prefix is ignored when serving teaspoon assets - it is impossible to run specs in browser (CLI run works fine).

I've fixed it locally by prepending result from methods:

.. with ENV['RAILS_RELATIVE_URL_ROOT'] (or Rails.config.action_controller.relative_url_root)

I was looking for just one place where relative_url_root could go, haven't found any.

Any ideas how this could be solved? I can provide a PR for start, just want to make sure if this is good approach.

jejacks0n commented 10 years ago

I'd love to see an example. I'm struggling to understand, but I vaguely get what you mean.. can you mock up a project so I can clone it and see if I have a good solution?

kowal commented 10 years ago

Rails application can be run on some application servers in context, let's say /app, so it is accessible in development at http://localhost:3000/app/. To configure it this way we're using relative_url_root [1] option.

Configuring it for production is different subject [2], important thing to note is that we want to have the same context root in all environments.

Given assumptions above, I created fresh Rails 4 application, configured to be visible at http://localhost:3000/app/ and added example spec [3].

When I hit http://localhost:3000/app/teaspoon I'm seeing request to Teaspoon::SpecController#suites ended with 200, however URLs to teaspon.css, teaspoon-teaspoon.js and all suites/examples on the page are missing /app prefix. Page looks ugly and doesn't work :)

I tried using Teaspoon.setup.mount_at option but I guess it wasn't created for such case.

[1] http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root [2] http://stevesaarinen.com/blog/2013/05/16/mounting-rails-in-a-subdirectory-with-nginx-and-unicorn/ [3] https://github.com/kowal/rails4_teaspoon_test_app