defra_ruby_area 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c70a4243bf5fb3a988ebf2dee7ff7757758f605
4
- data.tar.gz: 6730c29aedc4227152101469d4325c36024f9522
3
+ metadata.gz: d3eb4a2d30e01743dfd2ae40c2ee664e9e0ac763
4
+ data.tar.gz: d1b991b186aeef08dc521ec3edc39b5c63ece0be
5
5
  SHA512:
6
- metadata.gz: 85798b2577feb39b9853390f0bf243f271c4d7657a45769d88a1a35fea8cd38202b2b7a2a2464ee66ddda00207edf659d21c0b3a9adfed6e56fbc0fe430873b4
7
- data.tar.gz: bd9622f05d43ae590337b841d9e99b4e7e82ab327014ef2b6642fa87746daa085dbeb6b4640f82aac6f89d8c9245c15413a770c5a868a2d84c89e06f703ad9c3
6
+ metadata.gz: 69a76107b6789950ffa4c022f3d604826c70964e831511e2cda325f0f18ffc9eb085c796c6f37b416b7c7a20d9d0b4e42dcd96349fc095c93ab168c204b6cb29
7
+ data.tar.gz: 3f6e75ffbce0fcb9f8d95f8d107167cf20e5affaa73b2c9d338546f5c67697f7f4b6d122d869aa0cf55949b75dc8739837efeaa773425a26c11e9bedd3f2c420
data/README.md CHANGED
@@ -40,7 +40,7 @@ response.error
40
40
  If the call is successful (the query did not error and a match was found) then
41
41
 
42
42
  - `successful?()` will be `true`
43
- - `area` will contain an instance of `DefraRuby::Area::Area`. It contains the code, short name and long name of the matching administrative boundary
43
+ - `area` will contain an instance of `DefraRuby::Area::Area`. It contains the area ID, area name, code, short name and long name of the matching administrative boundary
44
44
  - `error` will be `nil`
45
45
 
46
46
  If the call is unsuccessful (the query errored or no match was found) then
@@ -1,18 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "nokogiri"
4
+
3
5
  module DefraRuby
4
6
  module Area
5
7
  class Area
6
- attr_reader :code, :long_name, :short_name
8
+ attr_reader :area_id, :area_name, :code, :long_name, :short_name
9
+
10
+ def initialize(type_name, wfs_xml_response)
11
+ @type_name = type_name
12
+ @xml = wfs_xml_response
7
13
 
8
- def initialize(code, long_name, short_name)
9
- @code = code
10
- @long_name = long_name
11
- @short_name = short_name
14
+ validate
15
+ parse_xml
12
16
  end
13
17
 
14
18
  def matched?
15
- "#{@code}#{@long_name}#{@short_name}" != ""
19
+ "#{@area_name}#{@code}#{@long_name}#{@short_name}" != ""
20
+ end
21
+
22
+ private
23
+
24
+ def validate
25
+ validate_type_name
26
+ validate_xml
27
+ end
28
+
29
+ def validate_type_name
30
+ raise(ArgumentError, "type_name is invalid") unless @type_name && @type_name != ""
31
+ end
32
+
33
+ def validate_xml
34
+ raise(ArgumentError, "wfs_xml_response is invalid") unless @xml&.is_a?(Nokogiri::XML::Document)
35
+ end
36
+
37
+ def parse_xml
38
+ @area_id = @xml.xpath(response_xml_path(:area_id)).text.to_i
39
+ @area_name = @xml.xpath(response_xml_path(:area_name)).text
40
+ @code = @xml.xpath(response_xml_path(:code)).text
41
+ @long_name = @xml.xpath(response_xml_path(:long_name)).text
42
+ @short_name = @xml.xpath(response_xml_path(:short_name)).text
43
+ end
44
+
45
+ # XML path to the value we wish to extract in the WFS query response.
46
+ def response_xml_path(property)
47
+ "//wfs:FeatureCollection/gml:featureMember/#{@type_name}/ms:#{property}"
16
48
  end
17
49
 
18
50
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "nokogiri"
4
3
  require "rest-client"
