Created
November 17, 2015 23:21
-
-
Save mkcode/fdc2bf7f5b25a5d4b0f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require "spec_helper" | |
RSpec.describe SchoolsIndex, chewy: true do | |
describe 'school model obersavation' do | |
it 'updates the index when a school is saved' do | |
school = FactoryGirl.build(:school) | |
expect { school.save! }.to update_index('schools') | |
end | |
it 'updates the index when a school is removed' do | |
school = FactoryGirl.create(:school) | |
expect { school.destroy! }.to update_index('schools') | |
end | |
it 'updates the index when a school is updated' do | |
school = FactoryGirl.create(:school) | |
expect { school.update!(name: 'school') }.to update_index('schools') | |
end | |
end | |
describe 'email domain model obersavation' do | |
it 'updates the index when an email domain with a school is saved' do | |
school = FactoryGirl.create(:school_with_email_domain) | |
domain = school.email_domains.first | |
expect { domain.update!(domain: 'other.net') }.to update_index('schools') | |
end | |
it 'does not update the index when an email domain without a school is saved' do | |
domain = EmailDomain.create(domain: 'test-domain.net') | |
expect { domain.update!(domain: 'other.net') }.to_not update_index('schools') | |
end | |
end | |
describe 'autocomplete results' do | |
before do | |
names = ["Freie Universität Berlin", | |
"Universität Vienna", | |
"Michigan State University", | |
"Massachusetts Institute of Technology"] | |
names.each do |name| | |
FactoryGirl.create(:school, name: name) | |
end | |
end | |
def schools_complete(name_search) | |
SchoolsIndex.query(match: {name_autocomplete: name_search}).map(&:name) | |
end | |
it 'contain the full school name' do | |
expect(schools_complete('Massach')).to include("Massachusetts Institute of Technology") | |
end | |
it 'contain full results' do | |
expect(schools_complete('Univers').size).to be(3) | |
end | |
it 'contain no results for less than 2 characters' do | |
expect(schools_complete('u').size).to be(0) | |
end | |
it 'do not contain extra results' do | |
expect(schools_complete('Massach').size).to eq(1) | |
end | |
# We can break relevance scoring down a lot more later. | |
it 'scores the most revelant result highest' do | |
expect(schools_complete('univ berl').first).to eq("Freie Universität Berlin") | |
end | |
it 'match with lowercase input' do | |
expect(schools_complete('massach').size).to be(1) | |
end | |
it 'match utf8 characters with non-utf8 input' do | |
expect(schools_complete('Universitat').size).to be(2) | |
end | |
it 'match utf8 characters with utf8 input' do | |
expect(schools_complete('Universität').size).to be(2) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment