#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

require 'database_cleaner'

Pact.configure do |config|
  config.include Factories
end

Pact.set_up do
  DatabaseCleaner.strategy = :transaction
  DatabaseCleaner.start
end

Pact.tear_down do
  DatabaseCleaner.clean
  ActiveRecord::Base.connection.tables.each do |t|
    ActiveRecord::Base.connection.reset_pk_sequence!(t)
  end
end

#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

require 'database_cleaner'

Pact.configure do |config|
  config.include Factories
end

Pact.set_up do
  DatabaseCleaner.strategy = :transaction
  DatabaseCleaner.start

  ActiveRecord::Base.connection.tables.each do |t|
    ActiveRecord::Base.connection.reset_pk_sequence!(t)
  end
end

Pact.tear_down do
  DatabaseCleaner.clean
end

Reset DB counter in set_up, not tear_down
spec: Reset DB counter in set_up, not tear_down

This avoids a problem where, if the tear_down doesn't happen (say, if
the process is aborted), things wouldn't have been reset for the next
run. By doing it in the set_up, we can always count on IDs starting
at 1 every time the tests run.

Change-Id: I90ab810c03ea7f153dabc40b346d92bb2a11726f
Reviewed-on: https://gerrit.instructure.com/155194
Tested-by: Jenkins
Reviewed-by: Anju Reddy <851202533fb1f0b615e4547ba226c76996d060dd@instructure.com>
Product-Review: Tucker McKnight <4b51b98c1d84aa97854d216bd061ce5d3eda8a28@instructure.com>
QA-Review: Tucker McKnight <4b51b98c1d84aa97854d216bd061ce5d3eda8a28@instructure.com>
