Skip to content

Commit d45ec13

Browse files
committed
[STORE] Raise NotImplementedError if administrative index methods are called on a Repository class
1 parent de87b40 commit d45ec13

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

elasticsearch-persistence/lib/elasticsearch/persistence/repository.rb

+23-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module Repository
1818
include Elasticsearch::Model::Indexing::ClassMethods
1919

2020
def self.included(base)
21-
base.send(:extend, ClassMethods)
2221
base.send(:extend, Elasticsearch::Model::Indexing::ClassMethods)
22+
base.send(:extend, ClassMethods)
2323
end
2424

2525
# These methods are necessary to define at the class-level so that the methods available
@@ -75,6 +75,28 @@ def klass(_class = nil)
7575
def client(_client = nil)
7676
@client ||= (_client || Elasticsearch::Transport::Client.new)
7777
end
78+
79+
def create_index!(*args)
80+
raise_not_implemented_error(__method__)
81+
end
82+
83+
def delete_index!(*args)
84+
raise_not_implemented_error(__method__)
85+
end
86+
87+
def refresh_index!(*args)
88+
raise_not_implemented_error(__method__)
89+
end
90+
91+
def index_exists?(*args)
92+
raise_not_implemented_error(__method__)
93+
end
94+
95+
private
96+
97+
def raise_not_implemented_error(_method_)
98+
raise NotImplementedError, "The '#{_method_}' method is not implemented at the Repository class-level."
99+
end
78100
end
79101

80102
# The default index name.

elasticsearch-persistence/spec/repository_spec.rb

+16-30
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ class NoteRepository
9999
end
100100
end
101101

102-
after do
103-
begin; NoteRepository.delete_index!; rescue; end
104-
end
105-
106102
context '#client' do
107103

108104
it 'allows the value to be set only once' do
@@ -218,13 +214,10 @@ class NoteRepository
218214
DEFAULT_REPOSITORY.class
219215
end
220216

221-
before do
222-
begin; repository.delete_index!; rescue; end
223-
repository.create_index!
224-
end
225-
226-
it 'creates the index' do
227-
expect(repository.index_exists?).to be(true)
217+
it 'raises a NotImplementedError' do
218+
expect {
219+
repository.create_index!
220+
}.to raise_exception(NotImplementedError)
228221
end
229222
end
230223
end
@@ -253,13 +246,10 @@ class NoteRepository
253246
DEFAULT_REPOSITORY.class
254247
end
255248

256-
before do
257-
begin; repository.delete_index!; rescue; end
258-
repository.create_index!
259-
end
260-
261-
it 'creates the index' do
262-
expect(repository.index_exists?).to be(true)
249+
it 'raises a NotImplementedError' do
250+
expect {
251+
repository.delete_index!
252+
}.to raise_exception(NotImplementedError)
263253
end
264254
end
265255
end
@@ -287,12 +277,10 @@ class NoteRepository
287277
DEFAULT_REPOSITORY.class
288278
end
289279

290-
before do
291-
repository.create_index!
292-
end
293-
294-
it 'creates the index' do
295-
expect(repository.refresh_index!['_shards']).to be_a(Hash)
280+
it 'raises a NotImplementedError' do
281+
expect {
282+
repository.refresh_index!
283+
}.to raise_exception(NotImplementedError)
296284
end
297285
end
298286
end
@@ -320,12 +308,10 @@ class NoteRepository
320308
DEFAULT_REPOSITORY.class
321309
end
322310

323-
before do
324-
repository.create_index!
325-
end
326-
327-
it 'creates the index' do
328-
expect(repository.index_exists?).to be(true)
311+
it 'raises a NotImplementedError' do
312+
expect {
313+
repository.index_exists?
314+
}.to raise_exception(NotImplementedError)
329315
end
330316
end
331317
end

0 commit comments

Comments
 (0)