test_data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +104 -0
- data/LICENSE.txt +25 -0
- data/README.md +35 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/.gitattributes +8 -0
- data/example/.gitignore +24 -0
- data/example/Gemfile +19 -0
- data/example/Gemfile.lock +211 -0
- data/example/README.md +24 -0
- data/example/Rakefile +6 -0
- data/example/app/assets/config/manifest.js +2 -0
- data/example/app/assets/stylesheets/application.css +15 -0
- data/example/app/controllers/application_controller.rb +2 -0
- data/example/app/controllers/boops_controller.rb +10 -0
- data/example/app/helpers/application_helper.rb +2 -0
- data/example/app/models/application_record.rb +3 -0
- data/example/app/models/boop.rb +2 -0
- data/example/app/views/boops/index.html.erb +8 -0
- data/example/app/views/layouts/application.html.erb +15 -0
- data/example/bin/bundle +114 -0
- data/example/bin/rails +4 -0
- data/example/bin/rake +4 -0
- data/example/bin/setup +33 -0
- data/example/config.ru +6 -0
- data/example/config/application.rb +35 -0
- data/example/config/boot.rb +4 -0
- data/example/config/credentials.yml.enc +1 -0
- data/example/config/database.yml +86 -0
- data/example/config/environment.rb +5 -0
- data/example/config/environments/development.rb +60 -0
- data/example/config/environments/production.rb +96 -0
- data/example/config/environments/test.rb +49 -0
- data/example/config/initializers/application_controller_renderer.rb +8 -0
- data/example/config/initializers/backtrace_silencers.rb +8 -0
- data/example/config/initializers/content_security_policy.rb +28 -0
- data/example/config/initializers/cookies_serializer.rb +5 -0
- data/example/config/initializers/filter_parameter_logging.rb +6 -0
- data/example/config/initializers/inflections.rb +16 -0
- data/example/config/initializers/mime_types.rb +4 -0
- data/example/config/initializers/permissions_policy.rb +11 -0
- data/example/config/initializers/wrap_parameters.rb +14 -0
- data/example/config/locales/en.yml +33 -0
- data/example/config/puma.rb +43 -0
- data/example/config/routes.rb +5 -0
- data/example/db/migrate/20210417143158_create_boops.rb +7 -0
- data/example/db/schema.rb +21 -0
- data/example/db/seeds.rb +11 -0
- data/example/public/404.html +67 -0
- data/example/public/422.html +67 -0
- data/example/public/500.html +66 -0
- data/example/public/apple-touch-icon-precomposed.png +0 -0
- data/example/public/apple-touch-icon.png +0 -0
- data/example/public/favicon.ico +0 -0
- data/example/public/robots.txt +1 -0
- data/example/test/application_system_test_case.rb +5 -0
- data/example/test/fixtures/boops.yml +5 -0
- data/example/test/integration/basic_boops_test.rb +18 -0
- data/example/test/integration/migrated_boops_test.rb +7 -0
- data/example/test/integration/parallel_boops_with_fixtures_test.rb +11 -0
- data/example/test/integration/parallel_boops_without_fixtures_test.rb +11 -0
- data/example/test/integration/updated_boops_test.rb +7 -0
- data/example/test/test_helper.rb +41 -0
- data/lib/generators/test_data/database_yaml_generator.rb +24 -0
- data/lib/generators/test_data/environment_file_generator.rb +29 -0
- data/lib/generators/test_data/webpacker_yaml_generator.rb +26 -0
- data/lib/test_data.rb +20 -0
- data/lib/test_data/active_support_ext.rb +9 -0
- data/lib/test_data/config.rb +52 -0
- data/lib/test_data/configuration_verification.rb +3 -0
- data/lib/test_data/configurators.rb +11 -0
- data/lib/test_data/configurators/database_yaml.rb +24 -0
- data/lib/test_data/configurators/environment_file.rb +25 -0
- data/lib/test_data/configurators/webpacker_yaml.rb +38 -0
- data/lib/test_data/detects_database_emptiness.rb +17 -0
- data/lib/test_data/dumps_database.rb +49 -0
- data/lib/test_data/error.rb +4 -0
- data/lib/test_data/installs_configuration.rb +9 -0
- data/lib/test_data/loads_database_dumps.rb +45 -0
- data/lib/test_data/railtie.rb +12 -0
- data/lib/test_data/rake.rb +104 -0
- data/lib/test_data/transactional_data_loader.rb +77 -0
- data/lib/test_data/verifies_configuration.rb +14 -0
- data/lib/test_data/verifies_dumps_are_loadable.rb +37 -0
- data/lib/test_data/version.rb +3 -0
- data/script/test +49 -0
- data/test_data.gemspec +27 -0
- metadata +150 -0
@@ -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
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BasicBoopsTest < SerializedNonTransactionalTestCase
|
4
|
+
i_suck_and_my_tests_are_order_dependent!
|
5
|
+
|
6
|
+
def test_contains_initially_seeded_boops
|
7
|
+
assert_equal 10, Boop.count
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_adds_some_boops
|
11
|
+
3.times { Boop.create! }
|
12
|
+
assert_equal 13, Boop.count
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_back_to_the_original_number_of_seeded_boops
|
16
|
+
assert_equal 10, Boop.count
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ParallelBoopsWithFixturesTest < ParallelizedTransactionalFixturefullTestCase
|
4
|
+
100.times do |i|
|
5
|
+
test "that boops don't change ##{i}" do
|
6
|
+
assert_equal 12, Boop.count
|
7
|
+
Boop.create!
|
8
|
+
assert_equal 13, Boop.count
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ParallelBoopsWithoutFixturesTest < ParallelizedNonTransactionalFixturelessTestCase
|
4
|
+
100.times do |i|
|
5
|
+
test "that boops don't change ##{i}" do
|
6
|
+
assert_equal 10, Boop.count
|
7
|
+
Boop.create!
|
8
|
+
assert_equal 11, Boop.count
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
|
+
require_relative "../config/environment"
|
3
|
+
require "rails/test_help"
|
4
|
+
|
5
|
+
class SerializedNonTransactionalTestCase < ActiveSupport::TestCase
|
6
|
+
parallelize(workers: 1)
|
7
|
+
self.use_transactional_tests = false
|
8
|
+
|
9
|
+
def setup
|
10
|
+
TestData.load_data_dump
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
TestData.rollback
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ParallelizedTransactionalFixturefullTestCase < ActiveSupport::TestCase
|
19
|
+
parallelize(workers: :number_of_processors)
|
20
|
+
self.use_transactional_tests = true
|
21
|
+
fixtures :all
|
22
|
+
|
23
|
+
def setup
|
24
|
+
TestData.load_data_dump
|
25
|
+
end
|
26
|
+
|
27
|
+
# use_transactional_tests will cause a single rollback on teardown
|
28
|
+
end
|
29
|
+
|
30
|
+
class ParallelizedNonTransactionalFixturelessTestCase < ActiveSupport::TestCase
|
31
|
+
parallelize(workers: :number_of_processors)
|
32
|
+
self.use_transactional_tests = false
|
33
|
+
|
34
|
+
def setup
|
35
|
+
TestData.load_data_dump
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
TestData.rollback
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module TestData
|
4
|
+
class DatabaseYamlGenerator < Rails::Generators::Base
|
5
|
+
BEFORE_TEST_DATABASE_STANZA_REGEX = /^$\n(?:^\#.*\n)*^test:/
|
6
|
+
|
7
|
+
def call
|
8
|
+
if Configurators::DatabaseYaml.new.verify.looks_good?
|
9
|
+
warn "'test_data' section already defined in config/database.yml"
|
10
|
+
else
|
11
|
+
app_name = Rails.application.railtie_name.chomp("_application")
|
12
|
+
inject_into_file "config/database.yml", before: BEFORE_TEST_DATABASE_STANZA_REGEX do
|
13
|
+
<<~YAML
|
14
|
+
|
15
|
+
# Used in conjunction with the test_data gem
|
16
|
+
test_data:
|
17
|
+
<<: *default
|
18
|
+
database: #{app_name}_test_data
|
19
|
+
YAML
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module TestData
|
4
|
+
class EnvironmentFileGenerator < Rails::Generators::Base
|
5
|
+
def call
|
6
|
+
create_file "config/environments/test_data.rb", <<~RUBY
|
7
|
+
require_relative "development"
|
8
|
+
|
9
|
+
TestData.config do |config|
|
10
|
+
# Where to store SQL dumps of the test_data database schema
|
11
|
+
# config.schema_dump_path = "test/support/test_data/schema.sql"
|
12
|
+
|
13
|
+
# Where to store SQL dumps of the test_data database test data
|
14
|
+
# config.data_dump_path = "test/support/test_data/data.sql"
|
15
|
+
|
16
|
+
# Where to store SQL dumps of the test_data database non-test data
|
17
|
+
# config.non_test_data_dump_path = "test/support/test_data/non_test_data.sql"
|
18
|
+
|
19
|
+
# Tables whose data shouldn't be loaded into tests
|
20
|
+
# config.non_test_data_tables = ["ar_internal_metadata", "schema_migrations"]
|
21
|
+
end
|
22
|
+
|
23
|
+
Rails.application.configure do
|
24
|
+
config.active_record.dump_schema_after_migration = false
|
25
|
+
end
|
26
|
+
RUBY
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module TestData
|
4
|
+
class WebpackerYamlGenerator < Rails::Generators::Base
|
5
|
+
AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX = /^development:/
|
6
|
+
BEFORE_TEST_WEBPACK_STANZA_REGEX = /^$\n(?:^\#.*\n)*^test:/
|
7
|
+
|
8
|
+
def call
|
9
|
+
if Configurators::WebpackerYaml.new.verify.looks_good?
|
10
|
+
warn "'test_data' section not needed in config/webpacker.yml"
|
11
|
+
else
|
12
|
+
inject_into_file "config/webpacker.yml", after: AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX do
|
13
|
+
" &development"
|
14
|
+
end
|
15
|
+
inject_into_file "config/webpacker.yml", before: BEFORE_TEST_WEBPACK_STANZA_REGEX do
|
16
|
+
<<~YAML
|
17
|
+
|
18
|
+
# Used in conjunction with the test_data gem
|
19
|
+
test_data:
|
20
|
+
<<: *development
|
21
|
+
YAML
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/test_data.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "test_data/active_support_ext"
|
2
|
+
require_relative "test_data/config"
|
3
|
+
require_relative "test_data/configuration_verification"
|
4
|
+
require_relative "test_data/configurators"
|
5
|
+
require_relative "test_data/configurators/environment_file"
|
6
|
+
require_relative "test_data/configurators/database_yaml"
|
7
|
+
require_relative "test_data/configurators/webpacker_yaml"
|
8
|
+
require_relative "test_data/detects_database_emptiness"
|
9
|
+
require_relative "test_data/dumps_database"
|
10
|
+
require_relative "test_data/error"
|
11
|
+
require_relative "test_data/installs_configuration"
|
12
|
+
require_relative "test_data/loads_database_dumps"
|
13
|
+
require_relative "test_data/railtie"
|
14
|
+
require_relative "test_data/transactional_data_loader"
|
15
|
+
require_relative "test_data/verifies_configuration"
|
16
|
+
require_relative "test_data/verifies_dumps_are_loadable"
|
17
|
+
require_relative "test_data/version"
|
18
|
+
require_relative "generators/test_data/environment_file_generator"
|
19
|
+
require_relative "generators/test_data/database_yaml_generator"
|
20
|
+
require_relative "generators/test_data/webpacker_yaml_generator"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module TestData
|
2
|
+
def self.config(pwd: Rails.root, &blk)
|
3
|
+
@configuration ||= Configuration.new(pwd: pwd)
|
4
|
+
|
5
|
+
@configuration.tap do |config|
|
6
|
+
blk&.call(config)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Configuration
|
11
|
+
# Where to save dumps of your test data's schema
|
12
|
+
attr_accessor :schema_dump_path
|
13
|
+
|
14
|
+
# Where to save dumps of your test data
|
15
|
+
attr_accessor :data_dump_path
|
16
|
+
|
17
|
+
# Where to save dumps of data needed by the test_data env but excluded from your tests
|
18
|
+
attr_accessor :non_test_data_dump_path
|
19
|
+
|
20
|
+
# Tables to exclude from test data dumps
|
21
|
+
attr_accessor :non_test_data_tables
|
22
|
+
|
23
|
+
attr_reader :pwd, :database_yaml_path
|
24
|
+
|
25
|
+
def self.full_path_reader(*relative_path_readers)
|
26
|
+
relative_path_readers.each do |relative_path_reader|
|
27
|
+
define_method(relative_path_reader.to_s.gsub(/_path$/, "_full_path")) do
|
28
|
+
"#{pwd}/#{send(relative_path_reader)}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
full_path_reader :schema_dump_path, :data_dump_path, :non_test_data_dump_path, :database_yaml_path
|
34
|
+
|
35
|
+
def initialize(pwd:)
|
36
|
+
@pwd = pwd
|
37
|
+
@schema_dump_path = "test/support/test_data/schema.sql"
|
38
|
+
@data_dump_path = "test/support/test_data/data.sql"
|
39
|
+
@non_test_data_dump_path = "test/support/test_data/non_test_data.sql"
|
40
|
+
@database_yaml_path = "config/database.yml"
|
41
|
+
@non_test_data_tables = ["ar_internal_metadata", "schema_migrations"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def database_yaml
|
45
|
+
YAML.load_file(database_yaml_full_path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def database_name
|
49
|
+
database_yaml.dig("test_data", "database")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|