openc_bot 0.0.11 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,6 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
- # load 'lib/tasks/openc_bot.rake'
3
- # require 'lib/tasks'
4
2
  require 'openc_bot/tasks'
5
3
 
6
4
 
@@ -9,6 +7,10 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
9
7
 
10
8
  Dir.glob('lib/tasks/*.rake').each { |r| import r }
11
9
 
12
- require 'rspec/core/rake_task'
13
- task :default => :spec
14
- RSpec::Core::RakeTask.new
10
+ begin
11
+ require 'rspec/core/rake_task'
12
+ task :default => :spec
13
+ RSpec::Core::RakeTask.new
14
+ rescue LoadError
15
+ #do nothing
16
+ end
@@ -5,7 +5,7 @@ module OpencBot
5
5
  extend self
6
6
  def validate(datum)
7
7
  datum.kind_of?(Hash) and
8
- datum[:company][:name] and
8
+ not datum[:company][:name].nil? and
9
9
  not datum[:company][:name].strip.empty? and
10
10
  not datum[:source_url].strip.empty? and
11
11
  not datum[:data].empty? and
@@ -32,6 +32,12 @@ module OpencBot
32
32
  super(default_options.merge(entity_info))
33
33
  end
34
34
 
35
+ def save_entity!(entity_info)
36
+ return if entity_info.blank?
37
+ default_options = {:jurisdiction_code => inferred_jurisdiction_code}
38
+ super(default_options.merge(entity_info))
39
+ end
40
+
35
41
  def schema_name
36
42
  super || 'company-schema'
37
43
  end
@@ -102,13 +102,17 @@ module OpencBot
102
102
  # and then saving it. It assumes the methods for doing this (#fetch_datum and #process_datum) are implemented
103
103
  # in the module that includes this method.
104
104
  #
105
- # If no second argument is passed to this method, or false is passed, the
106
- # method will return the processed data hash
105
+ # If no second argument is passed to this method (i.e. output_as_json is not
106
+ # requested), or false is passed, the method will return the processed data hash.
107
107
  # If true is passed as the second argument, the method will output the
108
108
  # updated result as json to STDOUT, which can then be consumed by, say,
109
109
  # something which triggered this method, for example if it was called by
110
110
  # a rake task, which in turn might have been called by the main
111
111
  # OpenCorporates application
112
+ #
113
+ # If the data to be saved is invalid then either the exception is raised,
114
+ # or, if output_as_json is requested then the validation error is included
115
+ # in the JSON error message
112
116
  def update_datum(uid, output_as_json=false,replace_existing_data=false)
113
117
  return unless raw_data = fetch_datum(uid)
114
118
  default_options = {primary_key_name => uid, :retrieved_at => Time.now}
@@ -122,7 +126,12 @@ module OpencBot
122
126
  processed_data
123
127
  end
124
128
  rescue Exception => e
125
- output_json_error_message(e) if output_as_json
129
+ if output_as_json
130
+ output_json_error_message(e)
131
+ else
132
+ puts e.inspect if verbose?
133
+ raise e
134
+ end
126
135
  end
127
136
 
128
137
  def update_stale(stale_count=nil)
@@ -1,3 +1,3 @@
1
1
  module OpencBot
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext'
2
3
  require 'openc_bot'
3
4
  require 'json-schema'
@@ -58,7 +59,7 @@ class SimpleOpencBot
58
59
  STDOUT.print(".")
59
60
  STDOUT.flush
60
61
  end
61
- ensure
62
+ ensure
62
63
  sqlite_magic_connection.execute("COMMIT") if sqlite_magic_connection.database.transaction_active?
63
64
  end
64
65
  end
@@ -97,7 +98,7 @@ class SimpleOpencBot
97
98
 
98
99
  def all_stored_records(opts={})
99
100
  if opts[:only_unexported]
100
- opts[:limit] ||= opts[:batch]
101
+ opts[:limit] ||= opts[:batch]
101
102
  end
102
103
 
103
104
  select = opts[:select] || "ocdata.*"
data/openc_bot.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.require_paths = ["lib",'lib/openc_bot/helpers']
21
21
 
22
22
  gem.add_dependency "rake"
23
- gem.add_dependency "activesupport", "3.2.17"
23
+ gem.add_dependency "activesupport", "4.1.4"
24
24
  gem.add_dependency "nokogiri"
25
25
  # gem.add_dependency "sqlite3"
26
26
  gem.add_dependency "json"
@@ -59,12 +59,24 @@
59
59
  "$ref": "includes/filing.json"
60
60
  }
