pupa 0.1.11 → 0.2.0

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/.yardopts +0 -1
  6. data/Gemfile +1 -3
  7. data/LICENSE +1 -1
  8. data/PERFORMANCE.md +1 -1
  9. data/README.md +19 -23
  10. data/Rakefile +2 -2
  11. data/lib/pupa.rb +0 -1
  12. data/lib/pupa/models/concerns/timestamps.rb +1 -1
  13. data/lib/pupa/processor/connection.rb +1 -1
  14. data/lib/pupa/processor/connection_adapters/mongodb_adapter.rb +5 -5
  15. data/lib/pupa/processor/connection_adapters/postgresql_adapter.rb +1 -1
  16. data/lib/pupa/processor/document_store/file_store.rb +2 -0
  17. data/lib/pupa/refinements/faraday_middleware.rb +3 -1
  18. data/lib/pupa/version.rb +1 -1
  19. data/pupa.gemspec +9 -9
  20. data/spec/models/area_spec.rb +1 -1
  21. data/spec/models/concerns/contactable_spec.rb +8 -8
  22. data/spec/models/concerns/identifiable_spec.rb +7 -7
  23. data/spec/models/concerns/linkable_spec.rb +3 -3
  24. data/spec/models/concerns/nameable_spec.rb +3 -3
  25. data/spec/models/concerns/sourceable_spec.rb +3 -3
  26. data/spec/models/concerns/timestamps_spec.rb +4 -4
  27. data/spec/models/contact_detail_list_spec.rb +6 -6
  28. data/spec/models/identifier_list_spec.rb +2 -2
  29. data/spec/models/membership_spec.rb +3 -3
  30. data/spec/models/model_spec.rb +32 -32
  31. data/spec/models/motion_spec.rb +1 -1
  32. data/spec/models/organization_spec.rb +3 -3
  33. data/spec/models/person_spec.rb +3 -3
  34. data/spec/models/post_spec.rb +2 -2
  35. data/spec/models/vote_event_spec.rb +8 -8
  36. data/spec/models/vote_spec.rb +1 -1
  37. data/spec/processor/client_spec.rb +4 -4
  38. data/spec/processor/connection_adapters/mongodb_adapter_spec.rb +8 -8
  39. data/spec/processor/connection_adapters/postgresql_adapter_spec.rb +1 -62
  40. data/spec/processor/connection_adapters/sqlite_adapter_spec.rb +5 -0
  41. data/spec/processor/connection_spec.rb +2 -2
  42. data/spec/processor/document_store/file_store_spec.rb +19 -19
  43. data/spec/processor/document_store/redis_store_spec.rb +18 -18
  44. data/spec/processor/document_store_spec.rb +2 -2
  45. data/spec/processor/middleware/logger_spec.rb +7 -7
  46. data/spec/processor/middleware/parse_json_spec.rb +1 -1
  47. data/spec/processor/yielder_spec.rb +4 -4
  48. data/spec/processor_spec.rb +41 -41
  49. data/spec/runner_spec.rb +9 -9
  50. data/spec/spec_helper.rb +9 -1
  51. data/spec/support/shared_examples_for_connection_adapters.rb +66 -0
  52. metadata +38 -35
  53. data/USAGE +0 -1
@@ -15,20 +15,20 @@ describe Pupa::Concerns::Nameable do
15
15
  describe '#other_names' do
16
16
  it 'should symbolize keys' do
17
17
  object.other_names = [{'name' => 'Mr. Ziggy Q. Public, Esq.', 'note' => 'Birth name'}]
18
- object.other_names.should == [{name: 'Mr. Ziggy Q. Public, Esq.', note: 'Birth name'}]
18
+ expect(object.other_names).to eq([{name: 'Mr. Ziggy Q. Public, Esq.', note: 'Birth name'}])
19
19
  end
20
20
  end
21
21
 
22
22
  describe '#add_name' do
23
23
  it 'should add a name' do
