Skip to content
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
merged 38 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
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 Feb 28, 2024
c5990b3
Remove test of ruby's Marshal
ellnix Feb 29, 2024
c4644e5
Remove test of Rails cache functionality
ellnix Feb 29, 2024
4c62567
Remove unused UniqUser class from specs
ellnix Feb 29, 2024
0994f36
Remove unused NullableId class from specs
ellnix Feb 29, 2024
355250e
Remove flawed MongoDocument specs
ellnix Feb 29, 2024
093bfbc
Remove unnecessary Color tests
ellnix Feb 29, 2024
26e607c
Move Post specs
ellnix Feb 29, 2024
3fda1a7
Move Color search specs
ellnix Feb 29, 2024
8504a7a
Move Book specs from integration_spec.rb
ellnix Mar 1, 2024
b0cc102
Move Color specs from integration_spec.rb
ellnix Mar 1, 2024
b9a278c
Move Cat and Doc specs from integration_spec.rb
ellnix Mar 1, 2024
4663f91
Move People specs from integration_spec.rb
ellnix Mar 1, 2024
5c7a6e4
Move Disabled specs from integration_spec.rb
ellnix Mar 1, 2024
55bf813
Move Movie, Restaurant, and pagination specs
ellnix May 25, 2024
91ac1af
`require --spec-helper` in .rspec
ellnix May 25, 2024
4cf7ad7
Move 'an imaginary store' tests
ellnix May 25, 2024
a437c8e
Refactor tests
ellnix May 25, 2024
50ec330
Move SerializedDocument and EncodedString tests
ellnix May 26, 2024
702888b
Move NamespacedDocument specs
ellnix May 26, 2024
862262b
Remove redundant `#search` method test
ellnix May 26, 2024
5deaef9
Move deactivation specs
ellnix May 27, 2024
208c9cb
Move :raise_on_failure specs
ellnix May 27, 2024
88bed6f
Fix a few more race conditions in tests
ellnix May 27, 2024
596a7b4
Move EnqueuedDocument-type tests
ellnix May 27, 2024
b328a69
Move Song specs
ellnix May 27, 2024
4f1663b
Move NestedItem tests
ellnix May 27, 2024
dcc4c08
Move misconfiguration test
ellnix May 27, 2024
de4cf44
Fix searchable attribute warning and its test
ellnix May 27, 2024
121b989
Fix regression in #ms_entries specs
ellnix May 27, 2024
84d355b
Merge test refactoring into main
ellnix May 27, 2024
eefe6be
Refactor proximity_precision test
ellnix May 27, 2024
79fe56a
Remove integration spec file & private method test
ellnix May 27, 2024
300b778
Hide ActiveRecord's create_table messages
ellnix May 27, 2024
f1b4ec3
Make rubocop happy
ellnix May 27, 2024
1d70659
Merge main again due to rubocop and integration_spec
ellnix May 27, 2024
cf8a17f
Fix will_paginate test race condition
ellnix May 27, 2024
487c780
Merge branch 'main' into refactor-integration-spec
brunoocasali Aug 7, 2024
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
10 changes: 10 additions & 0 deletions spec/instance_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@
a_hash_including('taskUid')
)
end

it 'throws error on non-persisted instances' do
expect { Color.new(name: 'purple').index!(true) }.to raise_error(ArgumentError)
end
end

describe '#ms_remove_from_index!' do
it 'throws error on non-persisted instances' do
expect { Color.new(name: 'purple').remove_from_index!(true) }.to raise_error(ArgumentError)
end
end
end
11 changes: 11 additions & 0 deletions spec/integration/active_record/record_is_updated_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
require 'support/models/book'
require 'support/models/color'

describe 'When record is updated' do
it 'updates the changed attributes on the index' do
purple = Color.create!(name: 'purple', short_name: 'p')
expect(Color.search('purple')).to be_one
expect(Color.search('pink')).to be_empty

purple.update name: 'pink'
expect(Color.search('purple')).to be_empty
expect(Color.search('pink')).to be_one
end

it 'automatically removes document from conditional indexes' do
TestUtil.reset_books!

Expand Down
58 changes: 0 additions & 58 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,64 +112,6 @@
end
end

describe 'Colors' do
before do
Color.clear_index!(true)
Color.delete_all
end

it 'auto indexes' do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already tested in options_spec.rb under :auto_index

blue = Color.create!(name: 'blue', short_name: 'b', hex: 0xFF0000)
results = Color.search('blue')
expect(results.size).to eq(1)
expect(results).to include(blue)
end


it 'is able to temporarily disable auto-indexing' do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to model_methods_spec.rb

