test/plugins/transaction_test.rb in rocketjob-3.4.3 vs test/plugins/transaction_test.rb in rocketjob-3.5.0
- old
+ new
@@ -1,9 +1,9 @@
require_relative '../test_helper'
require 'active_record'
-ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read('test/config/database.yml')).result)
+ActiveRecord::Base.configurations = YAML.safe_load(ERB.new(IO.read('test/config/database.yml')).result)
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Schema.define version: 0 do
create_table :users, force: true do |t|
t.string :login
@@ -14,11 +14,10 @@
end
module Plugins
module Job
class TransactionTest < Minitest::Test
-
class CommitTransactionJob < RocketJob::Job
# Wrap perform with a transaction, so that it is rolled back on exception.
include RocketJob::Plugins::Transaction
field :login, type: String
@@ -34,11 +33,11 @@
field :login, type: String
def perform
User.create!(login: login)
- raise "This must fail and rollback the transaction"
+ raise 'This must fail and rollback the transaction'
end
end
describe RocketJob::Plugins::Job::Logger do
before do
@@ -51,13 +50,13 @@
@job.destroy if @job && !@job.new_record?
end
describe '#rocket_job_transaction' do
it 'is registered' do
- assert CommitTransactionJob.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction }
- assert RollbackTransactionJob.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction }
- refute RocketJob::Job.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction }
+ assert(CommitTransactionJob.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction })
+ assert(RollbackTransactionJob.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction })
+ refute(RocketJob::Job.send(:get_callbacks, :perform).find { |c| c.filter == :rocket_job_transaction })
end
end
describe '#perform' do
it 'commits on success' do
@@ -77,10 +76,9 @@
end
assert job.failed?
assert_equal 0, User.count
end
end
-
end
end
end
end