dirty_seed 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +44 -0
- data/Rakefile +22 -0
- data/lib/dirty_seed.rb +23 -0
- data/lib/dirty_seed/assigners/dirty_assigner.rb +32 -0
- data/lib/dirty_seed/assigners/dirty_boolean.rb +14 -0
- data/lib/dirty_seed/assigners/dirty_date.rb +14 -0
- data/lib/dirty_seed/assigners/dirty_float.rb +28 -0
- data/lib/dirty_seed/assigners/dirty_integer.rb +86 -0
- data/lib/dirty_seed/assigners/dirty_string.rb +49 -0
- data/lib/dirty_seed/assigners/dirty_time.rb +14 -0
- data/lib/dirty_seed/data_model.rb +80 -0
- data/lib/dirty_seed/dirty_association.rb +106 -0
- data/lib/dirty_seed/dirty_attribute.rb +64 -0
- data/lib/dirty_seed/dirty_model.rb +123 -0
- data/lib/dirty_seed/engine.rb +11 -0
- data/lib/dirty_seed/exceptions.rb +6 -0
- data/lib/dirty_seed/method_missing_helper.rb +49 -0
- data/lib/dirty_seed/sorter.rb +118 -0
- data/lib/dirty_seed/version.rb +6 -0
- data/lib/tasks/dirty_seed_tasks.rake +8 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/packs/application.js +15 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/alfa.rb +5 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/bravo.rb +3 -0
- data/spec/dummy/app/models/charlie.rb +5 -0
- data/spec/dummy/app/models/delta.rb +4 -0
- data/spec/dummy/app/models/echo.rb +3 -0
- data/spec/dummy/app/models/foxtrot.rb +2 -0
- data/spec/dummy/app/models/golf.rb +2 -0
- data/spec/dummy/app/models/hotel.rb +4 -0
- data/spec/dummy/app/models/india.rb +4 -0
- data/spec/dummy/app/models/juliett.rb +21 -0
- data/spec/dummy/app/models/kilo.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +18 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +62 -0
- data/spec/dummy/config/environments/production.rb +112 -0
- data/spec/dummy/config/environments/test.rb +49 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +12 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +27 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +38 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20200923100317_create_alfas.rb +15 -0
- data/spec/dummy/db/migrate/20200923100328_create_bravos.rb +12 -0
- data/spec/dummy/db/migrate/20200923100329_create_charlies.rb +9 -0
- data/spec/dummy/db/migrate/20200923100330_create_deltas.rb +10 -0
- data/spec/dummy/db/migrate/20200923100331_create_echos.rb +9 -0
- data/spec/dummy/db/migrate/20200923100332_create_foxtrots.rb +9 -0
- data/spec/dummy/db/migrate/20200923100334_create_hotels.rb +7 -0
- data/spec/dummy/db/migrate/20200923100335_create_indias.rb +11 -0
- data/spec/dummy/db/migrate/20200923100336_create_julietts.rb +11 -0
- data/spec/dummy/db/migrate/20200923100337_create_kilos.rb +13 -0
- data/spec/dummy/db/schema.rb +105 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +217 -0
- data/spec/dummy/log/test.log +95379 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/factories/bars.rb +8 -0
- data/spec/dummy/spec/factories/foos.rb +7 -0
- data/spec/dummy/spec/models/alfa_spec.rb +6 -0
- data/spec/dummy/spec/models/bravo_spec.rb +6 -0
- data/spec/dummy/spec/models/charlie_spec.rb +6 -0
- data/spec/dummy/spec/models/delta_spec.rb +6 -0
- data/spec/dummy/spec/models/echo_spec.rb +6 -0
- data/spec/dummy/tmp/development_secret.txt +1 -0
- data/spec/lib/dirty_seed/assigners/dirty_assigner_spec.rb +13 -0
- data/spec/lib/dirty_seed/assigners/dirty_boolean_spec.rb +13 -0
- data/spec/lib/dirty_seed/assigners/dirty_date_spec.rb +15 -0
- data/spec/lib/dirty_seed/assigners/dirty_float_spec.rb +47 -0
- data/spec/lib/dirty_seed/assigners/dirty_integer_spec.rb +49 -0
- data/spec/lib/dirty_seed/assigners/dirty_string_spec.rb +15 -0
- data/spec/lib/dirty_seed/assigners/dirty_time_spec.rb +15 -0
- data/spec/lib/dirty_seed/data_model_spec.rb +72 -0
- data/spec/lib/dirty_seed/dirty_association_spec.rb +64 -0
- data/spec/lib/dirty_seed/dirty_attribute_spec.rb +49 -0
- data/spec/lib/dirty_seed/dirty_model_spec.rb +102 -0
- data/spec/lib/dirty_seed/sorter_spec.rb +46 -0
- data/spec/lib/tasks/dirty_seed_tasks_spec.rb +21 -0
- data/spec/rails_helper.rb +44 -0
- data/spec/support/helpers.rb +30 -0
- metadata +282 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe DirtySeed::DataModel do
|
6
|
+
describe '::seed' do
|
7
|
+
context 'when ApplicationRecord is defined' do
|
8
|
+
it 'seeds instances for each model' do
|
9
|
+
described_class.seed
|
10
|
+
# As expected, Juliett can not be seed
|
11
|
+
[Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Kilo].each do |active_record_model|
|
12
|
+
expect(active_record_model.count).to be > 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when ApplicationRecord is not defined' do
|
18
|
+
it 'puts an error message' do
|
19
|
+
hide_const('ApplicationRecord')
|
20
|
+
expect { described_class.seed }.to raise_error NameError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
xdescribe '::print_logs' do
|
26
|
+
it 'prints logs in the console' do
|
27
|
+
described_class.seed
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '::models' do
|
32
|
+
it 'returns an array of dirty models representing Active Record models' do
|
33
|
+
expect(described_class.models.map(&:name)).to match_array(
|
34
|
+
%w[Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliett Kilo]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '::active_record_models' do
|
40
|
+
let(:active_record_models) { described_class.active_record_models }
|
41
|
+
|
42
|
+
it 'returns an array of Active Record models' do
|
43
|
+
expect(active_record_models).to match_array(
|
44
|
+
[Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Juliett, Kilo]
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'sorts models with associations' do
|
49
|
+
expect(active_record_models.index(Alfa)).to be < active_record_models.index(Delta)
|
50
|
+
expect(active_record_models.index(Alfa)).to be < active_record_models.index(Echo)
|
51
|
+
expect(active_record_models.index(Alfa)).to be < active_record_models.index(Juliett)
|
52
|
+
expect(active_record_models.index(Charlie)).to be < active_record_models.index(Echo)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#method_missing' do
|
57
|
+
context 'when method_name matches an ActiveRecord model' do
|
58
|
+
it 'returns the related dirty model' do
|
59
|
+
dirty_alfa = described_class.models.find { |dirty_model| dirty_model.model == Alfa }
|
60
|
+
expect(described_class.respond_to_missing?(:alfa)).to be true
|
61
|
+
expect(described_class.alfa).to eq dirty_alfa
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when method_name does not match an ActiveRecord model' do
|
66
|
+
it 'raises a NoMethodError' do
|
67
|
+
expect(described_class.respond_to_missing?(:foo)).to be false
|
68
|
+
expect { described_class.foo }.to raise_error NoMethodError
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe DirtySeed::DirtyAssociation do
|
6
|
+
let(:dirty_model) { DirtySeed::DataModel.charlie }
|
7
|
+
let(:reflection) { Charlie.reflections['alfa'] }
|
8
|
+
let(:dirty_association) { described_class.new(dirty_model, reflection) }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
it 'instantiates an instance' do
|
12
|
+
expect(dirty_association).to be_a described_class
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#dirty_model' do
|
17
|
+
it 'returns dirty model' do
|
18
|
+
expect(dirty_association.dirty_model).to eq dirty_model
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#name' do
|
23
|
+
it 'returns attribute name' do
|
24
|
+
expect(dirty_association.name).to eq :alfa
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#attribute' do
|
29
|
+
it 'returns attribute of this association' do
|
30
|
+
expect(dirty_association.attribute).to eq :alfa_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#associated_models' do
|
35
|
+
context 'when the reflection is regular' do
|
36
|
+
it 'returns belongs_to association' do
|
37
|
+
expect(dirty_association.associated_models).to eq [Alfa]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when the reflection is polymorphic' do
|
42
|
+
it 'returns models associated with has_many or has_one' do
|
43
|
+
dirty_model = DirtySeed::DataModel.echo
|
44
|
+
reflection = Echo.reflections['echoable']
|
45
|
+
dirty_association = described_class.new(dirty_model, reflection)
|
46
|
+
expect(dirty_association.associated_models).to eq [Alfa, Charlie]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when the reflection is cyclic (a belongs to b and b optionnally belongs to a)' do
|
51
|
+
it 'returns models accepting this one as polymorphic' do
|
52
|
+
dirty_model = DirtySeed::DataModel.hotel
|
53
|
+
reflection = Hotel.reflections['india']
|
54
|
+
dirty_association = described_class.new(dirty_model, reflection)
|
55
|
+
expect(dirty_association.associated_models).to eq [India]
|
56
|
+
|
57
|
+
dirty_model = DirtySeed::DataModel.india
|
58
|
+
reflection = India.reflections['hotel']
|
59
|
+
dirty_association = described_class.new(dirty_model, reflection)
|
60
|
+
expect(dirty_association.associated_models).to eq [Hotel]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe DirtySeed::DirtyAttribute do
|
6
|
+
let(:dirty_attribute) { described_class.new(build_dirty_model, build_column) }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'instantiates an instance' do
|
10
|
+
expect(dirty_attribute).to be_a described_class
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#dirty_model' do
|
15
|
+
it 'returns dirty model' do
|
16
|
+
expect(dirty_attribute.dirty_model).to be_a DirtySeed::DirtyModel
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#type' do
|
21
|
+
context 'when column is a boolean' do
|
22
|
+
it 'returns :boolean' do
|
23
|
+
dirty_attribute = described_class.new(build_dirty_model, build_column(type: :boolean))
|
24
|
+
expect(dirty_attribute.type).to eq :boolean
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when column is an integer' do
|
29
|
+
it 'returns :integer' do
|
30
|
+
dirty_attribute = described_class.new(build_dirty_model, build_column(type: :integer))
|
31
|
+
expect(dirty_attribute.type).to eq :integer
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when column is a decimal' do
|
36
|
+
it 'returns :float' do
|
37
|
+
dirty_attribute = described_class.new(build_dirty_model, build_column(type: :float))
|
38
|
+
expect(dirty_attribute.type).to eq :float
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when column is a string' do
|
43
|
+
it 'returns :string' do
|
44
|
+
dirty_attribute = described_class.new(build_dirty_model, build_column(type: :string))
|
45
|
+
expect(dirty_attribute.type).to eq :string
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe DirtySeed::DirtyModel do
|
6
|
+
let(:data_model) { DirtySeed::DataModel }
|
7
|
+
|
8
|
+
describe '#initialize(model:)' do
|
9
|
+
it 'instantiates an instance' do
|
10
|
+
expect(described_class.new(Alfa)).to be_a described_class
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#seed(count)' do
|
15
|
+
it 'tries to create <count> instances of the model' do
|
16
|
+
expect { data_model.alfa.seed(3) }.to change { Alfa.count }.by(3)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'counts the number of successfully seeded instances' do
|
20
|
+
data_model.alfa.seed(3)
|
21
|
+
expect(data_model.alfa.count).to eq 3
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'logs the errors' do
|
25
|
+
Alfa.create!
|
26
|
+
data_model.juliett.seed(3)
|
27
|
+
expect(data_model.juliett.errors).to match_array(
|
28
|
+
[
|
29
|
+
'Alfa should be some specific alfa',
|
30
|
+
'String should be a specific string',
|
31
|
+
'Integer should be a specific integer'
|
32
|
+
]
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#associations' do
|
38
|
+
it 'returns associations' do
|
39
|
+
expect(data_model.alfa.associations.count).to eq 0
|
40
|
+
expect(data_model.bravo.associations.count).to eq 0
|
41
|
+
expect(data_model.charlie.associations.count).to eq 1
|
42
|
+
expect(data_model.delta.associations.count).to eq 2
|
43
|
+
expect(data_model.echo.associations.count).to eq 1
|
44
|
+
expect(data_model.foxtrot.associations.count).to eq 0
|
45
|
+
expect(data_model.golf.associations.count).to eq 0
|
46
|
+
expect(data_model.hotel.associations.count).to eq 1
|
47
|
+
expect(data_model.india.associations.count).to eq 1
|
48
|
+
expect(data_model.juliett.associations.count).to eq 1
|
49
|
+
expect(data_model.kilo.associations.count).to eq 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#associated_models' do
|
54
|
+
it 'returns belongs_to models' do
|
55
|
+
expect(data_model.alfa.associated_models).to be_empty
|
56
|
+
expect(data_model.bravo.associated_models).to be_empty
|
57
|
+
expect(data_model.charlie.associated_models).to match_array([Alfa])
|
58
|
+
expect(data_model.delta.associated_models).to match_array([Bravo, Charlie])
|
59
|
+
expect(data_model.echo.associated_models).to match_array([Alfa, Charlie])
|
60
|
+
expect(data_model.foxtrot.associated_models).to be_empty
|
61
|
+
expect(data_model.golf.associated_models).to be_empty
|
62
|
+
expect(data_model.hotel.associated_models).to match_array([India])
|
63
|
+
expect(data_model.india.associated_models).to match_array([Hotel])
|
64
|
+
expect(data_model.juliett.associated_models).to match_array([Alfa])
|
65
|
+
expect(data_model.kilo.associated_models).to be_empty
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#attributes' do
|
70
|
+
it 'defines attributes' do
|
71
|
+
expect(data_model.alfa.attributes.count).to eq 7
|
72
|
+
expect(data_model.bravo.attributes.count).to eq 4
|
73
|
+
expect(data_model.charlie.attributes.count).to eq 0
|
74
|
+
expect(data_model.delta.attributes.count).to eq 0
|
75
|
+
expect(data_model.echo.attributes.count).to eq 0
|
76
|
+
expect(data_model.foxtrot.attributes.count).to eq 0
|
77
|
+
expect(data_model.golf.attributes.count).to eq 0
|
78
|
+
expect(data_model.hotel.attributes.count).to eq 0
|
79
|
+
expect(data_model.india.attributes.count).to eq 0
|
80
|
+
expect(data_model.juliett.attributes.count).to eq 2
|
81
|
+
expect(data_model.kilo.attributes.count).to eq 0
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#method_missing' do
|
86
|
+
context 'when model respond to the method' do
|
87
|
+
it 'calls method on model' do
|
88
|
+
expect(DirtySeed::DirtyModel.instance_methods(false)).to_not include :name
|
89
|
+
expect(Alfa.methods).to include :name
|
90
|
+
expect(data_model.alfa.name).to eq Alfa.name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when model does not respond to the method' do
|
95
|
+
it 'raises a NoMethodError' do
|
96
|
+
expect(DirtySeed::DirtyModel.instance_methods(false)).to_not include :foo
|
97
|
+
expect(Alfa.methods).to_not include :foo
|
98
|
+
expect { data_model.alfa.foo }.to raise_error NoMethodError
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe DirtySeed::Sorter do
|
6
|
+
describe '#initialize' do
|
7
|
+
it 'instantiates an instance' do
|
8
|
+
expect(described_class.new([Alfa, Bravo])).to be_a described_class
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#sort' do
|
13
|
+
it 'returns an empty array if models is empty' do
|
14
|
+
sorted = DirtySeed::Sorter.new([]).sort!
|
15
|
+
expect(sorted).to be_empty
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sorts models by dependencies [1]' do
|
19
|
+
sorted = DirtySeed::Sorter.new([Alfa, Charlie]).sort!
|
20
|
+
expect(sorted).to eq([Alfa, Charlie])
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sorts models by dependencies [2]' do
|
24
|
+
sorted = DirtySeed::Sorter.new([Charlie, Alfa]).sort!
|
25
|
+
expect(sorted).to eq([Alfa, Charlie])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sorts models by dependencies [3]' do
|
29
|
+
active_record_models = [Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Juliett, Kilo]
|
30
|
+
10.times do
|
31
|
+
sorted = DirtySeed::Sorter.new(active_record_models.shuffle).sort!
|
32
|
+
expect(sorted.index(Alfa)).to be < sorted.index(Delta)
|
33
|
+
expect(sorted.index(Alfa)).to be < sorted.index(Echo)
|
34
|
+
expect(sorted.index(Charlie)).to be < sorted.index(Echo)
|
35
|
+
expect(sorted.index(Hotel)).to be < sorted.index(India)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when infinite loop could happens' do
|
40
|
+
it 'does not raise error' do
|
41
|
+
sorted = DirtySeed::Sorter.new([India, Hotel]).sort!
|
42
|
+
expect(sorted).to eq([Hotel, India])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
Rails.application.load_tasks
|
6
|
+
|
7
|
+
RSpec.describe 'Dirty Seed' do
|
8
|
+
describe 'dirty_seed:seed' do
|
9
|
+
before(:each) do
|
10
|
+
# prevent logs in specs
|
11
|
+
allow_any_instance_of(DirtySeed::DataModel).to(receive(:print_logs).and_return(nil))
|
12
|
+
Rake::Task[:'dirty_seed:seed'].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'seeds data' do
|
16
|
+
# As expected, Juliett can not be seed
|
17
|
+
active_record_models = [Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Kilo]
|
18
|
+
expect(active_record_models.map(&:count).all?(&:positive?)).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start 'rails' do
|
5
|
+
add_filter 'lib/dirty_seed/version.rb'
|
6
|
+
end
|
7
|
+
|
8
|
+
ENV['RAILS_ENV'] ||= 'test'
|
9
|
+
|
10
|
+
ENGINE_ROOT = File.join(File.dirname(__FILE__), '../')
|
11
|
+
|
12
|
+
# Load environment.rb from the dummy app.
|
13
|
+
require File.expand_path('dummy/config/environment', __dir__)
|
14
|
+
|
15
|
+
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
16
|
+
|
17
|
+
require 'database_cleaner'
|
18
|
+
require 'factory_bot_rails'
|
19
|
+
require 'rspec/rails'
|
20
|
+
Dir[Rails.root.join('..', '..', 'spec', 'support', '**', '*.rb')].sort.each { |f| require f }
|
21
|
+
|
22
|
+
# Load migrations from the dummy app.
|
23
|
+
ActiveRecord::Migrator.migrations_paths = File.join(ENGINE_ROOT, 'spec/dummy/db/migrate')
|
24
|
+
ActiveRecord::Migration.maintain_test_schema!
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.include FactoryBot::Syntax::Methods
|
28
|
+
|
29
|
+
config.before(:suite) do
|
30
|
+
DatabaseCleaner.clean_with(:truncation)
|
31
|
+
DatabaseCleaner.strategy = :transaction
|
32
|
+
end
|
33
|
+
|
34
|
+
config.around(:each) do |example|
|
35
|
+
DirtySeed::Engine.initializers.each(&:run)
|
36
|
+
DatabaseCleaner.cleaning do
|
37
|
+
example.run
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
config.use_transactional_fixtures = true
|
42
|
+
config.infer_spec_type_from_file_location!
|
43
|
+
config.filter_rails_from_backtrace!
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def build_column(name: nil, type: :boolean)
|
4
|
+
ActiveRecord::ConnectionAdapters::Column.new(
|
5
|
+
name || "my_#{type}",
|
6
|
+
false,
|
7
|
+
ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(type: sql_type(type))
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_dirty_attribute(name: nil, dirty_model: nil, type: :boolean)
|
12
|
+
DirtySeed::DirtyAttribute.new(
|
13
|
+
dirty_model || build_dirty_model,
|
14
|
+
build_column(name: name, type: type)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_dirty_model(model: Alfa)
|
19
|
+
DirtySeed::DirtyModel.new(model)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def sql_type(type)
|
25
|
+
case type
|
26
|
+
when :float then :decimal
|
27
|
+
when :time then :datetime
|
28
|
+
else type
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,282 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dirty_seed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edouard Piron
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faker
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.14.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.0'
|
41
|
+
description: Description of DirtySeed.
|
42
|
+
email:
|
43
|
+
- ed.piron@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/dirty_seed.rb
|
52
|
+
- lib/dirty_seed/assigners/dirty_assigner.rb
|
53
|
+
- lib/dirty_seed/assigners/dirty_boolean.rb
|
54
|
+
- lib/dirty_seed/assigners/dirty_date.rb
|
55
|
+
- lib/dirty_seed/assigners/dirty_float.rb
|
56
|
+
- lib/dirty_seed/assigners/dirty_integer.rb
|
57
|
+
- lib/dirty_seed/assigners/dirty_string.rb
|
58
|
+
- lib/dirty_seed/assigners/dirty_time.rb
|
59
|
+
- lib/dirty_seed/data_model.rb
|
60
|
+
- lib/dirty_seed/dirty_association.rb
|
61
|
+
- lib/dirty_seed/dirty_attribute.rb
|
62
|
+
- lib/dirty_seed/dirty_model.rb
|
63
|
+
- lib/dirty_seed/engine.rb
|
64
|
+
- lib/dirty_seed/exceptions.rb
|
65
|
+
- lib/dirty_seed/method_missing_helper.rb
|
66
|
+
- lib/dirty_seed/sorter.rb
|
67
|
+
- lib/dirty_seed/version.rb
|
68
|
+
- lib/tasks/dirty_seed_tasks.rake
|
69
|
+
- spec/dummy/Rakefile
|
70
|
+
- spec/dummy/app/assets/config/manifest.js
|
71
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
72
|
+
- spec/dummy/app/channels/application_cable/channel.rb
|
73
|
+
- spec/dummy/app/channels/application_cable/connection.rb
|
74
|
+
- spec/dummy/app/controllers/application_controller.rb
|
75
|
+
- spec/dummy/app/helpers/application_helper.rb
|
76
|
+
- spec/dummy/app/javascript/packs/application.js
|
77
|
+
- spec/dummy/app/jobs/application_job.rb
|
78
|
+
- spec/dummy/app/mailers/application_mailer.rb
|
79
|
+
- spec/dummy/app/models/alfa.rb
|
80
|
+
- spec/dummy/app/models/application_record.rb
|
81
|
+
- spec/dummy/app/models/bravo.rb
|
82
|
+
- spec/dummy/app/models/charlie.rb
|
83
|
+
- spec/dummy/app/models/delta.rb
|
84
|
+
- spec/dummy/app/models/echo.rb
|
85
|
+
- spec/dummy/app/models/foxtrot.rb
|
86
|
+
- spec/dummy/app/models/golf.rb
|
87
|
+
- spec/dummy/app/models/hotel.rb
|
88
|
+
- spec/dummy/app/models/india.rb
|
89
|
+
- spec/dummy/app/models/juliett.rb
|
90
|
+
- spec/dummy/app/models/kilo.rb
|
91
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
92
|
+
- spec/dummy/app/views/layouts/mailer.html.erb
|
93
|
+
- spec/dummy/app/views/layouts/mailer.text.erb
|
94
|
+
- spec/dummy/bin/rails
|
95
|
+
- spec/dummy/bin/rake
|
96
|
+
- spec/dummy/bin/setup
|
97
|
+
- spec/dummy/config.ru
|
98
|
+
- spec/dummy/config/application.rb
|
99
|
+
- spec/dummy/config/boot.rb
|
100
|
+
- spec/dummy/config/cable.yml
|
101
|
+
- spec/dummy/config/database.yml
|
102
|
+
- spec/dummy/config/environment.rb
|
103
|
+
- spec/dummy/config/environments/development.rb
|
104
|
+
- spec/dummy/config/environments/production.rb
|
105
|
+
- spec/dummy/config/environments/test.rb
|
106
|
+
- spec/dummy/config/initializers/application_controller_renderer.rb
|
107
|
+
- spec/dummy/config/initializers/assets.rb
|
108
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
109
|
+
- spec/dummy/config/initializers/content_security_policy.rb
|
110
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
111
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
112
|
+
- spec/dummy/config/initializers/inflections.rb
|
113
|
+
- spec/dummy/config/initializers/mime_types.rb
|
114
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
115
|
+
- spec/dummy/config/locales/en.yml
|
116
|
+
- spec/dummy/config/puma.rb
|
117
|
+
- spec/dummy/config/routes.rb
|
118
|
+
- spec/dummy/config/spring.rb
|
119
|
+
- spec/dummy/config/storage.yml
|
120
|
+
- spec/dummy/db/development.sqlite3
|
121
|
+
- spec/dummy/db/migrate/20200923100317_create_alfas.rb
|
122
|
+
- spec/dummy/db/migrate/20200923100328_create_bravos.rb
|
123
|
+
- spec/dummy/db/migrate/20200923100329_create_charlies.rb
|
124
|
+
- spec/dummy/db/migrate/20200923100330_create_deltas.rb
|
125
|
+
- spec/dummy/db/migrate/20200923100331_create_echos.rb
|
126
|
+
- spec/dummy/db/migrate/20200923100332_create_foxtrots.rb
|
127
|
+
- spec/dummy/db/migrate/20200923100334_create_hotels.rb
|
128
|
+
- spec/dummy/db/migrate/20200923100335_create_indias.rb
|
129
|
+
- spec/dummy/db/migrate/20200923100336_create_julietts.rb
|
130
|
+
- spec/dummy/db/migrate/20200923100337_create_kilos.rb
|
131
|
+
- spec/dummy/db/schema.rb
|
132
|
+
- spec/dummy/db/test.sqlite3
|
133
|
+
- spec/dummy/log/development.log
|
134
|
+
- spec/dummy/log/test.log
|
135
|
+
- spec/dummy/public/404.html
|
136
|
+
- spec/dummy/public/422.html
|
137
|
+
- spec/dummy/public/500.html
|
138
|
+
- spec/dummy/public/apple-touch-icon-precomposed.png
|
139
|
+
- spec/dummy/public/apple-touch-icon.png
|
140
|
+
- spec/dummy/public/favicon.ico
|
141
|
+
- spec/dummy/spec/factories/bars.rb
|
142
|
+
- spec/dummy/spec/factories/foos.rb
|
143
|
+
- spec/dummy/spec/models/alfa_spec.rb
|
144
|
+
- spec/dummy/spec/models/bravo_spec.rb
|
145
|
+
- spec/dummy/spec/models/charlie_spec.rb
|
146
|
+
- spec/dummy/spec/models/delta_spec.rb
|
147
|
+
- spec/dummy/spec/models/echo_spec.rb
|
148
|
+
- spec/dummy/tmp/development_secret.txt
|
149
|
+
- spec/lib/dirty_seed/assigners/dirty_assigner_spec.rb
|
150
|
+
- spec/lib/dirty_seed/assigners/dirty_boolean_spec.rb
|
151
|
+
- spec/lib/dirty_seed/assigners/dirty_date_spec.rb
|
152
|
+
- spec/lib/dirty_seed/assigners/dirty_float_spec.rb
|
153
|
+
- spec/lib/dirty_seed/assigners/dirty_integer_spec.rb
|
154
|
+
- spec/lib/dirty_seed/assigners/dirty_string_spec.rb
|
155
|
+
- spec/lib/dirty_seed/assigners/dirty_time_spec.rb
|
156
|
+
- spec/lib/dirty_seed/data_model_spec.rb
|
157
|
+
- spec/lib/dirty_seed/dirty_association_spec.rb
|
158
|
+
- spec/lib/dirty_seed/dirty_attribute_spec.rb
|
159
|
+
- spec/lib/dirty_seed/dirty_model_spec.rb
|
160
|
+
- spec/lib/dirty_seed/sorter_spec.rb
|
161
|
+
- spec/lib/tasks/dirty_seed_tasks_spec.rb
|
162
|
+
- spec/rails_helper.rb
|
163
|
+
- spec/support/helpers.rb
|
164
|
+
homepage: https://github.com/BigBigDoudou/dirty_seed
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '2.6'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubygems_version: 3.1.4
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: Summary of DirtySeed.
|
187
|
+
test_files:
|
188
|
+
- spec/lib/dirty_seed/assigners/dirty_assigner_spec.rb
|
189
|
+
- spec/lib/dirty_seed/assigners/dirty_time_spec.rb
|
190
|
+
- spec/lib/dirty_seed/assigners/dirty_string_spec.rb
|
191
|
+
- spec/lib/dirty_seed/assigners/dirty_float_spec.rb
|
192
|
+
- spec/lib/dirty_seed/assigners/dirty_date_spec.rb
|
193
|
+
- spec/lib/dirty_seed/assigners/dirty_boolean_spec.rb
|
194
|
+
- spec/lib/dirty_seed/assigners/dirty_integer_spec.rb
|
195
|
+
- spec/lib/dirty_seed/data_model_spec.rb
|
196
|
+
- spec/lib/dirty_seed/dirty_model_spec.rb
|
197
|
+
- spec/lib/dirty_seed/dirty_association_spec.rb
|
198
|
+
- spec/lib/dirty_seed/dirty_attribute_spec.rb
|
199
|
+
- spec/lib/dirty_seed/sorter_spec.rb
|
200
|
+
- spec/lib/tasks/dirty_seed_tasks_spec.rb
|
201
|
+
- spec/dummy/config.ru
|
202
|
+
- spec/dummy/public/apple-touch-icon.png
|
203
|
+
- spec/dummy/public/apple-touch-icon-precomposed.png
|
204
|
+
- spec/dummy/public/404.html
|
205
|
+
- spec/dummy/public/favicon.ico
|
206
|
+
- spec/dummy/public/500.html
|
207
|
+
- spec/dummy/public/422.html
|
208
|
+
- spec/dummy/db/development.sqlite3
|
209
|
+
- spec/dummy/db/schema.rb
|
210
|
+
- spec/dummy/db/test.sqlite3
|
211
|
+
- spec/dummy/db/migrate/20200923100334_create_hotels.rb
|
212
|
+
- spec/dummy/db/migrate/20200923100335_create_indias.rb
|
213
|
+
- spec/dummy/db/migrate/20200923100336_create_julietts.rb
|
214
|
+
- spec/dummy/db/migrate/20200923100337_create_kilos.rb
|
215
|
+
- spec/dummy/db/migrate/20200923100330_create_deltas.rb
|
216
|
+
- spec/dummy/db/migrate/20200923100332_create_foxtrots.rb
|
217
|
+
- spec/dummy/db/migrate/20200923100317_create_alfas.rb
|
218
|
+
- spec/dummy/db/migrate/20200923100329_create_charlies.rb
|
219
|
+
- spec/dummy/db/migrate/20200923100328_create_bravos.rb
|
220
|
+
- spec/dummy/db/migrate/20200923100331_create_echos.rb
|
221
|
+
- spec/dummy/config/routes.rb
|
222
|
+
- spec/dummy/config/puma.rb
|
223
|
+
- spec/dummy/config/environment.rb
|
224
|
+
- spec/dummy/config/initializers/inflections.rb
|
225
|
+
- spec/dummy/config/initializers/mime_types.rb
|
226
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
227
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
228
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
229
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
230
|
+
- spec/dummy/config/initializers/application_controller_renderer.rb
|
231
|
+
- spec/dummy/config/initializers/assets.rb
|
232
|
+
- spec/dummy/config/initializers/content_security_policy.rb
|
233
|
+
- spec/dummy/config/cable.yml
|
234
|
+
- spec/dummy/config/boot.rb
|
235
|
+
- spec/dummy/config/locales/en.yml
|
236
|
+
- spec/dummy/config/environments/test.rb
|
237
|
+
- spec/dummy/config/environments/development.rb
|
238
|
+
- spec/dummy/config/environments/production.rb
|
239
|
+
- spec/dummy/config/database.yml
|
240
|
+
- spec/dummy/config/application.rb
|
241
|
+
- spec/dummy/config/storage.yml
|
242
|
+
- spec/dummy/config/spring.rb
|
243
|
+
- spec/dummy/Rakefile
|
244
|
+
- spec/dummy/log/development.log
|
245
|
+
- spec/dummy/log/test.log
|
246
|
+
- spec/dummy/app/javascript/packs/application.js
|
247
|
+
- spec/dummy/app/assets/config/manifest.js
|
248
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
249
|
+
- spec/dummy/app/mailers/application_mailer.rb
|
250
|
+
- spec/dummy/app/views/layouts/mailer.text.erb
|
251
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
252
|
+
- spec/dummy/app/views/layouts/mailer.html.erb
|
253
|
+
- spec/dummy/app/jobs/application_job.rb
|
254
|
+
- spec/dummy/app/channels/application_cable/channel.rb
|
255
|
+
- spec/dummy/app/channels/application_cable/connection.rb
|
256
|
+
- spec/dummy/app/helpers/application_helper.rb
|
257
|
+
- spec/dummy/app/models/echo.rb
|
258
|
+
- spec/dummy/app/models/kilo.rb
|
259
|
+
- spec/dummy/app/models/hotel.rb
|
260
|
+
- spec/dummy/app/models/alfa.rb
|
261
|
+
- spec/dummy/app/models/india.rb
|
262
|
+
- spec/dummy/app/models/application_record.rb
|
263
|
+
- spec/dummy/app/models/delta.rb
|
264
|
+
- spec/dummy/app/models/charlie.rb
|
265
|
+
- spec/dummy/app/models/bravo.rb
|
266
|
+
- spec/dummy/app/models/juliett.rb
|
267
|
+
- spec/dummy/app/models/foxtrot.rb
|
268
|
+
- spec/dummy/app/models/golf.rb
|
269
|
+
- spec/dummy/app/controllers/application_controller.rb
|
270
|
+
- spec/dummy/bin/rake
|
271
|
+
- spec/dummy/bin/setup
|
272
|
+
- spec/dummy/bin/rails
|
273
|
+
- spec/dummy/tmp/development_secret.txt
|
274
|
+
- spec/dummy/spec/factories/bars.rb
|
275
|
+
- spec/dummy/spec/factories/foos.rb
|
276
|
+
- spec/dummy/spec/models/charlie_spec.rb
|
277
|
+
- spec/dummy/spec/models/bravo_spec.rb
|
278
|
+
- spec/dummy/spec/models/alfa_spec.rb
|
279
|
+
- spec/dummy/spec/models/delta_spec.rb
|
280
|
+
- spec/dummy/spec/models/echo_spec.rb
|
281
|
+
- spec/support/helpers.rb
|
282
|
+
- spec/rails_helper.rb
|