dirty_seed 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +44 -0
  4. data/Rakefile +22 -0
  5. data/lib/dirty_seed.rb +23 -0
  6. data/lib/dirty_seed/assigners/dirty_assigner.rb +32 -0
  7. data/lib/dirty_seed/assigners/dirty_boolean.rb +14 -0
  8. data/lib/dirty_seed/assigners/dirty_date.rb +14 -0
  9. data/lib/dirty_seed/assigners/dirty_float.rb +28 -0
  10. data/lib/dirty_seed/assigners/dirty_integer.rb +86 -0
  11. data/lib/dirty_seed/assigners/dirty_string.rb +49 -0
  12. data/lib/dirty_seed/assigners/dirty_time.rb +14 -0
  13. data/lib/dirty_seed/data_model.rb +80 -0
  14. data/lib/dirty_seed/dirty_association.rb +106 -0
  15. data/lib/dirty_seed/dirty_attribute.rb +64 -0
  16. data/lib/dirty_seed/dirty_model.rb +123 -0
  17. data/lib/dirty_seed/engine.rb +11 -0
  18. data/lib/dirty_seed/exceptions.rb +6 -0
  19. data/lib/dirty_seed/method_missing_helper.rb +49 -0
  20. data/lib/dirty_seed/sorter.rb +118 -0
  21. data/lib/dirty_seed/version.rb +6 -0
  22. data/lib/tasks/dirty_seed_tasks.rake +8 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/config/manifest.js +3 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  26. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  27. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/javascript/packs/application.js +15 -0
  31. data/spec/dummy/app/jobs/application_job.rb +7 -0
  32. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  33. data/spec/dummy/app/models/alfa.rb +5 -0
  34. data/spec/dummy/app/models/application_record.rb +3 -0
  35. data/spec/dummy/app/models/bravo.rb +3 -0
  36. data/spec/dummy/app/models/charlie.rb +5 -0
  37. data/spec/dummy/app/models/delta.rb +4 -0
  38. data/spec/dummy/app/models/echo.rb +3 -0
  39. data/spec/dummy/app/models/foxtrot.rb +2 -0
  40. data/spec/dummy/app/models/golf.rb +2 -0
  41. data/spec/dummy/app/models/hotel.rb +4 -0
  42. data/spec/dummy/app/models/india.rb +4 -0
  43. data/spec/dummy/app/models/juliett.rb +21 -0
  44. data/spec/dummy/app/models/kilo.rb +2 -0
  45. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  46. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  47. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  48. data/spec/dummy/bin/rails +4 -0
  49. data/spec/dummy/bin/rake +4 -0
  50. data/spec/dummy/bin/setup +33 -0
  51. data/spec/dummy/config.ru +5 -0
  52. data/spec/dummy/config/application.rb +18 -0
  53. data/spec/dummy/config/boot.rb +5 -0
  54. data/spec/dummy/config/cable.yml +10 -0
  55. data/spec/dummy/config/database.yml +25 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +62 -0
  58. data/spec/dummy/config/environments/production.rb +112 -0
  59. data/spec/dummy/config/environments/test.rb +49 -0
  60. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  61. data/spec/dummy/config/initializers/assets.rb +12 -0
  62. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  63. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  64. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  65. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  66. data/spec/dummy/config/initializers/inflections.rb +27 -0
  67. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  69. data/spec/dummy/config/locales/en.yml +33 -0
  70. data/spec/dummy/config/puma.rb +38 -0
  71. data/spec/dummy/config/routes.rb +3 -0
  72. data/spec/dummy/config/spring.rb +6 -0
  73. data/spec/dummy/config/storage.yml +34 -0
  74. data/spec/dummy/db/development.sqlite3 +0 -0
  75. data/spec/dummy/db/migrate/20200923100317_create_alfas.rb +15 -0
  76. data/spec/dummy/db/migrate/20200923100328_create_bravos.rb +12 -0
  77. data/spec/dummy/db/migrate/20200923100329_create_charlies.rb +9 -0
  78. data/spec/dummy/db/migrate/20200923100330_create_deltas.rb +10 -0
  79. data/spec/dummy/db/migrate/20200923100331_create_echos.rb +9 -0
  80. data/spec/dummy/db/migrate/20200923100332_create_foxtrots.rb +9 -0
  81. data/spec/dummy/db/migrate/20200923100334_create_hotels.rb +7 -0
  82. data/spec/dummy/db/migrate/20200923100335_create_indias.rb +11 -0
  83. data/spec/dummy/db/migrate/20200923100336_create_julietts.rb +11 -0
  84. data/spec/dummy/db/migrate/20200923100337_create_kilos.rb +13 -0
  85. data/spec/dummy/db/schema.rb +105 -0
  86. data/spec/dummy/db/test.sqlite3 +0 -0
  87. data/spec/dummy/log/development.log +217 -0
  88. data/spec/dummy/log/test.log +95379 -0
  89. data/spec/dummy/public/404.html +67 -0
  90. data/spec/dummy/public/422.html +67 -0
  91. data/spec/dummy/public/500.html +66 -0
  92. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  93. data/spec/dummy/public/apple-touch-icon.png +0 -0
  94. data/spec/dummy/public/favicon.ico +0 -0
  95. data/spec/dummy/spec/factories/bars.rb +8 -0
  96. data/spec/dummy/spec/factories/foos.rb +7 -0
  97. data/spec/dummy/spec/models/alfa_spec.rb +6 -0
  98. data/spec/dummy/spec/models/bravo_spec.rb +6 -0
  99. data/spec/dummy/spec/models/charlie_spec.rb +6 -0
  100. data/spec/dummy/spec/models/delta_spec.rb +6 -0
  101. data/spec/dummy/spec/models/echo_spec.rb +6 -0
  102. data/spec/dummy/tmp/development_secret.txt +1 -0
  103. data/spec/lib/dirty_seed/assigners/dirty_assigner_spec.rb +13 -0
  104. data/spec/lib/dirty_seed/assigners/dirty_boolean_spec.rb +13 -0
  105. data/spec/lib/dirty_seed/assigners/dirty_date_spec.rb +15 -0
  106. data/spec/lib/dirty_seed/assigners/dirty_float_spec.rb +47 -0
  107. data/spec/lib/dirty_seed/assigners/dirty_integer_spec.rb +49 -0
  108. data/spec/lib/dirty_seed/assigners/dirty_string_spec.rb +15 -0
  109. data/spec/lib/dirty_seed/assigners/dirty_time_spec.rb +15 -0
  110. data/spec/lib/dirty_seed/data_model_spec.rb +72 -0
  111. data/spec/lib/dirty_seed/dirty_association_spec.rb +64 -0
  112. data/spec/lib/dirty_seed/dirty_attribute_spec.rb +49 -0
  113. data/spec/lib/dirty_seed/dirty_model_spec.rb +102 -0
  114. data/spec/lib/dirty_seed/sorter_spec.rb +46 -0
  115. data/spec/lib/tasks/dirty_seed_tasks_spec.rb +21 -0
  116. data/spec/rails_helper.rb +44 -0
  117. data/spec/support/helpers.rb +30 -0
  118. metadata +282 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :bar do
