diff --git a/Gemfile b/Gemfile index be69a65e8..cfd78a5bd 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index eb9831e82..932dd689f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) diff --git a/features/support/env.rb b/features/support/env.rb index 2c6c90e38..66cf97fd8 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -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: diff --git a/spec/features/admin/action_creation_spec.rb b/spec/features/admin/action_creation_spec.rb index 748579655..ec147be89 100644 --- a/spec/features/admin/action_creation_spec.rb +++ b/spec/features/admin/action_creation_spec.rb @@ -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 diff --git a/spec/models/action_page_spec.rb b/spec/models/action_page_spec.rb index 606d51a20..77896610b 100644 --- a/spec/models/action_page_spec.rb +++ b/spec/models/action_page_spec.rb @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1bfae2b7b..bb33dd5f6 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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! @@ -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 diff --git a/spec/requests/action_pages_spec.rb b/spec/requests/action_pages_spec.rb index dbb2bf0f1..d0a591211 100644 --- a/spec/requests/action_pages_spec.rb +++ b/spec/requests/action_pages_spec.rb @@ -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" @@ -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 @@ -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 diff --git a/spec/requests/admin/action_pages_spec.rb b/spec/requests/admin/action_pages_spec.rb index 66a4dab10..455e2ecd8 100644 --- a/spec/requests/admin/action_pages_spec.rb +++ b/spec/requests/admin/action_pages_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b1d9cc540..a4273d258 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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.