Skip to content

Commit

Permalink
Fix invalidating attachment's blob in test
Browse files Browse the repository at this point in the history
Using `load_defaults` for Rails 6.1 (see 31712c2) makes
`active_storage.track_variants` true by default.

Here we remove the overridden setting and adapt our test to invalidate
the blob with the new default in place.

See also rails/rails#37901
  • Loading branch information
waiting-for-dev committed Apr 22, 2021
1 parent 40a3b73 commit 846b611
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 9 additions & 1 deletion backend/spec/features/admin/products/edit/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
end

click_button "Update"
Spree::Image.first.attachment.blob.update(key: 11)
invalidate_attachment(Spree::Image.first.attachment)
visit current_path
expect(page).to have_xpath("//img[contains(@src, 'assets/noimage/mini')]")
end
Expand Down Expand Up @@ -136,4 +136,12 @@
expect(page).to have_css("thead th", count: 4)
end
end

def invalidate_attachment(attachment)
blob = attachment.blob
blob.variant_records.each do |variant_record|
variant_record.update(variation_digest: SecureRandom.uuid)
end
blob.update(key: SecureRandom.uuid)
end
end
4 changes: 1 addition & 3 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ def self.setup(gem_root:, lib_name:, auto_migrate: true)

class Application < ::Rails::Application
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
# TODO: Remove the two following settings once the codebase has been adapted
# to load_defaults
# TODO: Remove once the codebase has been adapted to the new default
config.active_record.has_many_inversing = nil
config.active_storage.track_variants = nil
config.eager_load = false
config.cache_classes = true
config.cache_store = :memory_store
Expand Down

0 comments on commit 846b611

Please sign in to comment.