Skip to content

Commit 3fb9e1f

Browse files
committed
More version checks removed
1 parent 8c1024b commit 3fb9e1f

25 files changed

+79
-219
lines changed

test/db/h2/schema_dump_test.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ class H2SchemaDumpTest < Test::Unit::TestCase
1919
def test_schema_dump_decimal_when_scale_specified
2020
output = standard_dump(StringIO.new, [/^[^d]/]) # keep db_types
2121
# t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2, :default => 3.14
22-
if ar_version('4.0')
23-
assert_match %r{t.decimal\s+"sample_small_decimal",\s+precision: 3,\s+scale: 2}, output
24-
else
25-
assert_match %r{t.decimal\s+"sample_small_decimal",\s+:precision => 3,\s+:scale => 2}, output
26-
end
22+
assert_match %r{t.decimal\s+"sample_small_decimal",\s+precision: 3,\s+scale: 2}, output
2723
end
2824

2925
# @override
@@ -32,13 +28,7 @@ def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added
3228
match = output.match(%r{create_table "string_ids"(.*)do.*\n(.*)\n})
3329
assert_not_nil(match, "string_ids table not found")
3430
assert_match %r((:id => false)|(id: false)), match[1], "no table id not preserved"
35-
if ar_version('4.2')
36-
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+limit:[[:space:]]+255,[[:space:]]+null:[[:space:]]+false$}, match[2], "non-primary key id column not preserved"
37-
elsif ar_version('4.0')
38-
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+null: false$}, match[2], "non-primary key id column not preserved"
39-
else
40-
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
41-
end
31+
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+limit:[[:space:]]+255,[[:space:]]+null:[[:space:]]+false$}, match[2], "non-primary key id column not preserved"
4232
end
4333

44-
end
34+
end

test/db/h2/serialize_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ def test_serialized_attribute_should_raise_exception_on_save_with_wrong_type
1515
rescue ActiveRecord::JDBCError => e
1616
e.sql_exception.printStackTrace if e.sql_exception
1717
end
18-
end if Test::Unit::TestCase.ar_version('3.2')
18+
end
1919

2020
end

test/db/h2/simple_test.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
class H2SimpleTest < Test::Unit::TestCase
55
include SimpleTestMethods
6-
include ExplainSupportTestMethods if ar_version("3.1")
6+
include ExplainSupportTestMethods
77
include ActiveRecord3TestMethods
88
include CustomSelectTestMethods
99

1010
test 'returns correct visitor type' do
1111
assert_not_nil visitor = connection.instance_variable_get(:@visitor)
1212
assert defined? Arel::Visitors::HSQLDB
1313
assert_kind_of Arel::Visitors::HSQLDB, visitor
14-
end if ar_version('3.0')
14+
end
1515

1616
end
1717

@@ -56,13 +56,8 @@ def teardown
5656
end
5757

5858
def test_find_in_other_schema
59-
if ar_version('4.0')
60-
all = Entry.includes(:user).references(:user)
61-
assert ! all.empty?, "expected `Entry.includes(:user)` to not be empty but was"
62-
else
63-
all = Entry.all(:include => :user)
64-
assert ! all.empty?, "expected `Entry.all(:include => :user)` to not be empty but was"
65-
end
59+
all = Entry.includes(:user).references(:user)
60+
assert ! all.empty?, "expected `Entry.includes(:user)` to not be empty but was"
6661
end
6762

68-
end
63+
end

test/db/h2/transaction_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_transaction_isolation_read_committed
2323
end
2424
end
2525
assert_equal 1, Entry.count
26-
end if Test::Unit::TestCase.ar_version('4.0')
26+
end
2727

2828
# @override whole table gets locked!
2929
def test_transaction_isolation_repeatable_read
@@ -43,6 +43,6 @@ def test_transaction_isolation_repeatable_read
4343
end
4444
#entry.reload
4545
#assert_equal '567', entry.title
46-
end if Test::Unit::TestCase.ar_version('4.0')
46+
end
4747

4848
end

