spec: make sure we reset each shard before specs (if we have shards)
but make sure we have default roles everywhere. this will allow us to use schema snapshots (w/ no data) for all the shards in CI-land refs SD-857 Change-Id: I7f1ca2253af86f71a9bef243b6bb51f94a927aef Reviewed-on: https://gerrit.instructure.com/73143 Tested-by: Jenkins Reviewed-by: Cody Cutrer <cody@instructure.com> Product-Review: Jon Jensen <jon@instructure.com> QA-Review: Jon Jensen <jon@instructure.com>
This commit is contained in:
parent
e893a488c8
commit
8dc7dc31a5
|
@ -346,10 +346,6 @@ describe "content migrations", :non_parallel do
|
|||
@copy_from.enroll_teacher(@user).accept
|
||||
end
|
||||
|
||||
after :all do
|
||||
truncate_all_tables
|
||||
end
|
||||
|
||||
it "should show warning before self-copy" do
|
||||
visit_page
|
||||
select_migration_type
|
||||
|
|
|
@ -243,32 +243,34 @@ def truncate_table(model)
|
|||
end
|
||||
|
||||
def truncate_all_tables
|
||||
model_connections = ActiveRecord::Base.descendants.map(&:connection).uniq
|
||||
model_connections.each do |connection|
|
||||
if connection.adapter_name == "PostgreSQL"
|
||||
# use custom SQL to exclude tables from extensions
|
||||
schema = connection.shard.name if connection.instance_variable_get(:@config)[:use_qualified_names]
|
||||
table_names = connection.query(<<-SQL, 'SCHEMA').map(&:first)
|
||||
SELECT relname
|
||||
FROM pg_class INNER JOIN pg_namespace ON relnamespace=pg_namespace.oid
|
||||
WHERE nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
|
||||
AND relkind='r'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM pg_depend WHERE deptype='e' AND objid=pg_class.oid
|
||||
)
|
||||
SQL
|
||||
table_names.delete('schema_migrations')
|
||||
connection.execute("TRUNCATE TABLE #{table_names.map { |t| connection.quote_table_name(t) }.join(',')}")
|
||||
else
|
||||
connection.tables.each { |model| truncate_table(model) }
|
||||
raise "don't use truncate_all_tables with transactional fixtures. this kills the postgres" if ActiveRecord::Base.connection.open_transactions > 0
|
||||
|
||||
Shard.with_each_shard do
|
||||
model_connections = ActiveRecord::Base.descendants.map(&:connection).uniq
|
||||
model_connections.each do |connection|
|
||||
if connection.adapter_name == "PostgreSQL"
|
||||
# use custom SQL to exclude tables from extensions
|
||||
schema = connection.shard.name if connection.instance_variable_get(:@config)[:use_qualified_names]
|
||||
table_names = connection.query(<<-SQL, 'SCHEMA').map(&:first)
|
||||
SELECT relname
|
||||
FROM pg_class INNER JOIN pg_namespace ON relnamespace=pg_namespace.oid
|
||||
WHERE nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
|
||||
AND relkind='r'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM pg_depend WHERE deptype='e' AND objid=pg_class.oid
|
||||
)
|
||||
SQL
|
||||
table_names.delete('schema_migrations')
|
||||
connection.execute("TRUNCATE TABLE #{table_names.map { |t| connection.quote_table_name(t) }.join(',')}")
|
||||
else
|
||||
connection.tables.each { |model| truncate_table(model) }
|
||||
end
|
||||
end
|
||||
|
||||
Role.ensure_built_in_roles!
|
||||
end
|
||||
end
|
||||
|
||||
# wipe out the test db, in case some non-transactional tests crapped out before
|
||||
# cleaning up after themselves
|
||||
truncate_all_tables
|
||||
|
||||
# Make AR not puke if MySQL auto-commits the transaction
|
||||
module MysqlOutsideTransaction
|
||||
def outside_transaction?
|
||||
|
@ -373,7 +375,6 @@ RSpec.configure do |config|
|
|||
Onceler.configure do |c|
|
||||
c.before :record do
|
||||
Account.clear_special_account_cache!(true)
|
||||
Role.ensure_built_in_roles!
|
||||
AdheresToPolicy::Cache.clear
|
||||
Folder.reset_path_lookups!
|
||||
end
|
||||
|
@ -399,7 +400,6 @@ RSpec.configure do |config|
|
|||
config.before :all do
|
||||
# so before(:all)'s don't get confused
|
||||
Account.clear_special_account_cache!(true)
|
||||
Role.ensure_built_in_roles!
|
||||
AdheresToPolicy::Cache.clear
|
||||
# silence migration specs
|
||||
ActiveRecord::Migration.verbose = false
|
||||
|
@ -450,6 +450,10 @@ RSpec.configure do |config|
|
|||
# (it forks and changes the TEST_ENV_NUMBER)
|
||||
SimpleCov.command_name("rspec:#{Process.pid}:#{ENV['TEST_ENV_NUMBER']}")
|
||||
end
|
||||
|
||||
# wipe out the test db, in case some non-transactional tests crapped out before
|
||||
# cleaning up after themselves
|
||||
truncate_all_tables
|
||||
end
|
||||
|
||||
# this runs on post-merge builds to capture dependencies of each spec;
|
||||
|
|
Loading…
Reference in New Issue