This project is archived and is in readonly mode.
ActionView::TestCase does not honor default_url_options set in application_controller.rb
-
Andrew White
- State changed from new to open
- Milestone cleared.
- Assigned user set to Andrew White
- Importance changed from to Low
-
Andrew White
- State changed from open to invalid
When unit testing views the controller is just a stub controller which inherits from ActionController::Base and not ApplicationController. You need to override this stub if you need special behaviour like default_url_options, e.g:
# app/views/products/index.html.erb <%= link_to('Products', products_path) %> # test/unit/views/products_index_test.rb require 'test_helper' class ProductsIndexTest < ActionView::TestCase class ProductsController < TestController def default_url_options { :locale => 'de' } end end def setup @controller = ProductsController.new end def test_render render :template => "products/index" assert_match %r{href="/de/products"}, rendered end endNote that you have to define the controller in your test as using the real one will not have a test request and response.