Trying to figure out how to test my partial that calls another partial twice with different parameters. I'd like my test to verify those parameters in the two different calls.
The two partial calls in the main partial under test:
<div class="col-md-10">
<legend>Dates</legend>
<div class="form-group">
<%= f.label :start_date %>
<%= render partial: 'shared/common_date_time_chooser', locals: {prefix: :start_date, initial_time: Time.zone.now.beginning_of_day} %>
</div>
<div class="form-group">
<%= f.label :end_date %>
<%= render partial: 'shared/common_date_time_chooser', locals: {prefix: :end_date, initial_time: Time.zone.now.end_of_day} %>
</div>
So I want to verify that the two calls are made with the two different prefix and initial_time parameters.
The testing code renders like such:
require 'spec_helper'
describe 'notices/_form' do
subject do
assign(:notice, notice)
render
end
If the main partial made a single call to the 'common_date_time_chooser' partial I could use should render_template
which has a version in view specs that let's you test for passed parameters. However, that defers to Rails' assert_template
which seems to only keep track of the latest call.
In controller tests I have done something like
controller.should_receive(:render).
with({partial: 'shared/redirect_from_ajax', locals: {path: target_path, modal_id: modal_id}}).
and_call_original
but so far in the view test I can't figure out on what to put the should_receive
and what the expected received method is.
Seems like this 'twice called partial in a view partial' scenario doesn't have a way to test AFAIK.
All help/suggestions appreciated.