61
61
  },
62
+ "industry_codes": {
63
+ "type": "array",
64
+ "items": {
65
+ "$ref": "includes/industry_code.json"
66
+ }
67
+ },
62
68
  "previous_names": {
63
69
  "type": "array",
64
70
  "items": {
65
71
  "$ref": "includes/previous_name.json"
66
72
  }
67
73
  },
74
+ "alternative_names": {
75
+ "type": "array",
76
+ "items": {
77
+ "$ref": "includes/alternative_name.json"
78
+ }
79
+ },
68
80
  "branch": {
69
81
  "type": ["string","null"],
70
82
  "description": "A flag to denote whether a company is a branch entity. This should only be set if the company is a type of branch (otherwise should be null). In general the only option here is 'F' for a 'Foreign' branch, i.e. an out-of-jurisdiction entity that has registered as having a presence in the jurisdiction. In the US this is sometimes called a Foreign Corporation",
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "AlternativeName",
3
+ "description": "An alternative name of a company, e.g. abbreviation, trading (including dba or doing business as), legal. As well as trading names etc, it can be used for storing alternative language representations of the legal name, in which case the language should be represented as two-letter ISO-639 code",
4
+ "type": "object",
5
+ "properties": { "company_name": { "type": "string", "minLength": 1 },
6
+ "start_date": { "type": "date" },
7
+ "end_date": { "type": "date" },
8
+ "language": { "type": "string", "minLength": 2, "maxLength": 2 },
9
+ "type": { "type": "string", "enum": ["trading", "abbreviation", "legal"] }
10
+ },
11
+ "required": [ "company_name" ]
12
+ }
13
+
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "IndustryCode",
3
+ "description": "An industry code from a standard code list (e.g. NAICS 2007 or NACE 2)",
4
+ "type": "object",
5
+ "properties": { "name": { "type": "string" },
6
+ "code": { "type": "string" },
7
+ "code_scheme_id": { "type": "string", "enum": ["eu_nace_2", "uk_sic_2003", "uk_sic_2007", "us_naics_2002", "us_naics_2007", "be_nace_2008"] },
8
+ "start_date": { "type": "date" },
9
+ "end_date": { "type": "date" }
10
+ },
11
+ "required": [ "code", "code_scheme_id" ]
12
+ }
13
+
@@ -22,47 +22,47 @@ describe OpencBot::BotDataValidator do
22
22
 
23
23
  end
24
24
  it 'should return true if data is valid' do
25
- OpencBot::BotDataValidator.validate(@valid_data).should be_true
25
+ OpencBot::BotDataValidator.validate(@valid_data).should be true
26
26
  end
27
27
 
28
28
  it 'should return false if data is not a hash' do
29
- OpencBot::BotDataValidator.validate(nil).should be_false
30
- OpencBot::BotDataValidator.validate('foo').should be_false
31
- OpencBot::BotDataValidator.validate(['foo']).should be_false
29
+ OpencBot::BotDataValidator.validate(nil).should be false
30
+ OpencBot::BotDataValidator.validate('foo').should be false
31
+ OpencBot::BotDataValidator.validate(['foo']).should be false
32
32
  end
33
33
 
34
34
  it 'should return false if company_data is blank' do
35
- OpencBot::BotDataValidator.validate(@valid_data.merge(:company => nil)).should be_false
36
- OpencBot::BotDataValidator.validate(@valid_data.merge(:company => ' ')).should be_false
35
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:company => nil)).should be false
36
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:company => ' ')).should be false
37
37
  end
38
38
 
39
39
  it 'should return false if company_data is missing name' do
40
- OpencBot::BotDataValidator.validate(@valid_data.merge(:company => {:name => nil})).should be_false
41
- OpencBot::BotDataValidator.validate(@valid_data.merge(:company => {:name => ' '})).should be_false
40
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:company => {:name => nil})).should be false
41
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:company => {:name => ' '})).should be false
42
42
  end
43
43
 
44
44
  it 'should return false if source_url is blank' do
45
- OpencBot::BotDataValidator.validate(@valid_data.merge(:source_url => nil)).should be_false
46
- OpencBot::BotDataValidator.validate(@valid_data.merge(:source_url => ' ')).should be_false
45
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:source_url => nil)).should be false
46
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:source_url => ' ')).should be false
47
47
  end
48
48
 
49
49
  it 'should return false if data is empty' do
50
- OpencBot::BotDataValidator.validate(@valid_data.merge(:data => nil)).should be_false
51
- OpencBot::BotDataValidator.validate(@valid_data.merge(:data => [])).should be_false
50
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:data => nil)).should be false
51
+ OpencBot::BotDataValidator.validate(@valid_data.merge(:data => [])).should be false
52
52
  end
