Skip to content

Commit

Permalink
Merge pull request #720 from MITLibraries/etd-304-holds-author-names-…
Browse files Browse the repository at this point in the history
…bugfix

Bugfix for broken Hold dashboard searches
  • Loading branch information
jazairi authored Jun 11, 2021
2 parents c6b5562 + 5492db6 commit de6961b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/dashboards/hold_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class HoldDashboard < Administrate::BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
thesis: Field::BelongsTo,
author_names: Field::String,
degrees: Field::String,
thesis: Field::BelongsTo.with_options(searchable: true,
searchable_fields: ['title']),
author_names: Field::Text,
degrees: Field::Text,
grad_date: Field::DateTime.with_options(
format: "%Y %B",
),
Expand All @@ -20,9 +21,9 @@ class HoldDashboard < Administrate::BaseDashboard
date_start: Field::Date,
date_end: Field::Date,
date_released: Field::Date,
dates_thesis_files_received: Field::String,
dates_thesis_files_received: Field::Text,
case_number: Field::String,
status: Field::Select.with_options(searchable: false, collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys }),
status: Field::Select.with_options(searchable: true, collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys }),
processing_notes: Field::Text,
created_by: Field::Text,
created_at: Field::Date,
Expand Down Expand Up @@ -92,7 +93,9 @@ class HoldDashboard < Administrate::BaseDashboard
# open: ->(resources) { resources.where(open: true) }
# }.freeze
COLLECTION_FILTERS = {
active: ->(resources) { resources.where(status: :active) }
active: ->(resources) { resources.where(status: :active) },
expired: ->(resources) { resources.where(status: :expired) },
released: ->(resources) { resources.where(status: :released) }
}.freeze

# Overwrite this method to customize how holds are displayed
Expand Down
27 changes: 27 additions & 0 deletions test/integration/admin/admin_hold_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,31 @@ def teardown
assert_response :success
assert_select "a[href='/hold_history/#{hold.id}']", "View hold history"
end

test 'can filter active holds' do
mock_auth users(:thesis_admin)
get "/admin/holds?search=active%3A"
assert_response :success
assert_select 'a', 'active'
assert_select 'a', {count: 0, text: 'expired'}
assert_select 'a', {count: 0, text: 'released'}
end

test 'can filter expired holds' do
mock_auth users(:thesis_admin)
get "/admin/holds?search=expired%3A"
assert_response :success
assert_select 'a', 'expired'
assert_select 'a', {count: 0, text: 'active'}
assert_select 'a', {count: 0, text: 'released'}
end

test 'can filter released holds' do
mock_auth users(:thesis_admin)
get "/admin/holds?search=released%3A"
assert_response :success
assert_select 'a', 'released'
assert_select 'a', {count: 0, text: 'active'}
assert_select 'a', {count: 0, text: 'expired'}
end
end

0 comments on commit de6961b

Please sign in to comment.