hdo-storting-importer 0.0.8 → 0.0.9

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.
Files changed (50) hide show
  1. data/Gemfile +1 -1
  2. data/Rakefile +0 -1
  3. data/features/convert.feature +97 -79
  4. data/hdo-storting-importer.gemspec +5 -0
  5. data/lib/hdo/storting_importer/category.rb +16 -56
  6. data/lib/hdo/storting_importer/cli.rb +6 -34
  7. data/lib/hdo/storting_importer/committee.rb +13 -24
  8. data/lib/hdo/storting_importer/converter.rb +4 -9
  9. data/lib/hdo/storting_importer/district.rb +12 -24
  10. data/lib/hdo/storting_importer/fusion_table.rb +52 -0
  11. data/lib/hdo/storting_importer/has_json_schema.rb +85 -0
  12. data/lib/hdo/storting_importer/issue.rb +29 -60
  13. data/lib/hdo/storting_importer/party.rb +13 -24
  14. data/lib/hdo/storting_importer/promise.rb +60 -55
  15. data/lib/hdo/storting_importer/proposition.rb +61 -0
  16. data/lib/hdo/storting_importer/representative.rb +37 -70
  17. data/lib/hdo/storting_importer/schema/category.json +28 -0
  18. data/lib/hdo/storting_importer/schema/committee.json +21 -0
  19. data/lib/hdo/storting_importer/schema/district.json +21 -0
  20. data/lib/hdo/storting_importer/schema/issue.json +62 -0
  21. data/lib/hdo/storting_importer/schema/party.json +21 -0
  22. data/lib/hdo/storting_importer/schema/promise.json +42 -0
  23. data/lib/hdo/storting_importer/schema/proposition.json +34 -0
  24. data/lib/hdo/storting_importer/schema/representative.json +61 -0
  25. data/lib/hdo/storting_importer/schema/vote.json +64 -0
  26. data/lib/hdo/storting_importer/schema.json +5 -0
  27. data/lib/hdo/storting_importer/util.rb +13 -11
  28. data/lib/hdo/storting_importer/version.rb +1 -1
  29. data/lib/hdo/storting_importer/vote.rb +46 -143
  30. data/lib/hdo/storting_importer.rb +12 -3
  31. data/spec/fixtures/output/categories.json +1 -0
  32. data/spec/fixtures/output/committees.json +1 -0
  33. data/spec/fixtures/output/districts.json +1 -0
  34. data/spec/fixtures/output/issues.json +1 -0
  35. data/spec/fixtures/output/parties.json +1 -0
  36. data/spec/fixtures/output/representatives.json +1 -0
  37. data/spec/fixtures/output/votes.json +1 -0
  38. data/spec/hdo/storting_importer/category_spec.rb +29 -33
  39. data/spec/hdo/storting_importer/committee_spec.rb +29 -16
  40. data/spec/hdo/storting_importer/converter_spec.rb +3 -3
  41. data/spec/hdo/storting_importer/district_spec.rb +27 -18
  42. data/spec/hdo/storting_importer/issue_spec.rb +44 -27
  43. data/spec/hdo/storting_importer/party_spec.rb +25 -16
  44. data/spec/hdo/storting_importer/promise_spec.rb +54 -40
  45. data/spec/hdo/storting_importer/proposition_spec.rb +44 -0
  46. data/spec/hdo/storting_importer/representative_spec.rb +73 -26
  47. data/spec/hdo/storting_importer/vote_spec.rb +73 -75
  48. data/spec/spec_helper.rb +21 -1
  49. metadata +95 -3
  50. data/.gitmodules +0 -3
@@ -34,35 +34,46 @@ module Hdo
34
34
  district.external_id.should == 'Ak'
35
35
  end
36
36
 
37
- it 'can serialize as HDO XML' do
38
- District.new("Ak", "Akershus").to_hdo_xml.should == <<-XML
39
- <district>
40
- <externalId>Ak</externalId>
41
- <name>Akershus</name>
42
- </district>
43
- XML
37
+ it 'can serialize as JSON' do
38
+ expected = <<-JSON
39
+ {
40
+ "kind": "hdo#district",
41
+ "externalId": "Ak",
42
+ "name": "Akershus"
43
+ }
44
+ JSON
45
+
46
+ District.new("Ak", "Akershus").to_json.should be_json(expected)
44
47
  end
45
48
 
46
- it 'can deserialize a HDO XML node' do
49
+ it 'can deserialize JSON' do
47
50
  orig = District.new("Ak", "Akershus")
