forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter_multiple_test.rb
106 lines (82 loc) · 2.44 KB
/
adapter_multiple_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'test_helper'
class Elasticsearch::Model::MultipleTest < Test::Unit::TestCase
context "Adapter for multiple models" do
class ::DummyOne
include Elasticsearch::Model
index_name 'dummy'
document_type 'dummy_one'
def self.find(ids)
ids.map { |id| new(id) }
end
attr_reader :id
def initialize(id)
@id = id.to_i
end
end
module ::Namespace
class DummyTwo
include Elasticsearch::Model
index_name 'dummy'
document_type 'dummy_two'
def self.find(ids)
ids.map { |id| new(id) }
end
attr_reader :id
def initialize(id)
@id = id.to_i
end
end
end
class ::DummyTwo
include Elasticsearch::Model
index_name 'other_index'
document_type 'dummy_two'
def self.find(ids)
ids.map { |id| new(id) }
end
attr_reader :id
def initialize(id)
@id = id.to_i
end
end
HITS = [{_index: 'dummy',
_type: 'dummy_two',
_id: '2',
}, {
_index: 'dummy',
_type: 'dummy_one',
_id: '2',
}, {
_index: 'other_index',
_type: 'dummy_two',
_id: '1',
}, {
_index: 'dummy',
_type: 'dummy_two',
_id: '1',
}, {
_index: 'dummy',
_type: 'dummy_one',
_id: '3'}]
setup do
@multimodel = Elasticsearch::Model::Multimodel.new(DummyOne, DummyTwo, Namespace::DummyTwo)
end
context "when returning records" do
setup do
@multimodel.class.send :include, Elasticsearch::Model::Adapter::Multiple::Records
@multimodel.expects(:response).at_least_once.returns(stub(response: { 'hits' => { 'hits' => HITS } }))
end
should "keep the order from response" do
assert_instance_of Module, Elasticsearch::Model::Adapter::Multiple::Records
records = @multimodel.records
assert_equal 5, records.count
assert_kind_of ::Namespace::DummyTwo, records[0]
assert_kind_of ::DummyOne, records[1]
assert_kind_of ::DummyTwo, records[2]
assert_kind_of ::Namespace::DummyTwo, records[3]
assert_kind_of ::DummyOne, records[4]
assert_equal [2, 2, 1, 1, 3], records.map(&:id)
end
end
end
end