24
24
  object.add_name('Mr. Ziggy Q. Public, Esq.', start_date: '1920-01', end_date: '1949-12-31', note: 'Birth name', family_name: 'Public', given_name: 'John', additional_name: 'Quinlan', honorific_prefix: 'Mr.', honorific_suffix: 'Esq.')
25
- object.other_names.should == [{name: 'Mr. Ziggy Q. Public, Esq.', start_date: '1920-01', end_date: '1949-12-31', note: 'Birth name', family_name: 'Public', given_name: 'John', additional_name: 'Quinlan', honorific_prefix: 'Mr.', honorific_suffix: 'Esq.'}]
25
+ expect(object.other_names).to eq([{name: 'Mr. Ziggy Q. Public, Esq.', start_date: '1920-01', end_date: '1949-12-31', note: 'Birth name', family_name: 'Public', given_name: 'John', additional_name: 'Quinlan', honorific_prefix: 'Mr.', honorific_suffix: 'Esq.'}])
26
26
  end
27
27
 
28
28
  it 'should not add a name without a name' do
29
29
  object.add_name(nil)
30
30
  object.add_name('')
31
- object.other_names.blank?.should == true
31
+ expect(object.other_names.blank?).to eq(true)
32
32
  end
33
33
  end
34
34
  end
@@ -15,20 +15,20 @@ describe Pupa::Concerns::Sourceable do
15
15
  describe '#sources' do
16
16
  it 'should symbolize keys' do
17
17
  object.sources = [{'url' => 'http://example.com', 'note' => 'homepage'}]
18
- object.sources.should == [{url: 'http://example.com', note: 'homepage'}]
18
+ expect(object.sources).to eq([{url: 'http://example.com', note: 'homepage'}])
19
19
  end
20
20
  end
21
21
 
22
22
  describe '#add_source' do
23
23
  it 'should add a source' do
24
24
  object.add_source('http://example.com', note: 'homepage')
25
- object.sources.should == [{url: 'http://example.com', note: 'homepage'}]
25
+ expect(object.sources).to eq([{url: 'http://example.com', note: 'homepage'}])
26
26
  end
27
27
 
28
28
  it 'should not add a source without a url' do
29
29
  object.add_source(nil)
30
30
  object.add_source('')
31
- object.sources.blank?.should == true
31
+ expect(object.sources.blank?).to eq(true)
32
32
  end
33
33
  end
34
34
  end
@@ -20,14 +20,14 @@ describe Pupa::Concerns::Timestamps do
20
20
  it 'should set created_at and updated_at on create' do
21
21
  object = klass.new
22
22
  object.save
23
- object.created_at.should be_within(1).of(Time.now.utc)
24
- object.updated_at.should be_within(1).of(Time.now.utc)
23
+ expect(object.created_at).to be_within(1).of(Time.now.utc)
24
+ expect(object.updated_at).to be_within(1).of(Time.now.utc)
25
25
  end
26
26
 
27
27
  it 'should set updated_at on save' do
28
28
  object = klass.new(created_at: Time.new(2000))
29
29
  object.save
30
- object.created_at.should == Time.new(2000)
31
- object.updated_at.should be_within(1).of(Time.now.utc)
30
+ expect(object.created_at).to eq(Time.new(2000))
31
+ expect(object.updated_at).to be_within(1).of(Time.now.utc)
32
32
  end
33
33
  end
@@ -28,31 +28,31 @@ describe Pupa::ContactDetailList do
28
28
 
29
29
  describe '#address' do
30
30
  it 'should return the first postal address' do
31
- object.address.should == 'first'
31
+ expect(object.address).to eq('first')
32
32
  end
33
33
 
34
34
  it 'should return nil if no postal addresses' do
35
- Pupa::ContactDetailList.new.address.should == nil
35
+ expect(Pupa::ContactDetailList.new.address).to eq(nil)
36
36
  end
37
37
  end
38
38
 
39
39
  describe '#email' do
40
40
  it 'should return the first email address' do
41
- object.email.should == 'first'
41
+ expect(object.email).to eq('first')
42
42
  end
43
43
 
44
44
  it 'should return nil if no email addresses' do
