Skip to content

Commit a04fdea

Browse files
authored
Merge branch 'master' into fully-qualified-path
2 parents 7ec0189 + e8bff38 commit a04fdea

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ source "https://rubygems.org"
33
gemspec
44

55
gem "bundler", ">= 1.5"
6-
gem "database_cleaner"
76
gem "pg"
87
gem "pry"
98
gem "rake"

spec/acceptance_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
RSpec.configure do |config|
66
config.around(:each) do |example|
77
Dir.chdir("spec/dummy") do
8+
DatabaseReset.call
9+
810
example.run
11+
12+
DatabaseReset.call
913
end
1014
end
1115

@@ -24,6 +28,7 @@
2428
config.after(:suite) do
2529
Dir.chdir("spec/dummy") do
2630
ActiveRecord::Base.connection.disconnect!
31+
DatabaseReset.call
2732
system [
2833
"git add -A",
2934
"git reset --hard HEAD 1>/dev/null",

spec/dummy/config/application.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ class Application < Rails::Application
1212
config.eager_load = false
1313
config.active_support.deprecation = :stderr
1414

15-
config.load_defaults 7.0
16-
17-
if Rails.version >= "8.0"
18-
config.active_support.to_time_preserves_timezone = :zone
19-
end
15+
config.load_defaults 7.2
2016
end
2117
end

spec/fx/schema_dumper_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
expect(output.scan("create_trigger :test_public_trigger").size).to eq(1)
156156
expect(output.scan("create_function :test_schema_func").size).to eq(1)
157157
expect(output.scan("create_trigger :test_schema_trigger").size).to eq(1)
158-
158+
ensure
159159
connection.schema_search_path = "public"
160160
end
161161

spec/spec_helper.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ENV["RAILS_ENV"] = "test"
2-
require "database_cleaner"
32

43
require File.expand_path("../dummy/config/environment", __FILE__)
54
Dir["spec/support/**/*.rb"].sort.each { |file| load file }
@@ -11,14 +10,20 @@
1110
config.order = "random"
1211
config.disable_monkey_patching!
1312

14-
DatabaseCleaner.strategy = :transaction
13+
config.define_derived_metadata(file_path: %r{spec/(fx|features)/}) do |metadata|
14+
metadata[:db] = true
15+
end
16+
17+
config.before(:suite) do
18+
DatabaseReset.call
19+
end
1520

1621
config.around(:each, db: true) do |example|
17-
ActiveRecord::Base.connection.execute("SET search_path TO DEFAULT;")
22+
DatabaseReset.call
1823

19-
DatabaseCleaner.start
2024
example.run
21-
DatabaseCleaner.clean
25+
26+
DatabaseReset.call
2227
end
2328

2429
unless defined?(silence_stream)

spec/support/database_reset.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module DatabaseReset
2+
def self.call
3+
connection = ActiveRecord::Base.connection
4+
connection.execute("SET search_path TO DEFAULT;")
5+
6+
connection.execute <<~SQL
7+
DO $$
8+
DECLARE
9+
schema_name TEXT;
10+
BEGIN
11+
FOR schema_name IN
12+
SELECT nspname FROM pg_namespace
13+
WHERE nspname NOT LIKE 'pg_%'
14+
AND nspname != 'information_schema'
15+
LOOP
16+
EXECUTE format('DROP SCHEMA IF EXISTS %I CASCADE', schema_name);
17+
END LOOP;
18+
END $$;
19+
SQL
20+
21+
connection.execute("CREATE SCHEMA public;")
22+
connection.schema_search_path = "public"
23+
end
24+
end

0 commit comments

Comments
 (0)