ar_pg_array 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ar_pg_array/schema.rb +8 -0
- data/spec/pg_array_spec.rb +17 -4
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.1
|
data/lib/ar_pg_array/schema.rb
CHANGED
@@ -232,6 +232,14 @@ module ActiveRecord
|
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
|
+
def add_column_with_postgresql_arrays( table, column, type, options )
|
236
|
+
if type.to_s =~ /^(.+)_array$/ && options[:default].presence.is_a?(Array)
|
237
|
+
options = options.merge(:default => prepare_array_for_arel_by_base_type(options[:default], $1))
|
238
|
+
end
|
239
|
+
add_column_without_postgresql_arrays( table, column, type, options )
|
240
|
+
end
|
241
|
+
alias_method_chain :add_column, :postgresql_arrays
|
242
|
+
|
235
243
|
def type_to_sql_with_postgresql_arrays(type, limit = nil, precision = nil, scale = nil)
|
236
244
|
if type.to_s =~ /^(.+)_array$/
|
237
245
|
type_to_sql_without_postgresql_arrays($1.to_sym, limit, precision, scale)+'[]'
|
data/spec/pg_array_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe "PgArray" do
|
4
|
-
|
4
|
+
context "Array" do
|
5
5
|
before :all do
|
6
6
|
@ability_class = Class.new do
|
7
7
|
include CanCan::Ability
|
@@ -62,7 +62,7 @@ describe "PgArray" do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
context "AR" do
|
66
66
|
it "should adequatly insert fixtures" do
|
67
67
|
bulk = Bulk.find(1)
|
68
68
|
bulk.ints.should == [ 1 ]
|
@@ -127,7 +127,7 @@ describe "PgArray" do
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
|
130
|
+
context "CanCan" do
|
131
131
|
before :all do
|
132
132
|
@ability_class = Class.new do
|
133
133
|
include CanCan::Ability
|
@@ -184,7 +184,7 @@ describe "PgArray" do
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
|
187
|
+
context "references_by" do
|
188
188
|
it "should fetch tags in saved order" do
|
189
189
|
Item.find(3).tags.should == [Tag.find(1), Tag.find(3)]
|
190
190
|
Item.find(4).tags.should == [Tag.find(3), Tag.find(1)]
|
@@ -218,4 +218,17 @@ describe "PgArray" do
|
|
218
218
|
Item.where(cond).order('id').all
|
219
219
|
end
|
220
220
|
end
|
221
|
+
|
222
|
+
context "schema" do
|
223
|
+
it "should allow to add column" do
|
224
|
+
lambda do
|
225
|
+
ActiveRecord::Schema.define do
|
226
|
+
change_table :items do |t|
|
227
|
+
t.integer_array :ints, :default=>[0], :null=>false
|
228
|
+
end
|
229
|
+
add_column :items, :floats, :float_array, :default=>[0], :null=>false
|
230
|
+
end
|
231
|
+
end.should_not raise_error
|
232
|
+
end
|
233
|
+
end
|
221
234
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_pg_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 57
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 1
|
10
|
+
version: 0.9.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sokolov Yura aka funny_falcon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-10 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|