Skip to content

Commit 0d1151d

Browse files
committed
Revert "Skip needless Rails extension."
This reverts commit 4d3a671.
1 parent e90537d commit 0d1151d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

test/helper.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,27 @@
66

77
FIXTURES_ROOT = File.expand_path(File.dirname(__FILE__)) + "/fixtures"
88

9+
module Rails
10+
class << self
11+
def version_matches?(requirement_str)
12+
ver = Gem::Version.new(version)
13+
req = Gem::Requirement.new(requirement_str)
14+
req.satisfied_by?(ver)
15+
end
16+
end
17+
end
18+
919
class ActiveSupport::TestCase
1020
include ActiveRecord::TestFixtures
1121

1222
self.test_order = :random if self.respond_to?(:test_order=)
1323
self.fixture_path = FIXTURES_ROOT
1424
self.use_instantiated_fixtures = false
15-
self.use_transactional_fixtures = true if Rails.version.start_with?('4.0')
25+
self.use_transactional_fixtures = true if Rails.version_matches?('~> 4.0')
1626
self.use_transactional_tests = true if self.respond_to?(:use_transactional_tests=)
1727
end
1828

19-
if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=) && Rails.version.start_with?('4.0')
29+
if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=) && Rails.version_matches?('~> 4.0')
2030
ActiveRecord::Base.raise_in_transactional_callbacks = true
2131
end
2232

test/sweeper_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SweeperTestController < ActionController::Base
1313
cache_sweeper :app_sweeper
1414

1515
def show
16-
if Rails.version >= '5.0'
16+
if Rails.version_matches?('>= 5.0.0.beta1')
1717
render plain: 'hello world'
1818
else
1919
render text: 'hello world'

test/transaction_callbacks_test.rb

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require "helper"
22

33
class TransactionCallbacksTest < ActiveSupport::TestCase
4-
self.use_transactional_fixtures = false if Rails.version.start_with?('4.0')
5-
self.use_transactional_tests = false if respond_to?(:use_transactional_tests=)
4+
self.use_transactional_fixtures = false if Rails.version_matches?('~> 4.0')
5+
self.use_transactional_tests = false if self.respond_to?(:use_transactional_tests=)
66
fixtures :topics
77

88
class TopicWithCallbacks < ActiveRecord::Base
@@ -228,14 +228,14 @@ def @first.last_after_transaction_error; @last_transaction_error; end
228228
@second.after_commit_block{|r| r.history << :after_commit}
229229
@second.after_rollback_block{|r| r.history << :after_rollback}
230230

231-
action_without_rollback = -> do
231+
action_without_rollback = Proc.new do
232232
Topic.transaction do
233233
@first.save!
234234
@second.save!
235235
end
236236
end
237237

238-
if Rails.version >= '4.2'
238+
if Rails.version_matches?('>= 4.2')
239239
assert_raises RuntimeError, &action_without_rollback
240240
else
241241
action_without_rollback.call
@@ -244,15 +244,14 @@ def @first.last_after_transaction_error; @last_transaction_error; end
244244
assert_equal [:after_commit], @second.history
245245

246246
@second.history.clear
247-
action_with_rollback = -> do
247+
action_with_rollback = Proc.new do
248248
Topic.transaction do
249249
@first.save!
250250
@second.save!
251251
raise ActiveRecord::Rollback
252252
end
253253
end
254-
255-
if Rails.version >= '4.2'
254+
if Rails.version_matches?('>= 4.2')
256255
assert_raises RuntimeError, &action_with_rollback
257256
assert_equal :rollback, @first.last_after_transaction_error
258257
assert_equal [], @second.history

0 commit comments

Comments
 (0)