Skip to content

Commit 9632607

Browse files
committed
1 parent 6787f0c commit 9632607

File tree

7 files changed

+34
-50
lines changed

7 files changed

+34
-50
lines changed

app/models/retrieve.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ def fetch(id)
33
f = to_filter(id)
44
record = Timdex::EsClient.search(index: ENV['ELASTICSEARCH_INDEX'], body: f)
55

6-
if record['hits']['total'].zero?
7-
raise Elasticsearch::Transport::Transport::Errors::NotFound
8-
end
6+
raise Elasticsearch::Transport::Transport::Errors::NotFound if record['hits']['total'].zero?
97

108
record
119
end

app/models/search.rb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,15 @@ def query
6767
def filters
6868
f = []
6969
f.push filter(@params[:collection], 'collections') if @params[:collection]
70-
if @params[:contributor]
71-
f.push filter(@params[:contributor], 'contributors')
72-
end
70+
f.push filter(@params[:contributor], 'contributors') if @params[:contributor]
7371

74-
if @params[:content_type]
75-
f.push filter_single(@params[:content_type], 'content_type')
76-
end
72+
f.push filter_single(@params[:content_type], 'content_type') if @params[:content_type]
7773

78-
if @params[:content_format]
79-
f.push filter(@params[:content_format], 'format')
80-
end
74+
f.push filter(@params[:content_format], 'format') if @params[:content_format]
8175

8276
f.push filter(@params[:language], 'languages') if @params[:language]
8377

84-
if @params[:literary_form]
85-
f.push filter_single(@params[:literary_form], 'literary_form')
86-
end
78+
f.push filter_single(@params[:literary_form], 'literary_form') if @params[:literary_form]
8779

8880
f.push filter_single(@params[:source], 'source') if @params[:source]
8981
f.push filter(@params[:subject], 'subjects') if @params[:subject]
@@ -112,7 +104,7 @@ def filter(param, field)
112104
}
113105
)
114106
else
115-
terms.push('term': { "#{field}.keyword": t })
107+
terms.push(term: { "#{field}.keyword": t })
116108
end
117109
end
118110

@@ -122,7 +114,7 @@ def filter(param, field)
122114
# use `filter_single` when we only accept a single value in our data model
123115
def filter_single(param, field)
124116
{
125-
'term': { "#{field}.keyword": param }
117+
term: { "#{field}.keyword": param }
126118
}
127119
end
128120

app/views/api/v1/search/_extended.json.jbuilder

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ json.issns result['issns'] if result['issns']
33
json.dois result['dois'] if result['dois']
44
json.available 'Not Yet Implemented'
55
json.alternate_titles result['alternate_titles'] if result['alternate_titles']
6-
if json.place_of_publication result['place_of_publication']
7-
result['place_of_publication']
8-
end
6+
result['place_of_publication'] if json.place_of_publication result['place_of_publication']
97
json.languages result['languages'] if result['languages']
108
json.call_numbers result['call_numbers'] if result['call_numbers']
119
json.edition result['edition'] if result['edition']
1210
json.imprint result['imprint'] if result['imprint']
13-
if result['physical_description']
14-
json.physical_description result['physical_description']
15-
end
11+
json.physical_description result['physical_description'] if result['physical_description']
1612
json.summary result['summary'] if result['summary']
1713
json.imprint result['imprint'] if result['imprint']
1814
json.notes result['notes'] if result['notes']
19-
if result['publication_frequency']
20-
json.publication_frequency result['publication_frequency']
21-
end
15+
json.publication_frequency result['publication_frequency'] if result['publication_frequency']
2216
json.literary_form result['literary_form'] if result['literary_form']

config.ru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is used by Rack-based servers to start the application.
22

3-
require_relative "config/environment"
3+
require_relative 'config/environment'
44

55
run Rails.application
66
Rails.application.load_server

test/controllers/auth_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class AuthControllerTest < ActionDispatch::IntegrationTest
44
test 'valid credentials returns JWT' do
55
u = users(:yo)
66
b = Base64.encode64(u.email + ':123greetings')
7-
get '/api/v1/auth', headers: { 'Authorization': "Basic #{b}" }
7+
get '/api/v1/auth', headers: { Authorization: "Basic #{b}" }
88
assert_equal(200, response.status)
99
assert_equal(u.id, JwtWrapper.decode(JSON.parse(response.body))['user_id'])
1010
end

