Skip to content

Commit

Permalink
Updates the spotlight/browse/search_title View partial to use Search#…
Browse files Browse the repository at this point in the history
…count to retrieve total item counts
  • Loading branch information
jrgriffiniii committed Apr 27, 2018
1 parent 99f1d6d commit d842ac2
Show file tree
Hide file tree
Showing 5 changed files with 553 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/views/spotlight/browse/_search_title.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= search.title %>
<small class="item-count"><%= t :'spotlight.browse.search.item_count', count: params[:browse_q] ? parent_search_count: search.count %></small>
175 changes: 175 additions & 0 deletions spec/features/browse_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
require 'rails_helper'

RSpec.describe 'Browsing exhibits', type: :feature do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:user) { FactoryBot.create(:user, exhibit: exhibit) }
let(:id) { 'd279a557a62937a8895eebbca2d4744c' }
let(:title) { 'Panoramic alphabet of peace' }
let(:rights) { 'http://rightsstatements.org/vocab/NKC/1.0/' }
let(:document) do
SolrDocument.new(
id: id,
readonly_title_tesim: [
title
],
'exhibit_abc_books_readonly_edm-rights_ssim': [
rights
],
'readonly_edm-rights_tesim': [
rights
],
exhibit_abc_books_readonly_license_ssim: [
rights
],
readonly_license_tesim: [
rights
],
access_identifier_ssim: [
"1r66j4408"
],
full_title_tesim: [
title
],
readonly_title_ssim: [
title
],
'readonly_title-sort_ssim': [
title
],
'readonly_edm-rights_ssim': [
rights
],
readonly_license_ssim: [
rights
],
_version_: 159,
timestamp: "2018-02-19T22:19:52.244Z"
)
end
let(:id2) { 'b29876d5e07e00acc0b7a4ce6668791d' }
let(:title2) { 'Panoramic abugida of war' }
let(:document2) do
SolrDocument.new(
id: id2,
readonly_title_tesim: [
title2
],
'exhibit_abc_books_readonly_edm-rights_ssim': [
rights
],
'readonly_edm-rights_tesim': [
rights
],
exhibit_abc_books_readonly_license_ssim: [
rights
],
readonly_license_tesim: [
rights
],
access_identifier_ssim: [
"1r66j4408"
],
full_title_tesim: [
title
],
readonly_title_ssim: [
title
],
'readonly_title-sort_ssim': [
title
],
'readonly_edm-rights_ssim': [
rights
],
readonly_license_ssim: [
rights
],
_version_: 159,
timestamp: "2018-02-19T22:19:52.244Z"
)
end
let(:id3) { '236fa7d48276bf22696de744870e545f' }
let(:title3) { 'Panoramic abjad of wonder' }
let(:document3) do
SolrDocument.new(
id: id3,
readonly_title_tesim: [
title3
],
'exhibit_abc_books_readonly_edm-rights_ssim': [
rights
],
'readonly_edm-rights_tesim': [
rights
],
exhibit_abc_books_readonly_license_ssim: [
rights
],
readonly_license_tesim: [
rights
],
access_identifier_ssim: [
"1r66j4408"
],
full_title_tesim: [
title
],
readonly_title_ssim: [
title
],
'readonly_title-sort_ssim': [
title
],
'readonly_edm-rights_ssim': [
rights
],
readonly_license_ssim: [
rights
],
_version_: 159,
timestamp: "2018-02-19T22:19:52.244Z"
)
end

before do
sign_in user
document.make_public! exhibit
document.reindex
document2.make_public! exhibit
document2.reindex
document3.make_public! exhibit
document3.reindex
Blacklight.default_index.connection.commit
end

context 'when logged in as a site admin.' do
let(:user) { FactoryBot.create(:site_admin, exhibit: exhibit) }

context 'when browsing all exhibit items' do
before do
visit spotlight.exhibit_browse_path(exhibit, id: 'all-exhibit-items')
end

it 'displays the total number of publicly accessible items' do
expect(page).to have_css '.item-count', text: '3 items'
end
end

context 'when browsing all exhibit items in a saved search' do
before do
exhibit.searches.create(title: 'All Exhibit Items', long_description: 'All items in this exhibit.')

document2.make_private! exhibit
document2.reindex
Blacklight.default_index.connection.delete_by_id document3.id
Blacklight.default_index.connection.commit

visit spotlight.exhibit_browse_path(exhibit, id: 'all-exhibit-items')
end

it 'hides the privately accessible items and updates for deleted items' do
expect(page).to have_css '.item-count', text: '1 item'
end
end
end
end
4 changes: 2 additions & 2 deletions spec/features/catalog_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.feature 'Catalog', type: :feature do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:exhibit) { FactoryBot.create(:exhibit, title: 'Exhibit A') }
let(:id) { 'd279a557a62937a8895eebbca2d4744c' }
let(:title) { 'Panoramic alphabet of peace' }
let(:rights) { 'http://rightsstatements.org/vocab/NKC/1.0/' }
Expand Down Expand Up @@ -82,7 +82,7 @@