5
4
 
6
5
  module DefraRuby
@@ -31,7 +30,7 @@ module DefraRuby
31
30
  url: url,
32
31
  timeout: DefraRuby::Area.configuration.timeout
33
32
  )
34
- area = parse_xml(response)
33
+ area = Area.new(type_name, Nokogiri::XML(response))
35
34
  raise NoMatchError unless area.matched?
36
35
 
37
36
  { area: area }
@@ -42,20 +41,6 @@ module DefraRuby
42
41
  "#{domain}/spatialdata/#{dataset}/wfs?#{url_params}"
43
42
  end
44
43
 
45
- def parse_xml(response)
46
- xml = Nokogiri::XML(response)
47
- Area.new(
48
- xml.xpath(response_xml_path(:code)).text,
49
- xml.xpath(response_xml_path(:long_name)).text,
50
- xml.xpath(response_xml_path(:short_name)).text
51
- )
52
- end
53
-
54
- # XML path to the value we wish to extract in the WFS query response.
55
- def response_xml_path(property)
56
- "//wfs:FeatureCollection/gml:featureMember/#{type_name}/ms:#{property}"
57
- end
58
-
59
44
  # Domain where the WFS is hosted
60
45
  def domain
61
46
  "https://environment.data.gov.uk"
@@ -130,10 +115,16 @@ module DefraRuby
130
115
  # https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType
131
116
  #
132
117
  # In our case the administrative boundary features contain a number of
133
- # properties, but we are only interested in +code+, +long_name+ and
134
- # +short_name+.
118
+ # properties, but we are only interested in
119
+ #
120
+ # - +area_id+
121
+ # - +area_name+
122
+ # - +code+
123
+ # - +long_name+
124
+ # - +short_name+
125
+ #
135
126
  def property_name
136
- "code,long_name,short_name"
127
+ "area_id,area_name,code,long_name,short_name"
137
128
  end
138
129
 
139
130
  # SRS stands for Spatial Reference System. It can also be known as a
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DefraRuby
4
4
  module Area
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-environment-agency-and-natural-england-public-face-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E,%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=code,long_name,short_name&typeName=ms:Administrative_Boundaries_Environment_Agency_and_Natural_England_Public_Face_Areas
5
+ uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-environment-agency-and-natural-england-public-face-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E,%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=area_id,area_name,code,long_name,short_name&typeName=ms:Administrative_Boundaries_Environment_Agency_and_Natural_England_Public_Face_Areas
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -23,7 +23,7 @@ http_interactions:
23
23
  Server:
24
24
  - nginx
25
25
  Date:
26
- - Fri, 09 Aug 2019 17:08:26 GMT
26
+ - Sun, 11 Aug 2019 15:53:34 GMT
27
27
  Content-Type:
28
28
  - application/xml
29
29
  Content-Length:
