postgres_ext 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +6 -47
  4. data/lib/postgres_ext/active_record/relation/predicate_builder.rb +36 -55
  5. data/lib/postgres_ext/active_record/relation/query_methods.rb +0 -14
  6. data/lib/postgres_ext/active_record.rb +0 -3
  7. data/lib/postgres_ext/version.rb +1 -1
  8. data/postgres_ext.gemspec +6 -5
  9. data/spec/arel/arel_spec.rb +0 -1
  10. data/spec/dummy/app/models/person.rb +0 -1
  11. data/spec/dummy/config/application.rb +0 -3
  12. data/spec/dummy/config/environments/development.rb +2 -7
  13. data/spec/dummy/config/environments/production.rb +1 -0
  14. data/spec/dummy/config/environments/test.rb +1 -5
  15. data/spec/dummy/db/migrate/20120501163758_create_people.rb +3 -3
  16. data/spec/dummy/db/schema.rb +15 -12
  17. data/spec/queries/sanity_spec.rb +1 -1
  18. data/spec/spec_helper.rb +1 -2
  19. metadata +21 -105
  20. data/docs/indexes.md +0 -28
  21. data/docs/migrations.md +0 -92
  22. data/docs/type_casting.md +0 -70
  23. data/lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb +0 -537
  24. data/lib/postgres_ext/active_record/connection_adapters.rb +0 -1
  25. data/lib/postgres_ext/active_record/sanitization.rb +0 -30
  26. data/lib/postgres_ext/active_record/schema_dumper.rb +0 -157
  27. data/spec/columns/array_spec.rb +0 -119
  28. data/spec/columns/inet_spec.rb +0 -25
  29. data/spec/columns/ranges/daterange_spec.rb +0 -37
  30. data/spec/columns/ranges/int4range_spec.rb +0 -38
  31. data/spec/columns/ranges/int8range_spec.rb +0 -38
  32. data/spec/columns/ranges/numrange_spec.rb +0 -37
  33. data/spec/columns/ranges/tsrange_spec.rb +0 -37
  34. data/spec/migrations/active_record_migration_spec.rb +0 -29
  35. data/spec/migrations/array_spec.rb +0 -214
  36. data/spec/migrations/cidr_spec.rb +0 -26
  37. data/spec/migrations/citext_spec.rb +0 -32
  38. data/spec/migrations/ean13_spec.rb +0 -27
  39. data/spec/migrations/index_spec.rb +0 -67
  40. data/spec/migrations/inet_spec.rb +0 -26
  41. data/spec/migrations/macaddr_spec.rb +0 -26
  42. data/spec/migrations/ranges/daterange_spec.rb +0 -27
  43. data/spec/migrations/ranges/int4range_spec.rb +0 -27
  44. data/spec/migrations/ranges/int8range_spec.rb +0 -27
  45. data/spec/migrations/ranges/numrange_spec.rb +0 -27
  46. data/spec/migrations/ranges/tsrange_spec.rb +0 -27
  47. data/spec/migrations/ranges/tstzrange_spec.rb +0 -27
  48. data/spec/migrations/uuid_spec.rb +0 -26
  49. data/spec/models/array_spec.rb +0 -285
  50. data/spec/models/ean13_spec.rb +0 -57
  51. data/spec/models/inet_spec.rb +0 -88
  52. data/spec/models/ranges/daterange_spec.rb +0 -88
  53. data/spec/models/ranges/int4range_spec.rb +0 -85
  54. data/spec/models/ranges/int8range_spec.rb +0 -85
  55. data/spec/models/ranges/numrange_spec.rb +0 -85
  56. data/spec/models/ranges/tsrange_spec.rb +0 -89
  57. data/spec/models/ranges/tstzrange_spec.rb +0 -89
  58. data/spec/schema_dumper/array_spec.rb +0 -17
  59. data/spec/schema_dumper/cidr_spec.rb +0 -17
  60. data/spec/schema_dumper/citext_spec.rb +0 -17
  61. data/spec/schema_dumper/ean13_spec.rb +0 -17
  62. data/spec/schema_dumper/extension_spec.rb +0 -14
  63. data/spec/schema_dumper/index_spec.rb +0 -46
  64. data/spec/schema_dumper/inet_spec.rb +0 -17
  65. data/spec/schema_dumper/macaddr_spec.rb +0 -17
  66. data/spec/schema_dumper/ranges/daterange_spec.rb +0 -18
  67. data/spec/schema_dumper/ranges/int4range_spec.rb +0 -18
  68. data/spec/schema_dumper/ranges/int8range_spec.rb +0 -18
  69. data/spec/schema_dumper/ranges/numrange_spec.rb +0 -18
  70. data/spec/schema_dumper/ranges/tsrange_spec.rb +0 -18
  71. data/spec/schema_dumper/ranges/tstzrange_spec.rb +0 -17
  72. data/spec/schema_dumper/uuid_spec.rb +0 -17
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Models with numeric range columns' do
4
- let!(:adapter) { ActiveRecord::Base.connection }
5
-
6
- context 'no default value, range' do
7
- before do
8
- adapter.create_table :rangers, :force => true do |t|
9
- t.numrange :best_estimate
10
- end
11
- class Ranger < ActiveRecord::Base
12
- attr_accessible :best_estimate
13
- end
14
- end
15
-
16
- after do
17
- adapter.drop_table :rangers
18
- Object.send(:remove_const, :Ranger)
19
- end
20
-
21
- describe '#create' do
22
- it 'creates an record when there is no assignment' do
23
- range = Ranger.create()
24
- range.reload
25
- range.best_estimate.should eq nil
26
- end
27
-
28
- it 'creates an record with a range' do
29
- range = Ranger.create( :best_estimate => 0..4)
30
- range.reload
31
- range.best_estimate.should eq 0..4
32
- end
33
- end
34
-
35
- describe 'range assignment' do
36
- it 'updates an record with an range string' do
37
- range = Ranger.create( :best_estimate => 0..4)
38
- range.best_estimate = 0...9
39
- range.save
40
-
41
- range.reload
42
- range.best_estimate.should eq 0...9
43
- end
44
-
45
- it 'converts empty strings to nil' do
46
- range = Ranger.create
47
- range.best_estimate = ''
48
- range.save
49
-
50
- range.reload
51
- range.best_estimate.should eq nil
52
- end
53
- end
54
- end
55
-
56
- context 'default value, numeric range' do
57
- before do
58
- adapter.create_table :default_rangers, :force => true do |t|
59
- t.numrange :best_estimate, :default => 0..5
60
- end
61
- class DefaultRanger < ActiveRecord::Base
62
- attr_accessible :best_estimate
63
- end
64
- end
65
-
66
- after do
67
- adapter.drop_table :default_rangers
68
- Object.send(:remove_const, :DefaultRanger)
69
- end
70
-
71
- describe '#create' do
72
- it 'creates an record when there is no assignment' do
73
- range = DefaultRanger.create()
74
- range.reload
75
- range.best_estimate.should eq 0..5
76
- end
77
-
78
- it 'creates an record with a range' do
79
- range = DefaultRanger.create( :best_estimate => 0..4)
80
- range.reload
81
- range.best_estimate.should eq 0..4
82
- end
83
- end
84
- end
85
- end
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Models with tsrange columns' do
4
- let!(:adapter) { ActiveRecord::Base.connection }
5
-
6
- context 'no default value, range' do
7
- before do
8
- adapter.create_table :ts_rangers, :force => true do |t|
9
- t.tsrange :best_estimate
10
- end
11
- class TsRanger < ActiveRecord::Base
12
- attr_accessible :best_estimate
13
- end
14
- end
15
-
16
- after do
17
- adapter.drop_table :ts_rangers
18
- Object.send(:remove_const, :TsRanger)
19
- end
20
-
21
- describe '#create' do
22
- it 'creates an record when there is no assignment' do
23
- range = TsRanger.create()
24
- range.reload
25
- range.best_estimate.should eq nil
26
- end
27
-
28
- it 'creates an record with a range' do
29
- ts_range = Time.new(2011, 01, 01, 12, 34)..Time.new(2012, 01, 31, 8, 0, 1)
30
- range = TsRanger.create( :best_estimate => ts_range)
31
- range.reload
32
- range.best_estimate.should eq ts_range
33
- end
34
- end
35
-
36
- describe 'range assignment' do
37
- it 'updates an record with an range string' do
38
- ts_range = Time.new(2011, 01, 01, 12, 34)..Time.new(2012, 01, 31, 8, 0, 1)
39
- new_ts_range = Time.new(2012, 01, 01, 11, 0, 0)..Time.new(2012, 02, 01, 13, 0, 0)
40
- range = TsRanger.create( :best_estimate => ts_range)
41
- range.best_estimate = new_ts_range
42
- range.save
43
-
44
- range.reload
45
- range.best_estimate.should eq new_ts_range
46
- end
47
-
48
- it 'converdate empty strings to nil' do
49
- range = TsRanger.create
50
- range.best_estimate = ''
51
- range.save
52
-
53
- range.reload
54
- range.best_estimate.should eq nil
55
- end
56
- end
57
- end
58
-
59
- context 'default value, ts range' do
60
- before do
61
- adapter.create_table :ts_default_rangers, :force => true do |t|
62
- t.tsrange :best_estimate, :default => Time.new(2011, 01, 01, 12, 34)..Time.new(2011, 01, 31, 1, 0)
63
- end
64
- class TsDefaultRanger < ActiveRecord::Base
65
- attr_accessible :best_estimate
66
- end
67
- end
68
-
69
- after do
70
- adapter.drop_table :ts_default_rangers
71
- Object.send(:remove_const, :TsDefaultRanger)
72
- end
73
-
74
- describe '#create' do
75
- it 'creates an record when there is no assignment' do
76
- range = TsDefaultRanger.create()
77
- range.reload
78
- range.best_estimate.should eq Time.new(2011, 01, 01, 12, 34)..Time.new(2011, 01, 31, 1, 0)
79
- end
80
-
81
- it 'creates an record with a range' do
82
- new_ts_range = Time.new(2012, 01, 01, 9, 0, 0)..Time.new(2012, 12, 31, 9, 0, 0)
83
- range = TsDefaultRanger.create(:best_estimate => new_ts_range)
84
- range.reload
85
- range.best_estimate.should eq new_ts_range
86
- end
87
- end
88
- end
89
- end
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Models with tstzrange columns' do
4
- let!(:adapter) { ActiveRecord::Base.connection }
5
-
6
- context 'no default value, range' do
7
- before do
8
- adapter.create_table :tstz_rangers, :force => true do |t|
9
- t.tstzrange :best_estimate
10
- end
11
- class TstzRanger < ActiveRecord::Base
12
- attr_accessible :best_estimate
13
- end
14
- end
15
-
16
- after do
17
- adapter.drop_table :tstz_rangers
18
- Object.send(:remove_const, :TstzRanger)
19
- end
20
-
21
- describe '#create' do
22
- it 'creates an record when there is no assignment' do
23
- range = TstzRanger.create()
24
- range.reload
25
- range.best_estimate.should eq nil
26
- end
27
-
28
- it 'creates an record with a range' do
29
- ts_range = Time.new(2011, 01, 01, 12, 34)..Time.new(2012, 01, 31, 8, 0, 1)
30
- range = TstzRanger.create( :best_estimate => ts_range)
31
- range.reload
32
- range.best_estimate.should eq ts_range
33
- end
34
- end
35
-
36
- describe 'range assignment' do
37
- it 'updates an record with an range string' do
38
- ts_range = Time.new(2011, 01, 01, 12, 34)..Time.new(2012, 01, 31, 8, 0, 1)
39
- new_ts_range = Time.new(2012, 01, 01, 11, 0, 0)..Time.new(2012, 02, 01, 13, 0, 0)
40
- range = TstzRanger.create( :best_estimate => ts_range)
41
- range.best_estimate = new_ts_range
42
- range.save
43
-
44
- range.reload
45
- range.best_estimate.should eq new_ts_range
46
- end
47
-
48
- it 'converdate empty strings to nil' do
49
- range = TstzRanger.create
50
- range.best_estimate = ''
51
- range.save
52
-
53
- range.reload
54
- range.best_estimate.should eq nil
55
- end
56
- end
57
- end
58
-
59
- context 'default value, ts range' do
60
- before do
61
- adapter.create_table :tstz_default_rangers, :force => true do |t|
62
- t.tstzrange :best_estimate, :default => Time.new(2011, 01, 01, 12, 34, 0, '-07:00')..Time.new(2011, 01, 31, 1, 0, 0, '-07:00')
63
- end
64
- class TstzDefaultRanger < ActiveRecord::Base
65
- attr_accessible :best_estimate
66
- end
67
- end
68
-
69
- after do
70
- adapter.drop_table :tstz_default_rangers
71
- Object.send(:remove_const, :TstzDefaultRanger)
72
- end
73
-
74
- describe '#create' do
75
- it 'creates an record when there is no assignment' do
76
- range = TstzDefaultRanger.create()
77
- range.reload
78
- range.best_estimate.should eq Time.new(2011, 01, 01, 12, 34,0, '-07:00')..Time.new(2011, 01, 31, 1, 0, 0, '-07:00')
79
- end
80
-
81
- it 'creates an record with a range' do
82
- new_ts_range = Time.new(2012, 01, 01, 9, 0, 0, '-05:00')..Time.new(2012, 12, 31, 9, 0, 0, '-05:00')
83
- range = TstzDefaultRanger.create(:best_estimate => new_ts_range)
84
- range.reload
85
- range.best_estimate.should eq new_ts_range
86
- end
87
- end
88
- end
89
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'array schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates cidr array column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.cidr :network_column, :array => true
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.cidr "network_column".*?:array => true/
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'CIDR schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates cidr column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.cidr :network_column
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.cidr/
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'CITEXT schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates citext column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.citext :citext_column
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.citext/
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'ean13 schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates ean13 column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.ean13 :ean13_column
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.ean13/
16
- end
17
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'extension schema dump', :if => ActiveRecord::Base.connection.supports_extensions? do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- it 'correctly creates and exports database extensions' do
6
- stream = StringIO.new
7
- connection.add_extension 'hstore'
8
-
9
- ActiveRecord::SchemaDumper.dump(connection, stream)
10
- output = stream.string
11
-
12
- output.should match /add_extension "hstore"/
13
- end
14
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Index schema dumper' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
-
6
- after do
7
- [:tag_ids, :lucky_number, :biography].each do |column|
8
- begin
9
- connection.remove_index :people, column
10
- rescue ArgumentError
11
- end
12
- end
13
- end
14
-
15
- it 'handles index type parameters' do
16
- connection.add_index(:people, :tag_ids, :using => :gin)
17
-
18
- stream = StringIO.new
19
- ActiveRecord::SchemaDumper.dump(connection, stream)
20
- output = stream.string
21
-
22
- output.should match /:using => :gin/
23
- output.should_not match /:using => :btree/
24
- output.should_not match /:index_opclass =>/
25
- end
26
-
27
- it 'handles index where clauses' do
28
- connection.add_index(:people, :lucky_number, :where => '(lucky_number > 50)')
29
-
30
- stream = StringIO.new
31
- ActiveRecord::SchemaDumper.dump(connection, stream)
32
- output = stream.string
33
-
34
- output.should match /:where => "\(lucky_number > 50\)"/
35
- end
36
-
37
- it 'dumps index operator classes', :if => ActiveRecord::Base.connection.supports_extensions? do
38
- connection.add_index(:people, :biography, :using => :gin, :index_opclass => :gin_trgm_ops)
39
-
40
- stream = StringIO.new
41
- ActiveRecord::SchemaDumper.dump(connection, stream)
42
- output = stream.string
43
-
44
- output.should match /:using => :gin,\s+:index_opclass => :gin_trgm_ops/
45
- end
46
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'INET schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates inet column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.inet :ip_column
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.inet/
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'MACADDR schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates macaddr column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.macaddr :mac_address_column
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.macaddr/
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'daterange schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
-
7
- it 'correctly generates daterange column statements' do
8
- stream = StringIO.new
9
- connection.create_table :testings do |t|
10
- t.daterange :range
11
- end
12
-
13
- ActiveRecord::SchemaDumper.dump(connection, stream)
14
- output = stream.string
15
-
16
- output.should match /t\.daterange "range"/
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'intrange schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
-
7
- it 'correctly generates int4range column statements' do
8
- stream = StringIO.new
9
- connection.create_table :testings do |t|
10
- t.int4range :range
11
- end
12
-
13
- ActiveRecord::SchemaDumper.dump(connection, stream)
14
- output = stream.string
15
-
16
- output.should match /t\.int4range "range"/
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'int8range schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
-
7
- it 'correctly generates int8range column statements' do
8
- stream = StringIO.new
9
- connection.create_table :testings do |t|
10
- t.int8range :range
11
- end
12
-
13
- ActiveRecord::SchemaDumper.dump(connection, stream)
14
- output = stream.string
15
-
16
- output.should match /t\.int8range "range"/
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'numrange schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
-
7
- it 'correctly generates numrange column statements' do
8
- stream = StringIO.new
9
- connection.create_table :testings do |t|
10
- t.numrange :range
11
- end
12
-
13
- ActiveRecord::SchemaDumper.dump(connection, stream)
14
- output = stream.string
15
-
16
- output.should match /t\.numrange "range"/
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'tsrange schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
-
7
- it 'correctly generates tsrange column statements' do
8
- stream = StringIO.new
9
- connection.create_table :testings do |t|
10
- t.tsrange :range
11
- end
12
-
13
- ActiveRecord::SchemaDumper.dump(connection, stream)
14
- output = stream.string
15
-
16
- output.should match /t\.tsrange "range"/
17
- end
18
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'tstzrange schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates tstzrange column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.tstzrange :range
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.tstzrange "range"/
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'UUID schema dump' do
4
- let!(:connection) { ActiveRecord::Base.connection }
5
- after { connection.drop_table :testings }
6
- it 'correctly generates uuid column statements' do
7
- stream = StringIO.new
8
- connection.create_table :testings do |t|
9
- t.uuid :uuid_column
10
- end
11
-
12
- ActiveRecord::SchemaDumper.dump(connection, stream)
13
- output = stream.string
14
-
15
- output.should match /t\.uuid/
16
- end
17
- end