gds-api-adapters 10.4.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,11 @@ module GdsApi
9
9
  get_json!(search_url(:search, query, extra_params))
10
10
  end
11
11
 
12
+ def unified_search(args)
13
+ request_url = "#{base_url}/unified_search.json?#{Rack::Utils.build_nested_query(args)}"
14
+ get_json!(request_url)
15
+ end
16
+
12
17
  def advanced_search(args)
13
18
  raise ArgumentError.new("Args cannot be blank") if args.nil? || args.empty?
14
19
  request_path = "#{base_url}/advanced_search?#{Rack::Utils.build_nested_query(args)}"
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '10.4.0'
2
+ VERSION = '10.5.0'
3
3
  end
@@ -5,6 +5,7 @@ describe GdsApi::Rummager do
5
5
  before(:each) do
6
6
  stub_request(:get, /example.com\/search/).to_return(body: "[]")
7
7
  stub_request(:get, /example.com\/advanced_search/).to_return(body: "[]")
8
+ stub_request(:get, /example.com\/unified_search/).to_return(body: "[]")
8
9
  end
9
10
 
10
11
  it "should raise an exception if the service at the search URI returns a 500" do
@@ -140,4 +141,62 @@ describe GdsApi::Rummager do
140
141
  assert_requested :get, /order%5Bpublic_timestamp%5D=desc/
141
142
  end
142
143
 
144
+ # tests for unified search
145
+
146
+ it "#unified_search should raise an exception if the service at the search URI returns a 500" do
147
+ stub_request(:get, /example.com\/unified_search.json/).to_return(status: [500, "Internal Server Error"])
148
+ assert_raises(GdsApi::HTTPErrorResponse) do
149
+ GdsApi::Rummager.new("http://example.com").unified_search(q: "query")
150
+ end
151
+ end
152
+
153
+ it "#unified_search should raise an exception if the service at the search URI returns a 404" do
154
+ stub_request(:get, /example.com\/unified_search/).to_return(status: [404, "Not Found"])
155
+ assert_raises(GdsApi::HTTPNotFound) do
156
+ GdsApi::Rummager.new("http://example.com").unified_search(q: "query")
157
+ end
158
+ end
159
+
160
+ it "#unified_search should raise an exception if the service at the unified search URI returns a 400" do
161
+ stub_request(:get, /example.com\/unified_search/).to_return(
162
+ status: [400, "Bad Request"],
163
+ body: %q("error":"Filtering by \"coffee\" is not allowed"),
164
+ )
165
+ assert_raises(GdsApi::HTTPErrorResponse) do
166
+ GdsApi::Rummager.new("http://example.com").unified_search(q: "query", filter_coffee: "tea")
167
+ end
168
+ end
169
+
170
+ it "#unified_search should raise an exception if the service at the search URI times out" do
171
+ stub_request(:get, /example.com\/unified_search/).to_timeout
172
+ assert_raises(GdsApi::TimedOutException) do
173
+ GdsApi::Rummager.new("http://example.com").unified_search(q: "query")
174
+ end
175
+ end
176
+
177
+ it "#unified_search should return the search deserialized from json" do
178
+ search_results = [{"title" => "document-title"}]
179
+ stub_request(:get, /example.com\/unified_search/).to_return(body: search_results.to_json)
180
+ results = GdsApi::Rummager.new("http://example.com").unified_search(q: "query")
181
+ assert_equal search_results, results.to_hash
182
+ end
183
+
184
+ it "#unified_search should request the search results in JSON format" do
185
+ GdsApi::Rummager.new("http://example.com").unified_search(q: "query")
186
+
187
+ assert_requested :get, /.*/, headers: {"Accept" => "application/json"}
188
+ end
189
+
190
+ it "#unified_search should issue a request for all the params supplied" do
191
+ GdsApi::Rummager.new("http://example.com").unified_search(
192
+ q: "query & stuff",
193
+ filter_topics: ["1", "2"],
194
+ order: "-public_timestamp",
195
+ )
196
+
197
+ assert_requested :get, /q=query%20%26%20stuff/
198
+ assert_requested :get, /filter_topics%5B0%5D=1&filter_topics%5B1%5D=2/
199
+ assert_requested :get, /order=-public_timestamp/
200
+ end
201
+
143
202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.4.0
4
+ version: 10.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-31 00:00:00.000000000 Z
12
+ date: 2014-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -372,7 +372,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
372
372
  version: '0'
373
373
  segments:
374
374
  - 0
375
- hash: 227919718345110221
375
+ hash: -3888185947824795971
376
376
  required_rubygems_version: !ruby/object:Gem::Requirement
377
377
  none: false
378
378
  requirements:
@@ -381,7 +381,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
381
381
  version: '0'
382
382
  segments:
383
383
  - 0
384
- hash: 227919718345110221
384
+ hash: -3888185947824795971
385
385
  requirements: []
386
386
  rubyforge_project:
387
387
  rubygems_version: 1.8.23