Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 4 Mounted Engine Rspec Url adding params twice
    primarykey
    data
    text
    <p>I have a Rails 4 mounted engine <code>MyEngine</code></p> <p>Inside a <code>lib</code> module I'm using the <code>url_helper</code> to find a route.</p> <pre><code>MyEngine::Engine.routes.url_helpers.send("test_controller_url",{:id =&gt; 1, :lang =&gt; I18n.locale}) </code></pre> <p>And I have configured <code>rspec</code> with the <code>default_url_options</code> in <code>spec/spec_helper.rb</code> like this.</p> <pre><code>class ActionView::TestCase::TestController def default_url_options(options={}) { :params =&gt; { :lang =&gt; I18n.default_locale }, :host =&gt; "test.host" }.merge options end end class ActionDispatch::Routing::RouteSet def default_url_options(options={}) { :params =&gt; { :lang =&gt; I18n.default_locale }, :host =&gt; "test.host" }.merge options end end </code></pre> <p>The resultant <code>url</code> I'm expecting from the call is:</p> <pre><code>http://test.host/controller/1/test?lang=en </code></pre> <p>But I'm getting the <code>url</code>: </p> <pre><code>http://test.host/?lang=en/controller/1/test?lang=en </code></pre> <p>I did some debugging into <code>actionpack/action_dispatch/http/url.rb</code> in <code>actionpack-4.0.1</code> of <code>rails</code>.</p> <p>The options that come to the <code>url_for</code> method are:</p> <pre><code>{ :params=&gt;{:lang=&gt;:en}, :host=&gt;"test.host", :use_route=&gt;"my_engine", :only_path=&gt;true, :lang =&gt; :en, :path=&gt;"/", :script_name=&gt;nil, :user=&gt;nil, :password=&gt;nil } </code></pre> <p>and</p> <pre><code>{ :params=&gt;{:lang=&gt;:en}, :host=&gt;"test.host", :action=&gt;"test", :controller=&gt;"my_engine/controller", :use_route=&gt;"test_controller", :only_path=&gt;false, :id=&gt;1, :path=&gt;"/controller/1/test", :script_name=&gt;"/?lang=en", :user=&gt;nil, :password=&gt;nil } </code></pre> <p>And in the <code>dummy</code> rails application inside <code>spec/dummy/config/routes.rb</code> I've mounted the <code>engine</code> with:</p> <pre><code>mount MyEngine::Engine, :at =&gt; "/" </code></pre> <p>It seems to produce the malformed <code>url</code> only with <code>rspec</code> and not even with <code>rails console</code></p> <p>I also noticed that there are two calls being made to <code>url_for</code>, one for the <code>engine</code> and one for the actual <code>path</code>.</p> <p>What am I doing wrong here? Is it a configuration thing or is there an actual bug?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload