hdo-storting-importer 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,21 +31,25 @@ module Hdo
31
31
  data_source.should_receive(name).and_return(input_for(name))
32
32
 
33
33
  actual_output = converter.json_for(name)
34
- actual_output.should == output_for(name)
34
+ actual_output.should be_json(output_for(name))
35
35
  end
36
36
  }
37
37
 
38
38
  it "converts representatives" do
39
+ Date.stub(:today).and_return(Date.new(2012, 9, 20))
40
+
39
41
  data_source.should_receive(:representatives).and_return(input_for(:representatives))
40
42
  data_source.should_receive(:representatives_today).and_return(input_for(:representatives_today))
41
43
 
42
44
  actual = converter.json_for(:representatives)
43
45
  expected = output_for(:representatives)
44
46
 
45
- actual.should == expected
47
+ actual.should be_json(expected)
46
48
  end
47
49
 
48
50
  it "converts votes" do
51
+ Date.stub(:today).and_return(Date.new(2012, 9, 20))
52
+
49
53
  parsing_data_source.should_receive(:parliament_issues).and_return [mock(:external_id => 2175)]
50
54
 
51
55
  data_source.should_receive(:votes_for).and_return(input_for(:votes))
@@ -59,7 +63,7 @@ module Hdo
59
63
  actual = converter.json_for(:votes)
60
64
  expected = output_for(:votes)
61
65
 
62
- actual.should == expected
66
+ actual.should be_json(expected)
63
67
  end
64
68
 
65
69
  end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ module Hdo
5
+ module StortingImporter
6
+ describe PartyMembership do
7
+
8
+ it_behaves_like 'type with JSON schema'
9
+
10
+ it 'can serialize as JSON' do
11
+ str = PartyMembership.example.to_json
12
+ str.should be_json <<-JSON
13
+ {
14
+ "kind": "hdo#partyMembership",
15
+ "externalId": "A",
16
+ "startDate": "2009-09-01",
17
+ "endDate": "2013-08-01"
18
+ }
19
+ JSON
20
+ end
21
+
22
+ it 'can create a customized example' do
23
+ obj = PartyMembership.example('externalId' => 'foo')
24
+ obj.external_id.should == 'foo'
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -31,7 +31,7 @@ module Hdo
31
31
  </voteringsforslag>
32
32
  XML
33
33
 
34
- props = Proposition.from_storting_doc(parse(xml))
34
+ props = Proposition.from_storting_doc(parse(xml), Date.today)
35
35
  props.size.should == 1
36
36
 
37
37
  prop = props.first
@@ -73,7 +73,7 @@ module Hdo
73
73
  </voteringsforslag_oversikt>
74
74
  XML
75
75
 
76
- props = Proposition.from_storting_doc(parse(xml))
76
+ props = Proposition.from_storting_doc(parse(xml), Time.now)
77
77
  props.size.should == 1
78
78
 
79
79
  prop = props.first
@@ -34,6 +34,7 @@ module Hdo
34
34
  </parti>
35
35
  </representant>
36
36
  </representanter_liste>
37
+ <stortingsperiode_id>2009-2013</stortingsperiode_id>
37
38
  </representanter_oversikt>
38
39
  XML
39
40
 
@@ -45,7 +46,7 @@ module Hdo
45
46
  rep.last_name.should == 'Dahl'
46
47
  rep.gender.should == 'M'
47
48
  rep.district.should == 'Akershus'
48
- rep.party.should == 'Høyre'
49
+ rep.parties.should == [PartyMembership.from_hash('externalId' => 'H', 'startDate' => '2009-10-01', 'endDate' => '2013-09-30')]
49
50
  rep.external_id.should == 'ADA'
50
51
  rep.date_of_birth.should == '1975-07-07T00:00:00'
51
52
  rep.date_of_death.should == '0001-01-01T00:00:00'
@@ -63,9 +64,8 @@ module Hdo
63
64
  "dateOfBirth": "1975-07-07T00:00:00",
64
65
  "dateOfDeath": "0001-01-01T00:00:00",
65
66
  "district": "Akershus",
66
- "party": "Høyre",
67
- "committees": ["Justiskomiteen"],
68
- "period": "2011-2012"
67
+ "parties": [{"kind": "hdo#partyMembership", "externalId": "H", "startDate": "2011-10-01", "endDate": null}],
68
+ "committees": ["Justiskomiteen"]
69
69
  }