45
- Pupa::ContactDetailList.new.email.should == nil
45
+ expect(Pupa::ContactDetailList.new.email).to eq(nil)
46
46
  end
47
47
  end
48
48
 
49
49
  describe '#find_by_type' do
50
50
  it 'should return the value of the first contact detail matching the type' do
51
- object.find_by_type('custom').should == 'content'
51
+ expect(object.find_by_type('custom')).to eq('content')
52
52
  end
53
53
 
54
54
  it 'should return nil if no contact detail matches the type' do
55
- Pupa::ContactDetailList.new.find_by_type('custom').should == nil
55
+ expect(Pupa::ContactDetailList.new.find_by_type('custom')).to eq(nil)
56
56
  end
57
57
  end
58
58
  end
@@ -16,11 +16,11 @@ describe Pupa::IdentifierList do
16
16
 
17
17
  describe '#find_by_scheme' do
18
18
  it 'should return the first identifier matching the scheme' do
19
- object.find_by_scheme('ISIN').should == 'US0123456789'
19
+ expect(object.find_by_scheme('ISIN')).to eq('US0123456789')
20
20
  end
21
21
 
22
22
  it 'should return nil if no identifier matches the scheme' do
23
- Pupa::IdentifierList.new.find_by_scheme('ISIN').should == nil
23
+ expect(Pupa::IdentifierList.new.find_by_scheme('ISIN')).to eq(nil)
24
24
  end
25
25
  end
26
26
  end
@@ -13,18 +13,18 @@ describe Pupa::Membership do
13
13
 
14
14
  describe '#to_s' do
15
15
  it 'should return a human-readable string' do
16
- object.to_s.should == 'john-q-public in abc-inc'
16
+ expect(object.to_s).to eq('john-q-public in abc-inc')
17
17
  end
18
18
  end
19
19
 
20
20
  describe '#fingerprint' do
21
21
  it 'should return the fingerprint' do
22
- object.fingerprint.should == {
22
+ expect(object.fingerprint).to eq({
23
23
  '$or' => [
24
24
  {label: "Kitchen assistant at Joe's Diner", person_id: 'john-q-public', organization_id: 'abc-inc', end_date: '1971-12-31'},
25
25
  {person_id: 'john-q-public', organization_id: 'abc-inc', post_id: 'abc-inc-kitchen-assistant', end_date: '1971-12-31'},
26
26
  ],
27
- }
27
+ })
28
28
  end
29
29
  end
30
30
  end
@@ -39,20 +39,20 @@ describe Pupa::Model do
39
39
  describe '.dump' do
40
40
  it 'should add properties' do
41
41
  [:_id, :_type, :extras, :name, :label, :founding_date, :inactive, :label_id, :manager_id, :links].each do |property|
42
- Music::Band.properties.to_a.should include(property)
42
+ expect(Music::Band.properties.to_a).to include(property)
43
43
  end
44
44
  end
45
45
  end
46
46
 
47
47
  describe '.foreign_key' do
48
48
  it 'should add foreign keys' do
49
- Music::Band.foreign_keys.to_a.should == [:label_id, :manager_id]
49
+ expect(Music::Band.foreign_keys.to_a).to eq([:label_id, :manager_id])
50
50
  end
51
51
  end
52
52
 
53
53
  describe '.foreign_object' do
54
54
  it 'should add foreign objects' do
55
- Music::Band.foreign_objects.to_a.should == [:label]
55
+ expect(Music::Band.foreign_objects.to_a).to eq([:label])
56
56
  end
57
57
  end
58
58
 
@@ -72,7 +72,7 @@ describe Pupa::Model do
72
72
  end
73
73
 
74
74
  it 'should accept a hash' do
75
- Music::Band.json_schema.should == {
75
+ expect(Music::Band.json_schema).to eq({
76
76
  '$schema' => 'http://json-schema.org/draft-03/schema#',
77
77
  'properties' => {
78
78
  'links' => {
@@ -86,41 +86,41 @@ describe Pupa::Model do
86
86
  },
87
87
  },
88
88
  },
89
- }
89
+ })
90
90
  end