53
53
 
54
54
  it 'should return false if data is missing data_type' do
55
55
  OpencBot::BotDataValidator.validate(@valid_data.merge(:data => [{:data_type => nil,
56
- :properties => {:foo => 'bar'}}])).should be_false
56
+ :properties => {:foo => 'bar'}}])).should be false
57
57
  OpencBot::BotDataValidator.validate(@valid_data.merge(:data => [{:data_type => ' ',
58
- :properties => {:foo => 'bar'}}])).should be_false
58
+ :properties => {:foo => 'bar'}}])).should be false
59
59
  end
60
60
 
61
61
  it 'should return false if properties is blank' do
62
62
  OpencBot::BotDataValidator.validate(@valid_data.merge(:data => [{:data_type => :subsidiary_relationship,
63
- :properties => {}}])).should be_false
63
+ :properties => {}}])).should be false
64
64
  OpencBot::BotDataValidator.validate(@valid_data.merge(:data => [{:data_type => :subsidiary_relationship,
65
- :properties => nil}])).should be_false
65
+ :properties => nil}])).should be false
66
66
  end
67
67
 
68
68
  end
@@ -90,4 +90,35 @@ describe "A module that extends CompanyFetcherBot" do
90
90
  TestCompaniesFetcher.save_entity(:name => 'Foo Corp', :company_number => '12345', :jurisdiction_code => 'xx')
91
91
  end
92
92
  end
93
+
94
+ describe "#save_entity!" do
95
+ before do
96
+ TestCompaniesFetcher.stub(:inferred_jurisdiction_code).and_return('ab_cd')
97
+ end
98
+
99
+ it "should save_entity with inferred_jurisdiction_code" do
100
+ TestCompaniesFetcher.should_receive(:prepare_and_save_data).with(:name => 'Foo Corp', :company_number => '12345', :jurisdiction_code => 'ab_cd')
101
+ TestCompaniesFetcher.save_entity!(:name => 'Foo Corp', :company_number => '12345')
102
+ end
103
+
104
+ it "should save_entity with given jurisdiction_code" do
105
+ TestCompaniesFetcher.should_receive(:prepare_and_save_data).with(:name => 'Foo Corp', :company_number => '12345', :jurisdiction_code => 'xx')
106
+ TestCompaniesFetcher.save_entity!(:name => 'Foo Corp', :company_number => '12345', :jurisdiction_code => 'xx')
107
+ end
108
+
109
+ context "and entity_data is not valid" do
110
+ before do
111
+ TestCompaniesFetcher.stub(:validate_datum).and_return([{:message=>'Not valid'}])
112
+ end
113
+
114
+ it "should not prepare and save data" do
115
+ TestCompaniesFetcher.should_not_receive(:prepare_and_save_data)
116
+ lambda {ModuleThatIncludesRegisterMethods.save_entity!(:name => 'Foo Corp', :company_number => '12345')}
117
+ end
118
+
119
+ it "should raise exception" do
120
+ lambda {TestCompaniesFetcher.save_entity!(:name => 'Foo Corp', :company_number => '12345')}.should raise_error(OpencBot::RecordInvalid)
121
+ end
122
+ end
123
+ end
93
124
  end
@@ -41,11 +41,11 @@ describe 'a module that includes RegisterMethods' do
41
41
  it "should return true if result returned" do
42
42
  ModuleThatIncludesRegisterMethods.stub(:select).and_return([{'custom_uid' => '4567'}])
43
43
 
44
- ModuleThatIncludesRegisterMethods.datum_exists?('4567').should be_true
44
+ ModuleThatIncludesRegisterMethods.datum_exists?('4567').should be true
45
45
  end
46
46
 
47
47
  it "should return false if result returned" do
48
- ModuleThatIncludesRegisterMethods.datum_exists?('4567').should be_false
48
+ ModuleThatIncludesRegisterMethods.datum_exists?('4567').should be false
49
49
  end
50
50
  end
51
51
 
@@ -83,14 +83,14 @@ describe 'a module that includes RegisterMethods' do
83
83
  describe "#use_alpha_search" do
84
84
  context 'and no USE_ALPHA_SEARCH constant' do
85
85
  it "should not return true" do
86
- ModuleThatIncludesRegisterMethods.use_alpha_search.should_not be_true
86
+ ModuleThatIncludesRegisterMethods.use_alpha_search.should_not be true
87
87
  end
88
88
  end
89
89
 
90
90
  context 'and USE_ALPHA_SEARCH constant set' do
91
91
  it "should return USE_ALPHA_SEARCH" do
92
92
  stub_const("ModuleThatIncludesRegisterMethods::USE_ALPHA_SEARCH", true)
93
- ModuleThatIncludesRegisterMethods.use_alpha_search.should be_true
93
+ ModuleThatIncludesRegisterMethods.use_alpha_search.should be true
94
94
  end
95
95
  end
96
96
  end
@@ -228,7 +228,7 @@ describe 'a module that includes RegisterMethods' do
228
228
  end
229
229
 
230
230
  it "should return true" do
231
- ModuleThatIncludesRegisterMethods.prepare_and_save_data(@params).should be_true
231
+ ModuleThatIncludesRegisterMethods.prepare_and_save_data(@params).should be_truthy
232
232
  end
233
233
  end
234
234
 
@@ -244,8 +244,9 @@ describe 'a module that includes RegisterMethods' do
244
244
  ModuleThatIncludesRegisterMethods.stub(:fetch_datum).and_return(@fetch_datum_response)
245
245
  ModuleThatIncludesRegisterMethods.stub(:process_datum).and_return(@processed_data)
246
246
  @processed_data_with_retrieved_at_and_uid = @processed_data.merge(:custom_uid => @uid, :retrieved_at => @dummy_time)
247
- ModuleThatIncludesRegisterMethods.stub(:save_data)
247
+ ModuleThatIncludesRegisterMethods.stub(:save_data!)
248
248
  ModuleThatIncludesRegisterMethods.stub(:validate_datum).and_return([])
249
+ ModuleThatIncludesRegisterMethods.stub(:insert_or_update)
249
250
  end
250
251
 
251
252
  it "should fetch_datum for company number" do
@@ -264,7 +265,7 @@ describe 'a module that includes RegisterMethods' do
264
265
  end
265
266
 
266
267
  it "should not save data" do
267
- ModuleThatIncludesRegisterMethods.should_not_receive(:save_data)
268
+ ModuleThatIncludesRegisterMethods.should_not_receive(:save_data!)
268
269
  ModuleThatIncludesRegisterMethods.update_datum(@uid)
269
270
  end
270
271
 
@@ -281,17 +282,17 @@ describe 'a module that includes RegisterMethods' do
281
282
  end
282
283
 
283
284
  it "should validate processed data" do
284
- ModuleThatIncludesRegisterMethods.should_receive(:validate_datum).with(hash_including(@processed_data_with_retrieved_at_and_uid)).and_call_original
285
+ ModuleThatIncludesRegisterMethods.should_receive(:validate_datum).with(hash_including(@processed_data_with_retrieved_at_and_uid)).and_return([])
285
286
  ModuleThatIncludesRegisterMethods.update_datum(@uid)
286
287
  end
287
288
 
288
289
  it "should prepare processed data for saving including timestamp" do
289
- ModuleThatIncludesRegisterMethods.should_receive(:prepare_for_saving).with(hash_including(@processed_data_with_retrieved_at_and_uid)).and_call_original
290
+ ModuleThatIncludesRegisterMethods.should_receive(:prepare_for_saving).with(hash_including(@processed_data_with_retrieved_at_and_uid)).and_return({})
290
291
  ModuleThatIncludesRegisterMethods.update_datum(@uid)
291
292
  end
292
293
 
293
294
  it "should include data in data to be prepared for saving" do
294
- ModuleThatIncludesRegisterMethods.should_receive(:prepare_for_saving).with(hash_including(:data => @fetch_datum_response)).and_call_original
295
+ ModuleThatIncludesRegisterMethods.should_receive(:prepare_for_saving).with(hash_including(:data => @fetch_datum_response)).and_return({})
295
296
  ModuleThatIncludesRegisterMethods.update_datum(@uid)
296
297
  end
297
298
 
@@ -300,7 +301,7 @@ describe 'a module that includes RegisterMethods' do
300
301
  ModuleThatIncludesRegisterMethods.stub(:process_datum).
301
302
  and_return(@processed_data.merge(:retrieved_at => different_time))
302
303
  ModuleThatIncludesRegisterMethods.should_receive(:prepare_for_saving).
303
- with(hash_including(:retrieved_at => different_time)).and_call_original
304
+ with(hash_including(:retrieved_at => different_time)).and_return({})
304
305
  ModuleThatIncludesRegisterMethods.update_datum(@uid)
305
306
  end
306
307
 
@@ -320,32 +321,41 @@ describe 'a module that includes RegisterMethods' do
320
321
  ModuleThatIncludesRegisterMethods.update_datum(@uid)
321
322
  end
322
323
 
324
+ RSpec::Matchers.define :jsonified_output do |expected_output|
325
+ match do |actual|
326
+ parsed_actual_json = JSON.parse(actual)
327
+ parsed_actual_json.except('retrieved_at') == expected_output.except('retrieved_at') and
328
+ parsed_actual_json['retrieved_at'].to_time.to_s == expected_output['retrieved_at'].to_time.to_s
329
+
330
+ end
331
+ end
332
+
323
333
  it "should output jsonified processed data to STDOUT if passed true as second argument" do
324
334
  expected_output = @processed_data_with_retrieved_at_and_uid.
325
- merge(:retrieved_at => @processed_data_with_retrieved_at_and_uid[:retrieved_at].iso8601)
326
- # json output is in different, unknown order, so we test output like this
327
- ModuleThatIncludesRegisterMethods.should_receive(:puts) { |output| json_hash = JSON.parse(output); json_hash == expected_output }
335
+ merge(:retrieved_at => @processed_data_with_retrieved_at_and_uid[:retrieved_at].iso8601).stringify_keys
336
+ ModuleThatIncludesRegisterMethods.should_receive(:puts).with(jsonified_output(expected_output))
328
337
  ModuleThatIncludesRegisterMethods.update_datum(@uid, true)
329
338
  end
330
339
 
331
340
 
341
+ RSpec::Matchers.define :jsonified_error_details_including do |expected_output|
342
+ match { |actual| error_details = JSON.parse(actual)['error']; expected_output.all? { |k,v| error_details[k] == v } }
343
+ end
344
+
332
345
  context "and exception raised" do
333
346
  before do
334
347
  ModuleThatIncludesRegisterMethods.stub(:process_datum).and_raise('something went wrong')
335
348
  end
336
349
 
337
- it "should output error message if true passes as second argument" do
338
- ModuleThatIncludesRegisterMethods.should_receive(:puts).with(/error.+went wrong/m)
350
+ it "should output error message as JSON if true passes as second argument" do
351
+ ModuleThatIncludesRegisterMethods.should_receive(:puts).with(jsonified_error_details_including('message' => 'something went wrong', 'klass' => 'RuntimeError'))
352
+ # ModuleThatIncludesRegisterMethods.should_receive(:puts).
353
+ # with{ |error_output| error_hash = JSON.parse(error_output); error_hash['error']['message'].should == 'something went wrong' }
339
354
  ModuleThatIncludesRegisterMethods.update_datum(@uid, true)
340
355
  end
341
356
 
342
- it "should return nil if true not passed as second argument" do
343
- ModuleThatIncludesRegisterMethods.update_datum(@uid).should be_nil
344
- end
345
-
346
- it "should output error message if true not passed as second argument" do
347
- ModuleThatIncludesRegisterMethods.should_not_receive(:puts).with(/error/)
348
- ModuleThatIncludesRegisterMethods.update_datum(@uid).should be_nil
357
+ it "should raise exception if true not passed as second argument" do
358
+ lambda { ModuleThatIncludesRegisterMethods.update_datum(@uid)}.should raise_error('something went wrong')
349
359
  end
350
360
  end
351
361
  end
@@ -434,7 +444,7 @@ describe 'a module that includes RegisterMethods' do
434
444
  end
435
445
 
436
446
  it "should return true" do
437
- ModuleThatIncludesRegisterMethods.save_entity(@params).should be_true
447
+ ModuleThatIncludesRegisterMethods.save_entity(@params).should be_truthy
438
448
  end
439
449
  end
440
450
 
@@ -449,7 +459,7 @@ describe 'a module that includes RegisterMethods' do
449
459
  end
450
460
 
451
461
  it "should not return true" do
452
- ModuleThatIncludesRegisterMethods.save_entity(@params).should_not be_true
462
+ ModuleThatIncludesRegisterMethods.save_entity(@params).should_not be true
453
463
  end
454
464
  end
455
465
  end
@@ -475,7 +485,7 @@ describe 'a module that includes RegisterMethods' do
475
485
  end
476
486
 
477
487
  it "should return true" do
478
- ModuleThatIncludesRegisterMethods.save_entity!(@params).should be_true
488
+ ModuleThatIncludesRegisterMethods.save_entity!(@params).should be_truthy
479
489
  end
480
490
  end
481
491
 
@@ -532,7 +542,7 @@ describe 'a module that includes RegisterMethods' do
532
542
 
