Skip to content

Commit

Permalink
Remove DatabaseCleaner
Browse files Browse the repository at this point in the history
user rails_transactional_fixtures

see: #913
  • Loading branch information
jparr committed Apr 18, 2024
1 parent f899add commit 1896f98
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 31 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ end
group :development, :test do
gem "byebug"
gem "capybara", "~> 3"
gem "database_cleaner", "~> 1"
gem "factory_bot_rails", "~> 6.2"
gem "rails-controller-testing"
gem "rspec-rails", "~> 6.1"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ GEM
css_parser (1.16.0)
addressable
daemons (1.4.1)
database_cleaner (1.99.0)
date (3.3.4)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
Expand Down Expand Up @@ -529,7 +528,6 @@ DEPENDENCIES
cocoon (~> 1)
counter_culture (~> 2.0)
daemons (~> 1)
database_cleaner (~> 1)
delayed_job_active_record (~> 4)
devise (~> 4.7)
dotenv-rails (~> 2)
Expand Down
10 changes: 5 additions & 5 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@

# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
# begin
# DatabaseCleaner.strategy = :transaction
# rescue NameError
# raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
# end

# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
# See the DatabaseCleaner documentation for details. Example:
Expand Down
4 changes: 2 additions & 2 deletions spec/features/admin/action_creation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@

it "can add images" do
stub_request(:get, %r{uploads/featured-image.png}).to_return(status: 200, body: fixture_file_upload("test-image.png", "image/png").tempfile.to_io, headers: {})
stub_request(:any, %r{/action_pages/featured_images/000/000/([0-9]+)/original/featured-image.png}).to_return(status: 200, body: "", headers: {})
stub_request(:any, %r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/featured-image.png}).to_return(status: 200, body: "", headers: {})
stub_request(:get, %r{uploads/og-image.png}).to_return(status: 200, body: fixture_file_upload("test-image.png", "image/png").tempfile.to_io, headers: {})
stub_request(:any, %r{/action_pages/og_images/000/000/([0-9]+)/original/og-image.png}).to_return(status: 200, body: "", headers: {})
stub_request(:any, %r{/action_pages/og_images/([0-9]+)/([0-9]+)/([0-9]+)/original/og-image.png}).to_return(status: 200, body: "", headers: {})
FactoryBot.create(:source_file, key: "uploads/featured-image.png", file_name: "featured-image.png")
FactoryBot.create(:source_file, key: "uploads/og-image.png", file_name: "og-image.png")
visit new_admin_action_page_path
Expand Down
8 changes: 4 additions & 4 deletions spec/models/action_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@
let(:test_image_file_upload) { fixture_file_upload("test-image.png", "image/png").tempfile.to_io }
it "creates a new record with image fields" do
stub_request(:get, %r{fakeimages/test.png}).to_return(status: 200, body: test_image_file_upload, headers: { content_type: "image/png" })
stub_request(:put, %r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png}).to_return(status: 200, body: "", headers: {})
stub_request(:put, %r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png}).to_return(status: 200, body: "", headers: {})

page = ActionPage.create!(page_attr)
expect(page.featured_image_file_name).to eq("test.png")
expect(page.featured_image.content_type).to eq("image/png")
expect(WebMock).to have_requested(:put, %r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png})
expect(page.featured_image.url).to match(%r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png})
expect(page.image.url).to match(%r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png})
expect(WebMock).to have_requested(:put, %r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png})
expect(page.featured_image.url).to match(%r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png})
expect(page.image.url).to match(%r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png})
end
end
end
Expand Down
8 changes: 1 addition & 7 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# 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 = false
config.use_transactional_fixtures = true

# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
Expand All @@ -64,12 +64,6 @@
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!

config.before(:suite) { DatabaseCleaner.clean_with(:truncation) }
config.before(:each) { DatabaseCleaner.strategy = :transaction }
config.before(:each, js: true) { DatabaseCleaner.strategy = :truncation }
config.before(:each) { DatabaseCleaner.start }
config.append_after(:each) { DatabaseCleaner.clean }

config.before(:each, type: :feature) do
# disable call tool by default; it will be stubbed for tests that need it
disable_call_tool
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/action_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

it "returns image attributes in json" do
stub_request(:get, %r{fakeimages/test.png}).to_return(status: 200, body: fixture_file_upload("test-image.png", "image/png").tempfile.to_io, headers: { content_type: "image/png" })
stub_request(:any, %r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png}).to_return(status: 200, body: "", headers: {})
stub_request(:any, %r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png}).to_return(status: 200, body: "", headers: {})
FactoryBot.create(:action_page, remote_featured_image_url: "https://example.com/fakeimages/test.png")

get "/action.json"
Expand All @@ -53,7 +53,7 @@
"title" => "Sample Action Page",
"featured_image"=> a_hash_including({
"alt"=>"Test.Png",
"url"=> a_string_matching(%r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png})
"url"=> a_string_matching(%r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png})
})
}))
end
Expand All @@ -70,13 +70,13 @@
it "returns image attributes in atom" do
allow_any_instance_of(ActionPageImageUploader).to receive(:content_type).and_return("image/png")
stub_request(:get, %r{fakeimages/test.png}).to_return(status: 200, body: file_fixture("test-image.png").read, headers: {content_type: "image/png"})
stub_request(:any, %r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png}).to_return(status: 200, body: file_fixture("test-image.png").read, headers: {content_type: "image/png"})
stub_request(:any, %r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png}).to_return(status: 200, body: file_fixture("test-image.png").read, headers: {content_type: "image/png"})
FactoryBot.create(:action_page, remote_featured_image_url: "https://example.com/fakeimages/test.png")

get "/action.atom"
expect(response.code).to eq "200"
expect(response.body).to match("Sample Action Page")
expect(response.body).to match(%r{/action_pages/featured_images/000/000/([0-9]+)/original/test.png})
expect(response.body).to match(%r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png})
end
end
end
4 changes: 2 additions & 2 deletions spec/requests/admin/action_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
valid_attributes[:action_page][:remote_og_image_url] = "https://example.com/fakeimages/test-og-image.png"
test_image_file_upload = file_fixture("test-image.png").read
stub_request(:get, %r{fakeimages/test-featured-image.png}).to_return(status: 200, body: test_image_file_upload, headers: { content_type: "image/png" })
stub_request(:any, %r{/action_pages/featured_images/000/000/([0-9]+)/original/test-featured-image.png}).to_return(status: 200, body: "", headers: {})
stub_request(:any, %r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test-featured-image.png}).to_return(status: 200, body: "", headers: {})
stub_request(:get, %r{fakeimages/test-og-image.png}).to_return(status: 200, body: test_image_file_upload, headers: { content_type: "image/png" })
stub_request(:any, %r{/action_pages/og_images/000/000/([0-9]+)/original/test-og-image.png}).to_return(status: 200, body: "", headers: {})
stub_request(:any, %r{/action_pages/og_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test-og-image.png}).to_return(status: 200, body: "", headers: {})

post "/admin/action_pages", params: valid_attributes

Expand Down
4 changes: 0 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }

RSpec.configure do |config|
config.before(:each) do
DatabaseCleaner.clean_with :truncation
end

# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
Expand Down

0 comments on commit 1896f98

Please sign in to comment.