From 889bc7a4bb48be1196fbab1c6520441b88387b92 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:53:53 +0200 Subject: [PATCH] Fix SubmissionFileUpdateJob not being enqueued CLoses #100 --- config/application.rb | 3 +++ test/model/submission_file_test.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/config/application.rb b/config/application.rb index 844685f8..603a21e7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -35,6 +35,9 @@ class Application < Rails::Application }, } + # TODO: Remove this + config.active_record.run_after_transaction_callbacks_in_order_defined = false + config.action_controller.action_on_unpermitted_parameters = :raise config.cache_store = :file_store, Rails.root.join("tmp/file_store") diff --git a/test/model/submission_file_test.rb b/test/model/submission_file_test.rb index ed7ebd81..d3c813ac 100644 --- a/test/model/submission_file_test.rb +++ b/test/model/submission_file_test.rb @@ -3,6 +3,8 @@ require "test_helper" class SubmissionFileTest < ActiveSupport::TestCase + include ActiveJob::TestHelper + describe "#original" do it "must be attached on create" do e = assert_raises(ActiveRecord::RecordInvalid) { create(:submission_file, skip_original_validation: false) } @@ -21,5 +23,15 @@ class SubmissionFileTest < ActiveSupport::TestCase assert_not sm.original.attached? assert_predicate(sm, :valid?) end + + it "enqueues the update job on create" do + create(:submission_file_with_original, file_name: "1.webp") + assert_enqueued_jobs 1, only: SubmissionFileUpdateJob + end + + it "enqueues nothing if the attachment didn't change" do + sm = create(:submission_file_with_original, file_name: "1.webp") + assert_no_enqueued_jobs { sm.save } + end end end