test/db/hsqldb/schema_dump_test.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ class HSQLDBSchemaDumpTest < Test::Unit::TestCase
99
def test_schema_dump_decimal_when_scale_specified
1010
output = standard_dump(StringIO.new, [/^[^d]/]) # keep db_types
1111
# t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2, :default => 3.14
12-
if ar_version('4.0')
13-
assert_match %r{t.decimal\s+"sample_small_decimal",\s+precision: 3,\s+scale: 2}, output
14-
else
15-
assert_match %r{t.decimal\s+"sample_small_decimal",\s+:precision => 3,\s+:scale => 2}, output
16-
end
12+
assert_match %r{t.decimal\s+"sample_small_decimal",\s+precision: 3,\s+scale: 2}, output
1713
end
1814

1915
# @override
@@ -22,13 +18,7 @@ def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added
2218
match = output.match(%r{create_table "string_ids"(.*)do.*\n(.*)\n})
2319
assert_not_nil(match, "string_ids table not found")
2420
assert_match %r((:id => false)|(id: false)), match[1], "no table id not preserved"
25-
if ar_version('4.2')
26-
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+limit:[[:space:]]+255,[[:space:]]+null:[[:space:]]+false$}, match[2], "non-primary key id column not preserved"
27-
elsif ar_version('4.0')
28-
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+null: false$}, match[2], "non-primary key id column not preserved"
29-
else
30-
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
31-
end
21+
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+limit:[[:space:]]+255,[[:space:]]+null:[[:space:]]+false$}, match[2], "non-primary key id column not preserved"
3222
end
3323

34-
end
24+
end

test/db/hsqldb/simple_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33

44
class HsqldbSimpleTest < Test::Unit::TestCase
55
include SimpleTestMethods
6-
include ExplainSupportTestMethods if ar_version("3.1")
6+
include ExplainSupportTestMethods
77
include ActiveRecord3TestMethods
88
include CustomSelectTestMethods
99

1010
# @override
1111
def test_empty_insert_statement
1212
# "INSERT INTO table DEFAULT VALUES" only works if all columns have defaults
13-
pend if ar_version('4.0')
13+
pend
1414
super
1515
end
1616

1717
# @override
1818
def test_explain_with_binds
1919
skip 'HSQLDB seems to have issues EXPLAIN-ing with binds'
2020
super
21-
end if ar_version('3.1')
21+
end
2222

2323
test 'returns correct visitor type' do
2424
assert_not_nil visitor = connection.instance_variable_get(:@visitor)
2525
assert defined? Arel::Visitors::HSQLDB
2626
assert_kind_of Arel::Visitors::HSQLDB, visitor
27-
end if ar_version('3.0')
27+
end
2828

2929
end

test/db/hsqldb/transaction_test.rb

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_transaction_isolation_read_committed
2323
end
2424
end
2525
assert_equal 1, Entry.count
26-
end if Test::Unit::TestCase.ar_version('4.0')
26+
end
2727

2828
# @override whole table gets locked!
2929
def test_transaction_isolation_repeatable_read
@@ -43,34 +43,7 @@ def test_transaction_isolation_repeatable_read
4343
end
4444
#entry.reload
4545
#assert_equal '567', entry.title
46-
end if Test::Unit::TestCase.ar_version('4.0')
47-
48-
# @override
49-
def test_savepoint
50-
#omit 'savepoins not supported' unless @supports_savepoints
51-
Entry.create! :title => '1'
52-
assert_equal 1, Entry.count
53-
54-
connection = ActiveRecord::Base.connection
55-
connection.transaction do
56-
begin
57-
connection.create_savepoint
58-
savepoint_created = true
59-
60-
Entry.create! :title => '2'
61-
Entry.create! :title => '3'
62-
63-
assert_equal 3, Entry.count
64-
65-
connection.rollback_to_savepoint
66-
assert_equal 1, Entry.count
67-
ensure
68-
# NOTE: HSQLDB seems to not support release after rollback :
69-
# Invalid argument in JDBC call: 3B001 savepoint exception: invalid specification
70-
#connection.release_savepoint if savepoint_created
71-
end
72-
end
73-
end unless Test::Unit::TestCase.ar_version('4.1')
46+
end
7447

