EDIT:
I found that if I insert view.lookup_context.prefixes = %w[base]
before render
, the test knows the proper path. Is this the best/proper way of solving this?
I put all my partials in a base folder, and all the controller that have access to those partials inherit from the base_controller
this all works great, but the generated view tests can't find the partials that are in the base folder.
Here is the error:
Failure/Error: render
ActionView::Template::Error:
Missing partial /admin_menu, circuits/admin_menu with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :coffee, :jbuilder]}. Searched in:
* "/Users/Mac/Folder/ProjectName/app/views"
How do I tell my view test where to look for the partials?
for completeness, here is the spec:
require 'spec_helper'
describe "circuits/index" do
before(:each) do
assign(:circuits, [
stub_model(Circuit,
:name => "Name",
:description => "MyText"
),
stub_model(Circuit,
:name => "Name",
:description => "MyText"
)
])
end
it "renders a list of circuits" do
view.lookup_context.prefixes = %w[base application]
render
assert_select "tr>td", :text => "Name".to_s, :count => 2
assert_select "tr>td", :text => "MyText".to_s, :count => 2
end
end
I had a similar issue when using partial inheritance to add themes feature to my app. For Rails 4 it was a bit different than in the edited answer - I had to add this in my view specs:
before do
view.lookup_context.view_paths.push 'app/views/themes/light'
end
where the themes/light
folder contained some partials specific to the light theme.
You should use
<%= render 'base/admin_menu' %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With