/
specification_spec.rb
156 lines (135 loc) · 5.14 KB
/
specification_spec.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
require 'spec_helper'
describe Chewy::Index::Specification do
before { Chewy.massacre }
let(:index1) do
stub_index(:places) do
field :founded_on, type: 'date'
end
end
let(:index2) do
stub_index(:places) do
settings analyzer: {}
field :founded_on, type: 'date'
end
end
let(:index3) do
stub_index(:places) do
field :founded_on, type: 'date'
field :population, type: 'integer'
end
end
let(:index4) do
stub_index(:places) do
field :population, type: 'integer'
field :founded_on, type: 'date'
end
end
let(:index5) do
stub_index('namespace/cities') do
field :population, type: 'integer'
end
end
let(:specification1) { described_class.new(index1) }
let(:specification2) { described_class.new(index2) }
let(:specification3) { described_class.new(index3) }
let(:specification4) { described_class.new(index4) }
let(:specification5) { described_class.new(index5) }
describe '#lock!' do
specify do
expect { specification1.lock! }.to change { Chewy::Stash::Specification.all.hits }.from([]).to([{
'_index' => 'chewy_specifications',
'_id' => 'places',
'_score' => 1.0,
'_source' => {'specification' => Base64.encode64({
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}}
}.to_json)}
}])
end
context do
before { specification1.lock! }
specify do
expect { specification5.lock! }.to change { Chewy::Stash::Specification.all.hits }.to([{
'_index' => 'chewy_specifications',
'_id' => 'places',
'_score' => 1.0,
'_source' => {'specification' => Base64.encode64({
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}}
}.to_json)}
}, {
'_index' => 'chewy_specifications',
'_id' => 'namespace/cities',
'_score' => 1.0,
'_source' => {'specification' => Base64.encode64({
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'population' => {'type' => 'integer'}}}
}.to_json)}
}])
end
end
end
describe '#locked' do
specify do
expect { specification1.lock! }.to change { specification1.locked }.from({}).to(
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}}
)
end
specify do
expect { specification5.lock! }.to change { specification5.locked }.from({}).to(
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'population' => {'type' => 'integer'}}}
)
end
context do
before { specification1.lock! }
specify do
expect { specification2.lock! }.to change { specification2.locked }.from(
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}}
).to(
'settings' => {'analyzer' => {}, 'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}}
)
end
specify do
expect { specification3.lock! }.to change { specification3.locked }.from(
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}}
).to(
'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}},
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}, 'population' => {'type' => 'integer'}}}
)
end
end
end
describe '#current' do
specify do
expect(specification2.current).to eq(
'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}},
'settings' => {'analyzer' => {}, 'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}
)
end
end
describe '#changed?' do
specify { expect(specification1.changed?).to eq(true) }
specify { expect { specification1.lock! }.to change { specification1.changed? }.to(false) }
context do
before { specification1.lock! }
specify { expect { specification2.lock! }.to change { specification2.changed? }.from(true).to(false) }
end
context do
before { specification1.lock! }
specify { expect { specification3.lock! }.to change { specification3.changed? }.from(true).to(false) }
end
context do
before { specification1.lock! }
specify { expect { specification5.lock! }.to change { specification5.changed? }.from(true) }
end
context do
before { specification3.lock! }
specify { expect { specification4.lock! }.not_to change { specification4.changed? }.from(false) }
end
end
end