vendredi 11 septembre 2015

Rspec - how do I call a GET and send flash message?

I know it is strange to be passing this data via flash, but there's some (likely flawed) logic for why it's happening and rather than rewire it right now, I wanted to try to get this test working. The test keeps returning the :error template when it should return the :success based on a legit flash[:thing_id] (the actual app behavior works).

From Controller:

def post_multiple_new
  @thing = Thing.find_by_id(flash[:thing_id].to_i)
  unless @thing
    render :error
  else
    render :success
  end
end

From Spec:

context 'when valid id' do
  let(:thing) { create(:thing) }
  let(:flash) { {thing_id: thing.id.to_s} }
  it 'renders correctly' do
    get :post_multiple_new
    expect(response).to render_template(:success)
  end
end



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire