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 10 commits
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
16 changes: 16 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'spec_helper'
require 'support/models/book'
require 'support/models/color'

describe MeiliSearch::Rails::Configuration do
before { stub_const('MeiliSearch::Rails::VERSION', '0.0.1') }
Expand Down Expand Up @@ -63,6 +65,20 @@
end
end

context 'with per_environment' do
# per_environment is already enabled in testing
# no setup is required

it 'adds a Rails env-based index suffix' do
expect(Color.index_uid).to eq(safe_index_uid('Color') + "_#{Rails.env}")
end

it 'uses suffix in the additional index as well' do
index = Book.index(safe_index_uid('Book'))
expect(index.uid).to eq("#{safe_index_uid('Book')}_#{Rails.env}")
end
end

context 'when use Meilisearch without configuration' do
around do |example|
config = MeiliSearch::Rails.configuration
Expand Down
49 changes: 49 additions & 0 deletions spec/instance_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'support/models/book'

describe 'Instance methods' do
describe '#ms_entries' do
it 'includes conditionally enabled indexes' do
book = Book.create!(
name: 'Frankenstein', author: 'Mary Shelley',
premium: false, released: true
)

expect(book.ms_entries).to contain_exactly(
a_hash_including("index_uid" => safe_index_uid('SecuredBook')),
a_hash_including("index_uid" => safe_index_uid('BookAuthor')),
a_hash_including("index_uid" => safe_index_uid('Book')),
)
end

it 'includes conditionally disabled indexes' do
# non public book
book = Book.create!(
name: 'Frankenstein', author: 'Mary Shelley',
premium: false, released: false
)

expect(book.ms_entries).to contain_exactly(
a_hash_including("index_uid" => safe_index_uid('SecuredBook')),
a_hash_including("index_uid" => safe_index_uid('BookAuthor')),
# also includes book's id as if it was a public book
a_hash_including("index_uid" => safe_index_uid('Book')),
)
end
end

describe '#ms_index!' do
it 'returns array of tasks' do
TestUtil.reset_books!

moby_dick = Book.create! name: 'Moby Dick', author: 'Herman Melville', premium: false, released: true

tasks = moby_dick.ms_index!

expect(tasks).to contain_exactly(
a_hash_including('uid'),
a_hash_including('taskUid'),
a_hash_including('taskUid')
)
end
end
end
50 changes: 50 additions & 0 deletions spec/integration/active_record/attributes_have_changed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'support/models/color'
require 'support/models/book'

describe 'When record attributes have changed' do
it 'detects attribute changes' do
color = Color.new name: 'dark-blue', short_name: 'blue'

expect(Color.ms_must_reindex?(color)).to be(true)
color.save
expect(Color.ms_must_reindex?(color)).to be(false)

color.hex = 123_456
expect(Color.ms_must_reindex?(color)).to be(false)

color.not_indexed = 'strstr'
expect(Color.ms_must_reindex?(color)).to be(false)
color.name = 'red'
expect(Color.ms_must_reindex?(color)).to be(true)
color.delete
end

it 'detects attribute changes even in a transaction' do
color = Color.new name: 'dark-blue', short_name: 'blue'
color.save
expect(color.instance_variable_get('@ms_must_reindex')).to be_nil
Color.transaction do
color.name = 'red'
color.save
color.not_indexed = 'strstr'
color.save
expect(color.instance_variable_get('@ms_must_reindex')).to be(true)
end
expect(color.instance_variable_get('@ms_must_reindex')).to be_nil
color.delete
end

it 'detects change with ms_dirty? method' do
book = Book.new name: 'My life', author: 'Myself', premium: false, released: true

allow(book).to receive(:ms_dirty?).and_return(true)
expect(Book.ms_must_reindex?(book)).to be(true)

allow(book).to receive(:ms_dirty?).and_return(false)
expect(Book.ms_must_reindex?(book)).to be(false)

allow(book).to receive(:ms_dirty?).and_return(true)
expect(Book.ms_must_reindex?(book)).to be(true)
end
end

24 changes: 24 additions & 0 deletions spec/integration/active_record/record_has_associations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'support/models/post'

describe 'When a record has associations' do
before(:all) do
Post.clear_index!(true)
end

it 'eagerly loads associations' do
post1 = Post.new(title: 'foo')
post1.comments << Comment.new(body: 'one')
post1.comments << Comment.new(body: 'two')
post1.save!

post2 = Post.new(title: 'bar')
post2.comments << Comment.new(body: 'three')
post2.comments << Comment.new(body: 'four')
post2.save!

assert_queries(2) do
Post.reindex!
end
end
end

22 changes: 22 additions & 0 deletions spec/integration/active_record/record_is_updated_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'support/models/book'

describe 'When record is updated' do
it 'automatically removes document from conditional indexes' do
TestUtil.reset_books!

# add a new public book which is public (not premium but released)
book = Book.create! name: 'Public book', author: 'me', premium: false, released: true

# should be searchable in the 'Book' index
index = Book.index(safe_index_uid('Book'))
results = index.search('Public book')
expect(results['hits']).to be_one

# update the book and make it non-public anymore (not premium, not released)
book.update released: false

# should be removed from the index
results = index.search('Public book')
expect(results['hits']).to be_empty
end
end
Loading
Loading