data_migrater 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d23aa11964d870b88a42f582ada1573f58a781d08a359cc25eea5e2dbf7dab62
4
- data.tar.gz: cd3bbe075f0cc3ff091284ef1a00c23c27a8f725989f269cb33eebd2f7c07ebb
3
+ metadata.gz: f399d2a9cb8f0b2b4308d800542e259b9944d208ff2ed31ecdf8c001dbbc3861
4
+ data.tar.gz: 75dda4543f8a3eefac6c7158763891f51dbd73585653a0dfaeee89022f691663
5
5
  SHA512:
6
- metadata.gz: 8fadf53e7bd9f4eaeb709847d5f73b6a53369eca3a93ee766d0192e56195a940122cc330b687ff93a346f8ca550f7eeb150f2b71d0dd757818f4631330ed0d29
7
- data.tar.gz: e6beaa0daecc1926844ee50fe15684a673e5710b7bb3e68ae7eefcc31b508e634079a4fc78649953b1ed1e07257a741bada5640e5327b792d556beb5cc5cccff
6
+ metadata.gz: ec764ed1b0e4804054925a43443fc470f1e14d5698e0979cc3dccd264661e91ce8a77cfbe199c2d8ca9364d98c134445003a2c88121bfe0ff82cfcb77f3cc0f6
7
+ data.tar.gz: 644d8766d959b196401874fbaa7edfcfc32b3590dd0ebcf11a6a37c51b58ec891202c29c0a27837bb14a54c65d46fcfcea8e3c01565173a9dec8e239d815e48a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## v1.1.0
2
+
3
+ ### Fixes
4
+
5
+ - Does not raise error when file does not exist locally;
6
+ - Does not try to delete a non existent file locally.
7
+
8
+ ### Updates
9
+
10
+ - `csv_delete` now deletes the local file too.
11
+
1
12
  ## v1.0.0
2
13
 
3
14
  ### Break
data/README.md CHANGED
@@ -187,7 +187,7 @@ end
187
187
 
188
188
  ### CSV Delete
189
189
 
190
- You can delete the S3 file from your migration after process the CSV.
190
+ You can delete the S3 and local file from your migration after process the CSV.
191
191
 
192
192
  ```ruby
193
193
  class MyDataMigration
@@ -8,7 +8,9 @@ module DataMigrater
8
8
 
9
9
  included do
10
10
  def csv(processor: ::SmarterCSV)
11
- s3.download if csv_options.delete(:provider) == :s3
11
+ s3.download if s3_provider?
12
+
13
+ return [] unless File.exist?(csv_path)
12
14
 
13
15
  processor.process csv_path, csv_options
14
16
  end
@@ -20,7 +22,9 @@ module DataMigrater
20
22
  end
21
23
 
22
24
  def csv_delete
23
- s3.delete
25
+ s3.delete if s3_provider?
26
+
27
+ File.delete(csv_path) if File.exist?(csv_path)
24
28
  end
25
29
 
26
30
  private
@@ -41,12 +45,16 @@ module DataMigrater
41
45
  self.class.csv_options
42
46
  end
43
47
 
48
+ def s3
49
+ @s3 ||= DataMigrater::S3.new(csv_bucket, s3_credentials, csv_path)
50
+ end
51
+
44
52
  def s3_credentials
45
53
  csv_options.delete(:credentials) || {}
46
54
  end
47
55
 
48
- def s3
49
- @s3 ||= DataMigrater::S3.new(csv_bucket, s3_credentials, csv_path)
56
+ def s3_provider?
57
+ @s3_provider ||= csv_options.delete(:provider) == :s3
50
58
  end
51
59
  end
52
60
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DataMigrater
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -3,21 +3,65 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe '#csv_delete' do
6
- let!(:s3) { instance_double 'DataMigrater::S3' }
6
+ context 'when provider is s3' do
7
+ let!(:s3) { instance_double 'DataMigrater::S3' }
7
8
 
8
- before do
9
- stub_const 'Dummy', Class.new
9
+ before do
10
+ stub_const 'Dummy', Class.new
10
11
 
11
- Dummy.class_eval { include DataMigrater::CSV }
12
- Dummy.class_eval { data_csv provider: :s3 }
12
+ Dummy.class_eval { include DataMigrater::CSV }
13
+ Dummy.class_eval { data_csv provider: :s3 }
13
14
 
14
- allow(DataMigrater::S3).to receive(:new)
15
- .with('data-migrater', {}, 'db/data_migrate/support/csv/dummy.csv').and_return s3
15
+ allow(DataMigrater::S3).to receive(:new)
16
+ .with('data-migrater', {}, 'db/data_migrate/support/csv/dummy.csv').and_return s3
17
+ end
18
+
19
+ it 'delegates delete to s3 object and deletes the existent file' do
20
+ allow(File).to receive(:exist?).and_return true
21
+
22
+ expect(s3).to receive(:delete)
23
+
24
+ expect(File).to receive(:delete).with 'db/data_migrate/support/csv/dummy.csv'
25
+
26
+ Dummy.new.csv_delete
27
+ end
28
+ end
29
+
30
+ context 'when has no provider' do
31
+ before do
32
+ stub_const 'Dummy', Class.new
33
+
34
+ Dummy.class_eval { include DataMigrater::CSV }
35
+ Dummy.class_eval { data_csv }
36
+ end
37
+
38
+ it 'does not delegates delete to s3 object' do
39
+ expect(DataMigrater::S3).not_to receive(:new)
40
+
41
+ Dummy.new.csv_delete
42
+ end
43
+
44
+ it 'deletes the existent file' do
45
+ allow(File).to receive(:exist?).and_return true
46
+
47
+ expect(File).to receive(:delete).with 'db/data_migrate/support/csv/dummy.csv'
48
+
49
+ Dummy.new.csv_delete
50
+ end
16
51
  end
17
52
 
18
- it 'delegates delete to s3 object' do
19
- expect(s3).to receive(:delete)
53
+ context 'when local file does not exist' do
54
+ before do
55
+ stub_const 'Dummy', Class.new
56
+
57
+ Dummy.class_eval { include DataMigrater::CSV }
58
+ Dummy.class_eval { data_csv dir: 'missing/path' }
59
+ end
60
+
61
+ it 'does not delete the file' do
62
+ expect(File).not_to receive(:delete)
20
63
 
21
- Dummy.new.csv_delete
64
+ Dummy.new.csv_delete
65
+ end
22
66
  end
23
67
  end
data/spec/csv/csv_spec.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe '#data_csv' do
6
- context 'when path is not about s3' do
6
+ context 'when has no provider' do
7
7
  before do
8
8
  stub_const 'Dummy', Class.new
9
9
 
@@ -39,6 +39,8 @@ RSpec.describe '#data_csv' do
39
39
 
40
40
  allow(DataMigrater::S3).to receive(:new)
41
41
  .with('data-migrater', {}, 'db/data_migrate/support/csv/dummy.csv').and_return double(download: true)
42
+
43
+ allow(File).to receive(:exist?).and_return true
42
44
  end
43
45
 
44
46
  it 'reads csv from s3' do
@@ -47,4 +49,23 @@ RSpec.describe '#data_csv' do
47
49
  Dummy.new.csv
48
50
  end
49
51
  end
52
+
53
+ context 'when file does not exist locally' do
54
+ before do
55
+ stub_const 'Dummy', Class.new
56
+
57
+ Dummy.class_eval { include DataMigrater::CSV }
58
+ Dummy.class_eval { data_csv dir: 'missing/path' }
59
+ end
60
+
61
+ it 'does not process' do
62
+ expect(::SmarterCSV).not_to receive(:process)
63
+
64
+ Dummy.new.csv
65
+ end
66
+
67
+ it 'returns an empty array' do
68
+ expect(Dummy.new.csv).to eq []
69
+ end
70
+ end
50
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrater
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-23 00:00:00.000000000 Z
12
+ date: 2019-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord