hdo-storting-importer 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Rakefile +0 -1
- data/features/convert.feature +97 -79
- data/hdo-storting-importer.gemspec +5 -0
- data/lib/hdo/storting_importer/category.rb +16 -56
- data/lib/hdo/storting_importer/cli.rb +6 -34
- data/lib/hdo/storting_importer/committee.rb +13 -24
- data/lib/hdo/storting_importer/converter.rb +4 -9
- data/lib/hdo/storting_importer/district.rb +12 -24
- data/lib/hdo/storting_importer/fusion_table.rb +52 -0
- data/lib/hdo/storting_importer/has_json_schema.rb +85 -0
- data/lib/hdo/storting_importer/issue.rb +29 -60
- data/lib/hdo/storting_importer/party.rb +13 -24
- data/lib/hdo/storting_importer/promise.rb +60 -55
- data/lib/hdo/storting_importer/proposition.rb +61 -0
- data/lib/hdo/storting_importer/representative.rb +37 -70
- data/lib/hdo/storting_importer/schema/category.json +28 -0
- data/lib/hdo/storting_importer/schema/committee.json +21 -0
- data/lib/hdo/storting_importer/schema/district.json +21 -0
- data/lib/hdo/storting_importer/schema/issue.json +62 -0
- data/lib/hdo/storting_importer/schema/party.json +21 -0
- data/lib/hdo/storting_importer/schema/promise.json +42 -0
- data/lib/hdo/storting_importer/schema/proposition.json +34 -0
- data/lib/hdo/storting_importer/schema/representative.json +61 -0
- data/lib/hdo/storting_importer/schema/vote.json +64 -0
- data/lib/hdo/storting_importer/schema.json +5 -0
- data/lib/hdo/storting_importer/util.rb +13 -11
- data/lib/hdo/storting_importer/version.rb +1 -1
- data/lib/hdo/storting_importer/vote.rb +46 -143
- data/lib/hdo/storting_importer.rb +12 -3
- data/spec/fixtures/output/categories.json +1 -0
- data/spec/fixtures/output/committees.json +1 -0
- data/spec/fixtures/output/districts.json +1 -0
- data/spec/fixtures/output/issues.json +1 -0
- data/spec/fixtures/output/parties.json +1 -0
- data/spec/fixtures/output/representatives.json +1 -0
- data/spec/fixtures/output/votes.json +1 -0
- data/spec/hdo/storting_importer/category_spec.rb +29 -33
- data/spec/hdo/storting_importer/committee_spec.rb +29 -16
- data/spec/hdo/storting_importer/converter_spec.rb +3 -3
- data/spec/hdo/storting_importer/district_spec.rb +27 -18
- data/spec/hdo/storting_importer/issue_spec.rb +44 -27
- data/spec/hdo/storting_importer/party_spec.rb +25 -16
- data/spec/hdo/storting_importer/promise_spec.rb +54 -40
- data/spec/hdo/storting_importer/proposition_spec.rb +44 -0
- data/spec/hdo/storting_importer/representative_spec.rb +73 -26
- data/spec/hdo/storting_importer/vote_spec.rb +73 -75
- data/spec/spec_helper.rb +21 -1
- metadata +95 -3
- 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
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
49
|
+
it 'can deserialize JSON' do
|
47
50
|
orig = District.new("Ak", "Akershus")
|
48
|
-
District.
|
51
|
+
District.from_json(orig.to_json).should == orig
|
49
52
|
end
|
50
53
|
|
51
|
-
it 'can deserialize a
|
52
|
-
orig = District.new("Ak", "Akershus")
|
53
|
-
District.
|
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 '
|
57
|
-
|
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
|
65
|
-
District.
|
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
|
73
|
-
Issue.example.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
90
|
+
it 'can deserialize JSON' do
|
94
91
|
orig = Issue.example
|
95
|
-
Issue.
|
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.
|
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
|
104
|
-
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
|
112
|
-
Issue.
|
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
|
36
|
-
Party.new("A", "Arbeiderpartiet").
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
45
|
+
it 'can deserialize JSON' do
|
45
46
|
orig = Party.new('Sp', 'Senterpartiet')
|
46
|
-
Party.
|
47
|
+
Party.from_json(orig.to_json).should == orig
|
47
48
|
end
|
48
49
|
|
49
|
-
it 'can deserialize a
|
50
|
-
orig = Party.new('Sp', 'Senterpartiet')
|
51
|
-
Party.
|
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
|
55
|
-
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
|
63
|
-
Party.
|
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
|
37
|
-
Promise.example.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
85
|
-
Promise.
|
93
|
+
it 'has a kind' do
|
94
|
+
Promise.kind.should == 'hdo#promise'
|
86
95
|
end
|
87
96
|
|
88
|
-
it 'has a
|
89
|
-
Promise.
|
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 '
|
51
|
+
it 'can be serialized to JSON' do
|
51
52
|
rep = Representative.example
|
52
|
-
rep.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
70
|
+
it 'can deserialize JSON' do
|
71
71
|
rep = Representative.example
|
72
|
-
Representative.
|
72
|
+
Representative.from_json(rep.to_json).should == rep
|
73
73
|
end
|
74
74
|
|
75
|
-
it 'can deserialize a
|
76
|
-
|
77
|
-
Representative.
|
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
|
81
|
-
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
|
89
|
-
Representative.
|
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
|