Sha256: b896e0044f7ad2212fb4cb72535f29fc1868da0db66d1221e99f0fd14852d7ea

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

require 'test_helper'

module Elasticsearch
  module Model
    class ActiveRecordNamespacedModelIntegrationTest < Elasticsearch::Test::IntegrationTestCase

      module ::MyNamespace
        class Article < ActiveRecord::Base
          include Elasticsearch::Model
          include Elasticsearch::Model::Callbacks

          mapping { indexes :title }
        end
      end

      context "Namespaced ActiveRecord model integration" do
        setup do
          ActiveRecord::Schema.define(:version => 1) do
            create_table :articles do |t|
              t.string   :title
            end
          end

          MyNamespace::Article.delete_all
          MyNamespace::Article.__elasticsearch__.create_index! force: true

          MyNamespace::Article.create! title: 'Test'

          MyNamespace::Article.__elasticsearch__.refresh_index!
        end

        should "have proper index name and document type" do
          assert_equal "my_namespace-articles", MyNamespace::Article.index_name
          assert_equal "article",               MyNamespace::Article.document_type
        end

        should "save document into index on save and find it" do
          response = MyNamespace::Article.search 'title:test'

          assert       response.any?, "No results returned: #{response.inspect}"
          assert_equal 1, response.size

          assert_equal 'Test', response.results.first.title
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
elasticsearch-model-0.1.4 test/integration/active_record_namespaced_model_test.rb
elasticsearch-model-0.1.3 test/integration/active_record_namespaced_model_test.rb
elasticsearch-model-0.1.2 test/integration/active_record_namespaced_model_test.rb
elasticsearch-model-0.1.1 test/integration/active_record_namespaced_model_test.rb
elasticsearch-model-0.1.0 test/integration/active_record_namespaced_model_test.rb
elasticsearch-model-0.1.0.rc1 test/integration/active_record_namespaced_model_test.rb