Sha256: 719d4100d1c2ab9572032071220db720e113c6770ece22a1520e2301d1675813

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 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, include_type_name: 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 'has the proper document type' do
      expect(MyNamespace::Book.document_type).to eq('book')
    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

6 entries across 6 versions & 1 rubygems

Version Path
elasticsearch-model-7.1.2.pre spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
elasticsearch-model-7.1.1 spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
elasticsearch-model-7.1.0 spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
elasticsearch-model-7.1.0.pre spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
elasticsearch-model-7.0.0 spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
elasticsearch-model-7.0.0.pre spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb