turbot-runner 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module TurbotRunner
14
14
  begin
15
15
  if line.strip == "RUN ENDED"
16
16
  @record_handler.handle_run_ended
17
- @runner.interrupt
17
+ @runner.interrupt if @runner
18
18
  else
19
19
  record = JSON.parse(line)
20
20
  errors = validate(record)
@@ -23,16 +23,16 @@ module TurbotRunner
23
23
  begin
24
24
  @record_handler.handle_valid_record(record, @data_type)
25
25
  rescue InterruptRun
26
- @runner.interrupt
26
+ @runner.interrupt if @runner
27
27
  end
28
28
  else
29
29
  @record_handler.handle_invalid_record(record, @data_type, errors)
30
- @runner.interrupt_and_mark_as_failed
30
+ @runner.interrupt_and_mark_as_failed if @runner
31
31
  end
32
32
  end
33
33
  rescue JSON::ParserError
34
34
  @record_handler.handle_invalid_json(line)
35
- @runner.interrupt_and_mark_as_failed
35
+ @runner.interrupt_and_mark_as_failed if @runner
36
36
  end
37
37
  end
38
38
 
@@ -65,6 +65,10 @@ module TurbotRunner
65
65
  end
66
66
 
67
67
  def process_script_output(script_config)
68
+ # The first argument to the Processor constructor is a nil
69
+ # Runner. This is because no running behaviour
70
+ # (e.g. interruptions etc) is required; we just want to do
71
+ # record handling.
68
72
  processor = Processor.new(nil, script_config, @record_handler)
69
73
 
70
74
  File.open(output_file(script_config[:file])) do |f|
@@ -1,3 +1,3 @@
1
1
  module TurbotRunner
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
@@ -130,9 +130,11 @@
130
130
  "minLength": 1
131
131
  },
132
132
  "number_of_employees": {
133
- "type": "number",
134
- "description": "The number of employees",
135
- "minimum": 0
133
+ "anyOf": [
134
+ {"type":"string","minLength": 1},
135
+ {"type":"number","minimum": 0}
136
+ ],
137
+ "description": "The number of employees"
136
138
  },
137
139
  "merged_into": {
138
140
  "type": "object",
@@ -6,64 +6,91 @@ describe TurbotRunner::Processor do
6
6
  before do
7
7
  @handler = TurbotRunner::BaseHandler.new
8
8
  @data_type = 'primary data'
9
- script_config = {
9
+ @script_config = {
10
10
  :data_type => @data_type,
11
11
  :identifying_fields => ['number']
12
12
  }
13
- script_runner = instance_double('ScriptRunner')
14
- allow(script_runner).to receive(:interrupt_and_mark_as_failed)
15
- @processor = TurbotRunner::Processor.new(script_runner, script_config, @handler)
16
13
  end
17
14
 
18
- context 'with valid record' do
19
- it 'calls Handler#handle_valid_record' do
20
- record = {
21
- 'sample_date' => '2014-06-01',
22
- 'source_url' => 'http://example.com/123',
23
- 'number' => 123
24
- }
25
- expect(@handler).to receive(:handle_valid_record).with(record, @data_type)
26
- @processor.process(record.to_json)
15
+ context 'with a nil runner passed in' do
16
+ before do
17
+ @processor = TurbotRunner::Processor.new(nil, @script_config, @handler)
18
+ end
19
+
20
+ context 'with record missing required field' do
21
+ before do
22
+ @record = {
23
+ 'sample_date' => '2014-06-01',
24
+ 'number' => 123
25
+ }
26
+ end
27
+
28
+ it 'calls Handler#handle_invalid_record' do
29
+ expected_errors = ['Missing required attribute: source_url']
30
+ expect(@handler).to receive(:handle_invalid_record).
31
+ with(@record, @data_type, expected_errors)
32
+ @processor.process(@record.to_json)
33
+ end
27
34
  end
28
35
  end
29
36
 
30
- context 'with record missing required field' do
37
+ context 'with a runner passed in' do
31
38
  before do
32
- @record = {
33
- 'sample_date' => '2014-06-01',
34
- 'number' => 123
35
- }
39
+ script_runner = instance_double('ScriptRunner')
40
+ allow(script_runner).to receive(:interrupt_and_mark_as_failed)
41
+ @processor = TurbotRunner::Processor.new(script_runner, @script_config, @handler)
36
42
  end
37
43
 
38
- it 'calls Handler#handle_invalid_record' do
39
- expected_errors = ['Missing required attribute: source_url']
40
- expect(@handler).to receive(:handle_invalid_record).
41
- with(@record, @data_type, expected_errors)
42
- @processor.process(@record.to_json)
44
+ context 'with valid record' do
45
+ it 'calls Handler#handle_valid_record' do
46
+ record = {
47
+ 'sample_date' => '2014-06-01',
48
+ 'source_url' => 'http://example.com/123',
49
+ 'number' => 123
50
+ }
51
+ expect(@handler).to receive(:handle_valid_record).with(record, @data_type)
52
+ @processor.process(record.to_json)
53
+ end
43
54
  end
44
- end
45
55
 
46
- context 'with record missing all identifying fields' do
47
- before do
48
- @record = {
49
- 'sample_date' => '2014-06-01',
50
- 'source_url' => 'http://example.com/123'
51
- }
56
+ context 'with record missing required field' do
57
+ before do
58
+ @record = {
59
+ 'sample_date' => '2014-06-01',
60
+ 'number' => 123
61
+ }
62
+ end
63
+
64
+ it 'calls Handler#handle_invalid_record' do
65
+ expected_errors = ['Missing required attribute: source_url']
66
+ expect(@handler).to receive(:handle_invalid_record).
67
+ with(@record, @data_type, expected_errors)
68
+ @processor.process(@record.to_json)
69
+ end
52
70
  end
53
71
 
54
- it 'calls Handler#handle_invalid_record' do
55
- expected_errors = ['There were no values provided for any of the identifying fields: number']
56
- expect(@handler).to receive(:handle_invalid_record).
57
- with(@record, @data_type, expected_errors)
58
- @processor.process(@record.to_json)
72
+ context 'with record missing all identifying fields' do
73
+ before do
74
+ @record = {
75
+ 'sample_date' => '2014-06-01',
76
+ 'source_url' => 'http://example.com/123'
77
+ }
78
+ end
79
+
80
+ it 'calls Handler#handle_invalid_record' do
81
+ expected_errors = ['There were no values provided for any of the identifying fields: number']
82
+ expect(@handler).to receive(:handle_invalid_record).
83
+ with(@record, @data_type, expected_errors)
84
+ @processor.process(@record.to_json)
85
+ end
59
86
  end
60
- end
61
87
 
62
- context 'with invalid JSON' do
63
- it 'calls Handler#handle_invalid_json' do
64
- line = 'this is not JSON'
65
- expect(@handler).to receive(:handle_invalid_json).with(line)
66
- @processor.process(line)
88
+ context 'with invalid JSON' do
89
+ it 'calls Handler#handle_invalid_json' do
90
+ line = 'this is not JSON'
91
+ expect(@handler).to receive(:handle_invalid_json).with(line)
92
+ @processor.process(line)
93
+ end
67
94
  end
68
95
  end
69
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
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: 2014-09-17 00:00:00.000000000 Z
12
+ date: 2014-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json-schema