[rspec-users] RSpec Controller Testing - render_templte Issue
Curtis
curtis.schofield at gmail.com
Mon Jul 12 15:11:14 EDT 2010
On Jul 12, 2010, at 11:11 AM, Rails Learner <lists at ruby-forum.com>
wrote:
> Curtis j Schofield wrote:
>> On Mon, Jul 12, 2010 at 9:44 AM, Rails Learner <lists at ruby-forum.com>
>> wrote:
>>> # me error:
>>> response.should have_selector( 'input',
>>> :type => 'submit',
>>> :value => 'Print Form' )
>>> response.should be_success
>>> end
>>>
>>> Many Thanks!
>>
>>
>> Please include your controller code for create! :d
>>
>>
>> --
>> Make Haste Slowly
>
> Hi Curtis,
>
> I figure out the issue.
> My controller has render_to_string that renders a pdf and then it
> renders the "_show" partial. Now there is another problem. How I can
> test both renders?
>
The format param is used for this case - it is used to set content-
type properly - it is getting set by a route into a param var. Iirc
format.pdf is possible aswell - I suspect that the mime type I'd
already registered - it may not be.
> Here is the controller code:
> def create
> @page_title = 'ASQ Enrollment Form'
> @child = Child.new(params[:child])
>
> #Convert string to date.
> @child.EnrollmentDate = Date.strptime(@child.EnrollmentDate,
> '%Y-%m-%d')
>
> #Concatenate the date components and assign the complete date to
> ChildDob field
> @child.ChildDob = Date.strptime((params[:child]['ChildDob(2i)'] +
> '-' + params[:child]['ChildDob(3i)'] + '-' +
> params[:child]['ChildDob(1i)']), '%m-%d-%Y') unless
> ((params[:child]['ChildDob(1i)']).blank? ||
> (params[:child]['ChildDob(2i)']).blank? ||
> (params[:child]['ChildDob(3i)']).blank?)
>
> respond_to do |format|
> if @child.valid?
> FormMailer.deliver_enrollment_form(Date.today.strftime("%m-%d-
> %Y").to_s
> + ' - ASQ Enrollment Form - ' + @child.ChildFirstName + ' ' +
> @child.ChildLastName, @child, generate_pdf(@child, false))
> flash.now[:notice] = 'ASQ Enrollment form was successfully
> submitted'
> #format.html { redirect_to(@child, :notice => 'Child was
> successfully created.') }
> format.html { render :partial => 'show', :locals => { :child =>
> @child }, :layout => 'children' }
> format.xml { render :xml => @child, :status => :created,
> :location => @child }
> else
> format.html { render :action => 'new' }
> format.xml { render :xml => @child.errors, :status =>
> :unprocessable_entity }
> end
> end
> end
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users
mailing list