Reputation: 404
I am attempting to write a test verifying my controller's action. When tested manually, the code executes as expected. However, my test raises an error because it is unable to locate a template I am attempting to render.
Snippet from my controller code:
response = {:success => true}
response[:html] = {}
response[:html][:list] = render_to_string :partial => "data_source", :locals => {:data_source => @data_source}
respond_to do |format|
format.json {render :json => response}
end
My test:
before do
@data_source = FactoryGirl.create :data_source, :facebook_fan_page, :account_id => @account.id, :user_id => @user.id
post :delete, :format => :json, :id => @data_source.id
end
it "should disable the data source" do
assert_equal false, @data_source.reload.enabled?
end
The error message:
ActionView::MissingTemplate: Missing partial data_sources/data_source, capture/data_source, application/data_source with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :haml]}. Searched in:
* "/Users/me/code/my_app/app/views" * "/Users/me/code/my_app/vendor/bundle/ruby/1.9.1/gems/konacha-3.0.0/app/views" from /Users/me/code/my_app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.17/lib/action_view/path_set.rb:58:in `find'
There is definitely a partial in the app/view/data_sources directory "_data_source.html.haml".
Why can't the test find the partial? I suspect a setup issue
Thanks in advance.
Upvotes: 0
Views: 83
Reputation: 13181
As you are doing a json request, render_to_string
is looking for a json template. Try this:
render_to_string :partial => "data_source", :formats => [:html], :locals => {:data_source => @data_source}
Upvotes: 1