qa 5.7.0 → 5.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/qa/terms_controller.rb +26 -24
- data/app/services/qa/pagination_service.rb +586 -0
- data/config/initializers/authorities.rb +3 -1
- data/config/initializers/linked_data_authorities.rb +3 -1
- data/config/initializers/mime_types.rb +4 -0
- data/lib/qa/version.rb +2 -1
- data/spec/controllers/terms_controller_spec.rb +73 -1
- data/spec/services/pagination_service_spec.rb +682 -0
- metadata +10 -6
data/lib/qa/version.rb
CHANGED
@@ -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
|