-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass model names as strings when loading batches
ActiveJob < 6.1 cannot handle classes in params "Allow Class and Module instances to be serialized." appeared in Rails changelog at https://github.com/rails/rails/releases/tag/v6.1.0.rc1
- Loading branch information
1 parent
72e7e7e
commit 4dc410a
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
RSpec.describe DfE::Analytics::LoadEntityBatch do | ||
include ActiveJob::TestHelper | ||
|
||
with_model :Candidate do | ||
table do |t| | ||
t.string :email_address | ||
end | ||
end | ||
|
||
before do | ||
allow(DfE::Analytics::SendEvents).to receive(:perform_later) | ||
end | ||
|
||
around do |ex| | ||
perform_enqueued_jobs do | ||
ex.run | ||
end | ||
end | ||
|
||
it 'accepts its first arg as a String to support Rails < 6.1' do | ||
# Rails 6.1rc1 added support for deserializing Class and Module params | ||
c = Candidate.create(email_address: 'foo@example.com') | ||
|
||
described_class.perform_later("Candidate", [c.id], 1) | ||
|
||
expect(DfE::Analytics::SendEvents).to have_received(:perform_later).once | ||
end | ||
|
||
it 'accepts its first arg as a Class' do | ||
# backwards compatability with existing enqueued jobs | ||
c = Candidate.create(email_address: 'foo@example.com') | ||
|
||
described_class.perform_later(Candidate, [c.id], 1) | ||
|
||
expect(DfE::Analytics::SendEvents).to have_received(:perform_later).once | ||
end | ||
end |