postgres_ext 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ tmp
18
18
  bin/
19
19
  .rbenv-version*
20
20
 
21
+ spec/dummy/config/database.yml
@@ -7,6 +7,7 @@ rvm:
7
7
 
8
8
  before_script:
9
9
  - psql -c 'create database postgres_ext_test;' -U postgres
10
+ - cp spec/dummy/config/database.yml.example spec/dummy/config/database.yml
10
11
 
11
12
  notifications:
12
13
  email:
@@ -1,3 +1,7 @@
1
+ ## 0.0.8
2
+
3
+ Fixes add and change column
4
+
1
5
  ## 0.0.7
2
6
 
3
7
  Adds Arel predicate functions for array overlap operator (`&&`) and
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PostgresExt
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -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
- gem.add_development_dependency 'debugger', '~> 1.1.2' if RUBY_VERSION == '1.9.3'
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
@@ -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 :cidr_1
9
- t.uuid :cidr_2, :cidr_3
10
- t.column :cidr_4, :uuid
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
- cidr_1 = columns.detect { |c| c.name == 'cidr_1'}
16
- cidr_2 = columns.detect { |c| c.name == 'cidr_2'}
17
- cidr_3 = columns.detect { |c| c.name == 'cidr_3'}
18
- cidr_4 = columns.detect { |c| c.name == 'cidr_4'}
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
- cidr_1.sql_type.should eq 'uuid'
21
- cidr_2.sql_type.should eq 'uuid'
22
- cidr_3.sql_type.should eq 'uuid'
23
- cidr_4.sql_type.should eq 'uuid'
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
@@ -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
@@ -5,7 +5,7 @@ describe 'UUID schema dump' do
5
5
  it 'correctly generates uuid column statements' do
6
6
  stream = StringIO.new
7
7
  connection.create_table :testings do |t|
8
- t.uuid :network_column
8
+ t.uuid :uuid_column
9
9
  end
10
10
 
11
11
  ActiveRecord::SchemaDumper.dump(connection, stream)
@@ -3,7 +3,6 @@ ENV['RAILS_ENV'] = 'test'
3
3
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
4
4
 
5
5
  require 'rspec/rails'
6
- require 'debugger' if RUBY_VERSION == '1.9.3'
7
6
  require 'bourne'
8
7
 
9
8
  ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
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.7
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-14 00:00:00.000000000 Z
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: 169599389239444303
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: 169599389239444303
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