533
543
  it 'should not do anything with null value' do
534
544
  @processed_data[:serialised_field_6].should be_nil
535
- @processed_data.has_key?(:serialised_field_6).should be_true
545
+ @processed_data.has_key?(:serialised_field_6).should be true
536
546
  end
537
547
  end
538
548
 
@@ -542,7 +552,7 @@ describe 'a module that includes RegisterMethods' do
542
552
  end
543
553
 
544
554
  it 'should remove value from result' do
545
- @processed_data.has_key?(:serialised_field_6).should be_false
555
+ @processed_data.has_key?(:serialised_field_6).should be false
546
556
  end
547
557
  end
548
558
 
@@ -53,12 +53,12 @@ describe "A module that extends OpencBot" do
53
53
 
54
54
  describe '#verbose?' do
55
55
  it 'should return false if ENV["VERBOSE"] not set' do
56
- FooBot.verbose?.should be_false
56
+ FooBot.verbose?.should be_falsey
57
57
  end
58
58
 
59
- it 'should return false if ENV["VERBOSE"] set' do
59
+ it 'should return true if ENV["VERBOSE"] set' do
60
60
  ENV["VERBOSE"] = 'true'
61
- FooBot.verbose?.should be_true
61
+ FooBot.verbose?.should be_truthy
62
62
  ENV["VERBOSE"] = nil # reset
63
63
  end
64
64
  end
@@ -604,10 +604,10 @@ describe 'company-schema' do
604
604
  { :number => 123 }
605
605
  }
606
606
  ]
607
- valid_company_params.each do |valid_params|
608
- errors = validate_datum_and_return_errors(valid_params)
609
- errors.should be_empty, "Valid params were not valid: #{valid_params}.Errors = #{errors}"
610
- end
607
+ valid_company_params.each do |valid_params|
608
+ errors = validate_datum_and_return_errors(valid_params)
609
+ errors.should be_empty, "Valid params were not valid: #{valid_params}.Errors = #{errors}"
610
+ end
611
611
  end
612
612
 
613
613
  it "should not validate if share_parcels are not valid" do
@@ -644,6 +644,123 @@ describe 'company-schema' do
644
644
  end
645
645
  end
646
646
 
647
+ context "and company has alternative_names" do
648
+ it "should validate if alternative_names are valid" do
649
+ valid_company_params=
650
+ [
651
+ { :name => 'Foo Inc',
652
+ :company_number => '12345',
653
+ :jurisdiction_code => 'ie',
654
+ :alternative_names =>
655
+ [{ :company_name => 'Foobar Inc',
656
+ :type => :trading },
657
+ { :company_name => 'Foobar Inc',
658
+ :type => :legal,
659
+ :language => 'fr' },
660
+ ]
661
+ },
662
+ { :name => 'Foo Inc',
663
+ :company_number => '12345',
664
+ :jurisdiction_code => 'ie',
665
+ :alternative_names =>[]
666
+ }
667
+ ]
668
+
669
+ invalid_company_params =
670
+ [
671
+ { :name => 'Foo Inc',
672
+ :company_number => '12345',
673
+ :jurisdiction_code => 'ie',
674
+ :alternative_names =>
675
+ [{ :company_name => 'Foobar Inc'}]
676
+ },
677
+ { :name => 'Foo Inc',
678
+ :company_number => '12345',
679
+ :jurisdiction_code => 'ie',
680
+ :alternative_names =>
681
+ [{ :company_name => 'Foobar Inc', :type => 'foobar'}]
682
+ },
683
+ { :name => 'Foo Inc',
684
+ :company_number => '12345',
685
+ :jurisdiction_code => 'ie',
686
+ :alternative_names =>
687
+ [{ :company_name => 'Foobar Inc', :language => 'French'}]
688
+ },
689
+ { :name => 'Foo Inc',
690
+ :company_number => '12345',
691
+ :jurisdiction_code => 'ie',
692
+ :alternative_names => 'foo name'
693
+ },
694
+ { :name => 'Foo Inc',
695
+ :company_number => '12345',
696
+ :jurisdiction_code => 'ie',
697
+ :alternative_names => ['foo name']
698
+ }
699
+ ]
700
+ valid_company_params.each do |valid_params|
701
+ errors = validate_datum_and_return_errors(valid_params)
702
+ errors.should be_empty, "Valid params were not valid: #{valid_params}.Errors = #{errors}"
703
+ end
704
+ end
705
+ end
706
+
707
+ context "and company has industry_codes" do
708
+ it "should validate if industry_codes are valid" do
709
+ valid_company_params =
710
+ [
711
+ { :name => 'Foo Inc',
712
+ :company_number => '12345',
713
+ :jurisdiction_code => 'ie',
714
+ :industry_codes => [
715
+ {:code => '1234', :code_scheme_id => 'eu_nace_2', :name => 'Some Industry' },
716
+ {:code => '22.11', :code_scheme_id => 'uk_sic_2007' },
717
+ {:code => '43.21', :code_scheme_id => 'us_naics_2007', :name => 'Another Industry', :start_date => '2010-12-22', :end_date => '2011-01-03' }]
718
+ },
719
+ { :name => 'Foo Inc',
720
+ :company_number => '12345',
721
+ :jurisdiction_code => 'ie',
722
+ # allow empty arrays
723
+ :industry_codes => []
724
+ }
725
+ ]
726
+ valid_company_params.each do |valid_params|
727
+ errors = validate_datum_and_return_errors(valid_params)
728
+ errors.should be_empty, "Valid params were not valid: #{valid_params}.Errors = #{errors}"
729
+ end
730
+ end
731
+
732
+ it "should not validate if industry_codes are not valid" do
733
+ invalid_company_params =
734
+ [
735
+ { :name => 'Foo Inc',
736
+ :company_number => '12345',
737
+ :jurisdiction_code => 'ie',
738
+ :industry_codes => [ {:code => '1234'}]
739
+ },
740
+ { :name => 'Foo Inc',
741
+ :company_number => '12345',
742
+ :jurisdiction_code => 'ie',
743
+ :industry_codes => [ {:code_scheme_id => '1234'}]
744
+ },
745
+ { :name => 'Foo Inc',
746
+ :company_number => '12345',
747
+ :jurisdiction_code => 'ie',
748
+ :industry_codes => 'foo code'
749
+ },
750
+ { :name => 'Foo Inc',
751
+ :company_number => '12345',
752
+ :jurisdiction_code => 'ie',
753
+ :industry_codes => ['foo filing']
754
+ }
755
+ ]
756
+ invalid_company_params.each do |invalid_params|
757
+ errors = validate_datum_and_return_errors(invalid_params)
758
+ errors.should_not be_empty, "Invalid params were not invalid: #{invalid_params}"
759
+ end
760
+ end
761
+
762
+ end
763
+
647
764
  def validate_datum_and_return_errors(record)
