dirty_seed 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -12
- data/lib/dirty_seed/data_model.rb +2 -9
- data/lib/dirty_seed/logger.rb +27 -43
- data/lib/dirty_seed/seeder.rb +70 -42
- data/lib/dirty_seed/version.rb +1 -1
- data/spec/dummy/app/models/alfa.rb +12 -2
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1 -0
- data/spec/dummy/log/test.log +41982 -0
- data/spec/lib/dirty_seed/data_model_spec.rb +7 -5
- data/spec/lib/dirty_seed/seeder_spec.rb +22 -19
- metadata +2 -2
@@ -10,11 +10,13 @@ RSpec.describe DirtySeed::DataModel do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'when logger is "verbose"' do
|
13
|
-
it 'logs
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
it 'logs seeded records count' do
|
14
|
+
expect { described_class.instance.seed(2, verbose: true) }.to output(/seeded: 2/).to_stdout
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'logs unique errors' do
|
18
|
+
expect { described_class.instance.seed(1, verbose: true) }
|
19
|
+
.to output(/(errors:)(.*)(string should be specific)/).to_stdout
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -13,26 +13,25 @@ RSpec.describe DirtySeed::Seeder do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#seed(count)' do
|
16
|
-
it 'tries to create x
|
16
|
+
it 'tries to create x records of the model' do
|
17
17
|
expect { described_class.new(DirtySeed::Model.new(Bravo)).seed(3) }.to change(Bravo, :count).by(3)
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'stores the number of successfully seeded
|
20
|
+
it 'stores the number of successfully seeded records' do
|
21
21
|
seeder = described_class.new(alfa)
|
22
22
|
seeder.seed(3)
|
23
|
-
expect(seeder.
|
23
|
+
expect(seeder.records.count).to eq 3
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
expect(seeder.errors).to include('An integer should be specific')
|
26
|
+
context 'when it raises ActiveRecord::RecordInvalid error' do
|
27
|
+
it 'stores the error' do
|
28
|
+
seeder = described_class.new(DirtySeed::Model.new(Juliett))
|
29
|
+
seeder.seed(1)
|
30
|
+
expect(seeder.errors).to include('A string should be specific')
|
31
|
+
end
|
33
32
|
end
|
34
33
|
|
35
|
-
context 'when
|
34
|
+
context 'when it raises another StandardError' do
|
36
35
|
let(:seeder) { described_class.new(alfa) }
|
37
36
|
|
38
37
|
context 'when it happens on initialize' do
|
@@ -42,14 +41,16 @@ RSpec.describe DirtySeed::Seeder do
|
|
42
41
|
allow(seeder).to receive(:params_collection).and_return([{ a_string: bad_string }])
|
43
42
|
end
|
44
43
|
|
45
|
-
it 'rescues from
|
44
|
+
it 'rescues from StandardError' do
|
46
45
|
expect { Alfa.new(a_string: bad_string) }.to raise_error StandardError
|
47
46
|
expect { seeder.seed(1) }.not_to raise_error
|
48
47
|
end
|
49
48
|
|
50
|
-
it 'adds error to the errors list' do
|
51
|
-
seeder.seed(
|
52
|
-
expect(seeder.errors).to
|
49
|
+
it 'cleans and adds error message to the errors list' do
|
50
|
+
seeder.seed(10)
|
51
|
+
expect(seeder.errors.count).to eq 1
|
52
|
+
expect(seeder.errors.first.length).to be <= 200
|
53
|
+
expect(seeder.errors.first).not_to include("\n")
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -60,14 +61,16 @@ RSpec.describe DirtySeed::Seeder do
|
|
60
61
|
allow(seeder).to receive(:params_collection).and_return([{ a_string: bad_string }])
|
61
62
|
end
|
62
63
|
|
63
|
-
it 'rescues from
|
64
|
+
it 'rescues from StandardError' do
|
64
65
|
expect { Alfa.create(a_string: bad_string) }.to raise_error StandardError
|
65
66
|
expect { seeder.seed(1) }.not_to raise_error
|
66
67
|
end
|
67
68
|
|
68
|
-
it 'adds error to the errors list' do
|
69
|
-
seeder.seed(
|
70
|
-
expect(seeder.errors).to
|
69
|
+
it 'cleans and adds error message to the errors list' do
|
70
|
+
seeder.seed(10)
|
71
|
+
expect(seeder.errors.count).to eq 1
|
72
|
+
expect(seeder.errors.first.length).to be <= 200
|
73
|
+
expect(seeder.errors.first).not_to include("\n")
|
71
74
|
end
|
72
75
|
end
|
73
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dirty_seed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Piron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|