Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
27 changes: 0 additions & 27 deletions spec/models/sponsors_search_spec.rb

This file was deleted.

78 changes: 78 additions & 0 deletions spec/queries/sponsors_search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
RSpec.describe SponsorsSearch do
describe 'initialization' do
it 'configures its properties from the param hash' do
search = described_class.new(name: 'Acme', chapter: 'London')

expect(search.name).to eq('Acme')
expect(search.chapter).to eq('London')
end

it 'handles nil params' do
search = described_class.new(name: nil, chapter: nil)

expect(search.name).to be_nil
expect(search.chapter).to be_nil
end
end

describe '#call' do
it 'returns all sponsors when no filter is specified' do
Fabricate.times(3, :sponsor)

results = described_class.new(name: nil, chapter: nil).call

expect(results.size).to eq(3)
expect(results).to all(be_a(Sponsor))
end

it 'filters by name' do
matching = Fabricate(:sponsor, name: 'Zebra Technologies')
Fabricate(:sponsor, name: 'Apple Inc')

results = described_class.new(name: 'Zebra', chapter: nil).call

expect(results).to contain_exactly(matching)
end

it 'is case insensitive when filtering by name' do
matching = Fabricate(:sponsor, name: 'Zebra Technologies')

results = described_class.new(name: 'zebra', chapter: nil).call
expect(results).to contain_exactly(matching)

results = described_class.new(name: 'ZEBRA', chapter: nil).call
expect(results).to contain_exactly(matching)
end

it 'filters by chapter' do
chapter = Fabricate(:chapter)
matching = Fabricate(:sponsor)
Fabricate(:workshop_sponsor, workshop: Fabricate(:workshop_no_sponsor, chapter: chapter), sponsor: matching)
Fabricate(:sponsor)

results = described_class.new(name: nil, chapter: chapter.id.to_s).call

expect(results).to contain_exactly(matching)
end

it 'filters by name and chapter combined' do
chapter = Fabricate(:chapter)
matching = Fabricate(:sponsor, name: 'Zebra Technologies')
Fabricate(:workshop_sponsor, workshop: Fabricate(:workshop_no_sponsor, chapter: chapter), sponsor: matching)
Fabricate(:sponsor, name: 'Zebra Technologies')
Fabricate(:sponsor, name: 'Apple Inc')

results = described_class.new(name: 'Zebra', chapter: chapter.id.to_s).call

expect(results).to contain_exactly(matching)
end

it 'returns an empty relation when nothing matches' do
Fabricate(:sponsor, name: 'Apple Inc')

results = described_class.new(name: 'Nonexistent', chapter: nil).call

expect(results).to be_empty
end
end
end