-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split spec/integration_spec.rb
#350
Merged
brunoocasali
merged 38 commits into
meilisearch:main
from
ellnix:refactor-integration-spec
Aug 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
fc7bbac
Remove redundant Ebook model in specs
ellnix c5990b3
Remove test of ruby's Marshal
ellnix c4644e5
Remove test of Rails cache functionality
ellnix 4c62567
Remove unused UniqUser class from specs
ellnix 0994f36
Remove unused NullableId class from specs
ellnix 355250e
Remove flawed MongoDocument specs
ellnix 093bfbc
Remove unnecessary Color tests
ellnix 26e607c
Move Post specs
ellnix 3fda1a7
Move Color search specs
ellnix 8504a7a
Move Book specs from integration_spec.rb
ellnix b0cc102
Move Color specs from integration_spec.rb
ellnix b9a278c
Move Cat and Doc specs from integration_spec.rb
ellnix 4663f91
Move People specs from integration_spec.rb
ellnix 5c7a6e4
Move Disabled specs from integration_spec.rb
ellnix 55bf813
Move Movie, Restaurant, and pagination specs
ellnix 91ac1af
`require --spec-helper` in .rspec
ellnix 4cf7ad7
Move 'an imaginary store' tests
ellnix a437c8e
Refactor tests
ellnix 50ec330
Move SerializedDocument and EncodedString tests
ellnix 702888b
Move NamespacedDocument specs
ellnix 862262b
Remove redundant `#search` method test
ellnix 5deaef9
Move deactivation specs
ellnix 208c9cb
Move :raise_on_failure specs
ellnix 88bed6f
Fix a few more race conditions in tests
ellnix 596a7b4
Move EnqueuedDocument-type tests
ellnix b328a69
Move Song specs
ellnix 4f1663b
Move NestedItem tests
ellnix dcc4c08
Move misconfiguration test
ellnix de4cf44
Fix searchable attribute warning and its test
ellnix 121b989
Fix regression in #ms_entries specs
ellnix 84d355b
Merge test refactoring into main
ellnix eefe6be
Refactor proximity_precision test
ellnix 79fe56a
Remove integration spec file & private method test
ellnix 300b778
Hide ActiveRecord's create_table messages
ellnix f1b4ec3
Make rubocop happy
ellnix 1d70659
Merge main again due to rubocop and integration_spec
ellnix cf8a17f
Fix will_paginate test race condition
ellnix 487c780
Merge branch 'main' into refactor-integration-spec
brunoocasali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
require 'support/models/product' | ||
|
||
describe 'Tech shop' do | ||
before(:all) do | ||
Product.clear_index!(true) | ||
|
||
# Google products | ||
@blackberry = Product.create!(name: 'blackberry', href: 'google', tags: ['decent', 'businessmen love it']) | ||
@nokia = Product.create!(name: 'nokia', href: 'google', tags: ['decent']) | ||
|
||
# Amazon products | ||
@android = Product.create!(name: 'android', href: 'amazon', tags: ['awesome']) | ||
@samsung = Product.create!(name: 'samsung', href: 'amazon', tags: ['decent']) | ||
@motorola = Product.create!(name: 'motorola', href: 'amazon', tags: ['decent'], | ||
description: 'Not sure about features since I\'ve never owned one.') | ||
|
||
# Ebay products | ||
@palmpre = Product.create!(name: 'palmpre', href: 'ebay', tags: ['discontinued', 'worst phone ever']) | ||
@palm_pixi_plus = Product.create!(name: 'palm pixi plus', href: 'ebay', tags: ['terrible']) | ||
@lg_vortex = Product.create!(name: 'lg vortex', href: 'ebay', tags: ['decent']) | ||
@t_mobile = Product.create!(name: 't mobile', href: 'ebay', tags: ['terrible']) | ||
|
||
# Yahoo products | ||
@htc = Product.create!(name: 'htc', href: 'yahoo', tags: ['decent']) | ||
@htc_evo = Product.create!(name: 'htc evo', href: 'yahoo', tags: ['decent']) | ||
@ericson = Product.create!(name: 'ericson', href: 'yahoo', tags: ['decent']) | ||
|
||
# Apple products | ||
@iphone = Product.create!(name: 'iphone', href: 'apple', tags: ['awesome', 'poor reception'], | ||
description: 'Puts even more features at your fingertips') | ||
@macbook = Product.create!(name: 'macbookpro', href: 'apple') | ||
|
||
# Unindexed products | ||
@sekrit = Product.create!(name: 'super sekrit', href: 'amazon', release_date: Time.now + 1.day) | ||
@no_href = Product.create!(name: 'super sekrit too; missing href') | ||
|
||
# Subproducts | ||
@camera = Camera.create!(name: 'canon eos rebel t3', href: 'canon') | ||
|
||
100.times { Product.create!(name: 'crapoola', href: 'crappy', tags: ['crappy']) } | ||
|
||
@products_in_database = Product.all | ||
|
||
Product.reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true) | ||
end | ||
|
||
it 'is not synchronous' do | ||
p = Product.new | ||
p.valid? | ||
|
||
expect(p).not_to be_ms_synchronous | ||
end | ||
|
||
it 'is able to reindex manually' do | ||
results_before_clearing = Product.raw_search('') | ||
expect(results_before_clearing['hits'].size).not_to be(0) | ||
Product.clear_index!(true) | ||
results = Product.raw_search('') | ||
expect(results['hits'].size).to be(0) | ||
Product.reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true) | ||
results_after_reindexing = Product.raw_search('') | ||
expect(results_after_reindexing['hits'].size).not_to be(0) | ||
expect(results_before_clearing['hits'].size).to be(results_after_reindexing['hits'].size) | ||
end | ||
|
||
describe 'basic searching' do | ||
it 'finds the iphone' do | ||
results = Product.search('iphone') | ||
expect(results.size).to eq(1) | ||
expect(results).to include(@iphone) | ||
end | ||
|
||
it 'searches case insensitively' do | ||
results = Product.search('IPHONE') | ||
expect(results.size).to eq(1) | ||
expect(results).to include(@iphone) | ||
end | ||
|
||
it 'finds all amazon products' do | ||
results = Product.search('amazon') | ||
expect(results.size).to eq(3) | ||
expect(results).to include(@android, @samsung, @motorola) | ||
end | ||
|
||
it 'finds all "palm" phones with wildcard word search' do | ||
results = Product.search('pal') | ||
expect(results.size).to eq(2) | ||
expect(results).to include(@palmpre, @palm_pixi_plus) | ||
end | ||
|
||
it 'searches multiple words from the same field' do | ||
results = Product.search('palm pixi plus') | ||
expect(results.size).to eq(1) | ||
expect(results).to include(@palm_pixi_plus) | ||
end | ||
|
||
it 'finds using phrase search' do | ||
results = Product.search('coco "palm"') | ||
expect(results.size).to eq(1) | ||
expect(results).to include(@palm_pixi_plus) | ||
end | ||
|
||
it 'narrows the results by searching across multiple fields' do | ||
results = Product.search('apple iphone') | ||
expect(results.size).to eq(2) | ||
expect(results).to include(@iphone) | ||
end | ||
|
||
it 'does not search on non-indexed fields' do | ||
results = Product.search('features') | ||
expect(results.size).to eq(0) | ||
end | ||
|
||
it 'deletes the associated record' do | ||
ipad = Product.create!(name: 'ipad', href: 'apple', tags: ['awesome', 'great battery'], | ||
description: 'Big screen') | ||
|
||
ipad.index!(true) | ||
results = Product.search('ipad') | ||
expect(results.size).to eq(1) | ||
|
||
ipad.destroy | ||
results = Product.search('ipad') | ||
expect(results.size).to eq(0) | ||
end | ||
|
||
context 'when a document cannot be found in ActiveRecord' do | ||
it 'does not throw an exception' do | ||
Product.index.add_documents!(@palmpre.attributes.merge(id: -1)) | ||
expect { Product.search('pal').to_json }.not_to raise_error | ||
Product.index.delete_document!(-1) | ||
end | ||
|
||
it 'returns the other results if those are still available locally' do | ||
Product.index.add_documents!(@palmpre.attributes.merge(id: -1)) | ||
expect(JSON.parse(Product.search('pal').to_json).size).to eq(2) | ||
Product.index.delete_document!(-1) | ||
end | ||
end | ||
|
||
it 'does not duplicate an already indexed record' do | ||
expect(Product.search('nokia').size).to eq(1) | ||
@nokia.index! | ||
expect(Product.search('nokia').size).to eq(1) | ||
@nokia.index! | ||
@nokia.index! | ||
expect(Product.search('nokia').size).to eq(1) | ||
end | ||
|
||
it 'does not return products that are not indexable' do | ||
@sekrit.index! | ||
@no_href.index! | ||
results = Product.search('sekrit') | ||
expect(results.size).to eq(0) | ||
end | ||
|
||
it 'includes items belong to subclasses' do | ||
@camera.index! | ||
results = Product.search('eos rebel') | ||
expect(results.size).to eq(1) | ||
expect(results).to include(@camera) | ||
end | ||
|
||
it 'deletes a not-anymore-indexable product' do | ||
results = Product.search('sekrit') | ||
expect(results.size).to eq(0) | ||
|
||
@sekrit.release_date = Time.now - 1.day | ||
@sekrit.save! | ||
@sekrit.index!(true) | ||
results = Product.search('sekrit') | ||
expect(results.size).to eq(1) | ||
|
||
@sekrit.release_date = Time.now + 1.day | ||
@sekrit.save! | ||
@sekrit.index!(true) | ||
results = Product.search('sekrit') | ||
expect(results.size).to eq(0) | ||
end | ||
|
||
it 'finds using synonyms' do | ||
expect(Product.search('pomme').size).to eq(Product.search('apple').size) | ||
expect(Product.search('m_b_p').size).to eq(Product.search('macbookpro').size) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to mention in the commit, but is me adding another layer of tests (system tests).
We would have