Sha256: cf9371d22fea640ccb88345c61ce1351dea1bc1708c452d09f37e1449961f96c

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

require 'spec_helper'

describe 'Elasticsearch::Model::Adapter::ActiveRecord Namespaced Model' do

  before(:all) do
    ActiveRecord::Schema.define(:version => 1) do
      create_table :books do |t|
        t.string   :title
      end
    end

    MyNamespace::Book.delete_all
    MyNamespace::Book.__elasticsearch__.create_index!(force: true)
    MyNamespace::Book.create!(title: 'Test')
    MyNamespace::Book.__elasticsearch__.refresh_index!
  end

  after do
    clear_indices(MyNamespace::Book)
    clear_tables(MyNamespace::Book)
  end

  context 'when the model is namespaced' do

    it 'has the proper index name' do
      expect(MyNamespace::Book.index_name).to eq('my_namespace-books')
    end

    it 'saves the document into the index' do
      expect(MyNamespace::Book.search('title:test').results.size).to eq(1)
      expect(MyNamespace::Book.search('title:test').results.first.title).to eq('Test')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elasticsearch-model-8.0.0 spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
elasticsearch-model-8.0.0.pre spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb