qa 5.5.2 → 5.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/app/controllers/qa/terms_controller.rb +34 -23
- data/app/services/qa/pagination_service.rb +586 -0
- data/config/initializers/mime_types.rb +4 -0
- data/config/routes.rb +4 -0
- data/lib/qa/authorities/local/file_based_authority.rb +3 -2
- data/lib/qa/version.rb +1 -1
- data/spec/controllers/terms_controller_spec.rb +102 -1
- data/spec/fixtures/authorities/authority_U.yml +13 -0
- data/spec/lib/authorities/{file_based_authority_spec.rb → local/file_based_authority_spec.rb} +11 -0
- data/spec/lib/authorities/{mysql_table_based_authority_spec.rb → local/mysql_table_based_authority_spec.rb} +0 -0
- data/spec/lib/authorities/{table_based_authority_spec.rb → local/table_based_authority_spec.rb} +0 -0
- data/spec/lib/authorities/local_spec.rb +3 -1
- data/spec/services/pagination_service_spec.rb +682 -0
- metadata +20 -14
@@ -69,7 +69,7 @@ describe Qa::TermsController, type: :controller do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def search(_arg1, _arg2)
|
72
|
-
|
72
|
+
[]
|
73
73
|
end
|
74
74
|
end
|
75
75
|
Qa::Authorities::Local.register_subauthority('two_args', 'Qa::Authorities::Local::TwoArgs')
|
@@ -122,6 +122,78 @@ describe Qa::TermsController, type: :controller do
|
|
122
122
|
expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
|
123
123
|
end
|
124
124
|
end
|
125
|
+
|
126
|
+
context 'when pagination parameters are set' do
|
127
|
+
context 'and no format is specified' do
|
128
|
+
let(:params) do
|
129
|
+
{
|
130
|
+
q: "Berry", vocab: "loc", subauthority: "names",
|
131
|
+
page_limit: "5", page_offset: "6"
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns a subset of results as an Array<Hash>" do
|
136
|
+
# query without pagination is expected to return 20 results
|
137
|
+
get :search, params: params
|
138
|
+
expect(response).to be_successful
|
139
|
+
expect(response.content_type.split(';')).to include 'application/json'
|
140
|
+
results = JSON.parse(response.body)
|
141
|
+
expect(results.count).to eq 5
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'and format is specified as :jsonapi' do
|
146
|
+
let(:params) do
|
147
|
+
{
|
148
|
+
q: "Berry", vocab: "loc", subauthority: "names",
|
149
|
+
page_limit: "5", page_offset: "6", format: "jsonapi"
|
150
|
+
}
|
151
|
+
end
|
152
|
+
let(:total_num_found) { "20" } # query without pagination is expected to return 20 results
|
153
|
+
|
154
|
+
it "returns a subset of results in the JSON-API format" do
|
155
|
+
get :search, params: params
|
156
|
+
expect(response).to be_successful
|
157
|
+
expect(response.content_type.split(';')).to include 'application/vnd.api+json'
|
158
|
+
json_api_response = JSON.parse(response.body)
|
159
|
+
expect(json_api_response['data'].count).to eq 5
|
160
|
+
end
|
161
|
+
|
162
|
+
it "sets meta['page'] stats" do
|
163
|
+
get :search, params: params
|
164
|
+
json_api_response = JSON.parse(response.body)
|
165
|
+
expect(json_api_response["meta"]["page"]["page_offset"]).to eq "6"
|
166
|
+
expect(json_api_response["meta"]["page"]["page_limit"]).to eq "5"
|
167
|
+
expect(json_api_response["meta"]["page"]["actual_page_size"]).to eq "5"
|
168
|
+
expect(json_api_response["meta"]["page"]["total_num_found"]).to eq total_num_found
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'sets links with prev and next having values' do
|
172
|
+
get :search, params: params
|
173
|
+
|
174
|
+
base_url = request.base_url
|
175
|
+
url_path = request.path
|
176
|
+
first_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=1"
|
177
|
+
second_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=6"
|
178
|
+
third_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=11"
|
179
|
+
fourth_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=16"
|
180
|
+
last_page = fourth_page
|
181
|
+
|
182
|
+
json_api_response = JSON.parse(response.body)
|
183
|
+
expect(json_api_response['links']["self"]).to eq second_page
|
184
|
+
expect(json_api_response['links']["first"]).to eq first_page
|
185
|
+
expect(json_api_response['links']["prev"]).to eq first_page
|
186
|
+
expect(json_api_response['links']["next"]).to eq third_page
|
187
|
+
expect(json_api_response['links']["last"]).to eq last_page
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'does not include errors' do
|
191
|
+
get :search, params: params
|
192
|
+
json_api_response = JSON.parse(response.body)
|
193
|
+
expect(json_api_response.key?('errors')).to eq false
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
125
197
|
end
|
126
198
|
|
127
199
|
context "assign_fast" do
|
@@ -253,4 +325,33 @@ describe Qa::TermsController, type: :controller do
|
|
253
325
|
end
|
254
326
|
end
|
255
327
|
end
|
328
|
+
|
329
|
+
describe "#fetch" do
|
330
|
+
context "with supported authorities" do
|
331
|
+
it "returns an individual state term" do
|
332
|
+
get :fetch, params: { vocab: "local", subauthority: "authority_U", uri: "http://my.domain/terms/a2" }
|
333
|
+
expect(response).to be_successful
|
334
|
+
end
|
335
|
+
|
336
|
+
context 'when cors headers are enabled' do
|
337
|
+
before do
|
338
|
+
Qa.config.enable_cors_headers
|
339
|
+
end
|
340
|
+
it 'Access-Control-Allow-Origin is *' do
|
341
|
+
get :fetch, params: { vocab: "local", subauthority: "authority_U", uri: "http://my.domain/terms/a2" }
|
342
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context 'when cors headers are disabled' do
|
347
|
+
before do
|
348
|
+
Qa.config.disable_cors_headers
|
349
|
+
end
|
350
|
+
it 'Access-Control-Allow-Origin is not present' do
|
351
|
+
get :fetch, params: { vocab: "local", subauthority: "authority_U", uri: "http://my.domain/terms/a2" }
|
352
|
+
expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
256
357
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
:terms:
|
2
|
+
- :id: A1
|
3
|
+
:term: Abc Term A1
|
4
|
+
:uri: http://my.domain/terms/a1
|
5
|
+
:active: true
|
6
|
+
- :id: A2
|
7
|
+
:term: Term A2
|
8
|
+
:uri: http://my.domain/terms/a2
|
9
|
+
:active: false
|
10
|
+
- :id: A3
|
11
|
+
:term: Abc Term A3
|
12
|
+
:uri: http://my.domain/terms/a3
|
13
|
+
:active: true
|
data/spec/lib/authorities/{file_based_authority_spec.rb → local/file_based_authority_spec.rb}
RENAMED
@@ -5,6 +5,7 @@ describe Qa::Authorities::Local::FileBasedAuthority do
|
|
5
5
|
let(:authority_b) { Qa::Authorities::Local.subauthority_for("authority_B") }
|
6
6
|
let(:authority_c) { Qa::Authorities::Local.subauthority_for("authority_C") }
|
7
7
|
let(:authority_d) { Qa::Authorities::Local.subauthority_for("authority_D") }
|
8
|
+
let(:authority_u) { Qa::Authorities::Local.subauthority_for("authority_U") }
|
8
9
|
|
9
10
|
describe "#all" do
|
10
11
|
let(:expected) do
|
@@ -35,6 +36,16 @@ describe Qa::Authorities::Local::FileBasedAuthority do
|
|
35
36
|
expect(authority_c.all).to eq(expected)
|
36
37
|
end
|
37
38
|
end
|
39
|
+
context "when terms have uris" do
|
40
|
+
let(:expected) do
|
41
|
+
[{ 'id' => "A1", 'label' => "Abc Term A1", 'active' => true, 'uri' => 'http://my.domain/terms/a1' },
|
42
|
+
{ 'id' => "A2", 'label' => "Term A2", 'active' => false, 'uri' => 'http://my.domain/terms/a2' },
|
43
|
+
{ 'id' => "A3", 'label' => "Abc Term A3", 'active' => true, 'uri' => 'http://my.domain/terms/a3' }]
|
44
|
+
end
|
45
|
+
it "sets the id to be same as the label" do
|
46
|
+
expect(authority_u.all).to eq(expected)
|
47
|
+
end
|
48
|
+
end
|
38
49
|
context "YAML file is malformed" do
|
39
50
|
it "raises an error" do
|
40
51
|
expect { authority_d.all }.to raise_error Psych::SyntaxError
|
File without changes
|
data/spec/lib/authorities/{table_based_authority_spec.rb → local/table_based_authority_spec.rb}
RENAMED
File without changes
|
@@ -33,7 +33,9 @@ describe Qa::Authorities::Local do
|
|
33
33
|
|
34
34
|
describe "#names" do
|
35
35
|
it "returns a list of yaml files" do
|
36
|
-
expect(described_class.names)
|
36
|
+
expect(described_class.names)
|
37
|
+
.to include("authority_A", "authority_B", "authority_C",
|
38
|
+
"authority_D", "authority_U", "states")
|
37
39
|
end
|
38
40
|
|
39
41
|
context "when the path doesn't exist" do
|