activerecord-postgresql-extensions 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class ConstraintTests < Test::Unit::TestCase
5
+ class ConstraintTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def setup
@@ -250,4 +250,110 @@ EOF
250
250
  %{ALTER TABLE "foo" ADD EXCLUDE (length(name) WITH =) WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar";}
251
251
  ], statements)
252
252
  end
253
+
254
+ def test_primary_key_in_column_definition
255
+ Mig.create_table('foo', :id => false) do |t|
256
+ t.integer :foo_id, :primary_key => true
257
+ end
258
+
259
+ Mig.create_table('foo', :id => false) do |t|
260
+ t.integer :foo_id, :primary_key => {
261
+ :tablespace => 'fubar',
262
+ :index_parameters => 'FILLFACTOR=10'
263
+ }
264
+ end
265
+
266
+ assert_equal([
267
+ %{CREATE TABLE "foo" (
268
+ "foo_id" integer,
269
+ PRIMARY KEY ("foo_id")
270
+ );},
271
+
272
+ %{CREATE TABLE "foo" (
273
+ "foo_id" integer,
274
+ PRIMARY KEY ("foo_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar"
275
+ );}], statements)
276
+ end
277
+
278
+
279
+ def test_primary_key_in_table_definition
280
+ Mig.create_table('foo', :id => false) do |t|
281
+ t.integer :foo_id
282
+ t.primary_key_constraint :foo_id
283
+ end
284
+
285
+ Mig.create_table('foo', :id => false) do |t|
286
+ t.integer :foo_id
287
+ t.primary_key_constraint :foo_id, {
288
+ :tablespace => 'fubar',
289
+ :index_parameters => 'FILLFACTOR=10'
290
+ }
291
+ end
292
+
293
+ Mig.create_table('foo', :id => false) do |t|
294
+ t.integer :foo_id
295
+ t.integer :bar_id
296
+ t.primary_key_constraint [ :foo_id, :bar_id ], {
297
+ :tablespace => 'fubar',
298
+ :index_parameters => 'FILLFACTOR=10'
299
+ }
300
+ end
301
+
302
+ assert_equal([
303
+ %{CREATE TABLE "foo" (
304
+ "foo_id" integer,
305
+ PRIMARY KEY ("foo_id")
306
+ );},
307
+
308
+ %{CREATE TABLE "foo" (
309
+ "foo_id" integer,
310
+ PRIMARY KEY ("foo_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar"
311
+ );},
312
+
313
+ %{CREATE TABLE "foo" (
314
+ "foo_id" integer,
315
+ "bar_id" integer,
316
+ PRIMARY KEY ("foo_id", "bar_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar"
317
+ );}], statements)
318
+ end
319
+
320
+ def test_add_primary_key
321
+ Mig.add_primary_key(:foo, :bar_id)
322
+ Mig.add_primary_key(:foo, [ :bar_id, :baz_id ])
323
+ Mig.add_primary_key(:foo, :bar_id, :name => 'foo_pk')
324
+ Mig.add_primary_key(:foo, :bar_id, :tablespace => 'fubar', :index_parameters => 'FILLFACTOR=10')
325
+
326
+ assert_equal([
327
+ %{ALTER TABLE "foo" ADD PRIMARY KEY ("bar_id");},
328
+ %{ALTER TABLE "foo" ADD PRIMARY KEY ("bar_id", "baz_id");},
329
+ %{ALTER TABLE "foo" ADD CONSTRAINT "foo_pk" PRIMARY KEY ("bar_id");},
330
+ %{ALTER TABLE "foo" ADD PRIMARY KEY ("bar_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar";}
331
+ ], statements)
332
+ end
333
+
334
+ def test_not_valid
335
+ Mig.add_check_constraint(:foo, 'length(name) < 100', :not_valid => true)
336
+ Mig.add_foreign_key(:foo, :bar_id, :bar, :not_valid => true)
337
+
338
+ assert_equal([
339
+ "ALTER TABLE \"foo\" ADD CHECK (length(name) < 100) NOT VALID;",
340
+ "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" NOT VALID;"
341
+ ], statements)
342
+ end
343
+
344
+ def test_validate_constraint
345
+ Mig.validate_constraint(:foo, :foo_constraint)
346
+
347
+ assert_equal([
348
+ "ALTER TABLE \"foo\" VALIDATE CONSTRAINT \"foo_constraint\";"
349
+ ], statements)
350
+ end
351
+
352
+ def test_no_inherit
353
+ Mig.add_check_constraint(:foo, 'length(name) < 100', :no_inherit => true)
354
+
355
+ assert_equal([
356
+ "ALTER TABLE \"foo\" ADD CHECK (length(name) < 100) NO INHERIT;",
357
+ ], statements)
358
+ end
253
359
  end
@@ -2,10 +2,12 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class ExtensionsTests < Test::Unit::TestCase
5
+ class ExtensionsTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_extension
9
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
10
+
9
11
  ARBC.create_extension(:foo)
10
12
  ARBC.create_extension(:foo, :if_not_exists => true)
11
13
  ARBC.create_extension(:foo, :schema => :bar)
@@ -22,6 +24,8 @@ class ExtensionsTests < Test::Unit::TestCase
22
24
  end
23
25
 
24
26
  def test_drop_extension
27
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
28
+
25
29
  ARBC.drop_extension(:foo)
26
30
  ARBC.drop_extension(:foo, :if_exists => true)
27
31
  ARBC.drop_extension(:foo, :cascade => true)
@@ -36,6 +40,8 @@ class ExtensionsTests < Test::Unit::TestCase
36
40
  end
37
41
 
38
42
  def test_update_extension
43
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
44
+
39
45
  ARBC.update_extension(:foo)
40
46
  ARBC.update_extension(:foo, '2.0.0')
41
47
 
@@ -46,6 +52,8 @@ class ExtensionsTests < Test::Unit::TestCase
46
52
  end
47
53
 
48
54
  def test_update_schema
55
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
56
+
49
57
  ARBC.alter_extension_schema(:foo, :bar)
50
58
 
51
59
  assert_equal([
@@ -54,12 +62,16 @@ class ExtensionsTests < Test::Unit::TestCase
54
62
  end
55
63
 
56
64
  def test_alter_extension_empty
65
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
66
+
57
67
  ARBC.alter_extension(:foo)
58
68
 
59
69
  assert_equal([], statements)
60
70
  end
61
71
 
62
72
  def test_alter_extension_regular_options_with_hashes
73
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
74
+
63
75
  ARBC.alter_extension(:foo, {
64
76
  :collation => :bar,
65
77
  :conversion => :bar,
@@ -174,6 +186,8 @@ class ExtensionsTests < Test::Unit::TestCase
174
186
  end
175
187
 
176
188
  def test_alter_extension_regular_options_with_block
189
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
190
+
177
191
  ARBC.alter_extension(:foo) do |e|
178
192
  e.drop_collation :bar
179
193
  e.add_conversion :bar
@@ -188,6 +202,8 @@ ALTER EXTENSION "foo" ADD DOMAIN "bar";}
188
202
  end
189
203
 
190
204
  def test_alter_extension_cast_option
205
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
206
+
191
207
  ARBC.alter_extension(:foo) do |e|
192
208
  e.cast :hello => :world
193
209
  e.cast [ :hello, :world ]
@@ -202,6 +218,8 @@ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");}
202
218
  end
203
219
 
204
220
  def test_alter_extension_aggregate_option
221
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
222
+
205
223
  ARBC.alter_extension(:foo) do |e|
206
224
  e.aggregate :name => :bar, :types => %w{ type_a type_b type_c }
207
225
  e.aggregate :bar, :type_a, :type_b, :type_c
@@ -214,6 +232,8 @@ ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");}
214
232
  end
215
233
 
216
234
  def test_alter_extension_operator_option
235
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
236
+
217
237
  ARBC.alter_extension(:foo) do |e|
218
238
  e.operator :bar, :hello, :world
219
239
  e.operator [ :bar, :hello, :world ]
@@ -228,6 +248,8 @@ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");}
228
248
  end
229
249
 
230
250
  def test_alter_extension_operator_class_option
251
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
252
+
231
253
  ARBC.alter_extension(:foo) do |e|
232
254
  e.operator_class :hello => :world
233
255
  e.operator_class :hello, :world
@@ -244,6 +266,8 @@ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");}
244
266
  end
245
267
 
246
268
  def test_alter_extension_operator_family_option
269
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
270
+
247
271
  ARBC.alter_extension(:foo) do |e|
248
272
  e.operator_family :hello => :world
249
273
  e.operator_family :hello, :world
@@ -260,6 +284,8 @@ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");}
260
284
  end
261
285
 
262
286
  def test_alter_extension_function_option
287
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
288
+
263
289
  ARBC.alter_extension(:foo) do |e|
264
290
  e.function :bar, "VARIADIC hello world"
265
291
  e.function [ :bar, "VARIADIC hello world" ]
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class FunctionsTests < Test::Unit::TestCase
5
+ class FunctionsTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_function
@@ -2,251 +2,277 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- if ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION
6
- if ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] >= '2.0'
7
- class GeometryTests < Test::Unit::TestCase
8
- include PostgreSQLExtensionsTestHelper
9
-
10
- def test_create_geometry
11
- Mig.create_table(:foo) do |t|
12
- t.geometry :the_geom, :srid => 4326
13
- end
14
-
15
- assert_equal([
16
- %{CREATE TABLE "foo" (
5
+ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0'
6
+ class GeometryTests < MiniTest::Unit::TestCase
7
+ include PostgreSQLExtensionsTestHelper
8
+
9
+ def test_create_geometry
10
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
11
+
12
+ Mig.create_table(:foo) do |t|
13
+ t.geometry :the_geom, :srid => 4326
14
+ end
15
+
16
+ assert_equal([
17
+ %{CREATE TABLE "foo" (
17
18
  "id" serial primary key,
18
19
  "the_geom" geometry(GEOMETRY, 4326)
19
20
  );},
20
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
21
- ], statements)
22
- end
21
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
22
+ ], statements)
23
+ end
23
24
 
24
- def test_create_geometry_with_spatial
25
- Mig.create_table(:foo) do |t|
26
- t.spatial :the_geom, :srid => 4326
27
- end
25
+ def test_create_geometry_with_spatial
26
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
27
+
28
+ Mig.create_table(:foo) do |t|
29
+ t.spatial :the_geom, :srid => 4326
30
+ end
28
31
 
29
- assert_equal([
30
- %{CREATE TABLE "foo" (
32
+ assert_equal([
33
+ %{CREATE TABLE "foo" (
31
34
  "id" serial primary key,
32
35
  "the_geom" geometry(GEOMETRY, 4326)
33
36
  );},
34
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
35
- ], statements)
36
- end
37
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
38
+ ], statements)
39
+ end
37
40
 
38
- def test_create_geometry_with_spatial_and_spatial_column_type
39
- Mig.create_table(:foo) do |t|
40
- t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
41
- end
41
+ def test_create_geometry_with_spatial_and_spatial_column_type
42
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
43
+
44
+ Mig.create_table(:foo) do |t|
45
+ t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
46
+ end
42
47
 
43
- assert_equal([
44
- %{CREATE TABLE "foo" (
48
+ assert_equal([
49
+ %{CREATE TABLE "foo" (
45
50
  "id" serial primary key,
46
51
  "the_geom" geography(GEOMETRY, 4326)
47
52
  );},
48
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
49
- ], statements)
50
- end
53
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
54
+ ], statements)
55
+ end
56
+
57
+ def test_create_geography
58
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
51
59
 
52
- def test_create_geography
53
- Mig.create_table(:foo) do |t|
54
- t.geography :the_geom, :srid => 4326
55
- end
60
+ Mig.create_table(:foo) do |t|
61
+ t.geography :the_geom, :srid => 4326
62
+ end
56
63
 
57
- assert_equal([
58
- %{CREATE TABLE "foo" (
64
+ assert_equal([
65
+ %{CREATE TABLE "foo" (
59
66
  "id" serial primary key,
60
67
  "the_geom" geography(GEOMETRY, 4326)
61
68
  );},
62
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
63
- ], statements)
64
- end
69
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
70
+ ], statements)
71
+ end
72
+
73
+ def test_create_geometry_with_force_constraints
74
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
65
75
 
66
- def test_create_geometry_with_force_constraints
67
- Mig.create_table(:foo) do |t|
68
- t.geometry :the_geom, :srid => 4326, :force_constraints => true
69
- end
76
+ Mig.create_table(:foo) do |t|
77
+ t.geometry :the_geom, :srid => 4326, :force_constraints => true
78
+ end
70
79
 
71
- assert_equal([
72
- %{CREATE TABLE "foo" (
80
+ assert_equal([
81
+ %{CREATE TABLE "foo" (
73
82
  "id" serial primary key,
74
83
  "the_geom" geometry(GEOMETRY, 4326),
75
84
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
76
85
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
77
86
  );},
78
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
79
- ], statements)
80
- end
87
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
88
+ ], statements)
89
+ end
81
90
 
82
- def test_create_geometry_with_schema
83
- Mig.create_table('shabba.foo') do |t|
84
- t.geometry :the_geom, :srid => 4326
85
- end
91
+ def test_create_geometry_with_schema
92
+ Mig.create_table('shabba.foo') do |t|
93
+ t.geometry :the_geom, :srid => 4326
94
+ end
86
95
 
87
- assert_equal([
88
- %{CREATE TABLE "shabba"."foo" (
96
+ assert_equal([
97
+ %{CREATE TABLE "shabba"."foo" (
89
98
  "id" serial primary key,
90
99
  "the_geom" geometry(GEOMETRY, 4326)
91
100
  );},
92
- %{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
93
- ], statements)
94
- end
101
+ %{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
102
+ ], statements)
103
+ end
95
104
 
96
- def test_create_geometry_with_not_null
97
- Mig.create_table(:foo) do |t|
98
- t.geometry :the_geom, :srid => 4326, :null => false
99
- end
105
+ def test_create_geometry_with_not_null
106
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
107
+
108
+ Mig.create_table(:foo) do |t|
109
+ t.geometry :the_geom, :srid => 4326, :null => false
110
+ end
100
111
 
101
- assert_equal([
102
- %{CREATE TABLE "foo" (
112
+ assert_equal([
113
+ %{CREATE TABLE "foo" (
103
114
  "id" serial primary key,
104
115
  "the_geom" geometry(GEOMETRY, 4326) NOT NULL
105
116
  );},
106
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
107
- ], statements)
108
- end
117
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
118
+ ], statements)
119
+ end
120
+
121
+ def test_create_geometry_with_null_and_type
122
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
109
123
 
110
- def test_create_geometry_with_null_and_type
111
- Mig.create_table(:foo) do |t|
112
- t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
113
- end
124
+ Mig.create_table(:foo) do |t|
125
+ t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
126
+ end
114
127
 
115
- assert_equal([
116
- %{CREATE TABLE "foo" (
128
+ assert_equal([
129
+ %{CREATE TABLE "foo" (
117
130
  "id" serial primary key,
118
131
  "the_geom" geometry(POLYGON, 4326)
119
132
  );},
120
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
121
- ], statements)
122
- end
133
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
134
+ ], statements)
123
135
  end
124
- else
125
- class GeometryTests < Test::Unit::TestCase
126
- include PostgreSQLExtensionsTestHelper
136
+ end
137
+ else
138
+ class GeometryTests < Test::Unit::TestCase
139
+ include PostgreSQLExtensionsTestHelper
140
+
141
+ def test_create_geometry
142
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
127
143
 
128
- def test_create_geometry
129
- Mig.create_table(:foo) do |t|
130
- t.geometry :the_geom, :srid => 4326
131
- end
144
+ Mig.create_table(:foo) do |t|
145
+ t.geometry :the_geom, :srid => 4326
146
+ end
132
147
 
133
- assert_equal([
134
- %{CREATE TABLE "foo" (
148
+ assert_equal([
149
+ %{CREATE TABLE "foo" (
135
150
  "id" serial primary key,
136
151
  "the_geom" geometry,
137
152
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
138
153
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
139
154
  );},
140
- %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
141
- %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
142
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
143
- ], statements)
144
- end
155
+ %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
156
+ %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
157
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
158
+ ], statements)
159
+ end
145
160
 
146
- def test_create_geometry_with_spatial
147
- Mig.create_table(:foo) do |t|
148
- t.spatial :the_geom, :srid => 4326
149
- end
161
+ def test_create_geometry_with_spatial
162
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
150
163
 
151
- assert_equal([
152
- %{CREATE TABLE "foo" (
164
+ Mig.create_table(:foo) do |t|
165
+ t.spatial :the_geom, :srid => 4326
166
+ end
167
+
168
+ assert_equal([
169
+ %{CREATE TABLE "foo" (
153
170
  "id" serial primary key,
154
171
  "the_geom" geometry,
155
172
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
156
173
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
157
174
  );},
158
- %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
159
- %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
160
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
161
- ], statements)
162
- end
175
+ %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
176
+ %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
177
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
178
+ ], statements)
179
+ end
163
180
 
164
- def test_create_geometry_with_spatial_and_spatial_column_type
165
- Mig.create_table(:foo) do |t|
166
- t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
167
- end
181
+ def test_create_geometry_with_spatial_and_spatial_column_type
182
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
168
183
 
169
- assert_equal([
170
- %{CREATE TABLE "foo" (
184
+ Mig.create_table(:foo) do |t|
185
+ t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
186
+ end
187
+
188
+ assert_equal([
189
+ %{CREATE TABLE "foo" (
171
190
  "id" serial primary key,
172
191
  "the_geom" geography,
173
192
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
174
193
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
175
194
  );},
176
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
177
- ], statements)
178
- end
195
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
196
+ ], statements)
197
+ end
179
198
 
180
- def test_create_geography
181
- Mig.create_table(:foo) do |t|
182
- t.geography :the_geom, :srid => 4326
183
- end
199
+ def test_create_geography
200
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
184
201
 
185
- assert_equal([
186
- %{CREATE TABLE "foo" (
202
+ Mig.create_table(:foo) do |t|
203
+ t.geography :the_geom, :srid => 4326
204
+ end
205
+
206
+ assert_equal([
207
+ %{CREATE TABLE "foo" (
187
208
  "id" serial primary key,
188
209
  "the_geom" geography,
189
210
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
190
211
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
191
212
  );},
192
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
193
- ], statements)
194
- end
213
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
214
+ ], statements)
215
+ end
195
216
 
196
- def test_create_geometry_with_schema
197
- Mig.create_table('shabba.foo') do |t|
198
- t.geometry :the_geom, :srid => 4326
199
- end
217
+ def test_create_geometry_with_schema
218
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
200
219
 
201
- assert_equal([
202
- %{CREATE TABLE "shabba"."foo" (
220
+ Mig.create_table('shabba.foo') do |t|
221
+ t.geometry :the_geom, :srid => 4326
222
+ end
223
+
224
+ assert_equal([
225
+ %{CREATE TABLE "shabba"."foo" (
203
226
  "id" serial primary key,
204
227
  "the_geom" geometry,
205
228
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
206
229
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
207
230
  );},
208
- %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'shabba' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
209
- %{INSERT INTO "geometry_columns" VALUES ('', 'shabba', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
210
- %{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
211
- ], statements)
212
- end
231
+ %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'shabba' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
232
+ %{INSERT INTO "geometry_columns" VALUES ('', 'shabba', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
233
+ %{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
234
+ ], statements)
235
+ end
213
236
 
214
- def test_create_geometry_with_not_null
215
- Mig.create_table(:foo) do |t|
216
- t.geometry :the_geom, :srid => 4326, :null => false
217
- end
237
+ def test_create_geometry_with_not_null
238
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
218
239
 
219
- assert_equal([
220
- %{CREATE TABLE "foo" (
240
+ Mig.create_table(:foo) do |t|
241
+ t.geometry :the_geom, :srid => 4326, :null => false
242
+ end
243
+
244
+ assert_equal([
245
+ %{CREATE TABLE "foo" (
221
246
  "id" serial primary key,
222
247
  "the_geom" geometry NOT NULL,
223
248
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
224
249
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
225
250
  );},
226
- %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
227
- %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
228
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
229
- ], statements)
230
- end
251
+ %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
252
+ %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
253
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
254
+ ], statements)
255
+ end
231
256
 
232
- def test_create_geometry_with_null_and_type
233
- Mig.create_table(:foo) do |t|
234
- t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
235
- end
257
+ def test_create_geometry_with_null_and_type
258
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
236
259
 
237
- assert_equal([
238
- %{CREATE TABLE "foo" (
260
+ Mig.create_table(:foo) do |t|
261
+ t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
262
+ end
263
+
264
+ assert_equal([
265
+ %{CREATE TABLE "foo" (
239
266
  "id" serial primary key,
240
267
  "the_geom" geometry,
241
268
  CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
242
269
  CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2),
243
270
  CONSTRAINT "enforce_geotype_the_geom" CHECK (geometrytype("the_geom") = 'POLYGON'::text OR "the_geom" IS NULL)
244
271
  );},
245
- %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
246
- %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'POLYGON');},
247
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
248
- ], statements)
249
- end
272
+ %{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
273
+ %{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'POLYGON');},
274
+ %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
275
+ ], statements)
250
276
  end
251
277
  end
252
278
  end