Skip to content

Commit

Permalink
Introducing where clause for number_of_works()
Browse files Browse the repository at this point in the history
Based on some investigation around #3478, I suspect that the
`Hyrax::WorkRelation#where` call that uses only a depositor field and
user key is finding more results than the query run on the catalog
search page.

By adding the where clause, I hope to align the query logic of the
`number_of_works` and the `link_to_field` on the [_vitals.html.erb][1] partial.

Related to #3478

[1]: https://github.com/samvera/hyrax/blob/b04c41d2772505d8a548c3fd48774a5642d3ac90/app/views/hyrax/users/_vitals.html.erb#L11-L12
  • Loading branch information
jeremyf committed Sep 15, 2020
1 parent b0b5dc4 commit 980dc92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/helpers/hyrax/dashboard_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ def on_the_dashboard?
params[:controller].match(%r{^hyrax/dashboard|hyrax/my})
end

def number_of_works(user = current_user)
Hyrax::WorkRelation.new.where(DepositSearchBuilder.depositor_field => user.user_key).count
def number_of_works(user = current_user, where: {})
where_clause = where.merge(DepositSearchBuilder.depositor_field => user.user_key)
Hyrax::WorkRelation.new.where(where_clause).count
rescue RSolr::Error::ConnectionRefused
'n/a'
end
Expand Down
12 changes: 10 additions & 2 deletions spec/helpers/hyrax/dashboard_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
it "finds 3 works" do
expect(helper.number_of_works(user1)).to eq(3)
end

context "with a :where clause" do
it "limits to those matching the where clause" do
expect(helper.number_of_works(user1, where: { "generic_type_sim" => "Big Work" })).to eq(1)
end
end
end

describe "#number_of_files" do
Expand Down Expand Up @@ -61,11 +67,13 @@ def create_models(model, user1, user2)
solr_service = Hyrax::SolrService

# deposited by the first user
3.times do |t|
2.times do |t|
solr_service.add id: "199#{t}", "depositor_tesim" => user1.user_key, "has_model_ssim" => [model],
"depositor_ssim" => user1.user_key
"depositor_ssim" => user1.user_key, "generic_type_sim" => "Work"
end

solr_service.add id: "1993", "depositor_tesim" => user1.user_key, "generic_type_sim" => "Big Work", "has_model_ssim" => [model], "depositor_ssim" => user1.user_key

# deposited by the second user, but editable by the first
solr_service.add id: "1994", "depositor_tesim" => user2.user_key, "has_model_ssim" => [model],
"depositor_ssim" => user2.user_key, "edit_access_person_ssim" => user1.user_key
Expand Down

0 comments on commit 980dc92

Please sign in to comment.