48
- District.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
51
+ District.from_json(orig.to_json).should == orig
49
52
  end
50
53
 
51
- it 'can deserialize a HDO XML doc' do
52
- orig = District.new("Ak", "Akershus")
53
- District.from_hdo_doc(parse("<districts>#{orig.to_hdo_xml}</districts>")).should == [orig]
54
+ it 'can deserialize a JSON array' do
55
+ orig = [ District.new("Ak", "Akershus") ]
56
+ District.from_json(orig.to_json).should == orig
54
57
  end
55
58
 
56
- it 'has a type name' do
57
- District.type_name.should == 'district'
59
+ it 'fails if the given JSON is invalid' do
60
+ json = '{
61
+ "externalId": "1"
62
+ }'
63
+
64
+ expect { District.from_json(json) }.to raise_error(ValidationError)
65
+ end
66
+
67
+ it 'has a kind' do
68
+ District.kind.should == 'hdo#district'
58
69
  end
59
70
 
60
71
  it 'has a description' do
61
72
  District.description.should be_kind_of(String)
62
73
  end
63
74
 
64
- it 'has an XML example' do
65
- District.xml_example.should be_kind_of(String)
75
+ it 'has a JSON example' do
76
+ District.json_example.should be_kind_of(String)
66
77
  end
67
78
 
68
79
  it 'has a list of fields' do
@@ -73,8 +84,6 @@ module Hdo
73
84
  District.example.short_inspect.should be_kind_of(String)
74
85
  end
75
86
 
76
-
77
-
78
87
  end
79
88
  end
80
89
  end
@@ -69,47 +69,64 @@ module Hdo
69
69
  issue.type.should == 'alminneligsak'
70
70
  end
71
71
 
72
- it 'can serialize as HDO XML' do
73
- Issue.example.to_hdo_xml.should == <<-XML
74
- <issue>
75
- <externalId>53520</externalId>
76
- <summary>Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)</summary>
77
- <description>Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)</description>
78
- <type>alminneligsak</type>
79
- <status>mottatt</status>
80
- <lastUpdate>2012-04-20T00:00:00</lastUpdate>
81
- <reference>Prop. 90 S (2011-2012)</reference>
82
- <documentGroup>proposisjon</documentGroup>
83
- <committee>Transport- og kommunikasjonskomiteen</committee>
84
- <categories>
85
- <category>UTENRIKSSAKER</category>
86
- <category>TRAKTATER</category>
87
- <category>NORDISK SAMARBEID</category>
88
- </categories>
89
- </issue>
90
- XML
72
+ it 'can serialize as JSON' do
73
+ Issue.example.to_json.should be_json <<-JSON
74
+ {
75
+ "kind": "hdo#issue",
76
+ "externalId" : "53520",
77
+ "summary": "Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
78
+ "description": "Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
79
+ "type": "alminneligsak",
80
+ "status": "mottatt",
81
+ "lastUpdate": "2012-04-20T00:00:00",
82
+ "reference": "Prop. 90 S (2011-2012)",
83
+ "documentGroup": "proposisjon",
84
+ "committee": "Transport- og kommunikasjonskomiteen",
85
+ "categories": ["UTENRIKSSAKER", "TRAKTATER", "NORDISK SAMARBEID"]
86
+ }
87
+ JSON
91
88
  end
92
89
 
93
- it 'can deserialize an HDO XML node' do
90
+ it 'can deserialize JSON' do
94
91
  orig = Issue.example
95
- Issue.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
92
+ Issue.from_json(orig.to_json).should == orig
96
93
  end
97
94
 
98
95
  it 'can deserialize an HDO XML doc' do
99
- orig = Issue.example
100
- Issue.from_hdo_doc(parse("<issues>#{orig.to_hdo_xml}</issues>")).should == [orig]
96
+ orig = [Issue.example]
97
+ Issue.from_json(orig.to_json).should == orig
98
+ end
99
+
100
+ it 'fails if the given JSON is invalid' do
101
+ # summary is number.
102
+
103
+ json = '{
104
+ "kind": "hdo#issue",
105
+ "externalId" : "53520",
106
+ "summary": 1,
107
+ "description": "Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
108
+ "type": "alminneligsak",
109
+ "status": "mottatt",
110
+ "lastUpdate": "2012-04-20T00:00:00",
111
+ "reference": "Prop. 90 S (2011-2012)",
112
+ "documentGroup": "proposisjon",
113
+ "committee": "Transport- og kommunikasjonskomiteen",
114
+ "categories": ["UTENRIKSSAKER", "TRAKTATER", "NORDISK SAMARBEID"]
115
+ }'
116
+
117
+ expect { Issue.from_json(json) }.to raise_error(ValidationError)
101
118
  end
