Skip to content

Commit

Permalink
add spec for search history
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Sep 21, 2023
1 parent 3f22a33 commit 36590bc
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/controllers/search_history_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

RSpec.describe SearchHistoryController do
routes { Blacklight::Engine.routes }

describe 'index' do
let(:one) { Search.create }
let(:two) { Search.create }
let(:three) { Search.create }

it 'only fetches searches with ids in the session' do
session[:history] = [one.id, three.id]
get :index
searches = assigns(:searches)
expect(searches).to include(one)
expect(searches).not_to include(two)
end

it 'tolerates bad ids in session' do
session[:history] = [one.id, three.id, 'NOT_IN_DB']
get :index
searches = assigns(:searches)
expect(searches).to include(one)
expect(searches).to include(three)
end

it 'does not fetch any searches if there is no history' do
session[:history] = []
get :index
searches = assigns(:searches)
expect(searches).to be_empty
end
end
end

0 comments on commit 36590bc

Please sign in to comment.