7548
# @override
7649
def test_using_named_savepoints
@@ -93,6 +66,6 @@ def test_using_named_savepoints
9366
#Entry.connection.release_savepoint("first")
9467
#assert_equal 'f', first.reload.content
9568
end
96-
end if Test::Unit::TestCase.ar_version('4.1')
69+
end
9770

9871
end

test/db/mssql/custom_test.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ def self.shutdown
1919
entry.reload
2020
assert_equal 'Hello!', entry['My Name']
2121

22-
if ar_version('3.1')
23-
LegacyEntry.where('[My Name] IS NOT NULL').limit(1).to_a
24-
LegacyEntry.order(:'My Name').limit(1).to_a
25-
else
26-
LegacyEntry.all(:limit => 1)
27-
LegacyEntry.all(:order => :'My Name', :limit => 1)
28-
end
22+
LegacyEntry.where('[My Name] IS NOT NULL').limit(1).to_a
23+
LegacyEntry.order(:'My Name').limit(1).to_a
2924
end
3025

31-
end
26+
end

test/db/mssql/limit_offset_test.rb

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,24 @@ def test_limit_with_alternate_named_primary_key
108108
end
109109
ships = LegacyShip.limit(3)
110110
assert_equal(3, ships.size)
111-
end if ar_version('3.0')
111+
end
112112

113113
def test_limit_and_offset
114114
%w(one two three four five six seven eight).each do |name|
115115
LongShip.create!(:name => name)
116116
end
117-
if ar_version('4.0')
118-
ship_names = LongShip.offset(2).limit(3).to_a.map(&:name)
119-
else
120-
ship_names = LongShip.find(:all, :offset => 2, :limit => 3).map(&:name)
121-
end
117+
ship_names = LongShip.offset(2).limit(3).to_a.map(&:name)
122118
assert_equal(%w(three four five), ship_names)
123119
end
124120

125121
def test_limit_and_offset_with_order
126122
names = %w(one two three four five six seven eight).each do |name|
127123
LongShip.create!(:name => name)
128124
end
129-
if ar_version('4.0')
130-
ship_names = LongShip.order("name").offset(4).limit(2).to_a.map(&:name)
131-
else
132-
ship_names = LongShip.find(:all, :order => "name", :offset => 4, :limit => 2).map(&:name)
133-
end
125+
ship_names = LongShip.order("name").offset(4).limit(2).to_a.map(&:name)
134126
assert_equal(names.sort[4, 2], ship_names)
135127

136-
if ar_version('4.0')
137-
ship_names = LongShip.order("id").offset(4).limit(2).to_a.map(&:name)
138-
else
139-
ship_names = LongShip.find(:all, :order => "id", :offset => 4, :limit => 2).map(&:name)
140-
end
128+
ship_names = LongShip.order("id").offset(4).limit(2).to_a.map(&:name)
141129
assert_equal(%w(five six), ship_names)
142130
end
143131

@@ -146,11 +134,7 @@ def test_limit_and_offset_with_include
146134
skei.vikings.create!(:name => "Bob")
147135
skei.vikings.create!(:name => "Ben")
148136
skei.vikings.create!(:name => "Basil")
149-
if ar_version('4.0')
150-
ships = Viking.includes(:long_ship).offset(1).limit(2) #.all
151-
else
152-
ships = Viking.find(:all, :include => :long_ship, :offset => 1, :limit => 2)
153-
end
137+
ships = Viking.includes(:long_ship).offset(1).limit(2) #.all
154138
assert_equal(2, ships.size)
155139
end
156140

@@ -163,25 +147,15 @@ def test_limit_and_offset_with_include_and_order
163147
boat1.vikings.create!(:name => "Carl")
164148
boat2.vikings.create!(:name => "Donald")
165149

166-
if ar_version('4.0')
167-
vikings = Viking.includes(:long_ship).order('long_ships.name, vikings.name').references(:long_ship).offset(0).limit(3)
168-
else
169-
vikings = Viking.find(:all, :include => :long_ship, :order => "long_ships.name, vikings.name", :offset => 0, :limit => 3)
170-
end
150+
vikings = Viking.includes(:long_ship).order('long_ships.name, vikings.name').references(:long_ship).offset(0).limit(3)
171151
assert_equal ["Adam", "Carl", "Ben"], vikings.map(&:name)
172152
end
173153

