test_data 0.0.2 → 0.2.2

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -5
  3. data/.standard.yml +2 -0
  4. data/CHANGELOG.md +41 -0
  5. data/Gemfile.lock +16 -16
  6. data/LICENSE.txt +1 -6
  7. data/README.md +864 -501
  8. data/example/.gitignore +1 -4
  9. data/example/Gemfile.lock +74 -74
  10. data/example/config/application.rb +3 -0
  11. data/example/config/credentials.yml.enc +1 -2
  12. data/example/spec/rails_helper.rb +1 -1
  13. data/example/spec/requests/boops_spec.rb +1 -5
  14. data/example/spec/requests/rails_fixtures_override_spec.rb +106 -0
  15. data/example/test/integration/better_mode_switching_demo_test.rb +6 -10
  16. data/example/test/integration/fixture_load_count_test.rb +82 -0
  17. data/example/test/integration/load_rollback_truncate_test.rb +40 -45
  18. data/example/test/integration/mode_switching_demo_test.rb +4 -14
  19. data/example/test/integration/parallel_boops_with_fixtures_test.rb +2 -6
  20. data/example/test/integration/parallel_boops_without_fixtures_test.rb +2 -6
  21. data/example/test/integration/rails_fixtures_double_load_test.rb +10 -0
  22. data/example/test/integration/rails_fixtures_override_test.rb +110 -0
  23. data/example/test/integration/test_data_hooks_test.rb +89 -0
  24. data/example/test/integration/transaction_committing_boops_test.rb +5 -3
  25. data/example/test/test_helper.rb +2 -6
  26. data/lib/generators/test_data/cable_yaml_generator.rb +18 -0
  27. data/lib/generators/test_data/database_yaml_generator.rb +2 -3
  28. data/lib/generators/test_data/environment_file_generator.rb +7 -0
  29. data/lib/generators/test_data/initializer_generator.rb +20 -7
  30. data/lib/generators/test_data/secrets_yaml_generator.rb +19 -0
  31. data/lib/generators/test_data/webpacker_yaml_generator.rb +3 -2
  32. data/lib/test_data.rb +37 -1
  33. data/lib/test_data/active_record_ext.rb +11 -0
  34. data/lib/test_data/config.rb +33 -3
  35. data/lib/test_data/configurators.rb +2 -0
  36. data/lib/test_data/configurators/cable_yaml.rb +25 -0
  37. data/lib/test_data/configurators/environment_file.rb +3 -2
  38. data/lib/test_data/configurators/initializer.rb +3 -2
  39. data/lib/test_data/configurators/secrets_yaml.rb +25 -0
  40. data/lib/test_data/configurators/webpacker_yaml.rb +4 -3
  41. data/lib/test_data/custom_loaders/abstract_base.rb +25 -0
  42. data/lib/test_data/custom_loaders/rails_fixtures.rb +45 -0
  43. data/lib/test_data/dumps_database.rb +24 -1
  44. data/lib/test_data/generator_support.rb +3 -0
  45. data/lib/test_data/inserts_test_data.rb +25 -0
  46. data/lib/test_data/loads_database_dumps.rb +1 -1
  47. data/lib/test_data/log.rb +19 -1
  48. data/lib/test_data/{transactional_data_loader.rb → manager.rb} +78 -81
  49. data/lib/test_data/rake.rb +16 -7
  50. data/lib/test_data/statistics.rb +6 -1
  51. data/lib/test_data/truncates_test_data.rb +31 -0
  52. data/lib/test_data/version.rb +1 -1
  53. data/script/reset_example_app +1 -0
  54. data/script/test +31 -6
  55. data/test_data.gemspec +1 -1
  56. metadata +20 -4
@@ -4,7 +4,7 @@ module TestData
4
4
  end
5
5
 
6
6
  class Statistics
7
- attr_reader :load_count, :truncate_count
7
+ attr_reader :load_count, :truncate_count, :load_rails_fixtures_count
8
8
 
9
9
  def initialize
10
10
  reset
@@ -18,9 +18,14 @@ module TestData
18
18
  @truncate_count += 1
19
19
  end
20
20
 
21
+ def count_load_rails_fixtures!
22
+ @load_rails_fixtures_count += 1
23
+ end
24
+
21
25
  def reset
22
26
  @load_count = 0
23
27
  @truncate_count = 0
28
+ @load_rails_fixtures_count = 0
24
29
  end
25
30
  end
26
31
  end
@@ -0,0 +1,31 @@
1
+ module TestData
2
+ class TruncatesTestData
3
+ def initialize
4
+ @config = TestData.config
5
+ @statistics = TestData.statistics
6
+ end
7
+
8
+ def call
9
+ connection.disable_referential_integrity do
10
+ connection.execute("TRUNCATE TABLE #{tables_to_truncate.map { |t| connection.quote_table_name(t) }.join(", ")} #{"CASCADE" unless @config.truncate_these_test_data_tables.present?}")
11
+ end
12
+ @statistics.count_truncate!
13
+ end
14
+
15
+ private
16
+
17
+ def tables_to_truncate
18
+ if @config.truncate_these_test_data_tables.present?
19
+ @config.truncate_these_test_data_tables
20
+ else
21
+ @tables_to_truncate ||= IO.foreach(@config.data_dump_path).grep(/^INSERT INTO/) { |line|
22
+ line.match(/^INSERT INTO ([^\s]+)/)&.captures&.first
23
+ }.compact.uniq
24
+ end
25
+ end
26
+
27
+ def connection
28
+ ActiveRecord::Base.connection
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module TestData
2
- VERSION = "0.0.2"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -12,6 +12,7 @@ dropdb example_test_data 2>/dev/null || true
12
12
 
13
13
  # Reset files:
14
14
  git checkout app/models/boop.rb
15
+ git checkout config/application.rb
15
16
  git checkout config/database.yml
16
17
  git checkout db/schema.rb
17
18
  git clean -xdf .
data/script/test CHANGED
@@ -35,6 +35,9 @@ bin/rails test test/integration/updated_boops_test.rb
35
35
 
36
36
  # Test a migration being added and run and an out-of-date dump being loaded
37
37
  cp ../test/fixtures/20210418220133_add_beep_to_boops.rb db/migrate
38
+ cp ../test/fixtures/20210624180810_create_pants.rb db/migrate
39
+ cp ../test/fixtures/pant.rb app/models
40
+ cp ../test/fixtures/pants.yml test/fixtures
38
41
  bin/rake db:migrate
39
42
  bin/rake db:test:prepare
40
43
  bin/rake test_data:drop_database
@@ -46,6 +49,14 @@ bin/rails test test/integration/migrated_boops_test.rb
46
49
  # Run a test that commits test data thru to the database
47
50
  bin/rails test test/integration/transaction_committing_boops_test.rb
48
51
 
52
+ # Run a test that prevents Rails fixtures for preloading and then loads them in a transaction
53
+ bin/rails test test/integration/rails_fixtures_override_test.rb
54
+ bundle exec rspec spec/requests/rails_fixtures_override_spec.rb
55
+ bin/rails test test/integration/fixture_load_count_test.rb
56
+
57
+ # Run a test that forgets to prevent Rails fixtures but then tries to load them in a transaction
58
+ bin/rails test test/integration/rails_fixtures_double_load_test.rb
59
+
49
60
  # Add a second migration, this time without wiping the test_data db and with a table we want to ignore
50
61
  cp ../test/fixtures/20210423114916_add_table_we_want_to_ignore.rb db/migrate
51
62
  cp ../test/fixtures/chatty_audit_log.rb app/models
@@ -73,18 +84,32 @@ cp ../test/fixtures/20210423190737_add_foreign_keys.rb db/migrate/
73
84
  cp ../test/fixtures/boop_with_other_boops.rb app/models/boop.rb
74
85
  RAILS_ENV=test_data bin/rake db:migrate
75
86
  bin/rake test_data:dump
76
- bin/rake db:migrate
77
- bin/rake db:test:prepare
87
+ bin/rake db:migrate db:test:prepare
78
88
  bin/rails test test/integration/boops_that_boop_boops_test.rb
79
89
 
80
90
  # Make sure it loads cleanly again
81
91
  bin/rake test_data:drop_database
82
- if [ ! bin/rake test_data:load | grep -q "ERROR" ]; then
83
- echo "Running test_data:load after adding FK constraints led to errors"
84
- exit 1
85
- fi
92
+ bin/rake test_data:load
86
93
  bin/rails test test/integration/boops_that_boop_boops_test.rb
87
94
 
95
+ # Test all the after hooks!
96
+ cp ../test/fixtures/20210729130542_add_materialized_meta_boop_view.rb db/migrate/
97
+ cp ../test/fixtures/meta_boop.rb app/models/meta_boop.rb
98
+ # Gsub config file to switch to structure.sql b/c materialized view
99
+ ruby -e '
100
+ path = "config/application.rb"
101
+ IO.write(path, File.open(path) { |f|
102
+ f.read.gsub("# config.active_record.schema_format = :sql", "config.active_record.schema_format = :sql")
103
+ })
104
+ '
105
+ rm db/schema.rb
106
+ bin/rake db:migrate db:test:prepare
107
+ RAILS_ENV=test_data bin/rake db:migrate
108
+ bin/rake test_data:dump
109
+ bin/rails test test/integration/test_data_hooks_test.rb
110
+
88
111
  # Cleanup
89
112
  cd ..
90
113
  ./script/reset_example_app
