waterpig 0.8.1 → 0.9.0
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.
- checksums.yaml +4 -4
- data/lib/waterpig/database-cleaner.rb +70 -12
- data/lib/waterpig/template-refresh.rb +97 -93
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb3ae7798c87c5797fa48f5f879563361ac7d419
|
4
|
+
data.tar.gz: dea722855e6c224e2d976408f6e8c4491fae9db7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bca828861118469c32033ab0a9b657d6a13ae9c78b5e3f06a064fc79c0957bf33900ffe1659226eca983e355a11bc2acb1491418837bf335aae45b93e0f6e57b
|
7
|
+
data.tar.gz: 36b4b15b43e9f0fc048f94500c77e6eb0fa9db5661e4e31e33f5b55ce768e859d3da3320ae7f0932d5bde98b6bab4791e1c466ad7f18ab370969a9c725815934
|
@@ -1,16 +1,28 @@
|
|
1
1
|
require 'database_cleaner'
|
2
2
|
|
3
|
+
require 'waterpig/template-refresh'
|
4
|
+
require 'waterpig/request-wait-middleware'
|
5
|
+
|
3
6
|
RSpec.configure do |config|
|
4
7
|
#config.use_transactional_fixtures = false
|
5
8
|
DatabaseCleaner.strategy = :transaction
|
6
9
|
|
7
10
|
config.add_setting :waterpig_exclude_cleaning_key, :default => :manual_database_cleaning
|
11
|
+
config.add_setting :waterpig_explicit_cleaning_method_key, :default => :clean_with
|
12
|
+
|
13
|
+
config.add_setting :waterpig_database_reset_method, :default => :truncation
|
8
14
|
config.add_setting :waterpig_truncation_types, :default => [:feature]
|
15
|
+
config.add_setting :waterpig_reset_types, :default => [:feature]
|
16
|
+
|
9
17
|
config.add_setting :waterpig_skip_cleaning_types, :default => []
|
10
18
|
config.add_setting :waterpig_exclude_seeds_types, :default => []
|
19
|
+
|
11
20
|
config.add_setting :waterpig_database_truncation_config, :default => {:except => %w[spatial_ref_sys]}
|
12
21
|
config.add_setting :waterpig_db_seeds, :default => 'db/seeds.rb'
|
13
22
|
|
23
|
+
config.add_setting :waterpig_test_database_config, :default => :test
|
24
|
+
config.add_setting :waterpig_test_template_database_config, :default => :test_template
|
25
|
+
|
14
26
|
def with_showing(show, detailed)
|
15
27
|
begin
|
16
28
|
old_show, old_show_detailed =
|
@@ -25,18 +37,57 @@ RSpec.configure do |config|
|
|
25
37
|
end
|
26
38
|
end
|
27
39
|
|
40
|
+
def cleaning_policy(config, metadata)
|
41
|
+
return :no_clean if metadata[config.waterpig_exclude_cleaning_key]
|
42
|
+
unless (explicit_method = metadata[config.waterpig_explicit_cleaning_method_key]).nil?
|
43
|
+
if explicit_method == :reset
|
44
|
+
return config.waterpig_database_reset_method
|
45
|
+
else
|
46
|
+
return explicit_method
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
return :no_clean if config.waterpig_skip_cleaning_types.include?(metadata[:type])
|
51
|
+
|
52
|
+
if config.waterpig_database_reset_method == :truncation
|
53
|
+
return :truncate if config.waterpig_truncation_types.include?(metadata[:type])
|
54
|
+
return :truncate if config.waterpig_reset_types.include?(metadata[:type])
|
55
|
+
else
|
56
|
+
return :refresh if config.waterpig_reset_types.include?(metadata[:type])
|
57
|
+
end
|
58
|
+
return :transaction
|
59
|
+
end
|
60
|
+
|
61
|
+
def use_refresh?(config, metadata)
|
62
|
+
cleaning_policy(config, metadata) == :refresh
|
63
|
+
end
|
64
|
+
|
28
65
|
def use_truncate?(config, metadata)
|
29
|
-
|
30
|
-
return false if config.waterpig_skip_cleaning_types.include?(metadata[:type])
|
31
|
-
return false unless config.waterpig_truncation_types.include?(metadata[:type])
|
32
|
-
return true
|
66
|
+
cleaning_policy(config, metadata) == :truncate
|
33
67
|
end
|
34
68
|
|
35
69
|
def use_transaction?(config, metadata)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
70
|
+
cleaning_policy(config, metadata) == :transaction
|
71
|
+
end
|
72
|
+
|
73
|
+
last_type = nil
|
74
|
+
|
75
|
+
config.after(:all) do
|
76
|
+
last_type = self.class.metadata[:type].to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
config.before(:all, :description => proc{|value, metadata| use_refresh?(config, metadata)}) do
|
80
|
+
Waterpig::RequestWaitMiddleware.wait_for_idle do
|
81
|
+
Waterpig::TemplateRefresh.refresh_database(config.waterpig_test_database_config)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
#Before the first group following a refresh-group, refresh again.
|
86
|
+
#Faster than refreshing before and after all the feature groups
|
87
|
+
config.before(:all, :description => proc{|value, metadata| !use_refresh?(config, metadata) }) do
|
88
|
+
if config.waterpig_reset_types.include?(last_type)
|
89
|
+
Waterpig::TemplateRefresh.refresh_database(config.waterpig_test_database_config)
|
90
|
+
end
|
40
91
|
end
|
41
92
|
|
42
93
|
config.before :all, :description => proc{ |value, metadata| use_truncate?(config, metadata) } do
|
@@ -52,7 +103,6 @@ RSpec.configure do |config|
|
|
52
103
|
|
53
104
|
config.after :all, :description => proc{ |value, metadata| use_truncate?(config, metadata) } do
|
54
105
|
with_showing(true, true) do
|
55
|
-
Rails.application.config.action_dispatch.show_detailed_exceptions = true
|
56
106
|
DatabaseCleaner.clean_with :truncation, config.waterpig_database_truncation_config
|
57
107
|
if config.waterpig_db_seeds?
|
58
108
|
load config.waterpig_db_seeds
|
@@ -69,9 +119,17 @@ RSpec.configure do |config|
|
|
69
119
|
end
|
70
120
|
|
71
121
|
config.before :suite do
|
72
|
-
|
73
|
-
|
74
|
-
|
122
|
+
if config.waterpig_database_reset_method == :truncation
|
123
|
+
DatabaseCleaner.clean_with :truncation, config.waterpig_database_truncation_config
|
124
|
+
if config.waterpig_db_seeds?
|
125
|
+
load config.waterpig_db_seeds
|
126
|
+
end
|
127
|
+
elsif config.waterpig_database_reset_method == :refresh
|
128
|
+
Waterpig::TemplateRefresh.load_if_pending!(config.waterpig_test_template_database_config)
|
129
|
+
Waterpig::TemplateRefresh.commandeer_database(config.waterpig_test_database_config)
|
130
|
+
Waterpig::TemplateRefresh.refresh_database(config.waterpig_test_database_config)
|
131
|
+
else
|
132
|
+
warn "Waterpig: Unknown database reset method: #{config.waterpig_database_reset_method}"
|
75
133
|
end
|
76
134
|
end
|
77
135
|
end
|
@@ -1,122 +1,126 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
begin
|
2
|
+
require 'activerecord'
|
3
|
+
module Waterpig
|
4
|
+
|
5
|
+
|
6
|
+
# Tool to handle migrations and rebuilds on a test template database. For
|
7
|
+
# explanation of what the test templated DB is and how it's used, see the
|
8
|
+
# README.
|
9
|
+
#
|
10
|
+
# This should auto detect any needed migrations in that database. However, it
|
11
|
+
# does not detect changes to db/seeds.rb, so if you have changed seeds
|
12
|
+
# without adding a DB migration, you will need to drop and rebuild the
|
13
|
+
# test_template.
|
14
|
+
module TemplateRefresh
|
15
|
+
Base = ActiveRecord::Base
|
16
|
+
Migrator = ActiveRecord::Migrator
|
17
|
+
DatabaseTasks = ActiveRecord::Tasks::DatabaseTasks
|
18
|
+
|
19
|
+
extend self
|
20
|
+
|
21
|
+
def load_config
|
22
|
+
Base.configurations = DatabaseTasks.database_configuration || {}
|
23
|
+
Migrator.migrations_paths = DatabaseTasks.migrations_paths
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
def purge_env(env)
|
27
|
+
DatabaseTasks.purge(config_for(env))
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def with_temporary_connection(env)
|
31
|
+
begin
|
32
|
+
should_reconnect = Base.connection_pool.active_connection?
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
if should_reconnect
|
37
|
+
Base.establish_connection(config_for(DatabaseTasks.env))
|
38
|
+
end
|
36
39
|
end
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
#Assumes schema_format == ruby
|
43
|
+
def load_schema(env)
|
44
|
+
ActiveRecord::Schema.verbose = false
|
45
|
+
DatabaseTasks.load_schema_for config_for(env), :ruby, ENV['SCHEMA']
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def load_seed
|
49
|
+
DatabaseTasks.load_seed
|
50
|
+
# load('spec/test_seeds.rb')
|
51
|
+
end
|
50
52
|
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
def config_for(env)
|
55
|
+
Base.configurations.fetch(env.to_s)
|
56
|
+
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
def connection_for(env)
|
59
|
+
Base.establish_connection(env).connection
|
60
|
+
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
def if_needs_migration(env)
|
63
|
+
if Migrator.needs_migration?(connection_for(env))
|
64
|
+
begin
|
65
|
+
current_config = Base.connection_config
|
66
|
+
Base.clear_all_connections!
|
65
67
|
|
66
|
-
|
68
|
+
yield
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
+
ensure
|
71
|
+
Base.establish_connection(current_config)
|
70
72
|
|
71
|
-
|
73
|
+
ActiveRecord::Migration.check_pending!
|
74
|
+
end
|
72
75
|
end
|
73
76
|
end
|
74
|
-
end
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
def ensure_created(env)
|
79
|
+
Base.establish_connection(env).connection
|
80
|
+
rescue ActiveRecord::NoDatabaseError
|
81
|
+
DatabaseTasks.create(config_for(env))
|
82
|
+
end
|
81
83
|
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
def load_if_pending!(env)
|
86
|
+
ensure_created(env)
|
87
|
+
if_needs_migration(env) do
|
88
|
+
puts "Refreshing unmigrated test env: #{env}"
|
89
|
+
purge_env(env)
|
90
|
+
with_temporary_connection(env) do
|
91
|
+
load_schema(env)
|
92
|
+
load_seed
|
93
|
+
end
|
91
94
|
end
|
92
95
|
end
|
93
|
-
end
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
def commandeer_database(env)
|
98
|
+
config = config_for(env)
|
99
|
+
connection_for(env).select_all(
|
100
|
+
"select pid, pg_terminate_backend(pid) " +
|
101
|
+
"from pg_stat_activity where datname='#{config['database']}' AND state='idle';")
|
102
|
+
end
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
-
|
104
|
+
def refresh_database(env)
|
105
|
+
Rails.logger.fatal("Resetting test DB...")
|
106
|
+
config = config_for(env)
|
105
107
|
|
106
|
-
|
108
|
+
tasks = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(config)
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
110
|
+
start = Time.now
|
111
|
+
Rails.logger.fatal("Dropping")
|
112
|
+
begin
|
113
|
+
tasks.drop
|
114
|
+
end
|
115
|
+
Rails.logger.fatal("Creating")
|
116
|
+
begin
|
117
|
+
tasks.create
|
118
|
+
end
|
119
|
+
message = "Test database recopied in #{Time.now - start}s"
|
120
|
+
#puts message
|
121
|
+
Rails.logger.fatal(message)
|
116
122
|
end
|
117
|
-
message = "Test database recopied in #{Time.now - start}s"
|
118
|
-
#puts message
|
119
|
-
Rails.logger.fatal(message)
|
120
123
|
end
|
121
124
|
end
|
125
|
+
rescue LoadError
|
122
126
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waterpig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Judson Lester
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capybara
|
@@ -105,7 +105,7 @@ rdoc_options:
|
|
105
105
|
- --main
|
106
106
|
- doc/README
|
107
107
|
- --title
|
108
|
-
- waterpig-0.
|
108
|
+
- waterpig-0.9.0 Documentation
|
109
109
|
require_paths:
|
110
110
|
- lib/
|
111
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|