forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_index_name_test.rb
executable file
·47 lines (38 loc) · 1.35 KB
/
dynamic_index_name_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'test_helper'
require 'active_record'
module Elasticsearch
module Model
class DynamicIndexNameTest < Elasticsearch::Test::IntegrationTestCase
context "Dynamic index name" do
setup do
class ::ArticleWithDynamicIndexName < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
def self.counter=(value)
@counter = 0
end
def self.counter
(@counter ||= 0) && @counter += 1
end
mapping { indexes :title }
index_name { "articles-#{counter}" }
end
::ActiveRecord::Schema.define(:version => 1) do
create_table ::ArticleWithDynamicIndexName.table_name do |t|
t.string :title
end
end
::ArticleWithDynamicIndexName.counter = 0
end
should 'evaluate the index_name value' do
assert_equal ArticleWithDynamicIndexName.index_name, "articles-1"
end
should 're-evaluate the index_name value each time' do
assert_equal ArticleWithDynamicIndexName.index_name, "articles-1"
assert_equal ArticleWithDynamicIndexName.index_name, "articles-2"
assert_equal ArticleWithDynamicIndexName.index_name, "articles-3"
end
end
end
end
end