91
91
 
92
92
  it 'should accept an absolute path' do
93
- File.should_receive(:read).and_return('{}')
94
- klass_with_absolute_path.json_schema.should == {}
93
+ expect(File).to receive(:read).and_return('{}')
94
+ expect(klass_with_absolute_path.json_schema).to eq({})
95
95
  end
96
96
 
97
97
  it 'should accept a relative path' do
98
- File.should_receive(:read).and_return('{}')
99
- klass_with_relative_path.json_schema.should == {}
98
+ expect(File).to receive(:read).and_return('{}')
99
+ expect(klass_with_relative_path.json_schema).to eq({})
100
100
  end
101
101
  end
102
102
 
103
103
  describe '#initialize' do
104
104
  it 'should set the _type' do
105
- object._type.should == 'music/band'
105
+ expect(object._type).to eq('music/band')
106
106
  end
107
107
 
108
108
  it 'should set the _id' do
109
- object._id.should match(/\A[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/)
109
+ expect(object._id).to match(/\A[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/)
110
110
  end
111
111
 
112
112
  it 'should set properties' do
113
- object.name.should == 'Moderat'
114
- object.label.should == {name: 'Mute'}
115
- object.inactive.should == false
116
- object.manager_id.should == '1'
117
- object.links.should == [{url: 'http://moderat.fm/'}]
113
+ expect(object.name).to eq('Moderat')
114
+ expect(object.label).to eq({name: 'Mute'})
115
+ expect(object.inactive).to eq(false)
116
+ expect(object.manager_id).to eq('1')
117
+ expect(object.links).to eq([{url: 'http://moderat.fm/'}])
118
118
  end
119
119
  end
120
120
 
121
121
  describe '#[]' do
122
122
  it 'should get a property' do
123
- object[:name].should == 'Moderat'
123
+ expect(object[:name]).to eq('Moderat')
124
124
  end
125
125
 
126
126
  it 'should raise an error if the class is missing the property' do
@@ -131,7 +131,7 @@ describe Pupa::Model do
131
131
  describe '#[]=' do
132
132
  it 'should set a property' do
133
133
  object[:name] = 'Apparat'
134
- object[:name].should == 'Apparat'
134
+ expect(object[:name]).to eq('Apparat')
135
135
  end
136
136
 
137
137
  it 'should raise an error if the class is missing the property' do
@@ -142,38 +142,38 @@ describe Pupa::Model do
142
142
  describe '#_id=' do
143
143
  it 'should set the _id' do
144
144
  object._id = '1'
145
- object._id.should == '1'
145
+ expect(object._id).to eq('1')
146
146
  end
147
147
 
148
148
  it 'should coerce the _id to a string' do
149
149
  object._id = BSON::ObjectId.new
150
- object._id.should be_a(String)
150
+ expect(object._id).to be_a(String)
151
151
  end
152
152
  end
153
153
 
154
154
  describe '#links' do
155
155
  it 'should symbolize keys' do
156
156
  object.extras = {'age' => 10}
157
- object.extras.should == {age: 10}
157
+ expect(object.extras).to eq({age: 10})
158
158
  end
159
159
  end
160
160
 
161
161
  describe '#add_extra' do
162
162
  it 'should add an extra property' do
163
163
  object.add_extra(:age, 10)
164
- object.extras.should == {age: 10}
164
+ expect(object.extras).to eq({age: 10})
165
165
  end
166
166
  end
167
167
 
168
168
  describe '#fingerprint' do
169
169
  it 'should return the fingerprint' do
170
- object.fingerprint.should == {_type: 'music/band', name: 'Moderat', inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
170
+ expect(object.fingerprint).to eq({_type: 'music/band', name: 'Moderat', inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]})
171
171
  end
172
172
  end
173
173
 
174
174
  describe '#foreign_properties' do
175
175
  it 'should return the foreign keys and foreign objects' do
176
- object.foreign_properties.should == {label: {name: 'Mute'}, manager_id: '1'}
176
+ expect(object.foreign_properties).to eq({label: {name: 'Mute'}, manager_id: '1'})
177
177
  end
178
178
  end
179
179
 
@@ -185,11 +185,11 @@ describe Pupa::Model do
185
185
  end
186
186
 
187
187
  it 'should do nothing if the schema is not set' do
188
- klass_without_schema.new.validate!.should == nil
188
+ expect(klass_without_schema.new.validate!).to eq(nil)
189
189
  end
190
190
 
191
191
  it 'should return true if the object is valid' do
192
- object.validate!.should == true
192
+ expect(object.validate!).to eq(true)
193
193
  end
194
194
 
195
195
  it 'should raise an error if the object is invalid' do
@@ -200,29 +200,29 @@ describe Pupa::Model do
200
200
 
201
201
  describe '#to_h' do
202
202
  it 'should include all properties by default' do
203
- object.to_h.should == {_id: object._id, _type: 'music/band', name: 'Moderat', label: {name: 'Mute'}, inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
203
+ expect(object.to_h).to eq({_id: object._id, _type: 'music/band', name: 'Moderat', label: {name: 'Mute'}, inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]})
204
204
  end
205
205
 
206
206
  it 'should exclude foreign objects if persisting' do
207
- object.to_h(persist: true).should == {_id: object._id, _type: 'music/band', name: 'Moderat', inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
207
+ expect(object.to_h(persist: true)).to eq({_id: object._id, _type: 'music/band', name: 'Moderat', inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]})
208
208
  end
209
209
 
210
210
  it 'should not include blank properties' do
211
- object.to_h.should_not have_key(:founding_date)
211
+ expect(object.to_h).not_to have_key(:founding_date)
212
212
  end
213
213
 
214
214
  it 'should include false properties' do
215
- object.to_h.should have_key(:inactive)
215
+ expect(object.to_h).to have_key(:inactive)
216
216
  end
217
217
  end
218
218
 
219
219
  describe '#==' do
220
220
  it 'should return true if two objects are equal' do
221
- object.should == Music::Band.new(properties)
221
+ expect(object).to eq(Music::Band.new(properties))
222
222
  end
223
223
 
224
224
  it 'should return false if two objects are unequal' do
225
- object.should_not == Music::Band.new(properties.merge(name: 'Apparat'))
225
+ expect(object).not_to eq(Music::Band.new(properties.merge(name: 'Apparat')))
226
226
  end
227
227
  end
228
228
  end
@@ -7,7 +7,7 @@ describe Pupa::Motion do
7
7
 
8
8
  describe '#to_s' do
9
9
  it 'should return a human-readable string' do
10
- object.to_s.should == 'That the Bill is to be read a second time. in house-of-commons'
10
+ expect(object.to_s).to eq('That the Bill is to be read a second time. in house-of-commons')
11
11
  end
12
12
  end
13
13
  end
@@ -7,18 +7,18 @@ describe Pupa::Organization do
7
7
 
8
8
  describe '#to_s' do
9
9
  it 'should return a human-readable string' do
10
- object.to_s.should == 'ABC, Inc.'
10
+ expect(object.to_s).to eq('ABC, Inc.')
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#fingerprint' do
15
15
  it 'should return the fingerprint' do
16
- object.fingerprint.should == {
16
+ expect(object.fingerprint).to eq({
17
17
  '$or' => [
18
18
  {'name' => 'ABC, Inc.', classification: 'Corporation', parent_id: 'holding-company-corp'},
19
19
  {'other_names.name' => 'ABC, Inc.', classification: 'Corporation', parent_id: 'holding-company-corp'},
20
20
  ],
21
- }
21
+ })
22
22
  end
23
23
  end
24
24
  end
@@ -7,18 +7,18 @@ describe Pupa::Person do
7
7
 
8
8
  describe '#to_s' do
9
9
  it 'should return a human-readable string' do
10
- object.to_s.should == 'Mr. John Q. Public, Esq.'
10
+ expect(object.to_s).to eq('Mr. John Q. Public, Esq.')
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#fingerprint' do
15
15
  it 'should return the fingerprint' do
16
- object.fingerprint.should == {
16
+ expect(object.fingerprint).to eq({
17
17
  '$or' => [
18
18
  {'name' => 'Mr. John Q. Public, Esq.'},
19
19
  {'other_names.name' => 'Mr. John Q. Public, Esq.'},
20
20
  ],
21
- }
21
+ })
22
22
  end
23
23
  end
24
24
  end
@@ -7,13 +7,13 @@ describe Pupa::Post do
7
7
 
8
8
  describe '#to_s' do
9
9
  it 'should return a human-readable string' do
10
- object.to_s.should == 'Chef in abc-inc'
10
+ expect(object.to_s).to eq('Chef in abc-inc')
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#fingerprint' do
15
15
  it 'should return the fingerprint' do
16
- object.fingerprint.should == {label: 'Chef', organization_id: 'abc-inc', end_date: '2010'}
16
+ expect(object.fingerprint).to eq({label: 'Chef', organization_id: 'abc-inc', end_date: '2010'})
17
17
  end
18
18
  end
19
19
  end
@@ -7,53 +7,53 @@ describe Pupa::VoteEvent do
7
7
 
8
8
  describe '#to_s' do
9
9
  it 'should return a human-readable string' do
10
- object.to_s.should == '1 in legislative-council-of-hong-kong'
10
+ expect(object.to_s).to eq('1 in legislative-council-of-hong-kong')
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#group_results' do
15
15
  it 'should symbolize keys' do
16
16
  object.group_results = [{'result' => 'pass', 'group' => {'name' => 'Functional constituencies'}}]
17
- object.group_results.should == [{result: 'pass', group: {name: 'Functional constituencies'}}]
17
+ expect(object.group_results).to eq([{result: 'pass', group: {name: 'Functional constituencies'}}])
18
18
  end
19
19
  end
20
20
 
21
21
  describe '#add_group_result' do
22
22
  it 'should add a group result' do
23
23
  object.add_group_result('pass', group: {name: 'Functional constituencies'})
24
- object.group_results.should == [{result: 'pass', group: {name: 'Functional constituencies'}}]
24
+ expect(object.group_results).to eq([{result: 'pass', group: {name: 'Functional constituencies'}}])
25
25
  end
26
26
 
27
27
  it 'should not add a group result without a result' do
28
28
  object.add_group_result(nil)
29
29
  object.add_group_result('')
30
- object.group_results.blank?.should == true
30
+ expect(object.group_results.blank?).to eq(true)
31
31
  end
32
32
  end
33
33
 
34
34
  describe '#counts' do
35
35
  it 'should symbolize keys' do
36
36
  object.counts = [{'option' => 'yes', 'value' => 9, 'group' => {'name' => 'Functional constituencies'}}]
37
- object.counts.should == [{option: 'yes', value: 9, group: {name: 'Functional constituencies'}}]
37
+ expect(object.counts).to eq([{option: 'yes', value: 9, group: {name: 'Functional constituencies'}}])
38
38
  end
39
39
  end
40
40
 
41
41
  describe '#add_count' do
42
42
  it 'should add a count' do
43
43
  object.add_count('yes', 9, group: {name: 'Functional constituencies'})
44
- object.counts.should == [{option: 'yes', value: 9, group: {name: 'Functional constituencies'}}]
44
+ expect(object.counts).to eq([{option: 'yes', value: 9, group: {name: 'Functional constituencies'}}])
45
45
  end
46
46
 
47
47
  it 'should not add a contact detail without an option' do
48
48
  object.add_count(nil, 9)
49
49
  object.add_count('', 9)
50
- object.counts.blank?.should == true
50
+ expect(object.counts.blank?).to eq(true)
51
51
  end
52
52
 
53
53
  it 'should not add a contact detail without a value' do
54
54
  object.add_count('yes', nil)
55
55
  object.add_count('yes', '')
56
- object.counts.blank?.should == true
56
+ expect(object.counts.blank?).to eq(true)
57
57
  end
58
58
  end
59
59
  end