Skip to content

Commit 6b209f0

Browse files
committed
[STORE] Fix up tests to work with default document_type and klass on Repository object
1 parent f9213fd commit 6b209f0

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ module Naming
1414

1515
# Get or set the class used to initialize domain objects when deserializing them
1616
#
17-
def klass name=nil
18-
@klass = name || @klass
17+
def klass(name=nil)
18+
if name
19+
@klass = name
20+
else
21+
@klass
22+
end
1923
end
2024

2125
# Set the class used to initialize domain objects when deserializing them

elasticsearch-persistence/test/integration/repository/custom_class_test.rb

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ::MyNotesRepository
3030
include Elasticsearch::Persistence::Repository
3131

3232
klass MyNote
33+
document_type 'my_note'
3334

3435
settings number_of_shards: 1 do
3536
mapping do
@@ -45,6 +46,8 @@ def deserialize(document)
4546
end
4647

4748
@repository = MyNotesRepository.new
49+
@repository.klass = MyNotesRepository.klass
50+
@repository.document_type = MyNotesRepository.document_type
4851

4952
@repository.client.cluster.health wait_for_status: 'yellow'
5053
end

elasticsearch-persistence/test/integration/repository/default_class_test.rb

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def to_hash
1919
context "The default repository class" do
2020
setup do
2121
@repository = Elasticsearch::Persistence::Repository.new
22+
@repository.klass = ::Note
23+
@repository.document_type = 'note'
2224
@repository.client.cluster.health wait_for_status: 'yellow'
2325
end
2426

@@ -105,6 +107,7 @@ def to_hash
105107
end
106108

107109
should "save and find a plain hash" do
110+
@repository.klass = Hash
108111
@repository.save id: 1, title: 'Hash'
109112
result = @repository.find(1)
110113
assert_equal 'Hash', result['_source']['title']

elasticsearch-persistence/test/integration/repository/virtus_model_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def set_id(id)
2525
@repository = Elasticsearch::Persistence::Repository.new do
2626
index :pages
2727
klass Page
28+
document_type 'page'
2829

2930
def deserialize(document)
3031
page = klass.new document['_source']

0 commit comments

Comments
 (0)