Kanti Kanti - 7 months ago 94
Ruby Question

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)?

Answer

In an RSpec controller spec, specify query parameters as a hash argument to get:

describe YourController
  describe '#yearly_csv'
    # set up
    get :yearly_csv, demand: 'true'
    # assert results
  end
end
Comments