postgres_ext 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.1
2
+
3
+ * Fixes issue with array -> string code - Dan McClain
4
+ * Adds support for ISN types - Ezekiel Templin
5
+ * Fix for Squeel compatibility - Alexander Borovsky
6
+
1
7
  ## 0.3.0
2
8
 
3
9
  * Adds support to create indexes concurrently - Dan McClain
@@ -119,6 +119,8 @@ module ActiveRecord
119
119
  :cidr
120
120
  when 'macaddr'
121
121
  :macaddr
122
+ when 'ean13'
123
+ :ean13
122
124
  else
123
125
  simplified_type_without_extended_types field_type
124
126
  end
@@ -131,7 +133,7 @@ module ActiveRecord
131
133
  class UnsupportedFeature < Exception; end
132
134
 
133
135
  EXTENDED_TYPES = { :inet => {:name => 'inet'}, :cidr => {:name => 'cidr'}, :macaddr => {:name => 'macaddr'},
134
- :uuid => {:name => 'uuid'}, :citext => {:name => 'citext'} }
136
+ :uuid => {:name => 'uuid'}, :citext => {:name => 'citext'}, :ean13 => {:name => 'ean13'} }
135
137
 
136
138
  class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
137
139
  attr_accessor :array
@@ -383,7 +385,7 @@ module ActiveRecord
383
385
 
384
386
  casted_value = type_cast_extended(value, column, true)
385
387
 
386
- if casted_value.is_a? String
388
+ if casted_value.is_a?(String) && value.is_a?(String)
387
389
  casted_value = casted_value.dup
388
390
  # Encode backslashes. One backslash becomes 4 in the resulting SQL.
389
391
  # (why 4, and not 2? Trial and error shows 4 works, 2 fails to parse.)
@@ -71,11 +71,11 @@ module ActiveRecord
71
71
  end
72
72
  end
73
73
 
74
- def where_with_chaining(opts = :chaining, *rest)
75
- if opts == :chaining
74
+ def where_with_chaining(*opts, &block)
75
+ if opts.empty? && !block_given?
76
76
  WhereChain.new(self)
77
77
  else
78
- where_without_chaining(opts, *rest)
78
+ where_without_chaining(*opts, &block)
79
79
  end
80
80
  end
81
81
 
@@ -1,3 +1,3 @@
1
1
  module PostgresExt
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -61,6 +61,9 @@ describe 'Array column' do
61
61
  end
62
62
 
63
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
64
67
  it 'converts the PostgreSQL value containing escaped " to an array' do
65
68
  text_array_column.type_cast('{"has \" quote",another value}').should eq ['has " quote', 'another value']
66
69
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ean13 migrations' do
4
+ let!(:connection) { ActiveRecord::Base.connection }
5
+ before(:all) { ActiveRecord::Base.connection.add_extension('isn') if ActiveRecord::Base.connection.supports_extensions? }
6
+ after { connection.drop_table :data_types }
7
+ it 'creates an ean13 column' do
8
+ lambda do
9
+ connection.create_table :data_types do |t|
10
+ t.ean13 :ean13_1
11
+ t.ean13 :ean13_2, :ean13_3
12
+ t.column :ean13_4, :ean13
13
+ end
14
+ end.should_not raise_exception
15
+
16
+ columns = connection.columns(:data_types)
17
+ ean13_1 = columns.detect { |c| c.name == 'ean13_1'}
18
+ ean13_2 = columns.detect { |c| c.name == 'ean13_2'}
19
+ ean13_3 = columns.detect { |c| c.name == 'ean13_3'}
20
+ ean13_4 = columns.detect { |c| c.name == 'ean13_4'}
21
+
22
+ ean13_1.sql_type.should eq 'ean13'
23
+ ean13_2.sql_type.should eq 'ean13'
24
+ ean13_3.sql_type.should eq 'ean13'
25
+ ean13_4.sql_type.should eq 'ean13'
26
+ end
27
+ end
@@ -57,17 +57,26 @@ describe 'Models with array columns' do
57
57
  end
58
58
 
59
59
  context 'Setting values' do
60
- describe 'setting a new value' do
61
- it 'returns the value set when the record is retrieved' do
62
- u = User.create(:nick_names => ['some', 'things'])
63
- u.reload
60
+ it 'returns the value set when the record is retrieved' do
61
+ u = User.create(:nick_names => ['some', 'things'])
62
+ u.reload
64
63
 
65
- u.nick_names = ['different', 'values']
66
- u.save
64
+ u.nick_names = ['different', 'values']
65
+ u.save
67
66
 
68
- u.reload
69
- u.nick_names.should eq ['different', 'values']
70
- end
67
+ u.reload
68
+ u.nick_names.should eq ['different', 'values']
69
+ end
70
+
71
+ it 'creates a user with an int array of some values' do
72
+ u = User.create(:favorite_numbers => [2,3,5])
73
+ u.reload
74
+
75
+ u.favorite_numbers = [1,2,3]
76
+ u.save
77
+
78
+ u.reload
79
+ u.favorite_numbers.should eq [1,2,3]
71
80
  end
72
81
  end