102
119
 
103
- it 'has a type name' do
104
- Issue.type_name.should == 'issue'
120
+ it 'has a kind' do
121
+ Issue.kind.should == 'hdo#issue'
105
122
  end
106
123
 
107
124
  it 'has a description' do
108
125
  Issue.description.should be_kind_of(String)
109
126
  end
110
127
 
111
- it 'has an XML example' do
112
- Issue.xml_example.should be_kind_of(String)
128
+ it 'has a JSON example' do
129
+ Issue.json_example.should be_kind_of(String)
113
130
  end
114
131
 
115
132
  it 'has a list of fields' do
@@ -32,35 +32,44 @@ module Hdo
32
32
  parties.map(&:name).should == ['Arbeiderpartiet', 'Fremskrittspartiet']
33
33
  end
34
34
 
35
- it 'can serialize as HDO XML' do
36
- Party.new("A", "Arbeiderpartiet").to_hdo_xml.should == <<-XML
37
- <party>
38
- <externalId>A</externalId>
39
- <name>Arbeiderpartiet</name>
40
- </party>
41
- XML
35
+ it 'can serialize as JSON' do
36
+ Party.new("A", "Arbeiderpartiet").to_json.should be_json <<-JSON
37
+ {
38
+ "kind": "hdo#party",
39
+ "externalId": "A",
40
+ "name": "Arbeiderpartiet"
41
+ }
42
+ JSON
42
43
  end
43
44
 
44
- it 'can deserialize a HDO XML node' do
45
+ it 'can deserialize JSON' do
45
46
  orig = Party.new('Sp', 'Senterpartiet')
46
- Party.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
47
+ Party.from_json(orig.to_json).should == orig
47
48
  end
48
49
 
49
- it 'can deserialize a HDO XML doc' do
50
- orig = Party.new('Sp', 'Senterpartiet')
51
- Party.from_hdo_doc(parse("<parties>#{orig.to_hdo_xml}</parties>")).should == [orig]
50
+ it 'can deserialize a JSON array' do
51
+ orig = [Party.new('Sp', 'Senterpartiet')]
52
+ Party.from_json(orig.to_json).should == orig
53
+ end
54
+
55
+ it 'fails if the given JSON is invalid' do
56
+ json = '{
57
+ "externalId": "1"
58
+ }'
59
+
60
+ expect { Party.from_json(json) }.to raise_error(ValidationError)
52
61
  end
53
62
 
54
- it 'has a type name' do
55
- Party.type_name.should == 'party'
63
+ it 'has a kind' do
64
+ Party.kind.should == 'hdo#party'
56
65
  end
57
66
 
58
67
  it 'has a description' do
59
68
  Party.description.should be_kind_of(String)
60
69
  end
61
70
 
62
- it 'has an XML example' do
63
- Party.xml_example.should be_kind_of(String)
71
+ it 'has a JSON example' do
72
+ Party.json_example.should be_kind_of(String)
64
73
  end
65
74
 
66
75
  it 'has a list of fields' do
@@ -33,44 +33,53 @@ module Hdo
33
33
  prom.page.should == '10'
34
34
  end
35
35
 
36
- it 'serializes to HDO XML' do
37
- Promise.example.to_hdo_xml.should == <<-XML
38
- <promise>
39
- <party>H</party>
40
- <general>true</general>
41
- <categories>
42
- <category>GRUNNSKOLE</category>
43
- </categories>
44
- <source>PP:8</source>
45
- <body>Stille strengere krav til orden og oppførsel for å hindre at uro ødelegger undervisningen.</body>
46
- </promise>
47
- XML
36
+ it 'serializes to JSON' do
37
+ Promise.example.to_json.should be_json <<-JSON
38
+ {
39
+ "kind": "hdo#promise",
40
+ "externalId": "1",
41
+ "party": "H",
42
+ "general": true,
43
+ "categories": ["GRUNNSKOLE"],
44
+ "source": "PP",
45
+ "page": 8,
46
+ "body": "Stille strengere krav til orden og oppførsel for å hindre at uro ødelegger undervisningen."
47
+ }
48
+ JSON
48
49
  end
49
50
 
