Skip to content

Commit de87b40

Browse files
committed
[STORE] Remove #with method
1 parent 6872c68 commit de87b40

File tree

5 files changed

+5
-85
lines changed

5 files changed

+5
-85
lines changed

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,6 @@ def initialize(options = {})
119119
@options = options
120120
end
121121

122-
# Get a new instance of this repository with different options.
123-
# Any options that are not passed into the method will be kept from the original instance.
124-
#
125-
# Provides a new repository object with the passed options merged over the existing
126-
# options of this repository. Useful for one-offs to change specific options
127-
# without altering the original repository itself.
128-
#
129-
# @example Get a repository with changed options.
130-
# repository.with(index_name: 'other_index')
131-
#
132-
# @param [ Hash ] new_options The new options to use.
133-
#
134-
# @return [ Elasticsearch::Persistence::Repository ] A new repository instance.
135-
#
136-
# @since 6.0.0
137-
def with(new_options = {})
138-
clone.tap do |repository|
139-
repository.options.update(new_options)
140-
end
141-
end
142-
143122
# Get the client used by the repository.
144123
#
145124
# @example

elasticsearch-persistence/spec/repository/find_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@
9999
{ 'a' => 1 },
100100
{ 'a' => 2 }])
101101
end
102-
103-
104102
end
105103

106104
context 'when the document cannot be found' do
@@ -149,7 +147,7 @@
149147
context 'when a document_type is defined on the class' do
150148

151149
let(:repository) do
152-
DEFAULT_REPOSITORY.with(document_type:'other_type', client: DEFAULT_CLIENT)
150+
MyTestRepository.new(document_type:'other_type', client: DEFAULT_CLIENT)
153151
end
154152

155153
let!(:ids) do

elasticsearch-persistence/spec/repository/search_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
context 'when the repository does have a type set' do
5454

5555
let(:repository) do
56-
DEFAULT_REPOSITORY.with(document_type: 'other_note')
56+
MyTestRepository.new(document_type: 'other_note')
5757
end
5858

5959
before do
@@ -126,7 +126,7 @@
126126
context 'when the repository does have a type set' do
127127

128128
let(:repository) do
129-
DEFAULT_REPOSITORY.with(document_type: 'other_note')
129+
MyTestRepository.new(document_type: 'other_note')
130130
end
131131

132132
before do

elasticsearch-persistence/spec/repository/serialize_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def to_hash
3131

3232
let(:repository) do
3333
require 'set'
34-
DEFAULT_REPOSITORY.with(klass: Set)
34+
MyTestRepository.new(klass: Set)
3535
end
3636

3737
it 'instantiates an object of the klass' do

elasticsearch-persistence/spec/repository_spec.rb

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -71,55 +71,6 @@ class UserRepo
7171
end
7272
end
7373

74-
describe '#with' do
75-
76-
let(:repository) do
77-
UserRepo.new(index_name: 'users', document_type: 'user', klass: Hash)
78-
end
79-
80-
context 'when all the options are changed' do
81-
82-
let(:new_repository) do
83-
repository.with(index_name: 'other_users',
84-
document_type: 'other_user',
85-
klass: Array,
86-
client: double('client)', class: Elasticsearch::Transport::Client))
87-
end
88-
89-
it 'changes the options' do
90-
expect(new_repository.index_name).to eq('other_users')
91-
expect(new_repository.document_type).to eq('other_user')
92-
expect(new_repository.klass).to eq(Array)
93-
expect(new_repository.client.class).to eq(Elasticsearch::Transport::Client)
94-
end
95-
96-
it 'returns a new instance of the repository class' do
97-
expect(new_repository).not_to be(repository)
98-
end
99-
100-
it 'clones the options' do
101-
expect(new_repository.options).not_to be(repository.options)
102-
end
103-
end
104-
105-
context 'when only some options are changed' do
106-
107-
let(:new_repository) do
108-
repository.with(index_name: 'other_users')
109-
end
110-
111-
it 'only changes the new option' do
112-
expect(new_repository.index_name).to eq('other_users')
113-
expect(new_repository.document_type).to eq('user')
114-
expect(new_repository.klass).to eq(Hash)
115-
end
116-
117-
it 'returns a new instance of the repository class' do
118-
expect(new_repository).not_to be(repository)
119-
end
120-
end
121-
end
122-
12374
describe 'class methods' do
12475

12576
before(:all) do
@@ -402,10 +353,6 @@ class NoteRepository
402353
expect(NoteRepository.new(mapping: double('mapping', to_hash: { note: {} })).mapping.to_hash).to eq(note: {})
403354
end
404355

405-
it 'allows the value to be overwritten when #with is called on an instance' do
406-
expect(NoteRepository.new.with(mapping: double('mapping', to_hash: { note: {} })).mapping.to_hash).to eq(note: {})
407-
end
408-
409356
context 'when the instance has a different document type' do
410357

411358
let(:expected_mapping) do
@@ -418,7 +365,7 @@ class NoteRepository
418365
end
419366

420367
it 'updates the mapping to use the document type' do
421-
expect(NoteRepository.new.with(document_type: 'other_note').mapping.to_hash).to eq(expected_mapping)
368+
expect(NoteRepository.new(document_type: 'other_note').mapping.to_hash).to eq(expected_mapping)
422369
end
423370
end
424371
end
@@ -436,10 +383,6 @@ class NoteRepository
436383
it 'allows the value to be overwritten with options on the instance' do
437384
expect(NoteRepository.new(settings: { number_of_shards: 3 }).settings.to_hash).to eq({ number_of_shards: 3 })
438385
end
439-
440-
it 'allows the value to be overwritten when #with is called on an instance' do
441-
expect(NoteRepository.new.with(settings: { number_of_shards: 3 }).settings.to_hash).to eq({ number_of_shards: 3 })
442-
end
443386
end
444387
end
445388
end

0 commit comments

Comments
 (0)