Skip to content

Commit

Permalink
database cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed May 15, 2024
1 parent d4c8b1f commit 06bacd4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ group :test do
gem "webdrivers"
gem "shoulda-matchers", "~> 5.0"
gem "faker"
gem "database_cleaner"
gem 'database_cleaner-active_record'
end

# Or, run against the main branch
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ GEM
crass (1.0.6)
cssbundling-rails (1.2.0)
railties (>= 6.0.0)
database_cleaner (2.0.2)
database_cleaner-active_record (>= 2, < 3)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.4)
debug (1.8.0)
irb (>= 1.5.0)
Expand Down Expand Up @@ -649,6 +655,8 @@ DEPENDENCIES
browser (~> 5.3)
capybara
cssbundling-rails
database_cleaner
database_cleaner-active_record
debug
devise
devise_invitable (~> 2.0)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

describe ".published" do
it "returns published events" do
expect(Event.upcoming_events).to eq([@event1, @event3])
expect(Event.upcoming_events.map(&:id)).to eq([@event1.id, @event3.id])
end
end

Expand Down
19 changes: 18 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,28 @@
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
config.use_transactional_fixtures = false

config.include(Shoulda::Matchers::ActiveModel, type: :model)
config.include(Shoulda::Matchers::ActiveRecord, type: :model)


config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
#
#config.around(:each) do |example|
# DatabaseCleaner.cleaning do
# # example.run
# end
#end

# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false

Expand Down

0 comments on commit 06bacd4

Please sign in to comment.