174154
def test_offset_without_limit
175155
%w( egy keto harom negy ot hat het nyolc ).each do |name|
176156
LongShip.create!(:name => name)
177157
end
178-
if ar_version('4.0')
179-
ships = LongShip.select(:name).offset(3).to_a
180-
elsif ar_version('3.0')
181-
ships = LongShip.select(:name).offset(3).all
182-
else
183-
ships = LongShip.find(:all, :select => 'name', :offset => 3)
184-
end
158+
ships = LongShip.select(:name).offset(3).to_a
185159
assert_equal ['negy', 'ot', 'hat', 'het', 'nyolc'], ships.map(&:name)
186160
end
187161

@@ -195,7 +169,7 @@ def test_limit_with_group_by
195169

196170
ships = LongShip.select(:name).group(:name).limit(2).offset(2)
197171
assert_equal ['three', 'four'], ships.map(&:name)
198-
end if ar_version('3.0')
172+
end
199173

200174
# NOTE: can not work due how MS-SQL "rulezzz"
201175
# Column 'long_ships.id' is invalid in the select list because it is not
@@ -213,7 +187,7 @@ def test_limit_with_group_by
213187
#
214188
# ships = LongShip.select(:name).group(:name).limit(2).offset(2)
215189
# assert_equal ['three', 'four'], ships.map(&:name)
216-
# end if ar_version('3.0')
190+
# end
217191

218192
def test_limit_with_group_by_and_aggregate_in_order_clause
219193
%w( one two three four five six seven eight ).each_with_index do |name, i|
@@ -231,17 +205,13 @@ def test_limit_with_group_by_and_aggregate_in_order_clause
231205

232206
ships = LongShip.select(:name).group(:name).limit(2).order('MAX(width) DESC').all
233207
assert_equal ['eight', 'seven'], ships.map(&:name)
234-
end if ar_version('3.0')
208+
end
235209

236210
def test_select_distinct_with_limit
237211
%w(c a b a b a c d c d).each do |name|
238212
LongShip.create!(:name => name)
239213
end
240-
if ar_version('3.0')
241-
result = LongShip.select("DISTINCT name").order("name").limit(2)
242-
else
243-
result = LongShip.find(:all, :select => "DISTINCT name", :order => "name", :limit => 2)
244-
end
214+
result = LongShip.select("DISTINCT name").order("name").limit(2)
245215
assert_equal %w(a b), result.map(&:name)
246216
end
247217

@@ -257,7 +227,7 @@ def test_select_distinct_view_with_joins_and_limit
257227
joins(:long_ship).where(:long_ship_id => mega_ship.id).
258228
order('name')
259229
assert_equal [ '11', '12' ], result.map { |viking| viking.name }
260-
end if ar_version('3.0')
230+
end
261231

262232
class Viewking < ActiveRecord::Base
263233
belongs_to :long_ship
@@ -278,7 +248,7 @@ def test_order_and_limit_view_with_include
278248

279249
arel = Viewking.includes(:long_ship).limit(3)
280250
assert_equal 2, arel.to_a.size
281-
end if ar_version('3.0')
251+
end
282252

283253
test 'ordering_on_aggregate GH-532' do
284254
5.times { |i| LongShip.create! :name => "ship_#{i}", :length => 1000 + i }

test/db/mssql/multibyte_test.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ class MSSQLMultibyteTest < Test::Unit::TestCase
77

88
def test_select_multibyte_string
99
Entry.create!(:title => 'テスト', :content => '本文')
10-
if ar_version('4.0')
11-
entry = Entry.last
12-
else
13-
entry = Entry.find(:last)
14-
end
10+
entry = Entry.last
1511
assert_equal "テスト", entry.title
1612
assert_equal "本文", entry.content
1713
assert_equal entry, Entry.find_by_title("テスト")

0 commit comments

Comments
 (0)