Skip to content

Commit

Permalink
Merge pull request #302 from projectblacklight/fix_tests
Browse files Browse the repository at this point in the history
Avoid mutation of range config between tests, revealing fix for assumed_boundaries config
  • Loading branch information
seanaery authored Dec 2, 2024
2 parents dd1fc86 + fdc4e30 commit c11590f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/blacklight_range_limit/range_limit_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def bl_create_selected_range_value(selected_value, field_config)

range = if selected_value.is_a? Range
selected_value
elsif range_config[:assumed_boundaries]
elsif range_config[:assumed_boundaries].is_a?(Range)
range_config[:assumed_boundaries]
elsif range_config[:assumed_boundaries] # Array of two things please
Range.new(*range_config[:assumed_boundaries])
else
nil
Expand Down
28 changes: 15 additions & 13 deletions spec/features/run_through_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@
end

context 'when assumed boundaries configured' do
before do
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = {
assumed_boundaries: start_range.to_i...end_range.to_i
}
end
around do |example|
original = CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original.merge({
:assumed_boundaries=>1900...2100,
})

example.run

after do
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = {}
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original
end

it 'should show the range limit with set boundaries' do
Expand All @@ -156,14 +157,15 @@
end

context 'when missing facet item is configured not to show' do
before do
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = {
around do |example|
original = CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original.merge({
show_missing_link: false
}
end
})

example.run

after do
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = {}
CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original
end

it 'should not show the missing facet item' do
Expand Down

0 comments on commit c11590f

Please sign in to comment.