postgres_ext 0.0.7 → 0.0.8
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.
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +33 -0
- data/README.md +0 -7
- data/lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb +31 -1
- data/lib/postgres_ext/version.rb +1 -1
- data/postgres_ext.gemspec +4 -1
- data/spec/dummy/config/{database.yml → database.yml.example} +0 -0
- data/spec/migrations/array_spec.rb +22 -0
- data/spec/migrations/uuid_spec.rb +11 -11
- data/spec/models/array_spec.rb +33 -0
- data/spec/schema_dumper/uuid_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- metadata +7 -6
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Contribution Guidelines #
|
2
|
+
|
3
|
+
## Submitting a new issue ##
|
4
|
+
|
5
|
+
If you need to open a new issue you *must* provide the following:
|
6
|
+
|
7
|
+
1. Version of Rails
|
8
|
+
|
9
|
+
Failure to include the above mentioned requirements will result in the
|
10
|
+
issue being closed.
|
11
|
+
|
12
|
+
If you want to ensure that your issue gets fixed *fast* you should
|
13
|
+
attempt to reproduce the issue in an isolated example application that
|
14
|
+
you can share.
|
15
|
+
|
16
|
+
## Making a pull request ##
|
17
|
+
|
18
|
+
If you'd like to submit a pull request please adhere to the following:
|
19
|
+
|
20
|
+
1. Your code *must* be tested. Please TDD your code!
|
21
|
+
2. No single-character variables
|
22
|
+
3. Two-spaces instead of tabs
|
23
|
+
4. Single-quotes instead of double-quotes unless you are using string
|
24
|
+
interpolation or escapes.
|
25
|
+
5. General Rails/Ruby naming conventions for files and classes
|
26
|
+
6. *Do not* use Ruby 1.9 hash syntax
|
27
|
+
7. *Do not* use Ruby 1.9 stubby proc syntax
|
28
|
+
|
29
|
+
Plase note that you must adhere to each of the above mentioned rules.
|
30
|
+
Failure to do so will result in an immediate closing of the pull
|
31
|
+
request. If you update and rebase the pull request to follow the
|
32
|
+
guidelines your pull request will be re-opened and considered for
|
33
|
+
inclusion.
|
data/README.md
CHANGED
@@ -257,10 +257,3 @@ User.where(user_arel[:ip_address].contained_witin('127.0.0.1/24')).to_sql
|
|
257
257
|
|
258
258
|
Dan McClain [twitter](http://twitter.com/_danmcclain) [github](http://github.com/danmcclain)
|
259
259
|
|
260
|
-
## Contributing
|
261
|
-
|
262
|
-
1. Fork it
|
263
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
264
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
265
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
266
|
-
5. Create new Pull Request
|
@@ -145,7 +145,7 @@ module ActiveRecord
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
class Table
|
148
|
+
class Table < ActiveRecord::ConnectionAdapters::Table
|
149
149
|
EXTENDED_TYPES.keys.map(&:to_s).each do |column_type|
|
150
150
|
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
151
151
|
def #{column_type}(*args) # def string(*args)
|
@@ -179,6 +179,36 @@ module ActiveRecord
|
|
179
179
|
super
|
180
180
|
end
|
181
181
|
|
182
|
+
def change_table(table_name, options = {})
|
183
|
+
if supports_bulk_alter? && options[:bulk]
|
184
|
+
recorder = ActiveRecord::Migration::CommandRecorder.new(self)
|
185
|
+
yield Table.new(table_name, recorder)
|
186
|
+
bulk_change_table(table_name, recorder.commands)
|
187
|
+
else
|
188
|
+
yield Table.new(table_name, self)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
if RUBY_PLATFORM =~ /java/
|
193
|
+
# The activerecord-jbdc-adapter implements PostgreSQLAdapter#add_column differently from the active-record version
|
194
|
+
# so we have to patch that version in JRuby, but not in MRI/YARV
|
195
|
+
def add_column(table_name, column_name, type, options = {})
|
196
|
+
default = options[:default]
|
197
|
+
notnull = options[:null] == false
|
198
|
+
sql_type = type_to_sql(type, options[:limit], options[:precision], options[:scale])
|
199
|
+
|
200
|
+
if options[:array]
|
201
|
+
sql_type << '[]'
|
202
|
+
end
|
203
|
+
|
204
|
+
# Add the column.
|
205
|
+
execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{sql_type}")
|
206
|
+
|
207
|
+
change_column_default(table_name, column_name, default) if options_include_default?(options)
|
208
|
+
change_column_null(table_name, column_name, false, default) if notnull
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
182
212
|
def type_cast_with_extended_types(value, column, part_array = false)
|
183
213
|
case value
|
184
214
|
when NilClass
|
data/lib/postgres_ext/version.rb
CHANGED
data/postgres_ext.gemspec
CHANGED
@@ -26,6 +26,9 @@ Gem::Specification.new do |gem|
|
|
26
26
|
else
|
27
27
|
gem.add_development_dependency 'pg', '~> 0.13.2'
|
28
28
|
end
|
29
|
-
|
29
|
+
unless ENV['CI']
|
30
|
+
gem.add_development_dependency 'debugger', '~> 1.1.2' if RUBY_VERSION == '1.9.3'
|
31
|
+
gem.add_development_dependency 'ruby-debug' if RUBY_PLATFORM =~ /java/
|
32
|
+
end
|
30
33
|
gem.add_development_dependency 'fivemat'
|
31
34
|
end
|
File without changes
|
@@ -11,15 +11,37 @@ describe 'array migrations' do
|
|
11
11
|
end
|
12
12
|
end.should_not raise_exception
|
13
13
|
|
14
|
+
lambda do
|
15
|
+
connection.add_column :data_types, :cidr_5, :cidr, :array => true
|
16
|
+
end.should_not raise_exception
|
17
|
+
|
18
|
+
lambda do
|
19
|
+
connection.change_table :data_types do |t|
|
20
|
+
t.column :cidr_6, :cidr, :array => true
|
21
|
+
end
|
22
|
+
end.should_not raise_exception
|
23
|
+
|
24
|
+
lambda do
|
25
|
+
connection.change_table :data_types do |t|
|
26
|
+
t.cidr :cidr_7, :array => true
|
27
|
+
end
|
28
|
+
end.should_not raise_exception
|
29
|
+
|
14
30
|
columns = connection.columns(:data_types)
|
15
31
|
cidr_1 = columns.detect { |c| c.name == 'cidr_1'}
|
16
32
|
cidr_2 = columns.detect { |c| c.name == 'cidr_2'}
|
17
33
|
cidr_3 = columns.detect { |c| c.name == 'cidr_3'}
|
18
34
|
cidr_4 = columns.detect { |c| c.name == 'cidr_4'}
|
35
|
+
cidr_5 = columns.detect { |c| c.name == 'cidr_5'}
|
36
|
+
cidr_6 = columns.detect { |c| c.name == 'cidr_6'}
|
37
|
+
cidr_7 = columns.detect { |c| c.name == 'cidr_7'}
|
19
38
|
|
20
39
|
cidr_1.sql_type.should eq 'cidr[]'
|
21
40
|
cidr_2.sql_type.should eq 'cidr[]'
|
22
41
|
cidr_3.sql_type.should eq 'cidr[]'
|
23
42
|
cidr_4.sql_type.should eq 'cidr[]'
|
43
|
+
cidr_5.sql_type.should eq 'cidr[]'
|
44
|
+
cidr_6.sql_type.should eq 'cidr[]'
|
45
|
+
cidr_7.sql_type.should eq 'cidr[]'
|
24
46
|
end
|
25
47
|
end
|
@@ -5,21 +5,21 @@ describe 'UUID migrations' do
|
|
5
5
|
it 'creates an uuid column' do
|
6
6
|
lambda do
|
7
7
|
connection.create_table :data_types do |t|
|
8
|
-
t.uuid :
|
9
|
-
t.uuid :
|
10
|
-
t.column :
|
8
|
+
t.uuid :uuid_1
|
9
|
+
t.uuid :uuid_2, :uuid_3
|
10
|
+
t.column :uuid_4, :uuid
|
11
11
|
end
|
12
12
|
end.should_not raise_exception
|
13
13
|
|
14
14
|
columns = connection.columns(:data_types)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
uuid_1 = columns.detect { |c| c.name == 'uuid_1'}
|
16
|
+
uuid_2 = columns.detect { |c| c.name == 'uuid_2'}
|
17
|
+
uuid_3 = columns.detect { |c| c.name == 'uuid_3'}
|
18
|
+
uuid_4 = columns.detect { |c| c.name == 'uuid_4'}
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
uuid_1.sql_type.should eq 'uuid'
|
21
|
+
uuid_2.sql_type.should eq 'uuid'
|
22
|
+
uuid_3.sql_type.should eq 'uuid'
|
23
|
+
uuid_4.sql_type.should eq 'uuid'
|
24
24
|
end
|
25
25
|
end
|
data/spec/models/array_spec.rb
CHANGED
@@ -7,7 +7,10 @@ describe 'Models with array columns' do
|
|
7
7
|
before do
|
8
8
|
adapter.create_table :users, :force => true do |t|
|
9
9
|
t.string :nick_names, :array => true
|
10
|
+
|
11
|
+
t.timestamps
|
10
12
|
end
|
13
|
+
|
11
14
|
class User < ActiveRecord::Base
|
12
15
|
attr_accessible :nick_names
|
13
16
|
end
|
@@ -54,6 +57,36 @@ describe 'Models with array columns' do
|
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
60
|
+
|
61
|
+
context '#update_attribute' do
|
62
|
+
describe 'setting a value via update_attribute' do
|
63
|
+
it 'returns the value set when the record is retrieved' do
|
64
|
+
user = User.create(:nick_names => [])
|
65
|
+
user.reload
|
66
|
+
|
67
|
+
user.update_attribute(:nick_names, ['some', 'values'])
|
68
|
+
user.save
|
69
|
+
|
70
|
+
user.reload
|
71
|
+
user.nick_names.should eq ['some', 'values']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context '#update_attributes' do
|
77
|
+
describe 'setting a value via update_attributes' do
|
78
|
+
it 'returns the value set when the record is retrieved' do
|
79
|
+
user = User.create(:nick_names => [])
|
80
|
+
user.reload
|
81
|
+
|
82
|
+
user.update_attributes(:nick_names => ['some', 'values'])
|
83
|
+
user.save
|
84
|
+
|
85
|
+
user.reload
|
86
|
+
user.nick_names.should eq ['some', 'values']
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
57
90
|
end
|
58
91
|
|
59
92
|
context 'default values' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- .rspec
|
151
151
|
- .travis.yml
|
152
152
|
- CHANGELOG.md
|
153
|
+
- CONTRIBUTING.md
|
153
154
|
- Gemfile
|
154
155
|
- LICENSE
|
155
156
|
- README.md
|
@@ -186,7 +187,7 @@ files:
|
|
186
187
|
- spec/dummy/config.ru
|
187
188
|
- spec/dummy/config/application.rb
|
188
189
|
- spec/dummy/config/boot.rb
|
189
|
-
- spec/dummy/config/database.yml
|
190
|
+
- spec/dummy/config/database.yml.example
|
190
191
|
- spec/dummy/config/environment.rb
|
191
192
|
- spec/dummy/config/environments/development.rb
|
192
193
|
- spec/dummy/config/environments/production.rb
|
@@ -250,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
250
251
|
version: '0'
|
251
252
|
segments:
|
252
253
|
- 0
|
253
|
-
hash:
|
254
|
+
hash: -830312040655703419
|
254
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
255
256
|
none: false
|
256
257
|
requirements:
|
@@ -259,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
260
|
version: '0'
|
260
261
|
segments:
|
261
262
|
- 0
|
262
|
-
hash:
|
263
|
+
hash: -830312040655703419
|
263
264
|
requirements: []
|
264
265
|
rubyforge_project:
|
265
266
|
rubygems_version: 1.8.23
|
@@ -286,7 +287,7 @@ test_files:
|
|
286
287
|
- spec/dummy/config.ru
|
287
288
|
- spec/dummy/config/application.rb
|
288
289
|
- spec/dummy/config/boot.rb
|
289
|
-
- spec/dummy/config/database.yml
|
290
|
+
- spec/dummy/config/database.yml.example
|
290
291
|
- spec/dummy/config/environment.rb
|
291
292
|
- spec/dummy/config/environments/development.rb
|
292
293
|
- spec/dummy/config/environments/production.rb
|