Browse files

Fix PostgreSQL tests on Travis

Travis only has PostgreSQL 9.1.x but 9.2 is required for range datatypes.
  • Loading branch information...
1 parent 8ac94d7 commit c5989cc4837b5f814e14332a0b90a44dfa806b4e @pixeltrix pixeltrix committed Jan 24, 2013
View
5 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -575,6 +575,11 @@ def supports_explain?
true
end
+ # Range datatypes weren't introduced until PostgreSQL 9.2
+ def supports_ranges?
+ postgresql_version >= 90200
+ end
+
# Returns the configured supported identifier length supported by PostgreSQL
def table_alias_length
@table_alias_length ||= query('SHOW max_identifier_length', 'SCHEMA')[0][0].to_i
View
41 activerecord/test/cases/adapters/postgresql/datatype_test.rb
@@ -46,7 +46,7 @@ def setup
@connection.execute("INSERT INTO postgresql_arrays (id, commission_by_quarter, nicknames) VALUES (1, '{35000,21000,18000,17000}', '{foo,bar,baz}')")
@first_array = PostgresqlArray.find(1)
- @connection.execute <<_SQL
+ @connection.execute <<_SQL if @connection.supports_ranges?
INSERT INTO postgresql_ranges (
date_range,
num_range,
@@ -64,7 +64,7 @@ def setup
)
_SQL
- @connection.execute <<_SQL
+ @connection.execute <<_SQL if @connection.supports_ranges?
INSERT INTO postgresql_ranges (
date_range,
num_range,
@@ -82,7 +82,7 @@ def setup
)
_SQL
- @connection.execute <<_SQL
+ @connection.execute <<_SQL if @connection.supports_ranges?
INSERT INTO postgresql_ranges (
date_range,
num_range,
@@ -100,7 +100,7 @@ def setup
)
_SQL
- @connection.execute <<_SQL
+ @connection.execute <<_SQL if @connection.supports_ranges?
INSERT INTO postgresql_ranges (
date_range,
num_range,
@@ -118,7 +118,7 @@ def setup
)
_SQL
- @connection.execute <<_SQL
+ @connection.execute <<_SQL if @connection.supports_ranges?
INSERT INTO postgresql_ranges (
date_range,
num_range,
@@ -136,11 +136,13 @@ def setup
)
_SQL
- @first_range = PostgresqlRange.find(1)
- @second_range = PostgresqlRange.find(2)
- @third_range = PostgresqlRange.find(3)
- @fourth_range = PostgresqlRange.find(4)
- @empty_range = PostgresqlRange.find(5)
+ if @connection.supports_ranges?
+ @first_range = PostgresqlRange.find(1)
+ @second_range = PostgresqlRange.find(2)
+ @third_range = PostgresqlRange.find(3)
+ @fourth_range = PostgresqlRange.find(4)
+ @empty_range = PostgresqlRange.find(5)
+ end
@connection.execute("INSERT INTO postgresql_tsvectors (id, text_vector) VALUES (1, ' ''text'' ''vector'' ')")
@@ -183,6 +185,7 @@ def test_data_type_of_array_types
end
def test_data_type_of_range_types
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
assert_equal :daterange, @first_range.column_for_attribute(:date_range).type
assert_equal :numrange, @first_range.column_for_attribute(:num_range).type
assert_equal :tsrange, @first_range.column_for_attribute(:ts_range).type
@@ -238,6 +241,7 @@ def test_tsvector_values
end
def test_int4range_values
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
assert_equal 1...11, @first_range.int4_range
assert_equal 2...10, @second_range.int4_range
assert_equal 2...Float::INFINITY, @third_range.int4_range
@@ -246,6 +250,7 @@ def test_int4range_values
end
def test_int8range_values
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
assert_equal 10...101, @first_range.int8_range
assert_equal 11...100, @second_range.int8_range
assert_equal 11...Float::INFINITY, @third_range.int8_range
@@ -254,6 +259,7 @@ def test_int8range_values
end
def test_daterange_values
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
assert_equal Date.new(2012, 1, 2)...Date.new(2012, 1, 5), @first_range.date_range
assert_equal Date.new(2012, 1, 3)...Date.new(2012, 1, 4), @second_range.date_range
assert_equal Date.new(2012, 1, 3)...Float::INFINITY, @third_range.date_range
@@ -262,6 +268,7 @@ def test_daterange_values
end
def test_numrange_values
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
assert_equal BigDecimal.new('0.1')..BigDecimal.new('0.2'), @first_range.num_range
assert_equal BigDecimal.new('0.1')...BigDecimal.new('0.2'), @second_range.num_range
assert_equal BigDecimal.new('0.1')...BigDecimal.new('Infinity'), @third_range.num_range
@@ -270,6 +277,7 @@ def test_numrange_values
end
def test_tsrange_values
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
tz = ::ActiveRecord::Base.default_timezone
assert_equal Time.send(tz, 2010, 1, 1, 14, 30, 0)..Time.send(tz, 2011, 1, 1, 14, 30, 0), @first_range.ts_range
assert_equal Time.send(tz, 2010, 1, 1, 14, 30, 0)...Time.send(tz, 2011, 1, 1, 14, 30, 0), @second_range.ts_range
@@ -279,6 +287,7 @@ def test_tsrange_values
end
def test_tstzrange_values
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
assert_equal Time.parse('2010-01-01 09:30:00 UTC')..Time.parse('2011-01-01 17:30:00 UTC'), @first_range.tstz_range
assert_equal Time.parse('2010-01-01 09:30:00 UTC')...Time.parse('2011-01-01 17:30:00 UTC'), @second_range.tstz_range
assert_equal Time.parse('2010-01-01 09:30:00 UTC')...Float::INFINITY, @third_range.tstz_range
@@ -292,6 +301,7 @@ def test_money_values
end
def test_create_tstzrange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
tstzrange = Time.parse('2010-01-01 14:30:00 +0100')...Time.parse('2011-02-02 14:30:00 CDT')
range = PostgresqlRange.new(:tstz_range => tstzrange)
assert range.save
@@ -301,6 +311,7 @@ def test_create_tstzrange
end
def test_update_tstzrange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
new_tstzrange = Time.parse('2010-01-01 14:30:00 CDT')...Time.parse('2011-02-02 14:30:00 CET')
assert @first_range.tstz_range = new_tstzrange
assert @first_range.save
@@ -313,6 +324,7 @@ def test_update_tstzrange
end
def test_create_tsrange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
tz = ::ActiveRecord::Base.default_timezone
tsrange = Time.send(tz, 2010, 1, 1, 14, 30, 0)...Time.send(tz, 2011, 2, 2, 14, 30, 0)
range = PostgresqlRange.new(:ts_range => tsrange)
@@ -322,6 +334,7 @@ def test_create_tsrange
end
def test_update_tsrange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
tz = ::ActiveRecord::Base.default_timezone
new_tsrange = Time.send(tz, 2010, 1, 1, 14, 30, 0)...Time.send(tz, 2011, 2, 2, 14, 30, 0)
assert @first_range.ts_range = new_tsrange
@@ -335,6 +348,7 @@ def test_update_tsrange
end
def test_create_numrange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
numrange = BigDecimal.new('0.5')...BigDecimal.new('1')
range = PostgresqlRange.new(:num_range => numrange)
assert range.save
@@ -343,6 +357,7 @@ def test_create_numrange
end
def test_update_numrange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
new_numrange = BigDecimal.new('0.5')...BigDecimal.new('1')
assert @first_range.num_range = new_numrange
assert @first_range.save
@@ -355,6 +370,7 @@ def test_update_numrange
end
def test_create_daterange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
daterange = Range.new(Date.new(2012, 1, 1), Date.new(2013, 1, 1), true)
range = PostgresqlRange.new(:date_range => daterange)
assert range.save
@@ -363,6 +379,7 @@ def test_create_daterange
end
def test_update_daterange
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
new_daterange = Date.new(2012, 2, 3)...Date.new(2012, 2, 10)
assert @first_range.date_range = new_daterange
assert @first_range.save
@@ -375,6 +392,7 @@ def test_update_daterange
end
def test_create_int4range
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
int4range = Range.new(3, 50, true)
range = PostgresqlRange.new(:int4_range => int4range)
assert range.save
@@ -383,6 +401,7 @@ def test_create_int4range
end
def test_update_int4range
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
new_int4range = 6...10
assert @first_range.int4_range = new_int4range
assert @first_range.save
@@ -395,6 +414,7 @@ def test_update_int4range
end
def test_create_int8range
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
int8range = Range.new(30, 50, true)
range = PostgresqlRange.new(:int8_range => int8range)
assert range.save
@@ -403,6 +423,7 @@ def test_create_int8range
end
def test_update_int8range
+ skip "PostgreSQL 9.2 required for range datatypes" unless @connection.supports_ranges?
new_int8range = 60000...10000000
assert @first_range.int8_range = new_int8range
assert @first_range.save
View
2 activerecord/test/schema/postgresql_specific_schema.rb
@@ -73,7 +73,7 @@
);
_SQL
- execute <<_SQL
+ execute <<_SQL if supports_ranges?
CREATE TABLE postgresql_ranges (
id SERIAL PRIMARY KEY,
date_range daterange,

0 comments on commit c5989cc

Please sign in to comment.