648
765
  errors = JSON::Validator.fully_validate(
649
766
  @schema,
@@ -203,7 +203,7 @@ describe SimpleOpencBot do
203
203
  end
204
204
 
205
205
  it "should return records converted to pipeline format" do
206
- @bot.spotcheck_data.any? {|c| c[:company][:name] == @properties[0][:name]}.should be_true
206
+ @bot.spotcheck_data.any? {|c| c[:company][:name] == @properties[0][:name]}.should be true
207
207
  end
208
208
  end
209
209
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'rspec/autorun'
1
+ # require 'rspec/autorun'
2
2
  require 'debugger'
3
3
 
4
4
  RSpec.configure do |config|
metadata CHANGED
@@ -1,116 +1,132 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openc_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.16
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Chris Taggart
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-06-10 00:00:00.000000000 Z
12
+ date: 2014-07-04 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: activesupport
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - '='
32
36
  - !ruby/object:Gem::Version
33
- version: 3.2.17
37
+ version: 4.1.4
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - '='
39
44
  - !ruby/object:Gem::Version
40
- version: 3.2.17
45
+ version: 4.1.4
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: nokogiri
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - ">="
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - ">="
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: json
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - ">="
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - ">="
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0'
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: json-schema
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - ">="
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: '0'
76
86
  type: :runtime
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - ">="
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: '0'
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: httpclient
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - ">="
99
+ - - ! '>='
88
100
  - !ruby/object:Gem::Version
89
101
  version: '0'
90
102
  type: :runtime
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - ">="
107
+ - - ! '>='
95
108
  - !ruby/object:Gem::Version
96
109
  version: '0'
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: backports
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
- - - ">="
115
+ - - ! '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
- - - ">="
123
+ - - ! '>='
109
124
  - !ruby/object:Gem::Version
110
125
  version: '0'
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: scraperwiki
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
131
  - - '='
116
132
  - !ruby/object:Gem::Version
@@ -118,6 +134,7 @@ dependencies:
118
134
  type: :runtime
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
139
  - - '='
123
140
  - !ruby/object:Gem::Version
@@ -125,43 +142,49 @@ dependencies:
125
142
  - !ruby/object:Gem::Dependency
126
143
  name: perftools.rb
127
144
  requirement: !ruby/object:Gem::Requirement
145
+ none: false
128
146
  requirements:
129
- - - ">="
147
+ - - ! '>='
130
148
  - !ruby/object:Gem::Version
131
149
  version: '0'
132
150
  type: :development
133
151
  prerelease: false
134
152
  version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
135
154
  requirements:
136
- - - ">="
155
+ - - ! '>='
137
156
  - !ruby/object:Gem::Version
138
157
  version: '0'
139
158
  - !ruby/object:Gem::Dependency
140
159
  name: debugger
141
160
  requirement: !ruby/object:Gem::Requirement
161
+ none: false
142
162
  requirements:
143
- - - ">="
163
+ - - ! '>='
144
164
  - !ruby/object:Gem::Version
145
165
  version: '0'
146
166
  type: :development
147
167
  prerelease: false
148
168
  version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
149
170
  requirements:
150
- - - ">="
171
+ - - ! '>='
151
172
  - !ruby/object:Gem::Version
152
173
  version: '0'
153
174
  - !ruby/object:Gem::Dependency
154
175
  name: rspec
155
176
  requirement: !ruby/object:Gem::Requirement
177
+ none: false
156
178
  requirements:
157
- - - ">="
179
+ - - ! '>='
158
180
  - !ruby/object:Gem::Version
159
181
  version: '0'
160
182
  type: :development
161
183
  prerelease: false
162
184
  version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
163
186
  requirements:
164
- - - ">="
187
+ - - ! '>='
165
188
  - !ruby/object:Gem::Version
166
189
  version: '0'
167
190
  description: This gem is to make the writing and running of bots for OpenCorporates
@@ -173,8 +196,8 @@ executables:
173
196
  extensions: []
174
197
  extra_rdoc_files: []
175
198
  files:
176
- - ".gitignore"
177
- - ".travis.yml"
199
+ - .gitignore
200
+ - .travis.yml
178
201
  - CHANGELOG.md
179
202
  - Gemfile
180
203
  - LICENSE.txt
@@ -230,9 +253,11 @@ files:
230
253
  - openc_bot.gemspec
231
254
  - schemas/company-schema.json
232
255
  - schemas/includes/address.json
256
+ - schemas/includes/alternative_name.json
233
257
  - schemas/includes/base-statement.json
234
258
  - schemas/includes/company.json
235
259
  - schemas/includes/filing.json
260
+ - schemas/includes/industry_code.json
236
261
  - schemas/includes/license-data.json
237
262
  - schemas/includes/officer.json
238
263
  - schemas/includes/previous_name.json
@@ -260,27 +285,28 @@ files:
260
285
  - spec/spec_helper.rb
261
286
  homepage: ''
262
287
  licenses: []
263
- metadata: {}
264
288
  post_install_message:
265
289
  rdoc_options: []
266
290
  require_paths:
267
291
  - lib
268
292
  - lib/openc_bot/helpers
269
293
  required_ruby_version: !ruby/object:Gem::Requirement
294
+ none: false
270
295
  requirements:
271
- - - ">="
296
+ - - ! '>='
272
297
  - !ruby/object:Gem::Version
273
298
  version: '0'
274
299
  required_rubygems_version: !ruby/object:Gem::Requirement
300
+ none: false
275
301
  requirements:
276
- - - ">="
302
+ - - ! '>='
277
303
  - !ruby/object:Gem::Version
278
304
  version: '0'
279
305
  requirements: []
280
306
  rubyforge_project:
281
- rubygems_version: 2.2.2
307
+ rubygems_version: 1.8.23
282
308
  signing_key:
283
- specification_version: 4
309
+ specification_version: 3
284
310
  summary: Helper gem for writing external bots for OpenCorporates
285
311
  test_files:
286
312
  - spec/dummy_classes/foo_bot.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 2c2492325f145ede40b77b666ab93b99c47ba314
4
- data.tar.gz: 7aa0dd5faf896d3a7e6a2217092ced8227084e8b
5
- SHA512:
6
- metadata.gz: 9c2709f8c3cb91d06d6e356809e8adc2e16dd5499b5c85e217fe6637c2c4045b6e6add769ffded9844227ef16a04ea387f0d252a4d4ffeb80fd6cea5876f4faf
7
- data.tar.gz: 94d5a2d6222a04164ee5f93cb266129790651f3aae587faa20c52af81d4fbdbb15d899b11eb42a2dd2f06aa075d80bf282e1a503d39b3400b07f9da016061271