meilisearch / meilisearch-rails

Meilisearch integration for Ruby on Rails
https://www.meilisearch.com
MIT License
295 stars 48 forks source link

Index not created since 0.11.0 - 404 Not Found #328

Closed jeremylynch closed 6 months ago

jeremylynch commented 7 months ago

Ever since upgrading from Meilisearch 0.10.2 to 0.11.0 we are getting multiple errors in our test suite:

MeiliSearch::ApiError: 404 Not Found - Index `Cars_test` not found.

We are using Minitest/FactoryBot for testing.

Is there anything we need to do to ensure these indexes are created?

ellnix commented 7 months ago

Can I see the test where this is occurring?

Any set up such as the creation of the database table and model class would also be appreciated.

jeremylynch commented 7 months ago

Occurring in tests like this:

test 'page_url' do
  @page = create(:page) # factorybot
  assert @page.page_url == "https://www.testing.com"
end
jeremylynch commented 7 months ago

Confirming downgrading to version 0.10.2 fixes the issue

ellnix commented 7 months ago

I created a new rails app, with a Page model that has a `page_url' attribute:

ActiveRecord::Schema[7.1].define(version: 2024_02_17_123956) do
  create_table "pages", force: :cascade do |t|
    t.string "page_url"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end
end
class Page < ApplicationRecord
  include MeiliSearch::Rails

  meilisearch
end

Migrated, defined this factory in test/test_helper.rb:

FactoryBot.define do
  factory :page do
    page_url { 'https://www.testing.com' }
  end
end

And then added the test you provided:

require "test_helper"

class PageTest < ActiveSupport::TestCase
  test 'page_url' do
    @page = FactoryBot.create(:page) # factorybot
    assert @page.page_url == "https://www.testing.com"
  end
end

And I get no error:

» bin/rails test
Running 1 tests in a single process (parallelization threshold is 50)
Run options: --seed 39564

# Running:

.

Finished in 0.051185s, 19.5371 runs/s, 19.5371 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

Relevant lines in the Gemfile & Gemfile.lock:

gem "factory_bot", "~> 6.4"

gem "meilisearch-rails", "~> 0.11.0"
    meilisearch (0.26.0)
      httparty (>= 0.17.1, < 0.22.0)
    meilisearch-rails (0.11.0)
      meilisearch (~> 0.26.0)
ellnix commented 6 months ago

I am still not sure exactly where this is being caused, but it is possible that #330 fixes it. Please try it and let me know whenever you can.

ellnix commented 6 months ago

Reopening this until it's confirmed that #330 fixes it.

curquiza commented 6 months ago

@ellnix we need to do a release for this, feel free to start the process on the CONTRIBUTING when you think we are ready for a release. I'm available for any review you need

jeremylynch commented 6 months ago

I can confirm that we are no longer seeing this issue since upgrading to 0.12.0 👍