@@ -45,5 +45,5 @@ http_interactions:
45
45
  <ogc:ServiceException><![CDATA[Operator 'Intersects' can't parse geometry.]]></ogc:ServiceException>
46
46
  </ogc:ServiceExceptionReport>
47
47
  http_version:
48
- recorded_at: Fri, 09 Aug 2019 17:08:26 GMT
48
+ recorded_at: Sun, 11 Aug 2019 15:53:34 GMT
49
49
  recorded_with: VCR 4.0.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-environment-agency-and-natural-england-public-face-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E301233.0,221592.0%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=code,long_name,short_name&typeName=ms:Administrative_Boundaries_Environment_Agency_and_Natural_England_Public_Face_Areas
5
+ uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-environment-agency-and-natural-england-public-face-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E301233.0,221592.0%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=area_id,area_name,code,long_name,short_name&typeName=ms:Administrative_Boundaries_Environment_Agency_and_Natural_England_Public_Face_Areas
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -23,7 +23,7 @@ http_interactions:
23
23
  Server:
24
24
  - nginx
25
25
  Date:
26
- - Fri, 09 Aug 2019 17:08:26 GMT
26
+ - Sun, 11 Aug 2019 15:53:33 GMT
27
27
  Content-Type:
28
28
  - application/xml
29
29
  Content-Length:
@@ -48,5 +48,5 @@ http_interactions:
48
48
  </gml:boundedBy>
49
49
  </wfs:FeatureCollection>
50
50
  http_version:
51
- recorded_at: Fri, 09 Aug 2019 17:08:26 GMT
51
+ recorded_at: Sun, 11 Aug 2019 15:53:34 GMT
52
52
  recorded_with: VCR 4.0.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-environment-agency-and-natural-england-public-face-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E408602.61,257535.31%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=code,long_name,short_name&typeName=ms:Administrative_Boundaries_Environment_Agency_and_Natural_England_Public_Face_Areas
5
+ uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-environment-agency-and-natural-england-public-face-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E408602.61,257535.31%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=area_id,area_name,code,long_name,short_name&typeName=ms:Administrative_Boundaries_Environment_Agency_and_Natural_England_Public_Face_Areas
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -23,7 +23,7 @@ http_interactions:
23
23
  Server:
24
24
  - nginx
25
25
  Date:
26
- - Fri, 09 Aug 2019 17:08:33 GMT
26
+ - Sun, 11 Aug 2019 15:53:27 GMT
27
27
  Content-Type:
28
28
  - application/xml
29
29
  Content-Length:
@@ -58,5 +58,5 @@ http_interactions:
58
58
  </gml:featureMember>
59
59
  </wfs:FeatureCollection>
60
60
  http_version:
61
- recorded_at: Fri, 09 Aug 2019 17:08:34 GMT
61
+ recorded_at: Sun, 11 Aug 2019 15:53:28 GMT
62
62
  recorded_with: VCR 4.0.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E,%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=code,long_name,short_name&typeName=ms:Administrative_Boundaries_Water_Management_Areas
5
+ uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E,%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=area_id,area_name,code,long_name,short_name&typeName=ms:Administrative_Boundaries_Water_Management_Areas
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -23,7 +23,7 @@ http_interactions:
23
23
  Server:
24
24
  - nginx
25
25
  Date:
26
- - Fri, 09 Aug 2019 17:08:21 GMT
26
+ - Sun, 11 Aug 2019 15:53:35 GMT
27
27
  Content-Type:
28
28
  - application/xml
29
29
  Content-Length:
@@ -45,5 +45,5 @@ http_interactions:
45
45
  <ogc:ServiceException><![CDATA[Operator 'Intersects' can't parse geometry.]]></ogc:ServiceException>
46
46
  </ogc:ServiceExceptionReport>
47
47
  http_version:
48
- recorded_at: Fri, 09 Aug 2019 17:08:21 GMT
48
+ recorded_at: Sun, 11 Aug 2019 15:53:35 GMT
49
49
  recorded_with: VCR 4.0.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E301233.0,221592.0%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=code,long_name,short_name&typeName=ms:Administrative_Boundaries_Water_Management_Areas
5
+ uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E301233.0,221592.0%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=area_id,area_name,code,long_name,short_name&typeName=ms:Administrative_Boundaries_Water_Management_Areas
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -23,7 +23,7 @@ http_interactions:
23
23
  Server:
24
24
  - nginx
25
25
  Date:
26
- - Fri, 09 Aug 2019 17:08:14 GMT
26
+ - Sun, 11 Aug 2019 15:53:34 GMT
27
27
  Content-Type:
28
28
  - application/xml
29
29
  Content-Length:
@@ -48,5 +48,5 @@ http_interactions:
48
48
  </gml:boundedBy>
49
49
  </wfs:FeatureCollection>
50
50
  http_version:
51
- recorded_at: Fri, 09 Aug 2019 17:08:14 GMT
51
+ recorded_at: Sun, 11 Aug 2019 15:53:34 GMT
52
52
  recorded_with: VCR 4.0.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E408602.61,257535.31%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=code,long_name,short_name&typeName=ms:Administrative_Boundaries_Water_Management_Areas
5
+ uri: https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?Filter=(%3CFilter%3E%3CIntersects%3E%3CPropertyName%3ESHAPE%3C/PropertyName%3E%3Cgml:Point%3E%3Cgml:coordinates%3E408602.61,257535.31%3C/gml:coordinates%3E%3C/gml:Point%3E%3C/Intersects%3E%3C/Filter%3E)&REQUEST=GetFeature&SERVICE=WFS&SRSName=EPSG:27700&VERSION=1.0.0&propertyName=area_id,area_name,code,long_name,short_name&typeName=ms:Administrative_Boundaries_Water_Management_Areas
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -23,11 +23,11 @@ http_interactions:
23
23
  Server:
24
24
  - nginx
25
25
  Date:
26
- - Fri, 09 Aug 2019 17:08:14 GMT
26
+ - Sun, 11 Aug 2019 15:53:41 GMT
27
27
  Content-Type:
28
28
  - application/xml
29
29
  Content-Length:
30
- - '1530'
30
+ - '1607'
31
31
  Connection:
32
32
  - keep-alive
33
33
  Cache-Control:
@@ -52,11 +52,13 @@ http_interactions:
52
52
  <ms:long_name>Staffordshire Warwickshire and West Midlands</ms:long_name>
53
53
  <ms:short_name>Staffs Warks and West Mids</ms:short_name>
54
54
  <ms:code>STWKWM</ms:code>
55
+ <ms:area_id>29</ms:area_id>
56
+ <ms:area_name>Central</ms:area_name>
55
57
  <ms:st_area_shape_>6460280400.1</ms:st_area_shape_>
56
58
  <ms:st_perimeter_shape_>759189.708848595</ms:st_perimeter_shape_>
57
59
  </ms:Administrative_Boundaries_Water_Management_Areas>
58
60
  </gml:featureMember>
59
61
  </wfs:FeatureCollection>
60
62
  http_version:
61
- recorded_at: Fri, 09 Aug 2019 17:08:14 GMT
63
+ recorded_at: Sun, 11 Aug 2019 15:53:41 GMT
62
64
  recorded_with: VCR 4.0.0
@@ -1,26 +1,111 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
+ require "nokogiri"
4
5
 
5
6
  module DefraRuby
6
7
  module Area
7
8
  RSpec.describe Area do
8
- describe "#matched?" do
9
- context "when no attributes are populated" do
10
- let(:subject) { described_class.new(nil, nil, nil) }
9
+ let(:valid_type_name) { "ms:Administrative_Boundaries_Water_Management_Areas" }
10
+ let(:invalid_type_name) { "////" }
11
+ let(:no_match_type_name) { "ms:Marvel_Cinematic_Universe_Areas" }
11
12
 
12
- it "returns false" do
13
- expect(subject.matched?).to eq(false)
13
+ let(:valid_xml) { File.open("spec/fixtures/valid.xml") { |f| Nokogiri::XML(f) } }
14
+ let(:invalid_xml) { "foo" }
15
+ let(:no_match_xml) { File.open("spec/fixtures/no_match.xml") { |f| Nokogiri::XML(f) } }
16
+
17
+ let(:no_match_area) { described_class.new(valid_type_name, no_match_xml) }
18
+ let(:matched_area) { described_class.new(valid_type_name, valid_xml) }
19
+
20
+ describe "#initialize" do
21
+ context "when arguments are missing" do
22
+
23
+ context "and both arguments are missing" do
24
+ it "raises an ArgumentError" do
25
+ expect { described_class.new(nil, nil) }.to raise_error(ArgumentError, "type_name is invalid")
26
+ end
27
+ end
28
+
29
+ context "and `type_name` is missing" do
30
+ it "raises an ArgumentError" do
31
+ expect { described_class.new(nil, valid_xml) }.to raise_error(ArgumentError, "type_name is invalid")
32
+ end
33
+ end
34
+
35
+ context "and `wfs_xml_response` is missing" do
36
+ it "raises an ArgumentError" do
37
+ expect { described_class.new(valid_type_name, nil) }.to raise_error(ArgumentError, "wfs_xml_response is invalid")
38
+ end
39
+ end
40
+ end
41
+
42
+ context "when arguments are invalid" do
43
+
44
+ context "and passed an invalid Nokogiri::XML::Documentation instance" do
45
+ it "raises an error" do
46
+ expect { described_class.new(valid_type_name, invalid_xml) }.to raise_error(ArgumentError, "wfs_xml_response is invalid")
47
+ end
48
+ end
49
+
50
+ context "and passed an invalid type name" do
51
+ it "raises an error" do
52
+ expect { described_class.new(invalid_type_name, valid_xml) }.to raise_error(Nokogiri::XML::XPath::SyntaxError)
53
+ end
54
+ end
55
+ end
56
+
57
+ context "when passed valid arguments" do
58
+
59
+ context "and type name is recognised and there was a match" do
60
+ it "populates all an Area's attributes" do
61
+ subject = described_class.new(valid_type_name, valid_xml)
62
+
63
+ expect(subject.area_id).to eq(29)
64
+ expect(subject.area_name).to eq("Central")
65
+ expect(subject.code).to eq("STWKWM")
66
+ expect(subject.short_name).to eq("Staffs Warks and West Mids")
67
+ expect(subject.long_name).to eq("Staffordshire Warwickshire and West Midlands")
68
+ end
69
+ end
70
+
71
+ context "and type name does not match the xml" do
72
+ it "does not populate an Area's attributes" do
73
+ subject = described_class.new(no_match_type_name, valid_xml)
74
+
75
+ expect(subject.area_id).to eq(0)
76
+ expect(subject.area_name).to eq("")
77
+ expect(subject.code).to eq("")
78
+ expect(subject.short_name).to eq("")
79
+ expect(subject.long_name).to eq("")
80
+ end
81
+ end
82
+
83
+ context "and the WFS responded with no match" do
84
+ it "does not populate an Area's attributes" do
85
+ subject = described_class.new(valid_type_name, no_match_xml)
86
+
87
+ expect(subject.area_id).to eq(0)
88
+ expect(subject.area_name).to eq("")
89
+ expect(subject.code).to eq("")
90
+ expect(subject.short_name).to eq("")
91
+ expect(subject.long_name).to eq("")
92
+ end
14
93
  end
15
94
  end
16
95
  end
17
96
 
18
97
  describe "#matched?" do
19
- context "when at least one attribute is populated" do
20
- let(:subject) { described_class.new("foo", nil, nil) }
98
+ context "when no match was found" do
99
+
100
+ it "returns false" do
101
+ expect(no_match_area.matched?).to eq(false)
102
+ end
103
+ end
104
+
105
+ context "when a match was found" do
21
106
 
22
107
  it "returns true" do
23
- expect(subject.matched?).to eq(true)
108
+ expect(matched_area.matched?).to eq(true)
24
109
  end
25
110
  end
26
111
  end
@@ -6,7 +6,11 @@ module DefraRuby
6
6
  module Area
7
7
  RSpec.describe Response do
8
8
  subject(:response) { described_class.new(response_exe) }
9
- let(:successful) { -> { { area: Area.new("GFY", "Planet Gallifrey", "Gallifrey") } } }
9
+
10
+ let(:valid_type_name) { "ms:Administrative_Boundaries_Water_Management_Areas" }
11
+ let(:valid_xml) { File.open("spec/fixtures/valid.xml") { |f| Nokogiri::XML(f) } }
12
+
13
+ let(:successful) { -> { { area: Area.new(valid_type_name, valid_xml) } } }
10
14
  let(:errored) { -> { raise "Boom!" } }
11
15
 
12
16
  describe "#successful?" do
@@ -18,7 +22,7 @@ module DefraRuby
18
22
  end
19
23
  end
20
24
 
21
- context "when the response don't throw an error" do
25
+ context "when the response doesn't throw an error" do
22
26
  let(:response_exe) { successful }
23
27
 
24
28
  it "returns true" do
@@ -41,7 +45,7 @@ module DefraRuby
41
45
 
42
46
  it "returns an area" do
43
47
  expect(response.area).to be_instance_of(Area)
44
- expect(response.area.short_name).to eq("Gallifrey")
48
+ expect(response.area.short_name).to eq("Staffs Warks and West Mids")
45
49
  end
46
50
  end
47
51
  end
data/spec/examples.txt CHANGED
@@ -1,24 +1,32 @@
1
1
  example_id | status | run_time |
2
2
  -------------------------------------------------------------------------------- | ------ | --------------- |
3
- ./spec/defra_ruby/area/area_spec.rb[1:1:1:1] | passed | 0.00027 seconds |
4
- ./spec/defra_ruby/area/area_spec.rb[1:2:1:1] | passed | 0.00024 seconds |
5
- ./spec/defra_ruby/area/configuration_spec.rb[1:1] | passed | 0.00337 seconds |
6
- ./spec/defra_ruby/area/response_spec.rb[1:1:1:1] | passed | 0.00025 seconds |
7
- ./spec/defra_ruby/area/response_spec.rb[1:1:2:1] | passed | 0.00412 seconds |
3
+ ./spec/defra_ruby/area/area_spec.rb[1:1:1:1:1] | passed | 0.00032 seconds |
4
+ ./spec/defra_ruby/area/area_spec.rb[1:1:1:2:1] | passed | 0.00916 seconds |
5
+ ./spec/defra_ruby/area/area_spec.rb[1:1:1:3:1] | passed | 0.00064 seconds |
6
+ ./spec/defra_ruby/area/area_spec.rb[1:1:2:1:1] | passed | 0.0003 seconds |
7
+ ./spec/defra_ruby/area/area_spec.rb[1:1:2:2:1] | passed | 0.00063 seconds |
8
+ ./spec/defra_ruby/area/area_spec.rb[1:1:3:1:1] | passed | 0.00196 seconds |
9
+ ./spec/defra_ruby/area/area_spec.rb[1:1:3:2:1] | passed | 0.00152 seconds |
10
+ ./spec/defra_ruby/area/area_spec.rb[1:1:3:3:1] | passed | 0.00145 seconds |
11
+ ./spec/defra_ruby/area/area_spec.rb[1:2:1:1] | passed | 0.001 seconds |
12
+ ./spec/defra_ruby/area/area_spec.rb[1:2:2:1] | passed | 0.00297 seconds |
13
+ ./spec/defra_ruby/area/configuration_spec.rb[1:1] | passed | 0.00014 seconds |
14
+ ./spec/defra_ruby/area/response_spec.rb[1:1:1:1] | passed | 0.00019 seconds |
15
+ ./spec/defra_ruby/area/response_spec.rb[1:1:2:1] | passed | 0.00102 seconds |
8
16
  ./spec/defra_ruby/area/response_spec.rb[1:2:1:1] | passed | 0.00017 seconds |
9
- ./spec/defra_ruby/area/response_spec.rb[1:2:2:1] | passed | 0.00725 seconds |
10
- ./spec/defra_ruby/area/response_spec.rb[1:3:1:1] | passed | 0.0029 seconds |
11
- ./spec/defra_ruby/area/response_spec.rb[1:3:2:1] | passed | 0.00023 seconds |
12
- ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:1:1] | passed | 0.03685 seconds |
13
- ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:1:1] | passed | 0.06383 seconds |
14
- ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:2:1] | passed | 0.03793 seconds |
15
- ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:3:1:1] | passed | 0.06819 seconds |
16
- ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:3:2:1] | passed | 0.02928 seconds |
17
- ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:1:1] | passed | 0.03675 seconds |
18
- ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:1:1] | passed | 0.03188 seconds |
19
- ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:2:1] | passed | 0.03399 seconds |
20
- ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:3:1:1] | passed | 0.02733 seconds |
21
- ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:3:2:1] | passed | 0.04418 seconds |
22
- ./spec/defra_ruby/area_spec.rb[1:1:1] | passed | 0.00637 seconds |
23
- ./spec/defra_ruby/area_spec.rb[1:2:1:1] | passed | 0.00344 seconds |
24
- ./spec/defra_ruby/area_spec.rb[1:2:2:1] | passed | 0.00018 seconds |
17
+ ./spec/defra_ruby/area/response_spec.rb[1:2:2:1] | passed | 0.00153 seconds |
18
+ ./spec/defra_ruby/area/response_spec.rb[1:3:1:1] | passed | 0.00015 seconds |
19
+ ./spec/defra_ruby/area/response_spec.rb[1:3:2:1] | passed | 0.001 seconds |
20
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:1:1] | passed | 7.1 seconds |
21
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:1:1] | passed | 0.18395 seconds |
22
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:2:1] | passed | 6.23 seconds |
23
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:3:1:1] | passed | 0.03068 seconds |
24
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:3:2:1] | passed | 0.03346 seconds |
25
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:1:1] | passed | 5.59 seconds |
26
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:1:1] | passed | 0.4264 seconds |
27
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:2:1] | passed | 0.39163 seconds |
28
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:3:1:1] | passed | 0.03075 seconds |
29
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:3:2:1] | passed | 0.04335 seconds |
30
+ ./spec/defra_ruby/area_spec.rb[1:1:1] | passed | 0.01054 seconds |
31
+ ./spec/defra_ruby/area_spec.rb[1:2:1:1] | passed | 0.00278 seconds |
32
+ ./spec/defra_ruby/area_spec.rb[1:2:2:1] | passed | 0.00334 seconds |
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ms="https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?service=wfs%26version=1.0.0%26request=DescribeFeatureType">
3
+ <gml:boundedBy>
4
+ <gml:Box srsName="EPSG:27700">
5
+ <gml:coordinates>0,0,0,0</gml:coordinates>
6
+ </gml:Box>
7
+ </gml:boundedBy>
8
+ </wfs:FeatureCollection>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ms="https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs https://environment.data.gov.uk/spatialdata/administrative-boundaries-water-management-areas/wfs?service=wfs%26version=1.0.0%26request=DescribeFeatureType">
3
+ <gml:boundedBy>
4
+ <gml:Box srsName="EPSG:27700">
5
+ <gml:coordinates>0,0,0,0</gml:coordinates>
6
+ </gml:Box>
7
+ </gml:boundedBy>
8
+ <gml:featureMember>
9
+ <ms:Administrative_Boundaries_Water_Management_Areas fid="Administrative_Boundaries_Water_Management_Areas.15">
10
+ <ms:OBJECTID>15</ms:OBJECTID>
11
+ <ms:long_name>Staffordshire Warwickshire and West Midlands</ms:long_name>
12
+ <ms:short_name>Staffs Warks and West Mids</ms:short_name>
13
+ <ms:code>STWKWM</ms:code>
14
+ <ms:area_id>29</ms:area_id>
15
+ <ms:area_name>Central</ms:area_name>
16
+ <ms:st_area_shape_>6460280400.1</ms:st_area_shape_>
17
+ <ms:st_perimeter_shape_>759189.708848595</ms:st_perimeter_shape_>
18
+ </ms:Administrative_Boundaries_Water_Management_Areas>
19
+ </gml:featureMember>
20
+ </wfs:FeatureCollection>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_area
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-10 00:00:00.000000000 Z
11
+ date: 2019-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -214,6 +214,8 @@ files:
214
214
  - spec/defra_ruby/area/services/water_management_area_service_spec.rb
215
215
  - spec/defra_ruby/area_spec.rb
216
216
  - spec/examples.txt
217
+ - spec/fixtures/no_match.xml
218
+ - spec/fixtures/valid.xml
217
219
  - spec/spec_helper.rb
218
220
  - spec/support/defra_ruby_area.rb
219
221
  - spec/support/dotenv.rb
@@ -267,3 +269,5 @@ test_files:
267
269
  - spec/support/pry.rb
268
270
  - spec/support/dotenv.rb
269
271
  - spec/support/shared_examples/handle_request_errors.rb
272
+ - spec/fixtures/no_match.xml
273
+ - spec/fixtures/valid.xml