dirty_seed 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +246 -12
- data/lib/dirty_seed/assigners/dirty_boolean.rb +1 -1
- data/lib/dirty_seed/assigners/dirty_date.rb +1 -1
- data/lib/dirty_seed/assigners/dirty_float.rb +3 -3
- data/lib/dirty_seed/assigners/dirty_integer.rb +4 -4
- data/lib/dirty_seed/assigners/dirty_string.rb +33 -28
- data/lib/dirty_seed/assigners/dirty_time.rb +2 -2
- data/lib/dirty_seed/assigners/fakers.yml +93 -0
- data/lib/dirty_seed/data_model.rb +15 -13
- data/lib/dirty_seed/dirty_attribute.rb +10 -4
- data/lib/dirty_seed/dirty_model.rb +4 -10
- data/lib/dirty_seed/version.rb +1 -1
- data/spec/dummy/app/models/bravo.rb +4 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +3 -0
- data/spec/dummy/log/test.log +15456 -0
- data/spec/lib/dirty_seed/assigners/dirty_integer_spec.rb +0 -2
- data/spec/lib/dirty_seed/assigners/dirty_string_spec.rb +10 -0
- data/spec/lib/dirty_seed/data_model_spec.rb +3 -3
- data/spec/lib/dirty_seed/dirty_model_spec.rb +5 -5
- metadata +3 -2
@@ -34,8 +34,6 @@ RSpec.describe DirtySeed::Assigners::DirtyInteger do
|
|
34
34
|
it 'returns an integer greater than and less than the requirements' do
|
35
35
|
greater_than = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 1)
|
36
36
|
less_than = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, less_than: 5)
|
37
|
-
# greater_than = set_validator(type: :greater_than, value: 1)
|
38
|
-
# less_than = set_validator(type: :less_than, value: 5)
|
39
37
|
assigner = described_class.new(dirty_attribute, 0)
|
40
38
|
allow(assigner.dirty_attribute).to receive(:validators).and_return([greater_than, less_than])
|
41
39
|
5.times do
|
@@ -11,5 +11,15 @@ RSpec.describe DirtySeed::Assigners::DirtyString do
|
|
11
11
|
expect(described_class.new(dirty_attribute, 0).value).to be_a String
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
context 'when meaning can be guessed' do
|
16
|
+
it 'returns a meaningfull String' do
|
17
|
+
email_attribute = build_dirty_attribute(name: 'email', type: :string)
|
18
|
+
10.times do
|
19
|
+
value = described_class.new(email_attribute, 0).value
|
20
|
+
expect(URI::MailTo::EMAIL_REGEXP.match?(value)).to be true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
14
24
|
end
|
15
25
|
end
|
@@ -28,9 +28,9 @@ RSpec.describe DirtySeed::DataModel do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe '::
|
31
|
+
describe '::dirty_models' do
|
32
32
|
it 'returns an array of dirty models representing Active Record models' do
|
33
|
-
expect(described_class.
|
33
|
+
expect(described_class.dirty_models.map(&:name)).to match_array(
|
34
34
|
%w[Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliett Kilo]
|
35
35
|
)
|
36
36
|
end
|
@@ -56,7 +56,7 @@ RSpec.describe DirtySeed::DataModel do
|
|
56
56
|
describe '#method_missing' do
|
57
57
|
context 'when method_name matches an ActiveRecord model' do
|
58
58
|
it 'returns the related dirty model' do
|
59
|
-
dirty_alfa = described_class.
|
59
|
+
dirty_alfa = described_class.dirty_models.find { |dirty_model| dirty_model.model == Alfa }
|
60
60
|
expect(described_class.respond_to_missing?(:alfa)).to be true
|
61
61
|
expect(described_class.alfa).to eq dirty_alfa
|
62
62
|
end
|
@@ -11,19 +11,19 @@ RSpec.describe DirtySeed::DirtyModel do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe '#seed(count)' do
|
15
|
-
it 'tries to create
|
16
|
-
expect { data_model.alfa.seed(3) }.to change { Alfa.count }.by(3)
|
14
|
+
describe '#seed(count: x, offset: y)' do
|
15
|
+
it 'tries to create x instances of the model' do
|
16
|
+
expect { data_model.alfa.seed(count: 3) }.to change { Alfa.count }.by(3)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'counts the number of successfully seeded instances' do
|
20
|
-
data_model.alfa.seed(3)
|
20
|
+
data_model.alfa.seed(count: 3)
|
21
21
|
expect(data_model.alfa.count).to eq 3
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'logs the errors' do
|
25
25
|
Alfa.create!
|
26
|
-
data_model.juliett.seed(3)
|
26
|
+
data_model.juliett.seed(count: 3)
|
27
27
|
expect(data_model.juliett.errors).to match_array(
|
28
28
|
[
|
29
29
|
'Alfa should be some specific alfa',
|
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.1.
|
4
|
+
version: 0.1.6
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/dirty_seed/assigners/dirty_integer.rb
|
63
63
|
- lib/dirty_seed/assigners/dirty_string.rb
|
64
64
|
- lib/dirty_seed/assigners/dirty_time.rb
|
65
|
+
- lib/dirty_seed/assigners/fakers.yml
|
65
66
|
- lib/dirty_seed/data_model.rb
|
66
67
|
- lib/dirty_seed/dirty_association.rb
|
67
68
|
- lib/dirty_seed/dirty_attribute.rb
|