Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DatabaseCleaner with Active Record to truncate tables #294

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ gem "mysql2", github: "brianmario/mysql2"
gem "globalid"
gem "i18n"
gem "redis"
gem "database_cleaner"

gem "pry"
gem "mocha"
Expand Down
7 changes: 0 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.1.10)
connection_pool (2.2.5)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.12.0)
Expand Down Expand Up @@ -108,7 +102,6 @@ PLATFORMS

DEPENDENCIES
activerecord
database_cleaner
globalid
i18n
job-iteration!
Expand Down
9 changes: 5 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
require "active_record"
require "pry"
require "mocha/minitest"
require "database_cleaner"

GlobalID.app = "iteration"
ActiveRecord::Base.include(GlobalID::Identification) # https://github.com/rails/globalid/blob/main/lib/global_id/railtie.rb
Expand Down Expand Up @@ -74,8 +73,6 @@ class Product < ActiveRecord::Base
t.timestamps
end

DatabaseCleaner.strategy = :truncation

module LoggingHelpers
def assert_logged(message)
old_logger = ActiveJob::Base.logger
Expand Down Expand Up @@ -117,12 +114,16 @@ class IterationUnitTest < ActiveSupport::TestCase

teardown do
ActiveJob::Base.queue_adapter.enqueued_jobs = []
DatabaseCleaner.clean
truncate_fixtures
end

def insert_fixtures
10.times do |n|
Product.create!(name: "lipstick #{n}")
end
end

def truncate_fixtures
ActiveRecord::Base.connection.truncate(Product.table_name)
end
end