scenario 'user browses all collections' do
visit spotlight.search_exhibit_catalog_path(exhibit, search_field: 'all_fields', q: '')
expect(page).to have_link 'Home', href: '/exhibit-title-2'
expect(page).to have_link 'Home', href: '/exhibit-a'
expect(page).to have_css '#documents .document h3.index_title', text: id
end
end
Expand Down
192 changes: 192 additions & 0 deletions spec/models/spotlight/search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
require 'rails_helper'

describe Spotlight::Search, type: :model do
subject(:search) { exhibit.searches.build(title: 'Search') }

let(:exhibit) { FactoryBot.create(:exhibit) }
let(:blacklight_config) { ::CatalogController.blacklight_config }
let(:id) { 'd279a557a62937a8895eebbca2d4744c' }
let(:title) { 'Panoramic alphabet of peace' }
let(:rights) { 'http://rightsstatements.org/vocab/NKC/1.0/' }
let(:document) do
SolrDocument.new(
id: id,
readonly_title_tesim: [
title
],
'exhibit_abc_books_readonly_edm-rights_ssim': [
rights
],
'readonly_edm-rights_tesim': [
rights
],
exhibit_abc_books_readonly_license_ssim: [
rights
],
readonly_license_tesim: [
rights
],
access_identifier_ssim: [
"1r66j4408"
],
full_title_tesim: [
title
],
readonly_title_ssim: [
title
],
'readonly_title-sort_ssim': [
title
],
'readonly_edm-rights_ssim': [
rights
],
readonly_license_ssim: [
rights
],
_version_: 159,
timestamp: "2018-02-19T22:19:52.244Z"
)
end
let(:id2) { 'b29876d5e07e00acc0b7a4ce6668791d' }
let(:title2) { 'Panoramic abugida of war' }
let(:document2) do
SolrDocument.new(
id: id2,
readonly_title_tesim: [
title2
],
'exhibit_abc_books_readonly_edm-rights_ssim': [
rights
],
'readonly_edm-rights_tesim': [
rights
],
exhibit_abc_books_readonly_license_ssim: [
rights
],
readonly_license_tesim: [
rights
],
access_identifier_ssim: [
"1r66j4408"
],
full_title_tesim: [
title
],
readonly_title_ssim: [
title
],
'readonly_title-sort_ssim': [
title
],
'readonly_edm-rights_ssim': [
rights
],
readonly_license_ssim: [
rights
],
_version_: 159,
timestamp: "2018-02-19T22:19:52.244Z"
)
end
let(:id3) { '236fa7d48276bf22696de744870e545f' }
let(:title3) { 'Panoramic abjad of wonder' }
let(:document3) do
SolrDocument.new(
id: id3,
readonly_title_tesim: [
title3
],
'exhibit_abc_books_readonly_edm-rights_ssim': [
rights
],
'readonly_edm-rights_tesim': [
rights
],
exhibit_abc_books_readonly_license_ssim: [
rights
],
readonly_license_tesim: [
rights
],
access_identifier_ssim: [
"1r66j4408"
],
full_title_tesim: [
title
],
readonly_title_ssim: [
title
],
'readonly_title-sort_ssim': [
title
],
'readonly_edm-rights_ssim': [
rights
],
readonly_license_ssim: [
rights
],
_version_: 159,
timestamp: "2018-02-19T22:19:52.244Z"
)
end

before do
document.make_public! exhibit
document.reindex
document2.make_public! exhibit
document2.reindex
document3.make_public! exhibit
document3.reindex
Blacklight.default_index.connection.commit
end

context 'when Exhibit items are updated as private and deleted' do
subject(:new_search) { exhibit.searches.create(title: 'All Exhibit Items', long_description: 'All items in this exhibit.') }

before do
new_search
document2.make_private! exhibit
document2.reindex
Blacklight.default_index.connection.delete_by_id document3.id
Blacklight.default_index.connection.commit
end

describe '#documents' do
it 'retrieves the updated documents' do
expect(new_search.documents.to_a).not_to be_empty
expect(new_search.documents.size).to eq 1
end
end

describe '#count' do
it 'counts the updated documents' do
expect(search.count).to eq 1
expect(search.count).to eq search.documents.size
end
end
end

context 'when creating a search to browse all items in an Exhibit' do
subject(:search) do
exhibit.searches.create(title: 'All Exhibit Items', long_description: 'All items in this exhibit.')
end

describe '#documents' do
it 'retrieves all documents within an exhibit' do
expect(search.documents.to_a).not_to be_empty
expect(search.documents.size).to eq 3
expect(search.documents.first).to be_a SolrDocument
end
end

describe '#count' do
it 'counts all documents within an exhibit' do
expect(search.count).to eq 3
expect(search.count).to eq search.documents.size
end
end
end
end
Loading

0 comments on commit d842ac2

Please sign in to comment.