Color.without_auto_index do
Color.create!(name: 'blue', short_name: 'b', hex: 0xFF0000)
end
expect(Color.search('blue').size).to eq(0)
Color.reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true)
expect(Color.search('blue').size).to eq(1)
end

it 'updates the index if the attribute changed' do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to record_is_updated_spec.rb

purple = Color.create!(name: 'purple', short_name: 'p')
expect(Color.search('purple').size).to eq(1)
expect(Color.search('pink').size).to eq(0)
purple.name = 'pink'
purple.save
expect(Color.search('purple').size).to eq(0)
expect(Color.search('pink').size).to eq(1)
end

it 'uses the specified scope' do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to model_methods_spec.rb

Color.create!(name: 'red', short_name: 'r3', hex: 3)
Color.create!(name: 'red', short_name: 'r1', hex: 1)
Color.create!(name: 'red', short_name: 'r2', hex: 2)
Color.create!(name: 'purple', short_name: 'p')
Color.clear_index!(true)
Color.where(name: 'red').reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true)
expect(Color.search('').size).to eq(3)
Color.clear_index!(true)
Color.where(id: Color.first.id).reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true)
expect(Color.search('').size).to eq(1)
end

it 'indexes an array of documents' do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to model_methods_spec.rb

json = Color.raw_search('')
Color.index_documents Color.limit(1), true # reindex last color, `limit` is incompatible with the reindex! method
expect(json['hits'].count).to eq(Color.raw_search('')['hits'].count)
end

it 'does not index non-saved document' do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to instance_method_specs.rb

expect { Color.new(name: 'purple').index!(true) }.to raise_error(ArgumentError)
expect { Color.new(name: 'purple').remove_from_index!(true) }.to raise_error(ArgumentError)
end
end

describe 'An imaginary store' do
before(:all) do
Product.clear_index!(true)
Expand Down
64 changes: 64 additions & 0 deletions spec/model_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'support/models/color'
require 'support/models/book'

describe 'Model methods' do
describe '.reindex!' do
it 'uses the specified scope' do
TestUtil.reset_colors!

Color.create!(name: 'red', short_name: 'r3', hex: 3)
Color.create!(name: 'red', short_name: 'r1', hex: 1)
Color.create!(name: 'purple', short_name: 'p')

Color.clear_index!(true)

Color.where(name: 'red').reindex!(3, true)
expect(Color.search('').size).to eq(2)

Color.clear_index!(true)
Color.where(id: Color.first.id).reindex!(3, true)
expect(Color.search('').size).to eq(1)
end
end

describe '.without_auto_index' do
it 'disables auto indexing for the model' do
TestUtil.reset_colors!

Color.without_auto_index do
Color.create!(name: 'blue', short_name: 'b', hex: 0xFF0000)
end

expect(Color.search('blue')).to be_empty

Color.reindex!(2, true)
expect(Color.search('blue')).to be_one
end

it 'does not disable auto indexing for other models' do
TestUtil.reset_books!

Color.without_auto_index do
Book.create!(
name: 'Frankenstein', author: 'Mary Shelley',
premium: false, released: true
)
end

expect(Book.search('Frankenstein')).to be_one
end
end

describe '.index_documents' do
it 'updates existing documents' do
TestUtil.reset_colors!

_blue = Color.create!(name: 'blue', short_name: 'blu', hex: 0x0000FF)
_black = Color.create!(name: 'black', short_name: 'bla', hex: 0x000000)

json = Color.raw_search('')
Color.index_documents Color.limit(1), true # reindex last color, `limit` is incompatible with the reindex! method
expect(json['hits'].count).to eq(Color.raw_search('')['hits'].count)
end
end
end
5 changes: 2 additions & 3 deletions spec/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
end

describe ':auto_index' do
it 'auto indexes by default' do
Color.clear_index!(true)
Color.delete_all
it 'is enabled by default' do
TestUtil.reset_colors!

Color.create!(name: 'blue', short_name: 'b', hex: 0xFF0000)
results = Color.raw_search('blue')
Expand Down
4 changes: 2 additions & 2 deletions spec/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

describe '#raw_search' do
it 'allows for access to meilisearch-ruby search' do
Color.clear_index!(true)
Color.delete_all
TestUtil.reset_colors!

Color.create!(name: 'blue', short_name: 'b', hex: 0xFF0000)

raw_results = Color.raw_search('blue')
Expand Down
7 changes: 7 additions & 0 deletions spec/support/models/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ def will_save_change_to_short_name?
false
end
end

module TestUtil
def self.reset_colors!
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same rationale as reset_books!

Color.clear_index!(true)
Color.delete_all
end
end
Loading