Skip to content

Commit 41719d2

Browse files
authored
Merge pull request #69 from MITLibraries/rdi-238-update-view-online
Return sourceLink as href for view online links
2 parents 97d6799 + c0877d7 commit 41719d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+306
-429
lines changed

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
TIMDEX_HOST=FAKE_TIMDEX_HOST
22
TIMDEX_GRAPHQL=https://FAKE_TIMDEX_HOST/graphql
3+
TIMDEX_INDEX=FAKE_TIMDEX_INDEX

app/helpers/search_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ def trim_highlights(result)
88

99
result['highlight'].reject { |h| displayed_fields.include? h['matchedField'] }
1010
end
11+
12+
def view_online(result)
13+
return unless result['sourceLink'].present?
14+
15+
link_to 'View online', result['sourceLink'], class: 'button button-primary green'
16+
end
1117
end

app/models/timdex_search.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class TimdexSearch < TimdexBase
5353
matchedField
5454
matchedPhrases
5555
}
56+
sourceLink
5657
}
5758
aggregations {
5859
contentType {

app/views/search/_result.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
</div>
2828

2929
<div class="result-get">
30-
<%= link_to 'View online', "##{Random.rand(100000)}", class: 'button button-primary green' %>
30+
<%= view_online(result) %>
3131
</div>
3232
</li>

test/controllers/search_controller_test.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def source_facet_count(controller)
362362
query = {
363363
q: 'data',
364364
advanced: 'true',
365-
source: ['dspace@mit']
365+
source: ['Woods Hole Open Access Server']
366366
}.to_query
367367
get "/results?#{query}"
368368
assert_response :success
@@ -384,9 +384,8 @@ def source_facet_count(controller)
384384
assert_response :success
385385
assert_nil flash[:error]
386386

387-
# Assumption is we'll always have at least 3 default sources
388-
# DSpace, Aspace, Aleph (RDI sources are in now, but may not be default later)
389-
assert(source_facet_count(@controller) > 3)
387+
# Assumption is we'll have at least 2 RDI sources for the time being
388+
assert(source_facet_count(@controller) > 2)
390389
end
391390
end
392391

@@ -400,7 +399,7 @@ def source_facet_count(controller)
400399
query = {
401400
q: 'data',
402401
advanced: 'true',
403-
source: ['dspace@mit', 'Woods Hole Open Access Server']
402+
source: ['Abdul Latif Jameel Poverty Action Lab Dataverse', 'Woods Hole Open Access Server']
404403
}.to_query
405404
get "/results?#{query}"
406405
assert_response :success

test/helpers/search_helper_test.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,21 @@ class SearchHelperTest < ActionView::TestCase
1919

2020
test 'returns correct set of highlights when result includes displayed and undisplayed fields' do
2121
result = { 'highlight' => [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' },
22-
{ 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' },
23-
{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
24-
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }] }
22+
{ 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' },
23+
{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
24+
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }] }
2525
assert_equal [{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
26-
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }], trim_highlights(result)
26+
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }], trim_highlights(result)
27+
end
28+
29+
test 'renders view_online link if sourceLink is present' do
30+
result = { 'title' => 'A record', 'sourceLink' => 'https://example.org' }
31+
assert_equal '<a class="button button-primary green" href="https://example.org">View online</a>',
32+
view_online(result)
33+
end
34+
35+
test 'does not render view_online link if sourceLink is absent' do
36+
result = { 'title' => 'A record' }
37+
assert_nil view_online(result)
2738
end
2839
end

test/models/query_builder_test.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
class QueryBuilderTest < ActiveSupport::TestCase
44
test 'query builder trims spaces' do
5-
expected = { 'from' => '0', 'q' => 'blah' }
5+
expected = { 'from' => '0', 'q' => 'blah', 'index' => 'FAKE_TIMDEX_INDEX' }
66
search = { q: ' blah ' }
77
assert_equal(expected, QueryBuilder.new(search).query)
88
end
99