73
82
 
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Models with ean13 columns' do
4
+ let!(:adapter) { ActiveRecord::Base.connection }
5
+
6
+ context 'no default value, ean' do
7
+ before do
8
+ adapter.create_table :books, :force => true do |t|
9
+ t.ean13 :ean
10
+ end
11
+
12
+ class Book < ActiveRecord::Base
13
+ attr_accessible :ean
14
+ end
15
+ end
16
+
17
+ after do
18
+ adapter.drop_table :books
19
+ Object.send(:remove_const, :Book)
20
+ end
21
+
22
+ context 'no default value, ean' do
23
+ describe '#create' do
24
+ it 'create a book when there is no ean assignment' do
25
+ book = Book.create()
26
+ book.reload
27
+ book.ean.should eq nil
28
+ end
29
+
30
+ it 'creates a book with an ean string' do
31
+ book = Book.create(:ean => '9780312174910')
32
+ book.reload
33
+ book.ean.should eq '978-0-312-17491-0'
34
+ end
35
+ end
36
+
37
+ describe 'ean assignment' do
38
+ it 'updates a book with an ean string' do
39
+ book = Book.create(:ean => '9783037781265')
40
+ book.ean = '9780312174910'
41
+ book.save
42
+
43
+ book.reload
44
+ book.ean.should eq '978-0-312-17491-0'
45
+ end
46
+ end
47
+
48
+ describe 'find_by_ean' do
49
+ let!(:ean) { Book.create(:ean => '9783037781265') }
50
+
51
+ it 'finds book using string value' do
52
+ Book.find_by_ean('9783037781265').should eq ean
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,17 @@
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
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Dan McClain
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-26 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activerecord
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: pg_array_parser
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rails
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ~>
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rspec-rails
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: bourne
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: pg
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ~>
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ~>
95
108
  - !ruby/object:Gem::Version
@@ -193,11 +206,13 @@ files:
193
206
  - spec/migrations/array_spec.rb
194
207
  - spec/migrations/cidr_spec.rb
195
208
  - spec/migrations/citext_spec.rb
209
+ - spec/migrations/ean13_spec.rb
196
210
  - spec/migrations/index_spec.rb
197
211
  - spec/migrations/inet_spec.rb
198
212
  - spec/migrations/macaddr_spec.rb
199
213
  - spec/migrations/uuid_spec.rb
200
214
  - spec/models/array_spec.rb
215
+ - spec/models/ean13_spec.rb
201
216
  - spec/models/inet_spec.rb
202
217
  - spec/queries/array_queries_spec.rb
203
218
  - spec/queries/contains_querie_spec.rb
@@ -205,6 +220,7 @@ files:
205
220
  - spec/schema_dumper/array_spec.rb
206
221
  - spec/schema_dumper/cidr_spec.rb
207
222
  - spec/schema_dumper/citext_spec.rb
223
+ - spec/schema_dumper/ean13_spec.rb
208
224
  - spec/schema_dumper/extension_spec.rb
209
225
  - spec/schema_dumper/index_spec.rb
210
226
  - spec/schema_dumper/inet_spec.rb
@@ -213,26 +229,33 @@ files:
213
229
  - spec/spec_helper.rb
214
230
  homepage: ''
215
231
  licenses: []
216
- metadata: {}
217
232
  post_install_message:
218
233
  rdoc_options: []
219
234
  require_paths:
220
235
  - lib
221
236
  required_ruby_version: !ruby/object:Gem::Requirement
237
+ none: false
222
238
  requirements:
223
- - - '>='
239
+ - - ! '>='
224
240
  - !ruby/object:Gem::Version
225
241
  version: '0'
242
+ segments:
243
+ - 0
244
+ hash: 3683941487581046941
226
245
  required_rubygems_version: !ruby/object:Gem::Requirement
246
+ none: false
227
247
  requirements:
228
- - - '>='
248
+ - - ! '>='
229
249
  - !ruby/object:Gem::Version
230
250
  version: '0'
251
+ segments:
252
+ - 0
253
+ hash: 3683941487581046941
231
254
  requirements: []
232
255
  rubyforge_project:
233
- rubygems_version: 2.0.3
256
+ rubygems_version: 1.8.23
234
257
  signing_key:
235
- specification_version: 4
258
+ specification_version: 3
236
259
  summary: Extends ActiveRecord to handle native PostgreSQL data types
237
260
  test_files:
238
261
  - spec/arel/arel_spec.rb
@@ -295,11 +318,13 @@ test_files:
295
318
  - spec/migrations/array_spec.rb
296
319
  - spec/migrations/cidr_spec.rb
297
320
  - spec/migrations/citext_spec.rb
321
+ - spec/migrations/ean13_spec.rb
298
322
  - spec/migrations/index_spec.rb
299
323
  - spec/migrations/inet_spec.rb
300
324
  - spec/migrations/macaddr_spec.rb
301
325
  - spec/migrations/uuid_spec.rb
302
326
  - spec/models/array_spec.rb
327
+ - spec/models/ean13_spec.rb
303
328
  - spec/models/inet_spec.rb
304
329
  - spec/queries/array_queries_spec.rb
305
330
  - spec/queries/contains_querie_spec.rb
@@ -307,6 +332,7 @@ test_files:
307
332
  - spec/schema_dumper/array_spec.rb
308
333
  - spec/schema_dumper/cidr_spec.rb
309
334
  - spec/schema_dumper/citext_spec.rb
335
+ - spec/schema_dumper/ean13_spec.rb
310
336
  - spec/schema_dumper/extension_spec.rb
311
337
  - spec/schema_dumper/index_spec.rb
312
338
  - spec/schema_dumper/inet_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 78f29ab859ad31017d1173ec07e12a0b5603b823
4
- data.tar.gz: 3ae3cbc58fc1cdf7018721d01078855cc4fcc089
5
- SHA512:
6
- metadata.gz: 995ffd20fefb645371140742c7742cee1ebb9bc1cdbc9bd9bd7f9b32fa8057ac83fc661daed70bffb311700cb9c5e1b87ad64102008509ddf93ec6a7e2f11d14
7
- data.tar.gz: ae873dde5e07a41dee3b5ccccbbdd6f06443f7a0ccb0e65ff3f2678a7a8fcb91d5323afb6bbcbf17be03a30dd9278ff6fee71b96b5e0bc7e863ef9274615d992