Skip to content

Commit b872466

Browse files
tamsin johnsontamsin johnson
tamsin johnson
authored and
tamsin johnson
committed
support legacy "Collection" and "AdminSet" in SolrDocumentBehavior
when models are indexed as "Collection" or "AdminSet" treat them as `#collection?` and `#admin_set?` regardless of configured model classes. this should better support legacy index documents and an easier transition.
1 parent 5a30bb5 commit b872466

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

app/models/concerns/hyrax/solr_document_behavior.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,22 @@ def to_model
5353
##
5454
# @return [Boolean]
5555
def collection?
56-
hydra_model == Hyrax.config.collection_class
56+
hydra_model == Hyrax.config.collection_class ||
57+
("Collection".safe_constantize == hydra_model)
5758
end
5859

5960
##
6061
# @return [Boolean]
6162
def file_set?
62-
hydra_model == ::FileSet || hydra_model == Hyrax::FileSet
63+
hydra_model == Hyrax::FileSet ||
64+
("::FileSet".safe_constantize == hydra_model)
6365
end
6466

6567
##
6668
# @return [Boolean]
6769
def admin_set?
68-
hydra_model == Hyrax.config.admin_set_class
70+
(hydra_model == Hyrax.config.admin_set_class) ||
71+
("AdminSet".safe_constantize == hydra_model)
6972
end
7073

7174
##

spec/models/solr_document_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,27 @@ class Mimes
158158
end
159159

160160
describe "#admin_set?" do
161-
let(:attributes) { { 'has_model_ssim' => 'AdminSet' } }
161+
let(:attributes) { { 'has_model_ssim' => Hyrax.config.admin_set_model } }
162162

163163
it { is_expected.to be_admin_set }
164+
165+
context "with legacy indexed admin set" do
166+
let(:attributes) { { 'has_model_ssim' => "AdminSet" } }
167+
168+
it { is_expected.to be_admin_set }
169+
end
164170
end
165171

166172
describe "#collection?" do
167173
let(:attributes) { { 'has_model_ssim' => Hyrax.config.collection_model } }
168174

169175
it { is_expected.to be_collection }
176+
177+
context "with legacy indexed collection" do
178+
let(:attributes) { { 'has_model_ssim' => "Collection" } }
179+
180+
it { is_expected.to be_collection }
181+
end
170182
end
171183

172184
describe "#work?" do

0 commit comments

Comments
 (0)