Skip to content

Commit

Permalink
only clear valkyrie solr when :clean_repo is specified in a spec
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle authored and tamsin johnson committed Jul 28, 2021
1 parent 1ee404e commit 495180d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/services/hyrax/solr_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def select_path
'Use `Hyrax.config.solr_select_path` instead'
end

delegate :add, :commit, :count, :delete, :get, :instance, :ping, :post, :query, :delete_by_query, :search_by_id, to: :new
delegate :add, :commit, :count, :delete, :get, :instance, :ping, :post,
:query, :delete_by_query, :search_by_id, :wipe!, to: :new
end

# Wraps rsolr get
Expand Down Expand Up @@ -100,6 +101,12 @@ def delete(id)
connection.delete_by_id(id, params: COMMIT_PARAMS)
end

# Deletes all solr documents
def wipe!
delete_by_query("*:*")
commit
end

# Wraps rsolr add
# @return [Hash] the hash straight form rsolr
def add(solr_doc, commit: true)
Expand Down
19 changes: 19 additions & 0 deletions spec/services/hyrax/solr_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@
end
end

describe ".wipe!" do
it "calls solr" do
expect(mock_conn).to receive(:delete_by_query).with("*:*", params: {})
allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
expect(mock_conn).to receive(:commit)
described_class.wipe!
end

context "when use_valkyrie: true" do
let(:service) { described_class.new(use_valkyrie: true) }

it "uses valkyrie solr based on config query_index_from_valkyrie" do
expect(mock_conn).to receive(:delete_by_query).with("*:*", params: {})
expect(mock_conn).to receive(:commit)
service.wipe!
end
end
end

describe '.instance' do
let(:mock_instance) { double("instance", conn: mock_conn) }

Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def clean_active_fedora_repository
# The JS is executed in a different thread, so that other thread
# may think the root path has already been created:
ActiveFedora.fedora.connection.send(:init_base_path)
Hyrax.persister.wipe! if Hyrax.config.query_index_from_valkyrie
end

RSpec.configure do |config|
Expand Down Expand Up @@ -236,6 +235,10 @@ def clean_active_fedora_repository
config.before(:example, :clean_repo) do
clean_active_fedora_repository
Hyrax::RedisEventStore.instance.redis.flushdb

# Not needed to clean the Solr core used by ActiveFedora since
# clean_active_fedora_repository will wipe that core
Hyrax::SolrService.wipe! if Hyrax.config.query_index_from_valkyrie
end

# Use this example metadata when you want to perform jobs inline during testing.
Expand Down

0 comments on commit 495180d

Please sign in to comment.