Navigation Menu

Skip to content

Commit

Permalink
after_commit is now called inside transactional tests
Browse files Browse the repository at this point in the history
Rails 5 feature rails/rails#18458
  • Loading branch information
hallelujah committed Oct 2, 2019
1 parent 7311d90 commit 5d2638a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
13 changes: 4 additions & 9 deletions test/unit/account/states_test.rb
Expand Up @@ -92,18 +92,15 @@ def test_events_when_state_not_changed

test 'sends notification email when account is made pending' do
account = FactoryBot.create(:buyer_account_with_provider)
AccountMailer.any_instance.expects(:confirmed)
account.make_pending!

AccountMailer.any_instance.expects(:confirmed)
account.send(:_run_after_commit_queue)
end

test 'sends notification email when account is rejected' do
account = FactoryBot.create(:buyer_account_with_provider)
account.reject!

AccountMailer.any_instance.expects(:rejected)
account.send(:_run_after_commit_queue)
account.reject!
end

test 'sends notification email when buyer account is approved' do
Expand All @@ -112,19 +109,17 @@ def test_events_when_state_not_changed
account.update_attribute(:state, 'pending')
account.buy! FactoryBot.create(:account_plan, :approval_required => true)
account.reload
account.approve!

AccountMailer.any_instance.expects(:approved)
account.send(:_run_after_commit_queue)
account.approve!

end

test 'does not send notification email when non buyer account is approved' do
AccountMailer.any_instance.expects(:approved).never

account = FactoryBot.create(:pending_account)
account.approve!

account.send(:_run_after_commit_queue)
end


Expand Down
8 changes: 2 additions & 6 deletions test/unit/user/states_test.rb
@@ -1,20 +1,16 @@
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
require 'test_helper'

class User::StatesTest < ActiveSupport::TestCase

test 'notify_activation for first_admin' do
account = FactoryBot.create(:simple_provider)

user1 = FactoryBot.create(:admin, account: account)
ThreeScale::Analytics.expects(:track).with(user1, instance_of(String)).once
user1.activate!

user2 = FactoryBot.create(:admin, account: account)
user2.activate!

ThreeScale::Analytics.expects(:track).with(user1, instance_of(String)).once

user1.send(:_run_after_commit_queue)
user2.send(:_run_after_commit_queue)
end

test 'initializes activation_code upon creation' do
Expand Down

0 comments on commit 5d2638a

Please sign in to comment.