cijoe
cijoe copied to clipboard
Rspec (1.3) redirect_to not resolving properly for multi-project cijoe using Rack+Passenger+Nginx
Not sure if this is a bug in our code, in the RedirectTo rspec matcher, or cijoe itself.
Here is the setup
Multiple Cijoe's + Rack + Nginx similar to the described at
- http://chrismdp.github.com/2010/03/multiple-ci-joes-with-rack-and-passenger/
The only tweaking was to change the directory structure (using cijoe/app/repos for the actual projects instead of cijoe-repos and cijoe/public for root instead of cijoe)
The setup works great, the environment is properly configured and the git hooks properly fire.
Here is problem rspec code
response.should redirect_to(:action => :index)
When run from the command line using the same cijoe.runner command, it works fine. When run inside Cijoe, the paths do not properly resolve resulting in a precondition-like expection
Here is the failing stack trace (not overly useful)
/home/deployer/.rvm/gems/ruby-1.8.7-p334@oss_db/gems/actionpack-2.3.11/lib/action_controller/routing/recognition_optimisation.rb:66:in `recognize_path'
/home/deployer/.rvm/gems/ruby-1.8.7-p334@oss_db/gems/rspec-expectations-2.4.0/lib/rspec/expectations/handler.rb:11:in `handle_matcher'
/home/deployer/.rvm/gems/ruby-1.8.7-p334@oss_db/gems/rspec-expectations-2.4.0/lib/rspec/expectations/extensions/kernel.rb:27:in `should'
./spec/controllers/main_spec.rb:44:
I dug deeper and determined which line in rspec's RedirectTo class is causing the exception.
Rspec is failing on the "actual" path around line 32 (shown below)
if @expected.instance_of? Hash
return false unless @actual =~ %r{^\w+://#{@request.host}}
return false unless actual_redirect_to_valid_route # this method is failing
return actual_hash == expected_hash && @status_matched
else
If you inspect the response, you see that the REQUEST_URI is invalidly set to
/myproject/admin/index
The "myproject" is not valid and it should just be /admin/index. When run within Cijoe, the URI is prepending the name of the project (i.e. myproject), which is not a valid path resulting in that internal exception shown above. When run on the same machine, from the same environment on the command line, the "myproject" is not added to the URI and the test passes.
Things I have tried already
- An internet search. Unfortunately most of the hits were about the incorrect use of redirect_to, or the hard-coding of @request.host
- Running the "rake ci:build" on the command line, and yes it works
- Inspecting "RAILS_ROOT" and it properly points to myproject/app
- Trial and error inspecting several objects to see where / how "myproject" is being added to URL
What I am looking for
Direction, if possible on how best to resolve this issue. Is Cijoe setting something up that Rspec doesn't expect, is Rack doing something special, is Rspec not handling this subdirectory case properly
I would prefer to not change my test (at least not that much), so any insight would be greatly appreciated.
Looks like the culprit is in url_rewriter.rb (rails actionpack 2.3.11) line 198
rewritten_url << ActionController::Base.relative_url_root.to_s unless options[:skip_relative_url_root]
First thought is to figure out how to turn on "skip_relative_url_root" from within the specs, or better yet figure out why relative_url_root is set to one directory higher.
I added the following line to my spec_helper.rb as a work-around.
# To deal redirect_to problems (see https://github.com/defunkt/cijoe/issues/62)
ActionController::Base.relative_url_root = ''