Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specifiy the query string in an RSpec test of a Rails controller action?

I have an action called yearly_csv. In this action I perform two operations like demand and supply.

def yearly_csv
   if demand == 'true'
       demand_csv
   else
       supply_csv
   end
end

I have two radio buttons in my view to select one of the operations. Now I want to test each operation individually in RSpec. For example, one spec for supply and another spec for demand. My question is how to pass the radio button value to the yearly_csv action (get)?

like image 213
Kanti Avatar asked Aug 01 '14 12:08

Kanti


1 Answers

In newer versions for RSpec, you must declare query string params using the params key:

get :yearly_csv, params: { demand: 'true' }
like image 122
Sean Moubry Avatar answered Oct 11 '22 11:10

Sean Moubry