50
- it 'deserializes from HDO XML' do
51
- promises = Promise.from_hdo_doc(parse(<<-XML))
52
- <promises>
53
- <promise>
54
- <party>H</party>
55
- <general>true</general>
56
- <categories>
57
- <category>GRUNNSKOLE</category>
58
- </categories>
59
- <source>PP:8</source>
60
- <body>Stille strengere krav til orden og oppførsel for å hindre at uro ødelegger undervisningen.</body>
61
- </promise>
62
- </promises>
63
- XML
64
-
65
- promises.size.should == 1
66
- promise = promises.first
67
-
68
- promise.party.should == "H"
69
- promise.should be_general
70
- promise.categories.should == ["GRUNNSKOLE"]
71
- promise.source.should == "PP"
72
- promise.page.should == "8"
73
- promise.body.should == "Stille strengere krav til orden og oppførsel for å hindre at uro ødelegger undervisningen."
51
+ it 'deserializes from JSON' do
52
+ orig = Promise.example
53
+ Promise.from_json(orig.to_json).should == orig
54
+ end
55
+
56
+ it 'deserializes from a JSON array' do
57
+ orig = [Promise.example]
58
+ Promise.from_json(orig.to_json).should == orig
59
+ end
60
+
61
+ it 'deserializes from hash with externalId missing' do
62
+ pr = Promise.example
63
+ pr.external_id = nil
64
+
65
+ Promise.from_json(pr.to_json).should be_kind_of(Promise)
66
+ end
67
+
68
+ it 'fails if the given JSON is invalid' do
69
+ # missing general
70
+
71
+ json = '
72
+ {
73
+ "kind": "hdo#promise",
74
+ "externalId": "1",
75
+ "party": "H",
76
+ "categories": ["GRUNNSKOLE"],
77
+ "source": "PP",
78
+ "page": 8,
79
+ "body": "Stille strengere krav til orden og oppførsel for å hindre at uro ødelegger undervisningen."
80
+ }'
81
+
82
+ expect { Promise.from_json(json) }.to raise_error(ValidationError)
74
83
  end
75
84
 
76
85
  it 'has a description' do
@@ -81,18 +90,23 @@ XML
81
90
  Promise.fields.should_not be_empty
82
91
  end
83
92
 
84
- it 'has a type name' do
85
- Promise.type_name.should == 'promise'
93
+ it 'has a kind' do
94
+ Promise.kind.should == 'hdo#promise'
86
95
  end
87
96
 
88
- it 'has a an XML example' do
89
- Promise.xml_example.should be_kind_of(String)
97
+ it 'has a JSON example' do
98
+ Promise.json_example.should be_kind_of(String)
90
99
  end
91
100
 
92
101
  it 'has #short_inspect' do
93
102
  Promise.example.short_inspect.should be_kind_of(String)
94
103
  end
95
104
 
105
+ it 'strips trailing space from the body' do
106
+ promise = Promise.new("Party", "Body ", true, ["æøå"], "PP", 8)
107
+ promise.body.should == "Body"
108
+ end
109
+
96
110
  it 'correctly upcases non-ASCII category names' do
97
111
  promise = Promise.new("Party", "Body", true, ["æøå"], "PP", 8)
98
112
  promise.categories.should == ["ÆØÅ"]
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ module Hdo
4
+ module StortingImporter
5
+ describe Proposition do
6
+
7
+ it 'can deserialize JSON' do
8
+ orig = Proposition.example
9
+ Proposition.from_json(orig.to_json).should == orig
10
+ end
11
+
12
+ it 'can deserialize a JSON array' do
13
+ orig = [Proposition.example]
14
+ Proposition.from_json(orig.to_json).should == orig
15
+ end
16
+
17
+ it 'fails if the given JSON is invalid' do
18
+ json = Proposition.example.to_hash
19
+ json.delete :description
20
+
21
+ expect { Proposition.from_json(json.to_json) }.to raise_error(ValidationError)
22
+ end
23
+
24
+ it 'has a kind' do
25
+ Proposition.kind.should == 'hdo#proposition'
26
+ end
27
+
28
+ it 'has a description' do
29
+ Proposition.description.should be_kind_of(String)
30
+ end
31
+
32
+ it 'has a JSON example' do
33
+ Proposition.json_example.should be_kind_of(String)
34
+ end
35
+
36
+ it 'has #short_inspect' do
37
+ str = Proposition.example.short_inspect
38
+ str.should be_kind_of(String)
39
+ str.should_not include("nil")
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ require 'spec_helper'
2
3
 
3
4
  module Hdo
4
5
  module StortingImporter
