From 7b8a0d391473eb631ec5291097e395fca4a322b4 Mon Sep 17 00:00:00 2001 From: Halimat Mercy Oseni Date: Sun, 28 Jul 2019 06:38:10 +0100 Subject: [PATCH] Add controller specs --- spec/controllers/mushrooms_controller_spec.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/controllers/mushrooms_controller_spec.rb diff --git a/spec/controllers/mushrooms_controller_spec.rb b/spec/controllers/mushrooms_controller_spec.rb new file mode 100644 index 0000000..82864a2 --- /dev/null +++ b/spec/controllers/mushrooms_controller_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +RSpec.describe MushroomsController, type: :controller do + describe '#index' do + context 'when filter params is present' do + it 'runs the FilterMushroom service and returns results' do + get :index, params: { filter: { odor: 'almond' } } + + allow(FilterMushroom.new(response.request.params[:filter], 1)) + .to receive(:run) + + expect(response).to have_http_status(200) + expect(response).to render_template(:index) + end + end + + context 'when filter params is NOT present' do + it 'renders the index template' do + get :index + + expect(FilterMushroom).not_to receive(:new) + + expect(response).to have_http_status(200) + expect(response).to render_template(:index) + end + end + end +end