test/controllers/graphql_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
137137
test 'search with multiple subjects applied' do
138138
VCR.use_cassette('graphql search multiple subjects') do
139139
post '/graphql', params: { query: '{
140-
search(searchterm: "space",
140+
search(searchterm: "space",
141141
subjects: ["space and time.",
142142
"quantum theory."]) {
143143
hits
@@ -167,7 +167,7 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
167167
json = JSON.parse(response.body)
168168
assert(json['errors'].first['message'].present?)
169169
assert_equal("Field 'search' doesn't accept argument 'fake'",
170-
json['errors'].first['message'])
170+
json['errors'].first['message'])
171171
end
172172
end
173173

test/controllers/search_controller_test.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
55
token = JwtWrapper.encode(user_id: users(:yo).id)
66
VCR.use_cassette('q super cool search') do
77
get '/api/v1/search?q=super+cool+search',
8-
headers: { 'Authorization': "Bearer #{token}" }
8+
headers: { Authorization: "Bearer #{token}" }
99
assert_equal(200, response.status)
1010
json = JSON.parse(response.body)
1111
assert_equal(21_502, json['hits'])
@@ -16,7 +16,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
1616
token = JwtWrapper.encode(user_id: 'fakeid')
1717
VCR.use_cassette('invalid token') do
1818
get '/api/v1/search?q=super+cool+search',
19-
headers: { 'Authorization': "Bearer #{token}" }
19+
headers: { Authorization: "Bearer #{token}" }
2020
assert_equal(200, response.status)
2121
json = JSON.parse(response.body)
2222
assert_equal(100, json['request_limit'])
@@ -29,7 +29,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
2929
end
3030
VCR.use_cassette('expired token') do
3131
get '/api/v1/search?q=super+cool+search',
32-
headers: { 'Authorization': "Bearer #{token}" }
32+
headers: { Authorization: "Bearer #{token}" }
3333
assert_equal(200, response.status)
3434
json = JSON.parse(response.body)
3535
assert_equal(100, json['request_limit'])
@@ -44,7 +44,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
4444

4545
test 'ping with valid token' do
4646
token = JwtWrapper.encode(user_id: users(:yo).id)
47-
get '/api/v1/ping', headers: { 'Authorization': "Bearer #{token}" }
47+
get '/api/v1/ping', headers: { Authorization: "Bearer #{token}" }
4848
assert_equal(200, response.status)
4949
assert_equal('pong', JSON.parse(response.body))
5050
end
@@ -53,7 +53,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
5353
token = JwtWrapper.encode(user_id: users(:yo).id)
5454
VCR.use_cassette('record 001714562') do
5555
get '/api/v1/record/001714562',
56-
headers: { 'Authorization': "Bearer #{token}" }
56+
headers: { Authorization: "Bearer #{token}" }
5757
assert_equal(200, response.status)
5858
json = JSON.parse(response.body)
5959
assert_equal('001714562', json['id'])
@@ -65,7 +65,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
6565
token = JwtWrapper.encode(user_id: users(:yo).id)
6666
VCR.use_cassette('record asdf') do
6767
get '/api/v1/record/asdf',
68-
headers: { 'Authorization': "Bearer #{token}" }
68+
headers: { Authorization: "Bearer #{token}" }
6969
assert_equal(404, response.status)
7070
end
7171
end
@@ -74,47 +74,47 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
7474
token = JwtWrapper.encode(user_id: users(:yo).id)
7575
VCR.use_cassette('record period') do
7676
get '/api/v1/record/MIT:archivespace:MC.0044',
77-
headers: { 'Authorization': "Bearer #{token}" }
78-
assert_equal(200, response.status)
79-
json = JSON.parse(response.body)
80-
assert_equal('MIT:archivespace:MC.0044', json['id'])
77+
headers: { Authorization: "Bearer #{token}" }
78+
assert_equal(200, response.status)
79+
json = JSON.parse(response.body)
80+
assert_equal('MIT:archivespace:MC.0044', json['id'])
8181
end
8282
end
8383

8484
test 'pagination' do
8585
token = JwtWrapper.encode(user_id: users(:yo).id)
8686
VCR.use_cassette('pagination') do
8787
get '/api/v1/search?q=marvel',
88-
headers: { 'Authorization': "Bearer #{token}" }
88+
headers: { Authorization: "Bearer #{token}" }
8989
assert_equal(200, response.status)
9090
json = JSON.parse(response.body)
9191
assert_equal(394, json['hits'])
9292
assert_equal('002312360', json['results'][0]['id'])
9393

9494
get '/api/v1/search?q=marvel&page=2',
95-
headers: { 'Authorization': "Bearer #{token}" }
95+
headers: { Authorization: "Bearer #{token}" }
9696
assert_equal(200, response.status)
9797
json = JSON.parse(response.body)
9898
assert_equal(394, json['hits'])
9999
assert_equal('002611432', json['results'][0]['id'])
100100

101101
get '/api/v1/search?q=marvel&page=10',
102-
headers: { 'Authorization': "Bearer #{token}" }
102+
headers: { Authorization: "Bearer #{token}" }
103103
assert_equal(200, response.status)
104104
json = JSON.parse(response.body)
105105
assert_equal(394, json['hits'])
106106
assert_equal('002602394', json['results'][0]['id'])
107107

108108
get '/api/v1/search?q=marvel&page=25',
109-
headers: { 'Authorization': "Bearer #{token}" }
109+
headers: { Authorization: "Bearer #{token}" }
110110
assert_equal(200, response.status)
111111
json = JSON.parse(response.body)
112112
assert_equal(394, json['hits'])
113113
assert_equal('Invalid page parameter: requested page past last result',
114114
json['error'])
115115

116116
get '/api/v1/search?q=marvel&page=400',
117-
headers: { 'Authorization': "Bearer #{token}" }
117+
headers: { Authorization: "Bearer #{token}" }
118118
assert_equal(400, response.status)
119119
json = JSON.parse(response.body)
120120
assert_nil(json['hits'])
@@ -127,21 +127,21 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
127127
token = JwtWrapper.encode(user_id: users(:yo).id)
128128
VCR.use_cassette('filtering multiple values') do
129129
get '/api/v1/search?q=marvel',
130-
headers: { 'Authorization': "Bearer #{token}" }
130+
headers: { Authorization: "Bearer #{token}" }
131131
assert_equal(200, response.status)
132132
json = JSON.parse(response.body)
133133
assert_equal(394, json['hits'])
134134
assert_equal('002312360', json['results'][0]['id'])
135135

136136
get '/api/v1/search?q=marvel&subject[]=Graphic%20Novels.',
137-
headers: { 'Authorization': "Bearer #{token}" }
137+
headers: { Authorization: "Bearer #{token}" }
138138
assert_equal(200, response.status)
139139
json = JSON.parse(response.body)
140140
assert_equal(20, json['hits'])
141141
assert_equal('002295630', json['results'][0]['id'])
142142

143143
get '/api/v1/search?q=marvel&subject[]=Graphic%20Novels.&subject[]=science%20fiction%20comic%20books,%20strips,%20etc.',
144-
headers: { 'Authorization': "Bearer #{token}" }
144+
headers: { Authorization: "Bearer #{token}" }
145145
assert_equal(200, response.status)
146146
json = JSON.parse(response.body)
147147
assert_equal(11, json['hits'])
@@ -153,14 +153,14 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
153153
token = JwtWrapper.encode(user_id: users(:yo).id)
154154
VCR.use_cassette('filtering single value') do
155155
get '/api/v1/search?q=marvel',
156-
headers: { 'Authorization': "Bearer #{token}" }
156+
headers: { Authorization: "Bearer #{token}" }
157157
assert_equal(200, response.status)
158158
json = JSON.parse(response.body)
159159
assert_equal(394, json['hits'])
160160
assert_equal('002312360', json['results'][0]['id'])
161161

162162
get '/api/v1/search?q=marvel&literary_form=fiction',
163-
headers: { 'Authorization': "Bearer #{token}" }
163+
headers: { Authorization: "Bearer #{token}" }
164164
assert_equal(200, response.status)
165165
json = JSON.parse(response.body)
166166
assert_equal(227, json['hits'])

0 commit comments

Comments
 (0)