@@ -47,46 +48,92 @@ module Hdo
47
48
  rep.date_of_death.should == '0001-01-01T00:00:00'
48
49
  end
49
50
 
50
- it 'converts itself into HDO XML' do
51
+ it 'can be serialized to JSON' do
51
52
  rep = Representative.example
52
- rep.to_hdo_xml.should == <<-XML
53
- <representative>
54
- <externalId>ADA</externalId>
55
- <firstName>André Oktay</firstName>
56
- <lastName>Dahl</lastName>
57
- <gender>M</gender>
58
- <dateOfBirth>1975-07-07T00:00:00</dateOfBirth>
59
- <dateOfDeath>0001-01-01T00:00:00</dateOfDeath>
60
- <district>Akershus</district>
61
- <party>Høyre</party>
62
- <committees>
63
- <committee>Justiskomiteen</committee>
64
- </committees>
65
- <period>2011-2012</period>
66
- </representative>
67
- XML
53
+ rep.to_json.should be_json <<-JSON
54
+ {
55
+ "kind": "hdo#representative",
56
+ "externalId": "ADA",
57
+ "firstName": "André Oktay",
58
+ "lastName": "Dahl",
59
+ "gender": "M",
60
+ "dateOfBirth": "1975-07-07T00:00:00",
61
+ "dateOfDeath": "0001-01-01T00:00:00",
62
+ "district": "Akershus",
63
+ "party": "Høyre",
64
+ "committees": ["Justiskomiteen"],
65
+ "period": "2011-2012"
66
+ }
67
+ JSON
68
68
  end
69
69
 
70
- it 'can deserialize a HDO XML node' do
70
+ it 'can deserialize JSON' do
71
71
  rep = Representative.example
72
- Representative.from_hdo_node(parse(rep.to_hdo_xml)).should == rep
72
+ Representative.from_json(rep.to_json).should == rep
73
73
  end
74
74
 
75
- it 'can deserialize a HDO XML doc' do
76
- rep = Representative.example
77
- Representative.from_hdo_doc(parse("<representatives>#{rep.to_hdo_xml}</representatives>")).should == [rep]
75
+ it 'can deserialize a JSON array' do
76
+ reps = [Representative.example]
77
+ Representative.from_json(reps.to_json).should == reps
78
+ end
79
+
80
+ it 'raises if the JSON if voteResult is invalid' do
81
+ pending "find a validator that checks format"
82
+
83
+ invalid = <<-JSON
84
+ {
85
+ "kind": "hdo#representative",
86
+ "externalId": "ADA",
87
+ "firstName": "André Oktay",
88
+ "lastName": "Dahl",
89
+ "gender": "M",
90
+ "dateOfBirth": "1975-07-07T00:00:00",
91
+ "dateOfDeath": "0001-01-01T00:00:00",
92
+ "district": "Akershus",
93
+ "party": "Høyre",
94
+ "committees": ["Justiskomiteen"],
95
+ "period": "2011-2012",
96
+ "voteResult": "blah"
97
+ }
98
+
99
+ JSON
100
+
101
+ expect {
102
+ Representative.from_json(invalid)
103
+ }.to raise_error(ValidationError)
104
+ end
105
+
106
+ it 'raises if the JSON data is invalid' do
107
+ invalid = <<-JSON
108
+ {
109
+ "kind": "hdo#representative",
110
+ "externalId": "ADA",
111
+ "lastName": "Dahl",
112
+ "gender": "M",
113
+ "dateOfBirth": "1975-07-07T00:00:00",
114
+ "dateOfDeath": "0001-01-01T00:00:00",
115
+ "district": "Akershus",
116
+ "party": "Høyre",
117
+ "committees": ["Justiskomiteen"],
118
+ "period": "2011-2012"
119
+ }
120
+ JSON
121
+
122
+ expect {
123
+ Representative.from_json(invalid)
124
+ }.to raise_error(ValidationError)
78
125
  end
79
126
 
80
- it 'has a type name' do
81
- Representative.type_name.should == 'representative'
127
+ it 'has a kind' do
128
+ Representative.kind.should == 'hdo#representative'
82
129
  end
83
130
 
84
131
  it 'has a description' do
85
132
  Representative.description.should be_kind_of(String)
86
133
  end
87
134
 
88
- it 'has an XML example' do
89
- Representative.xml_example.should be_kind_of(String)
135
+ it 'has an JSON example' do
136
+ Representative.json_example.should be_kind_of(String)
90
137
  end
91
138
 
92
139
  it 'has a list of fields' do