Skip to content

Commit

Permalink
Update data_request_spec.rb (#339)
Browse files Browse the repository at this point in the history
update validation check: Rails 4 -> 5 changes validation message. It is enough to say that the validation has failed without checking for a specific error message. Especially if we did not customize the error message.

add version check to check correct worker is run after_commit. after_commit tests work differently from Rails 4 to Rails 5, do to commit callbacks not getting called in transactional tests in rails versions less than 5. (This bug gets fixed in Rails 5)
  • Loading branch information
yuenmichelle1 authored Jul 2, 2024
1 parent ade4660 commit 16c1c8b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions spec/models/data_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
context 'validating' do
it 'should require a user' do
without_user = build :data_request, user: nil
expect(without_user).to fail_validation user: "can't be blank"
expect(without_user).to fail_validation
end

it 'should require a section' do
Expand Down Expand Up @@ -75,9 +75,19 @@

describe '#spawn_worker' do
it 'should run the worker' do
data_request = create :tags_data_request
expect(TagExportWorker).to receive(:perform_async).with data_request.id
data_request.run_callbacks :commit
# TODO: Once on Rails 5, Can Remove this Version Check
# In Rails Versions < 5, commit callbacks are not getting called in transactional tests.
# See https://stackoverflow.com/a/30901628/15768801 for more details.
if Rails.version.starts_with?('5')
allow(TagExportWorker).to receive(:perform_async)
data_request = build :tags_data_request
data_request.save!
expect(TagExportWorker).to have_received(:perform_async).with data_request.id
else
data_request = create :tags_data_request
expect(TagExportWorker).to receive(:perform_async).with data_request.id
data_request.run_callbacks :commit
end
end
end

Expand Down

0 comments on commit 16c1c8b

Please sign in to comment.