114
+
115
+ echo "You win!"
data/test_data.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
 
13
13
  spec.metadata["homepage_uri"] = spec.homepage
14
14
  spec.metadata["source_code_uri"] = spec.homepage
15
- spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
15
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
16
16
 
17
17
  # Specify which files should be added to the gem when it is released.
18
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".github/workflows/ruby.yml"
35
35
  - ".gitignore"
36
+ - ".standard.yml"
36
37
  - CHANGELOG.md
37
38
  - Gemfile
38
39
  - Gemfile.lock
@@ -93,6 +94,7 @@ files:
93
94
  - example/public/robots.txt
94
95
  - example/spec/rails_helper.rb
95
96
  - example/spec/requests/boops_spec.rb
97
+ - example/spec/requests/rails_fixtures_override_spec.rb
96
98
  - example/spec/spec_helper.rb
97
99
  - example/test/application_system_test_case.rb
98
100
  - example/test/factories.rb
@@ -101,38 +103,52 @@ files:
101
103
  - example/test/integration/better_mode_switching_demo_test.rb
102
104
  - example/test/integration/boops_that_boop_boops_test.rb
103
105
  - example/test/integration/dont_dump_tables_test.rb
106
+ - example/test/integration/fixture_load_count_test.rb
104
107
  - example/test/integration/load_rollback_truncate_test.rb
105
108
  - example/test/integration/migrated_boops_test.rb
106
109
  - example/test/integration/mode_switching_demo_test.rb
107
110
  - example/test/integration/parallel_boops_with_fixtures_test.rb
108
111
  - example/test/integration/parallel_boops_without_fixtures_test.rb
112
+ - example/test/integration/rails_fixtures_double_load_test.rb
113
+ - example/test/integration/rails_fixtures_override_test.rb
114
+ - example/test/integration/test_data_hooks_test.rb
109
115
  - example/test/integration/transaction_committing_boops_test.rb
110
116
  - example/test/integration/updated_boops_test.rb
111
117
  - example/test/test_helper.rb
118
+ - lib/generators/test_data/cable_yaml_generator.rb
112
119
  - lib/generators/test_data/database_yaml_generator.rb
113
120
  - lib/generators/test_data/environment_file_generator.rb
114
121
  - lib/generators/test_data/initializer_generator.rb
122
+ - lib/generators/test_data/secrets_yaml_generator.rb
115
123
  - lib/generators/test_data/webpacker_yaml_generator.rb
116
124
  - lib/test_data.rb
125
+ - lib/test_data/active_record_ext.rb
117
126
  - lib/test_data/active_support_ext.rb
118
127
  - lib/test_data/config.rb
119
128
  - lib/test_data/configuration_verification.rb
120
129
  - lib/test_data/configurators.rb
130
+ - lib/test_data/configurators/cable_yaml.rb
121
131
  - lib/test_data/configurators/database_yaml.rb
122
132
  - lib/test_data/configurators/environment_file.rb
123
133
  - lib/test_data/configurators/initializer.rb
134
+ - lib/test_data/configurators/secrets_yaml.rb
124
135
  - lib/test_data/configurators/webpacker_yaml.rb
136
+ - lib/test_data/custom_loaders/abstract_base.rb
137
+ - lib/test_data/custom_loaders/rails_fixtures.rb
125
138
  - lib/test_data/detects_database_emptiness.rb
126
139
  - lib/test_data/dumps_database.rb
127
140
  - lib/test_data/error.rb
141
+ - lib/test_data/generator_support.rb
142
+ - lib/test_data/inserts_test_data.rb
128
143
  - lib/test_data/installs_configuration.rb
129
144
  - lib/test_data/loads_database_dumps.rb
130
145
  - lib/test_data/log.rb
146
+ - lib/test_data/manager.rb
131
147
  - lib/test_data/railtie.rb
132
148
  - lib/test_data/rake.rb
133
149
  - lib/test_data/save_point.rb
134
150
  - lib/test_data/statistics.rb
135
- - lib/test_data/transactional_data_loader.rb
151
+ - lib/test_data/truncates_test_data.rb
136
152
  - lib/test_data/verifies_configuration.rb
137
153
  - lib/test_data/verifies_dumps_are_loadable.rb
138
154
  - lib/test_data/version.rb
@@ -144,7 +160,7 @@ licenses: []
144
160
  metadata:
145
161
  homepage_uri: https://github.com/testdouble/test_data
146
162
  source_code_uri: https://github.com/testdouble/test_data
147
- changelog_uri: https://github.com/testdouble/test_data/blob/master/CHANGELOG.md
163
+ changelog_uri: https://github.com/testdouble/test_data/blob/main/CHANGELOG.md
148
164
  post_install_message:
149
165
  rdoc_options: []
150
166
  require_paths: