gds-api-adapters 10.13.0 → 10.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,13 @@ module GdsApi
7
7
  module TestHelpers
8
8
  module BusinessSupportHelper
9
9
  def setup_business_support_stubs(endpoint, path)
10
- @stubbed_business_supports = {}
10
+ @stubbed_business_supports = []
11
11
  stub_request(:get, %r{\A#{endpoint}/#{path}\.json}).to_return do |request|
12
12
  if request.uri.query_values
13
- key = facet_key(request.uri.query_values)
14
- results = @stubbed_business_supports[key] || []
13
+ facets = sanitise_facets(request.uri.query_values)
14
+ results = stubs_for_facets(facets) || []
15
15
  else
16
- results = @stubbed_business_supports['default']
16
+ results = @stubbed_business_supports
17
17
  end
18
18
  {:body => plural_response_base.merge("results" => results, "total" => results.size).to_json}
19
19
  end
@@ -21,19 +21,34 @@ module GdsApi
21
21
  end
22
22
 
23
23
  def api_has_business_support(business_support, facets={})
24
- key = facet_key(facets)
25
- unless @stubbed_business_supports.has_key?(key)
26
- @stubbed_business_supports[key] = []
24
+ facets = sanitise_facets(facets)
25
+ if business_support.is_a?(Symbol)
26
+ bs_with_facets = facets.merge(:title => business_support)
27
+ else
28
+ bs_with_facets = facets.merge(business_support)
27
29
  end
28
- @stubbed_business_supports[key] << business_support
30
+ @stubbed_business_supports << bs_with_facets unless @stubbed_business_supports.include?(bs_with_facets)
29
31
  end
30
32
 
31
33
  private
32
34
 
33
- def facet_key(facets)
34
- key = 'default'
35
- key = facets.values.flatten.sort.hash.to_s if facets and !facets.empty?
36
- key
35
+ def stubs_for_facets(facets)
36
+ @stubbed_business_supports.select do |bs|
37
+ facet_matches = 0
38
+ facets.each do |k,v|
39
+ if bs[k] and (v & bs[k]).any?
40
+ facet_matches += 1
41
+ end
42
+ end
43
+ facet_matches == facets.keys.size
44
+ end
45
+ end
46
+
47
+ def sanitise_facets(facets)
48
+ Hash[facets.map{ |k, v|
49
+ v = v.split(',') if v.is_a?(String)
50
+ [k.to_sym, v]
51
+ }]
37
52
  end
38
53
  end
39
54
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '10.13.0'
2
+ VERSION = '10.14.0'
3
3
  end
@@ -15,12 +15,13 @@ describe GdsApi::BusinessSupportApi do
15
15
  it "should return all schemes when called with no facets" do
16
16
  business_support_api_has_schemes([:scheme1, :scheme2, :scheme3])
17
17
  response = @api.schemes
18
- assert_equal ["scheme1", "scheme2", "scheme3"], response['results']
18
+ assert_equal [{"title" => "scheme1"}, {"title" => "scheme2"}, {"title" => "scheme3"}], response['results']
19
19
  end
20
20
  it "should return schemes for applicable facets" do
21
21
  business_support_api_has_scheme(:scottish_manufacturing, {locations: 'scotland', sectors: 'manufacturing', support_types: 'grant,loan'})
22
22
  response = @api.schemes({locations: 'scotland', sectors: 'manufacturing', support_types: 'grant,loan'})
23
- assert_equal ["scottish_manufacturing"], response["results"]
23
+ assert_equal 1, response["results"].size
24
+ assert_equal "scottish_manufacturing", response["results"].first["title"]
24
25
  end
25
26
  it "should return an empty result when facets are not applicable" do
26
27
  business_support_api_has_scheme(:super_secret, {locations: 'the moon', sectors: 'espionage'})
@@ -620,7 +620,8 @@ describe GdsApi::ContentApi do
620
620
  response = @api.business_support_schemes(:locations => "england", :sectors => "farming").to_hash
621
621
 
622
622
  assert_equal 2, response["total"]
623
- assert_equal [s1, s3], response["results"]
623
+ assert_equal s1["title"], response["results"].first["title"]
624
+ assert_equal s3["title"], response["results"].last["title"]
624
625
  end
625
626
  end
626
627
  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.13.0
4
+ version: 10.14.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-05-29 00:00:00.000000000 Z
12
+ date: 2014-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
@@ -382,7 +382,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
382
382
  version: '0'
383
383
  segments:
384
384
  - 0
385
- hash: 4445085740245273405
385
+ hash: -4129704915142926265
386
386
  required_rubygems_version: !ruby/object:Gem::Requirement
387
387
  none: false
388
388
  requirements:
@@ -391,7 +391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
391
391
  version: '0'
392
392
  segments:
393
393
  - 0
394
- hash: 4445085740245273405
394
+ hash: -4129704915142926265
395
395
  requirements: []
396
396
  rubyforge_project:
397
397
  rubygems_version: 1.8.23