postgres_ext 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +6 -47
- data/lib/postgres_ext/active_record/relation/predicate_builder.rb +36 -55
- data/lib/postgres_ext/active_record/relation/query_methods.rb +0 -14
- data/lib/postgres_ext/active_record.rb +0 -3
- data/lib/postgres_ext/version.rb +1 -1
- data/postgres_ext.gemspec +6 -5
- data/spec/arel/arel_spec.rb +0 -1
- data/spec/dummy/app/models/person.rb +0 -1
- data/spec/dummy/config/application.rb +0 -3
- data/spec/dummy/config/environments/development.rb +2 -7
- data/spec/dummy/config/environments/production.rb +1 -0
- data/spec/dummy/config/environments/test.rb +1 -5
- data/spec/dummy/db/migrate/20120501163758_create_people.rb +3 -3
- data/spec/dummy/db/schema.rb +15 -12
- data/spec/queries/sanity_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -2
- metadata +21 -105
- data/docs/indexes.md +0 -28
- data/docs/migrations.md +0 -92
- data/docs/type_casting.md +0 -70
- data/lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb +0 -537
- data/lib/postgres_ext/active_record/connection_adapters.rb +0 -1
- data/lib/postgres_ext/active_record/sanitization.rb +0 -30
- data/lib/postgres_ext/active_record/schema_dumper.rb +0 -157
- data/spec/columns/array_spec.rb +0 -119
- data/spec/columns/inet_spec.rb +0 -25
- data/spec/columns/ranges/daterange_spec.rb +0 -37
- data/spec/columns/ranges/int4range_spec.rb +0 -38
- data/spec/columns/ranges/int8range_spec.rb +0 -38
- data/spec/columns/ranges/numrange_spec.rb +0 -37
- data/spec/columns/ranges/tsrange_spec.rb +0 -37
- data/spec/migrations/active_record_migration_spec.rb +0 -29
- data/spec/migrations/array_spec.rb +0 -214
- data/spec/migrations/cidr_spec.rb +0 -26
- data/spec/migrations/citext_spec.rb +0 -32
- data/spec/migrations/ean13_spec.rb +0 -27
- data/spec/migrations/index_spec.rb +0 -67
- data/spec/migrations/inet_spec.rb +0 -26
- data/spec/migrations/macaddr_spec.rb +0 -26
- data/spec/migrations/ranges/daterange_spec.rb +0 -27
- data/spec/migrations/ranges/int4range_spec.rb +0 -27
- data/spec/migrations/ranges/int8range_spec.rb +0 -27
- data/spec/migrations/ranges/numrange_spec.rb +0 -27
- data/spec/migrations/ranges/tsrange_spec.rb +0 -27
- data/spec/migrations/ranges/tstzrange_spec.rb +0 -27
- data/spec/migrations/uuid_spec.rb +0 -26
- data/spec/models/array_spec.rb +0 -285
- data/spec/models/ean13_spec.rb +0 -57
- data/spec/models/inet_spec.rb +0 -88
- data/spec/models/ranges/daterange_spec.rb +0 -88
- data/spec/models/ranges/int4range_spec.rb +0 -85
- data/spec/models/ranges/int8range_spec.rb +0 -85
- data/spec/models/ranges/numrange_spec.rb +0 -85
- data/spec/models/ranges/tsrange_spec.rb +0 -89
- data/spec/models/ranges/tstzrange_spec.rb +0 -89
- data/spec/schema_dumper/array_spec.rb +0 -17
- data/spec/schema_dumper/cidr_spec.rb +0 -17
- data/spec/schema_dumper/citext_spec.rb +0 -17
- data/spec/schema_dumper/ean13_spec.rb +0 -17
- data/spec/schema_dumper/extension_spec.rb +0 -14
- data/spec/schema_dumper/index_spec.rb +0 -46
- data/spec/schema_dumper/inet_spec.rb +0 -17
- data/spec/schema_dumper/macaddr_spec.rb +0 -17
- data/spec/schema_dumper/ranges/daterange_spec.rb +0 -18
- data/spec/schema_dumper/ranges/int4range_spec.rb +0 -18
- data/spec/schema_dumper/ranges/int8range_spec.rb +0 -18
- data/spec/schema_dumper/ranges/numrange_spec.rb +0 -18
- data/spec/schema_dumper/ranges/tsrange_spec.rb +0 -18
- data/spec/schema_dumper/ranges/tstzrange_spec.rb +0 -17
- data/spec/schema_dumper/uuid_spec.rb +0 -17
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'active_record/sanitization'
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module Sanitization
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def sanitize_sql_hash_for_assignment(attrs)
|
9
|
-
attrs.map do |attr, value|
|
10
|
-
"#{connection.quote_column_name(attr)} = #{quote_bound_value(value, attr)}"
|
11
|
-
end.join(', ')
|
12
|
-
end
|
13
|
-
|
14
|
-
def quote_bound_value(value, column = nil, c = connection)
|
15
|
-
if column.present? && column != c
|
16
|
-
record_column = self.columns.select {|col| col.name == column}.first
|
17
|
-
c.quote(value, record_column)
|
18
|
-
elsif value.respond_to?(:map) && !value.acts_like?(:string)
|
19
|
-
if value.respond_to?(:empty?) && value.empty?
|
20
|
-
c.quote(nil)
|
21
|
-
else
|
22
|
-
value.map { |v| c.quote(v) }.join(',')
|
23
|
-
end
|
24
|
-
else
|
25
|
-
c.quote(value)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
require 'active_record/schema_dumper'
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
class SchemaDumper
|
5
|
-
VALID_COLUMN_SPEC_KEYS = [:name, :limit, :precision, :scale, :default, :null, :array]
|
6
|
-
def self.valid_column_spec_keys
|
7
|
-
VALID_COLUMN_SPEC_KEYS
|
8
|
-
end
|
9
|
-
|
10
|
-
def dump(stream)
|
11
|
-
header(stream)
|
12
|
-
# added
|
13
|
-
extensions(stream) if @connection.respond_to?(:supports_extensions?) &&
|
14
|
-
@connection.supports_extensions?
|
15
|
-
# /added
|
16
|
-
tables(stream)
|
17
|
-
trailer(stream)
|
18
|
-
stream
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def extensions(stream)
|
24
|
-
exts = @connection.extensions
|
25
|
-
|
26
|
-
unless exts.empty?
|
27
|
-
stream.puts exts.map { |name| " add_extension \"#{name}\""}.join("\n") + "\n\n"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def table(table, stream)
|
32
|
-
columns = @connection.columns(table)
|
33
|
-
begin
|
34
|
-
tbl = StringIO.new
|
35
|
-
|
36
|
-
# first dump primary key column
|
37
|
-
if @connection.respond_to?(:pk_and_sequence_for)
|
38
|
-
pk, _ = @connection.pk_and_sequence_for(table)
|
39
|
-
elsif @connection.respond_to?(:primary_key)
|
40
|
-
pk = @connection.primary_key(table)
|
41
|
-
end
|
42
|
-
|
43
|
-
tbl.print " create_table #{table.inspect}"
|
44
|
-
if columns.detect { |c| c.name == pk }
|
45
|
-
if pk != 'id'
|
46
|
-
tbl.print %Q(, :primary_key => "#{pk}")
|
47
|
-
end
|
48
|
-
else
|
49
|
-
tbl.print ", :id => false"
|
50
|
-
end
|
51
|
-
tbl.print ", :force => true"
|
52
|
-
tbl.puts " do |t|"
|
53
|
-
|
54
|
-
# then dump all non-primary key columns
|
55
|
-
column_specs = columns.map do |column|
|
56
|
-
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" if @types[column.type].nil?
|
57
|
-
next if column.name == pk
|
58
|
-
spec = column_spec(column)
|
59
|
-
(spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k.inspect} => ")}
|
60
|
-
spec
|
61
|
-
end.compact
|
62
|
-
|
63
|
-
# find all migration keys used in this table
|
64
|
-
keys = self.class.valid_column_spec_keys & column_specs.map{ |k| k.keys }.flatten
|
65
|
-
|
66
|
-
# figure out the lengths for each column based on above keys
|
67
|
-
lengths = keys.map{ |key| column_specs.map{ |spec| spec[key] ? spec[key].length + 2 : 0 }.max }
|
68
|
-
|
69
|
-
# the string we're going to sprintf our values against, with standardized column widths
|
70
|
-
format_string = lengths.map{ |len| "%-#{len}s" }
|
71
|
-
|
72
|
-
# find the max length for the 'type' column, which is special
|
73
|
-
type_length = column_specs.map{ |column| column[:type].length }.max
|
74
|
-
|
75
|
-
# add column type definition to our format string
|
76
|
-
format_string.unshift " t.%-#{type_length}s "
|
77
|
-
|
78
|
-
format_string *= ''
|
79
|
-
|
80
|
-
column_specs.each do |colspec|
|
81
|
-
values = keys.zip(lengths).map{ |key, len| colspec.key?(key) ? colspec[key] + ", " : " " * len }
|
82
|
-
values.unshift colspec[:type]
|
83
|
-
tbl.print((format_string % values).gsub(/,\s*$/, ''))
|
84
|
-
tbl.puts
|
85
|
-
end
|
86
|
-
|
87
|
-
tbl.puts " end"
|
88
|
-
tbl.puts
|
89
|
-
|
90
|
-
indexes(table, tbl)
|
91
|
-
|
92
|
-
tbl.rewind
|
93
|
-
stream.print tbl.read
|
94
|
-
rescue => e
|
95
|
-
stream.puts "# Could not dump table #{table.inspect} because of following #{e.class}"
|
96
|
-
stream.puts "# #{e.message}"
|
97
|
-
stream.puts
|
98
|
-
end
|
99
|
-
|
100
|
-
stream
|
101
|
-
end
|
102
|
-
|
103
|
-
#mostly rails 3.2 code
|
104
|
-
def indexes(table, stream)
|
105
|
-
if (indexes = @connection.indexes(table)).any?
|
106
|
-
add_index_statements = indexes.map do |index|
|
107
|
-
statement_parts = [
|
108
|
-
('add_index ' + index.table.inspect),
|
109
|
-
index.columns.inspect,
|
110
|
-
(':name => ' + index.name.inspect),
|
111
|
-
]
|
112
|
-
statement_parts << ':unique => true' if index.unique
|
113
|
-
|
114
|
-
index_lengths = (index.lengths || []).compact
|
115
|
-
statement_parts << (':length => ' + Hash[index.columns.zip(index.lengths)].inspect) unless index_lengths.empty?
|
116
|
-
|
117
|
-
index_orders = (index.orders || {})
|
118
|
-
statement_parts << (':order => ' + index.orders.inspect) unless index_orders.empty?
|
119
|
-
|
120
|
-
# changed from rails 2.3
|
121
|
-
statement_parts << (':where => ' + index.where.inspect) if index.where
|
122
|
-
statement_parts << (':using => ' + index.using.inspect) if index.using
|
123
|
-
statement_parts << (':index_opclass => ' + index.index_opclass.inspect) if index.index_opclass.present?
|
124
|
-
# /changed
|
125
|
-
|
126
|
-
' ' + statement_parts.join(', ')
|
127
|
-
end
|
128
|
-
|
129
|
-
stream.puts add_index_statements.sort.join("\n")
|
130
|
-
stream.puts
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
#mostly rails 3.2 code (pulled out of table method)
|
135
|
-
def column_spec(column)
|
136
|
-
spec = {}
|
137
|
-
spec[:name] = column.name.inspect
|
138
|
-
|
139
|
-
# AR has an optimization which handles zero-scale decimals as integers. This
|
140
|
-
# code ensures that the dumper still dumps the column as a decimal.
|
141
|
-
spec[:type] = if column.type == :integer && [/^numeric/, /^decimal/].any? { |e| e.match(column.sql_type) }
|
142
|
-
'decimal'
|
143
|
-
else
|
144
|
-
column.type.to_s
|
145
|
-
end
|
146
|
-
spec[:limit] = column.limit.inspect if column.limit != @types[column.type][:limit] && spec[:type] != 'decimal'
|
147
|
-
spec[:precision] = column.precision.inspect if column.precision
|
148
|
-
spec[:scale] = column.scale.inspect if column.scale
|
149
|
-
spec[:null] = 'false' unless column.null
|
150
|
-
spec[:default] = default_string(column.default) if column.has_default?
|
151
|
-
# changed from rails 3.2 code
|
152
|
-
spec[:array] = 'true' if column.respond_to?(:array) && column.array
|
153
|
-
# /changed
|
154
|
-
spec
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
data/spec/columns/array_spec.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Array column' do
|
6
|
-
let!(:integer_array_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'integer[]'}
|
7
|
-
let!(:string_array_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'character varying(255)[]'}
|
8
|
-
let!(:text_array_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'text[]'}
|
9
|
-
let!(:adapter) { ActiveRecord::Base.connection }
|
10
|
-
|
11
|
-
context 'string array' do
|
12
|
-
describe '#type_cast' do
|
13
|
-
context 'has null value' do
|
14
|
-
it 'converts the PostgreSQL value to an array with a nil value' do
|
15
|
-
string_array_column.type_cast('{1,NULL,"NULL"}').should eq ['1',nil,'NULL']
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'utf8' do
|
20
|
-
it "handles incoming UTF8 as UTF8" do
|
21
|
-
string_array_column.type_cast('{"Аркалио"}').should eq ['Аркалио']
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'corner cases, strings with commas and quotations' do
|
26
|
-
it 'converts the PostgreSQL value containing escaped " to an array' do
|
27
|
-
string_array_column.type_cast('{"has \" quote",another value}').should eq ['has " quote', 'another value']
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'converts the PostgreSQL value containing commas to an array' do
|
31
|
-
string_array_column.type_cast('{"has , comma",another value,"more, commas"}').should eq ['has , comma', 'another value', 'more, commas']
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'converts strings containing , to the proper value' do
|
35
|
-
adapter.type_cast(['c,'], string_array_column).should eq '{"c,"}'
|
36
|
-
end
|
37
|
-
|
38
|
-
it "handles strings with double quotes" do
|
39
|
-
adapter.type_cast(['a"b'], string_array_column).should eq '{"a\\"b"}'
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'converts arrays of strings containing nil to the proper value' do
|
43
|
-
adapter.type_cast(['one', nil, 'two'], string_array_column).should eq '{"one",NULL,"two"}'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'text array' do
|
50
|
-
describe '#type_cast' do
|
51
|
-
context 'has null value' do
|
52
|
-
it 'converts the PostgreSQL value to an array with a nil value' do
|
53
|
-
text_array_column.type_cast('{1,NULL,"NULL"}').should eq ['1',nil,'NULL']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'utf8' do
|
58
|
-
it "handles incoming UTF8 as UTF8" do
|
59
|
-
text_array_column.type_cast('{"Аркалио"}').should eq ['Аркалио']
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'corner cases, strings with commas and quotations' do
|
64
|
-
it 'converts one element, 2 dimensional arrays' do
|
65
|
-
adapter.type_cast([['one','two']], text_array_column).should eq '{{"one","two"}}'
|
66
|
-
end
|
67
|
-
it 'converts the PostgreSQL value containing escaped " to an array' do
|
68
|
-
text_array_column.type_cast('{"has \" quote",another value}').should eq ['has " quote', 'another value']
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'converts the PostgreSQL value containing commas to an array' do
|
72
|
-
text_array_column.type_cast('{"has , comma",another value,"more, commas"}').should eq ['has , comma', 'another value', 'more, commas']
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'converts strings containing , to the proper value' do
|
76
|
-
adapter.type_cast(['c,'], text_array_column).should eq '{"c,"}'
|
77
|
-
end
|
78
|
-
|
79
|
-
it "handles strings with double quotes" do
|
80
|
-
adapter.type_cast(['a"b'], text_array_column).should eq '{"a\\"b"}'
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'converts arrays of strings containing nil to the proper value' do
|
84
|
-
adapter.type_cast(['one', nil, 'two'], text_array_column).should eq '{"one",NULL,"two"}'
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'integer array' do
|
91
|
-
describe '#type_cast' do
|
92
|
-
context 'has null value' do
|
93
|
-
it 'converts a Postgres Array with nulls in it' do
|
94
|
-
integer_array_column.type_cast('{1,NULL,2}').should eq [1,nil,2]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
context 'one dimensional array' do
|
98
|
-
it 'converts a PostgreSQL array value to an array of integers' do
|
99
|
-
integer_array_column.type_cast('{1,2,3,4}').should eq [1,2,3,4]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe 'integer array to SQL statment conversion' do
|
105
|
-
context 'contains a nil value' do
|
106
|
-
it 'returns a PostgreSQL array' do
|
107
|
-
value = integer_array_column.type_cast('{1,NULL,2}')
|
108
|
-
adapter.type_cast(value, integer_array_column).should eq '{1,NULL,2}'
|
109
|
-
end
|
110
|
-
end
|
111
|
-
context 'one dimensional array' do
|
112
|
-
it 'returns a PostgreSQL array' do
|
113
|
-
value = integer_array_column.type_cast('{1,2,3,4}')
|
114
|
-
adapter.type_cast(value, integer_array_column).should eq '{1,2,3,4}'
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
data/spec/columns/inet_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'INET column' do
|
4
|
-
let!(:column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'inet'}
|
5
|
-
let!(:adapter) { ActiveRecord::Base.connection }
|
6
|
-
|
7
|
-
describe '#type_class_code' do
|
8
|
-
it 'returns code for converting strings to IPAddr' do
|
9
|
-
column.type_cast_code('v').should eq 'ActiveRecord::ConnectionAdapters::PostgreSQLColumn.string_to_cidr_address(v)'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'inet type casting' do
|
14
|
-
it 'converts ip strings to NetAddr::CIDR objects' do
|
15
|
-
column.type_cast('127.0.0.1').should be_a_kind_of IPAddr
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'inet value conversion for SQL statments' do
|
20
|
-
it 'returns the string value of the IPAddr address' do
|
21
|
-
value = column.type_cast('127.0.0.1')
|
22
|
-
adapter.type_cast(value, column).should eq '127.0.0.1/32'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'daterange column' do
|
4
|
-
let!(:adapter) { ActiveRecord::Base.connection }
|
5
|
-
let!(:date_range_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'daterange'}
|
6
|
-
|
7
|
-
describe '#type_class' do
|
8
|
-
it 'converts an end-inclusive PostgreSQL integer range to a Ruby range' do
|
9
|
-
date_range_column.type_cast('[2011-01-01,2012-01-31]').should eq Date.new(2011,01,01)..Date.new(2012,01,31)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'converts an end-exclusive PostgreSQL integer range to a Ruby range' do
|
13
|
-
date_range_column.type_cast('[2011-01-01,2012-01-31)').should eq Date.new(2011,01,01)...Date.new(2012,01,31)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
17
|
-
# Cannot have a range from -Infinity to a date
|
18
|
-
# date_range_column.type_cast('(,2011-01-01)').should eq -(1.0/0.0)...4
|
19
|
-
date_range_column.type_cast('[2011-01-01,)').should eq Date.new(2011,01,01)..(1.0/0.0)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'date range to SQL statment conversion' do
|
24
|
-
it 'returns an end-inclusive PostgreSQL range' do
|
25
|
-
value = date_range_column.type_cast('[2011-01-01,2012-01-31]')
|
26
|
-
adapter.type_cast(value, date_range_column).should eq '[2011-01-01,2012-01-31]'
|
27
|
-
end
|
28
|
-
it 'returns an end-exclusive PostgreSQL range' do
|
29
|
-
value = date_range_column.type_cast('[2011-01-01,2012-01-31)')
|
30
|
-
adapter.type_cast(value, date_range_column).should eq '[2011-01-01,2012-01-31)'
|
31
|
-
end
|
32
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
33
|
-
value = date_range_column.type_cast('[2011-01-01,)')
|
34
|
-
adapter.type_cast(value, date_range_column).should eq '[2011-01-01,)'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'int4range column' do
|
4
|
-
let!(:adapter) { ActiveRecord::Base.connection }
|
5
|
-
let!(:int4_range_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'int4range'}
|
6
|
-
|
7
|
-
describe '#type_class' do
|
8
|
-
it 'converts an end-inclusive PostgreSQL integer range to a Ruby range' do
|
9
|
-
int4_range_column.type_cast('[0,4]').should eq 0..4
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'converts an end-exclusive PostgreSQL integer range to a Ruby range' do
|
13
|
-
int4_range_column.type_cast('[0,4)').should eq 0...4
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
17
|
-
int4_range_column.type_cast('(,4)').should eq -(1.0/0.0)...4
|
18
|
-
int4_range_column.type_cast('[0,)').should eq 0..(1.0/0.0)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'int4 range to SQL statment conversion' do
|
23
|
-
it 'returns an end-inclusive PostgreSQL range' do
|
24
|
-
value = int4_range_column.type_cast('[0,4]')
|
25
|
-
adapter.type_cast(value, int4_range_column).should eq '[0,4]'
|
26
|
-
end
|
27
|
-
it 'returns an end-exclusive PostgreSQL range' do
|
28
|
-
value = int4_range_column.type_cast('[0,4)')
|
29
|
-
adapter.type_cast(value, int4_range_column).should eq '[0,4)'
|
30
|
-
end
|
31
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
32
|
-
value = int4_range_column.type_cast('(,4)')
|
33
|
-
adapter.type_cast(value, int4_range_column).should eq '(,4)'
|
34
|
-
value = int4_range_column.type_cast('[0,)')
|
35
|
-
adapter.type_cast(value, int4_range_column).should eq '[0,)'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'int8range column' do
|
4
|
-
let!(:adapter) { ActiveRecord::Base.connection }
|
5
|
-
let!(:int8_range_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'int8range'}
|
6
|
-
|
7
|
-
describe '#type_class' do
|
8
|
-
it 'converts an end-inclusive PostgreSQL integer range to a Ruby range' do
|
9
|
-
int8_range_column.type_cast('[0,4]').should eq 0..4
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'converts an end-exclusive PostgreSQL integer range to a Ruby range' do
|
13
|
-
int8_range_column.type_cast('[0,4)').should eq 0...4
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
17
|
-
int8_range_column.type_cast('(,4)').should eq -(1.0/0.0)...4
|
18
|
-
int8_range_column.type_cast('[0,)').should eq 0..(1.0/0.0)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'int8 range to SQL statment conversion' do
|
23
|
-
it 'returns an end-inclusive PostgreSQL range' do
|
24
|
-
value = int8_range_column.type_cast('[0,4]')
|
25
|
-
adapter.type_cast(value, int8_range_column).should eq '[0,4]'
|
26
|
-
end
|
27
|
-
it 'returns an end-exclusive PostgreSQL range' do
|
28
|
-
value = int8_range_column.type_cast('[0,4)')
|
29
|
-
adapter.type_cast(value, int8_range_column).should eq '[0,4)'
|
30
|
-
end
|
31
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
32
|
-
value = int8_range_column.type_cast('(,4)')
|
33
|
-
adapter.type_cast(value, int8_range_column).should eq '(,4)'
|
34
|
-
value = int8_range_column.type_cast('[0,)')
|
35
|
-
adapter.type_cast(value, int8_range_column).should eq '[0,)'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'numrange column' do
|
4
|
-
let!(:adapter) { ActiveRecord::Base.connection }
|
5
|
-
let!(:numeric_range_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'numrange'}
|
6
|
-
describe '#type_class' do
|
7
|
-
it 'converts an end-inclusive PostgreSQL integer range to a Ruby range' do
|
8
|
-
numeric_range_column.type_cast('[0,4.1]').should eq 0.0..4.1
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'converts an end-exclusive PostgreSQL integer range to a Ruby range' do
|
12
|
-
numeric_range_column.type_cast('[0,4)').should eq 0.0...4.0
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
16
|
-
numeric_range_column.type_cast('(,4)').should eq -(1.0/0.0)...4.0
|
17
|
-
numeric_range_column.type_cast('[0,)').should eq 0.0..(1.0/0.0)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'Numeric range to SQL statment conversion' do
|
22
|
-
it 'returns an end-inclusive PostgreSQL range' do
|
23
|
-
value = numeric_range_column.type_cast('[0,4.0]')
|
24
|
-
adapter.type_cast(value, numeric_range_column).should eq '[0.0,4.0]'
|
25
|
-
end
|
26
|
-
it 'returns an end-exclusive PostgreSQL range' do
|
27
|
-
value = numeric_range_column.type_cast('[0,4.0)')
|
28
|
-
adapter.type_cast(value, numeric_range_column).should eq '[0.0,4.0)'
|
29
|
-
end
|
30
|
-
it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
31
|
-
value = numeric_range_column.type_cast('(,4.0)')
|
32
|
-
adapter.type_cast(value, numeric_range_column).should eq '(,4.0)'
|
33
|
-
value = numeric_range_column.type_cast('[0,)')
|
34
|
-
adapter.type_cast(value, numeric_range_column).should eq '[0.0,)'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'tsrange column' do
|
4
|
-
let!(:adapter) { ActiveRecord::Base.connection }
|
5
|
-
let!(:ts_range_column) { ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new 'field', nil, 'tsrange'}
|
6
|
-
|
7
|
-
describe '#type_class' do
|
8
|
-
it 'converts an end-inclusive PostgreSQL integer range to a Ruby range' do
|
9
|
-
ts_range_column.type_cast('[2011-01-01 12:34:00,2012-01-31 08:00:01]').should eq Time.new(2011, 01, 01, 12, 34)..Time.new(2012, 01, 31, 8, 0, 1)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'converts an end-exclusive PostgreSQL integer range to a Ruby range' do
|
13
|
-
ts_range_column.type_cast('[2011-01-01 12:34:00,2012-01-31 08:00:01)').should eq Time.new(2011, 01, 01, 12, 34)...Time.new(2012, 01, 31, 8, 0, 1)
|
14
|
-
end
|
15
|
-
|
16
|
-
#it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
17
|
-
## Cannot have a range from -Infinity to a ts
|
18
|
-
## ts_range_column.type_cast('(,2011-01-01)').should eq -(1.0/0.0)...4
|
19
|
-
#ts_range_column.type_cast('[2011-01-01 12:34:00,)').should eq Time.new(2011,01,01, 12, 34)..(1.0/0.0)
|
20
|
-
#end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'Time range to SQL statment conversion' do
|
24
|
-
it 'returns an end-inclusive PostgreSQL range' do
|
25
|
-
value = ts_range_column.type_cast('[2011-01-01 12:34:00,2012-01-31 08:00:01]')
|
26
|
-
adapter.type_cast(value, ts_range_column).should eq '[2011-01-01 12:34:00,2012-01-31 08:00:01]'
|
27
|
-
end
|
28
|
-
it 'returns an end-exclusive PostgreSQL range' do
|
29
|
-
value = ts_range_column.type_cast('[2011-01-01 12:34:00,2012-01-31 08:00:01)')
|
30
|
-
adapter.type_cast(value, ts_range_column).should eq '[2011-01-01 12:34:00,2012-01-31 08:00:01)'
|
31
|
-
end
|
32
|
-
#it 'converts an infinite PostgreSQL integer range to a Ruby range' do
|
33
|
-
#value = ts_range_column.type_cast('[2011-01-01 12:34:00,)')
|
34
|
-
#adapter.type_cast(value, ts_range_column).should eq '[2011-01-01 12:34:00,)'
|
35
|
-
#end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'ActiveRecord Migrations' do
|
4
|
-
let!(:connection) { ActiveRecord::Base.connection }
|
5
|
-
after { connection.drop_table :generic_data_types }
|
6
|
-
it 'creates non-postgres_ext columns' do
|
7
|
-
lambda do
|
8
|
-
connection.create_table :generic_data_types do |t|
|
9
|
-
t.integer :col_1
|
10
|
-
t.string :col_2
|
11
|
-
t.datetime :col_3
|
12
|
-
end
|
13
|
-
connection.add_column :generic_data_types, :col_4, :text
|
14
|
-
end.should_not raise_exception
|
15
|
-
|
16
|
-
columns = connection.columns(:generic_data_types)
|
17
|
-
col_1 = columns.detect { |c| c.name == 'col_1'}
|
18
|
-
col_2 = columns.detect { |c| c.name == 'col_2'}
|
19
|
-
col_3 = columns.detect { |c| c.name == 'col_3'}
|
20
|
-
col_4 = columns.detect { |c| c.name == 'col_4'}
|
21
|
-
|
22
|
-
|
23
|
-
col_1.sql_type.should eq 'integer'
|
24
|
-
col_2.sql_type.should eq 'character varying(255)'
|
25
|
-
col_3.sql_type.should eq 'timestamp without time zone'
|
26
|
-
col_4.sql_type.should eq 'text'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|