5
+ sequence(:name) { |n| "bar_#{n}" }
6
+ foo
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :foo do
5
+ sequence(:name) { |n| "foo_#{n}" }
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Alfa, type: :model do
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Bravo, type: :model do
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Charlie, type: :model do
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Delta, type: :model do
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Echo, type: :model do
6
+ end
@@ -0,0 +1 @@
1
+ f34061e10e7d7e07535776334a213e311892a60589edc78bb8d7ffde3cb3edb1bd31459ee107ed4eea67ecffa87ae0219ee36ceaf9b084fc30744b1103e36b65
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe DirtySeed::Assigners::DirtyAssigner do
6
+ let(:dirty_attribute) { build_dirty_attribute }
7
+
8
+ describe '#initialize' do
9
+ it 'instantiates an instance' do
10
+ expect(described_class.new(dirty_attribute, 0)).to be_a described_class
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe DirtySeed::Assigners::DirtyBoolean do
6
+ let(:dirty_attribute) { build_dirty_attribute(type: :boolean) }
7
+
8
+ describe '#value' do
9
+ it 'returns a Boolean' do
10
+ expect([true, false]).to include described_class.new(dirty_attribute, 0).value
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe DirtySeed::Assigners::DirtyDate do
6
+ let(:dirty_attribute) { build_dirty_attribute(type: :date) }
7
+
8
+ describe '#value' do
9
+ context 'when there are no validators' do
10
+ it 'returns a Date' do
11
+ expect(described_class.new(dirty_attribute, 0).value).to be_a Date
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe DirtySeed::Assigners::DirtyFloat do
6
+ let(:dirty_attribute) { build_dirty_attribute(type: :float) }
7
+
8
+ describe '#value' do
9
+ context 'when there are no validators' do
10
+ it 'returns an integer' do
11
+ expect(described_class.new(dirty_attribute, 0).value).to be_a Float
12
+ end
13
+ end
14
+
15
+ context 'when there is greater_than validator' do
16
+ it 'returns an integer greater than the requirement' do
17
+ assigner = described_class.new(dirty_attribute, 0)
18
+ validator = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 1_000)
19
+ allow(assigner.dirty_attribute).to receive(:validators).and_return([validator])
20
+ 5.times { expect(assigner.value).to be >= 1_000 }
21
+ end
22
+ end
23
+
24
+ context 'when there is less_than validator' do
25
+ it 'returns an integer less than the requirement' do
26
+ assigner = described_class.new(dirty_attribute, 0)
27
+ validator = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, less_than: -1_000)
28
+ allow(assigner.dirty_attribute).to receive(:validators).and_return([validator])
29
+ 5.times { expect(assigner.value).to be < -1_000 }
30
+ end
31
+ end
32
+
33
+ context 'when there are less_than and greater_than validators' do
34
+ it 'returns an integer greater than and less than the requirements' do
35
+ greater_than = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 1)
36
+ less_than = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, less_than: 5)
37
+ assigner = described_class.new(dirty_attribute, 0)
38
+ allow(assigner.dirty_attribute).to(receive(:validators).and_return([greater_than, less_than]))
39
+ 5.times do
40
+ value = assigner.value
41
+ expect(value).to be > 1
42
+ expect(value).to be < 5
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe DirtySeed::Assigners::DirtyInteger do
6
+ let(:dirty_attribute) { build_dirty_attribute(type: :integer) }
7
+
8
+ describe '#value' do
9
+ context 'when there are no validators' do
10
+ it 'returns an integer' do
11
+ expect(described_class.new(dirty_attribute, 0).value).to be_an Integer
12
+ end
13
+ end
14
+
15
+ context 'when there is greater_than validator' do
16
+ it 'returns an integer greater than the requirement' do
17
+ assigner = described_class.new(dirty_attribute, 0)
18
+ validator = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 1_000)
19
+ allow(assigner.dirty_attribute).to receive(:validators).and_return([validator])
20
+ 5.times { expect(assigner.value).to be >= 1_000 }
21
+ end
22
+ end
23
+
24
+ context 'when there is less_than validator' do
25
+ it 'returns an integer less than the requirement' do
26
+ assigner = described_class.new(dirty_attribute, 0)
27
+ validator = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, less_than: -1_000)
28
+ allow(assigner.dirty_attribute).to receive(:validators).and_return([validator])
29
+ 5.times { expect(assigner.value).to be < -1_000 }
30
+ end
31
+ end
32
+
33
+ context 'when there are less_than and greater_than validators' do
34
+ it 'returns an integer greater than and less than the requirements' do
35
+ greater_than = ActiveModel::Validations::NumericalityValidator.new(attributes: :fake, greater_than: 1)
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
+ assigner = described_class.new(dirty_attribute, 0)
40
+ allow(assigner.dirty_attribute).to receive(:validators).and_return([greater_than, less_than])
41
+ 5.times do
42
+ value = assigner.value
43
+ expect(value).to be > 1
44
+ expect(value).to be < 5
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe DirtySeed::Assigners::DirtyString do
6
+ let(:dirty_attribute) { build_dirty_attribute(type: :string) }
7
+
8
+ describe '#value' do
9
+ context 'when there are no validators' do
10
+ it 'returns a String' do
11
+ expect(described_class.new(dirty_attribute, 0).value).to be_a String
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe DirtySeed::Assigners::DirtyTime do
6
+ let(:dirty_attribute) { build_dirty_attribute(type: :time) }
7
+
8
+ describe '#value' do
9
+ context 'when there are no validators' do
10
+ it 'returns a Time' do
11
+ expect(described_class.new(dirty_attribute, 0).value).to be_a Time
12
+ end
13
+ end
14
+ end
15
+ end