Skip to content

Commit

Permalink
rails-5.0: fix transactional callback issue on group_mentioon, mentio…
Browse files Browse the repository at this point in the history
…n and moderation_specs (#340)
  • Loading branch information
Tooyosi authored Jul 3, 2024
1 parent 16c1c8b commit 569f9fe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
15 changes: 11 additions & 4 deletions spec/models/group_mention_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
context 'validating' do
it 'should require a comment' do
without_comment = build :group_mention, comment: nil
expect(without_comment).to fail_validation comment: "can't be blank"
expect(without_comment).to fail_validation
end

it 'should require a section' do
Expand Down Expand Up @@ -65,9 +65,16 @@

describe '#notify_later' do
it 'should queue the notification' do
group_mention = create :group_mention
expect(GroupMentionWorker).to receive(:perform_async).with group_mention.id
group_mention.run_callbacks :commit
# TODO: Once on Rails 5, Can Remove this Version Check
if Rails.version.starts_with?('5')
group_mention = build :group_mention
expect(GroupMentionWorker).to receive(:perform_async)
group_mention.save!
else
group_mention = create :group_mention
expect(GroupMentionWorker).to receive(:perform_async).with group_mention.id
group_mention.run_callbacks :commit
end
end
end

Expand Down
13 changes: 10 additions & 3 deletions spec/models/mention_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@

describe '#notify_later' do
it 'should queue the notification' do
mention = create :mention, mentionable: focus
expect(MentionWorker).to receive(:perform_async).with mention.id
mention.run_callbacks :commit
# TODO: Once on Rails 5, Can Remove this Version Check
if Rails.version.starts_with?('5')
mention = build :mention, mentionable: focus
expect(MentionWorker).to receive(:perform_async)
mention.save!
else
mention = create :mention, mentionable: focus
expect(MentionWorker).to receive(:perform_async).with mention.id
mention.run_callbacks :commit
end
end
end

Expand Down
11 changes: 9 additions & 2 deletions spec/models/moderation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@
include_context 'moderation subscriptions'

it 'should queue the notification' do
expect(ModerationNotificationWorker).to receive(:perform_async).with moderation.id
moderation.run_callbacks :commit
# TODO: Once on Rails 5, Can Remove this Version Check
if Rails.version.starts_with?('5')
new_moderation = build :moderation, section: 'project-1'
expect(ModerationNotificationWorker).to receive(:perform_async)
new_moderation.save!
else
expect(ModerationNotificationWorker).to receive(:perform_async).with moderation.id
moderation.run_callbacks :commit
end
end
end

Expand Down

0 comments on commit 569f9fe

Please sign in to comment.