1010
test 'query builder handles supported fields' do
11-
expected = { 'from' => '0', 'q' => 'blah', 'citation' => 'Citations are cool. Journal of cool citations. Vol 3, page 123.',
11+
expected = { 'from' => '0', 'q' => 'blah',
12+
'citation' => 'Citations are cool. Journal of cool citations. Vol 3, page 123.',
1213
'contributors' => 'Vonnegut, Kurt', 'fundingInformation' => 'National Science Foundation',
1314
'identifiers' => 'doi://1234.123/123.123', 'locations' => 'Cambridge, MA',
14-
'subjects' => 'Subjects are the worst', 'title' => 'Hi I like titles' }
15+
'subjects' => 'Subjects are the worst', 'title' => 'Hi I like titles', 'index' => 'FAKE_TIMDEX_INDEX' }
1516
search = {
1617
q: ' blah ',
1718
citation: 'Citations are cool. Journal of cool citations. Vol 3, page 123.',
@@ -26,10 +27,11 @@ class QueryBuilderTest < ActiveSupport::TestCase
2627
end
2728

2829
test 'query builder ignores unsupported fields' do
29-
expected = { 'from' => '0', 'q' => 'blah', 'citation' => 'Citations are cool. Journal of cool citations. Vol 3, page 123.',
30+
expected = { 'from' => '0', 'q' => 'blah',
31+
'citation' => 'Citations are cool. Journal of cool citations. Vol 3, page 123.',
3032
'contributors' => 'Vonnegut, Kurt', 'fundingInformation' => 'National Science Foundation',
3133
'identifiers' => 'doi://1234.123/123.123', 'locations' => 'Cambridge, MA',
32-
'subjects' => 'Subjects are the worst', 'title' => 'Hi I like titles' }
34+
'subjects' => 'Subjects are the worst', 'title' => 'Hi I like titles', 'index' => 'FAKE_TIMDEX_INDEX' }
3335
search = {
3436
q: ' blah ',
3537
citation: 'Citations are cool. Journal of cool citations. Vol 3, page 123.',
@@ -47,7 +49,7 @@ class QueryBuilderTest < ActiveSupport::TestCase
4749
test 'query builder ignores supported fields that were not included' do
4850
expected = { 'from' => '0', 'q' => 'blah', 'contributors' => 'Vonnegut, Kurt',
4951
'fundingInformation' => 'National Science Foundation',
50-
'identifiers' => 'doi://1234.123/123.123' }
52+
'identifiers' => 'doi://1234.123/123.123', 'index' => 'FAKE_TIMDEX_INDEX' }
5153
search = {
5254
q: ' blah ',
5355
contributors: 'Vonnegut, Kurt',
@@ -65,7 +67,9 @@ class QueryBuilderTest < ActiveSupport::TestCase
6567
end
6668

6769
test 'query builder index is nil if TIMDEX_INDEX not provided in env' do
68-
search = { q: 'blah' }
69-
assert_nil(QueryBuilder.new(search).query['index'])
70+
ClimateControl.modify TIMDEX_INDEX: nil do
71+
search = { q: 'blah' }
72+
assert_nil(QueryBuilder.new(search).query['index'])
73+
end
7074
end
7175
end

test/models/timdex_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def basic_search
1010

1111
def basic_record
1212
{
13-
'id' => 'jpal:doi:10.7910-DVN-MNIBOL'
13+
'id' => 'jpal:doi:10.7910-DVN-MNIBOL', 'index' => ENV.fetch('TIMDEX_INDEX', nil).to_s
1414
}
1515
end
1616

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
config.allow_http_connections_when_no_cassette = false
2020
config.filter_sensitive_data('FAKE_TIMDEX_HOST') { ENV.fetch('TIMDEX_HOST').to_s }
2121
config.filter_sensitive_data('http://FAKE_TIMDEX_HOST/graphql/') { ENV.fetch('TIMDEX_GRAPHQL').to_s }
22+
config.filter_sensitive_data('FAKE_TIMDEX_INDEX') { ENV.fetch('TIMDEX_INDEX').to_s }
2223
end
2324

2425
module ActiveSupport

test/vcr_cassettes/advanced.yml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)