70
70
  JSON
71
71
  end
@@ -102,9 +102,8 @@ module Hdo
102
102
  "dateOfBirth": "1975-07-07T00:00:00",
103
103
  "dateOfDeath": "0001-01-01T00:00:00",
104
104
  "district": "Akershus",
105
- "party": "Høyre",
105
+ "parties": [{"kind": "hdo#partyMembership", "externalId": "H", "startDate": "2011-10-01", "endDate": null}],
106
106
  "committees": ["Justiskomiteen"],
107
- "period": "2011-2012",
108
107
  "voteResult": "for"
109
108
  }
110
109
  ],
@@ -124,9 +123,8 @@ module Hdo
124
123
  "dateOfBirth": "1975-07-07T00:00:00",
125
124
  "dateOfDeath": "0001-01-01T00:00:00",
126
125
  "district": "Akershus",
127
- "party": "Høyre",
128
- "committees": ["Justiskomiteen"],
129
- "period": "2011-2012"
126
+ "parties": [{"kind": "hdo#partyMembership", "externalId": "H", "startDate": "2011-10-01", "endDate": null}],
127
+ "committees": ["Justiskomiteen"]
130
128
  }
131
129
  }
132
130
  ]
data/spec/spec_helper.rb CHANGED
@@ -43,16 +43,25 @@ module Hdo
43
43
  def initialize(expected)
44
44
  @expected = MultiJson.decode(expected)
45
45
  end
46
+
46
47
  def matches?(target)
47
48
  @target = MultiJson.decode(target)
48
49
  @target.eql?(@expected)
49
50
  end
51
+
50
52
  def failure_message
51
- "expected #{@target.inspect} to be #{@expected}"
53
+ "expected #{@target.inspect} to be #{@expected}\n#{diff}"
52
54
  end
55
+
53
56
  def negative_failure_message
54
57
  "expected #{@target.inspect} not to be #{@expected}"
55
58
  end
59
+
60
+ private
61
+
62
+ def diff
63
+ RSpec::Expectations::Differ.new.diff_as_object(@target, @expected)
64
+ end
56
65
  end
57
66
 
58
67
  def be_json(expected)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdo-storting-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
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: 2012-09-25 00:00:00.000000000 Z
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -289,6 +289,7 @@ files:
289
289
  - lib/hdo/storting_importer/parliament_issue.rb
290
290
  - lib/hdo/storting_importer/parsing_data_source.rb
291
291
  - lib/hdo/storting_importer/party.rb
292
+ - lib/hdo/storting_importer/party_membership.rb
292
293
  - lib/hdo/storting_importer/promise.rb
293
294
  - lib/hdo/storting_importer/proposition.rb
294
295
  - lib/hdo/storting_importer/representative.rb
@@ -298,6 +299,7 @@ files:
298
299
  - lib/hdo/storting_importer/schema/district.json
299
300
  - lib/hdo/storting_importer/schema/parliament_issue.json
300
301
  - lib/hdo/storting_importer/schema/party.json
302
+ - lib/hdo/storting_importer/schema/party_membership.json
301
303
  - lib/hdo/storting_importer/schema/promise.json
302
304
  - lib/hdo/storting_importer/schema/proposition.json
303
305
  - lib/hdo/storting_importer/schema/representative.json
@@ -331,6 +333,7 @@ files:
331
333
  - spec/hdo/storting_importer/converter_spec.rb
332
334
  - spec/hdo/storting_importer/district_spec.rb
333
335
  - spec/hdo/storting_importer/parliament_issue_spec.rb
336
+ - spec/hdo/storting_importer/party_membership_spec.rb
334
337
  - spec/hdo/storting_importer/party_spec.rb
335
338
  - spec/hdo/storting_importer/promise_spec.rb
336
339
  - spec/hdo/storting_importer/proposition_spec.rb
@@ -392,6 +395,7 @@ test_files:
392
395
  - spec/hdo/storting_importer/converter_spec.rb
393
396
  - spec/hdo/storting_importer/district_spec.rb
394
397
  - spec/hdo/storting_importer/parliament_issue_spec.rb
398
+ - spec/hdo/storting_importer/party_membership_spec.rb
395
399
  - spec/hdo/storting_importer/party_spec.rb
396
400
  - spec/hdo/storting_importer/promise_spec.rb
397
401
  - spec/hdo/storting_importer/proposition_spec.rb