Topic: Set params for use in a helper test

Hello all,

I have been messing about a bit and I cannot figure out how to test the following helper:

module OrdersHelper

  def select_value(field)
    if params[:order]
      params[:order][:address_attributes] ? params[:order][:address_attributes][field] : current_user.address[field]
    end      
  end
end

The idea of select_value (used to set the values of address text_fields) is that the first time the create order page is loaded the address is populated with the current_user's address. If the page is reloaded due to validation failure then use the (possibly edited) values submitted in the parameters (Address is polymorphic association to User and Order)

So to test this helper I need to fake request parameters. My question is how can I do this? I cannot find any documentation that would help, I am sure I am missing something here.

Cheers

RJ

Last edited by RurouniJones (2010-06-23 01:21:08)

Re: Set params for use in a helper test

Got it.

To set parameters simply use

To simulate params[:object]
use
helper.params = {:object => "Blah"}

To set instance variables use

To simulate @price
use
helper.instance_variable_set(:@price,1000)

Last edited by RurouniJones (2010-06-25 03:39:48)