[rspec-users] Problems with form_for and partials
rsl at swimcommunity.org
Sat Oct 20 10:18:15 EDT 2007
i'm having problem with a form_for situation where i'm trying to DRY
out the repeated parts of my forms and put them in common/form and
render the form elements via another partial in controller_name/_form.
Here's the first form
<% form_for ... do |f| -%>
<%= render :partial => "params[:controller]/form", :object => f %>
<% end -%>
I'm having problems with stub_render because of the :object => f. I
have tried creating a FormBuilder instance to use there as the :object
but it doesn't seem to want to match the actual instance there, which
has a large amount of additional information due to the template being
run at that point.
Then in the partial:
<%= f.text_field :user, ... %>
I can create a FormBuilder instance here and solve the 'f' problem by
stubbing f and returnign the new FormBuilder but then I have to stub
the text_field method which is what i'm actually spec'ing.
I'd appreciate any suggestions on how to accomplish this without
having to repeat the same basic form information and buttons over
multiple forms. Something about sacrificing DRYness to achieve BDD
seems off. I'd imagine you can have both and I'm just not hitting the
Thanks in advance.
More information about the rspec-users