Skip to content

Commit 56c72cf

Browse files
committed
Ensure config#solr_response_model and config#solr_document_model are not deep-dup'ed to preserve the original classes
Fixes #1061 If those class names are dup'ed, methods that expect ActiveModel::Naming don't behave correctly
1 parent 4ab2b19 commit 56c72cf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/blacklight/configuration.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,16 @@ def deep_copy
252252
end
253253
alias_method :inheritable_copy, :deep_copy
254254
else
255-
alias_method :deep_copy, :deep_dup
256-
alias_method :inheritable_copy, :deep_dup
255+
##
256+
# Rails 4.x provides `#deep_dup`, but it aggressively `#dup`'s class names
257+
# too. These model names should not be `#dup`'ed or we might break ActiveModel::Naming.
258+
def deep_copy
259+
deep_dup.tap do |copy|
260+
copy.solr_response_model = self.solr_response_model
261+
copy.solr_document_model = self.solr_document_model
262+
end
263+
end
264+
alias_method :inheritable_copy, :deep_copy
257265
end
258266

259267
##

spec/lib/blacklight/configuration_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
expect(@config.facet_fields).to_not include(@mock_facet)
8585
end
8686

87+
it "should not dup solr_response_model or solr_document_model" do
88+
@config.solr_response_model = Blacklight::SolrResponse
89+
@config.solr_document_model = SolrDocument
90+
91+
config_copy = @config.inheritable_copy
92+
93+
expect(config_copy.solr_response_model).to eq Blacklight::SolrResponse
94+
expect(config_copy.solr_document_model).to eq SolrDocument
95+
end
96+
8797
it "should provide cloned copies of mutable data structures" do
8898
@config.a = { value: 1 }
8999
@config.b = [1,2,3]

0 commit comments

Comments
 (0)