activerecord-postgresql-extensions 0.2.2 → 0.3.0

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.
Files changed (54) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +1 -0
  4. data/Guardfile +3 -3
  5. data/MIT-LICENSE +1 -1
  6. data/README.rdoc +10 -3
  7. data/lib/active_record/postgresql_extensions/adapter_extensions.rb +100 -60
  8. data/lib/active_record/postgresql_extensions/constraints.rb +13 -17
  9. data/lib/active_record/postgresql_extensions/event_triggers.rb +129 -0
  10. data/lib/active_record/postgresql_extensions/extensions.rb +14 -15
  11. data/lib/active_record/postgresql_extensions/features.rb +80 -41
  12. data/lib/active_record/postgresql_extensions/functions.rb +1 -1
  13. data/lib/active_record/postgresql_extensions/geometry.rb +6 -8
  14. data/lib/active_record/postgresql_extensions/indexes.rb +19 -11
  15. data/lib/active_record/postgresql_extensions/languages.rb +1 -1
  16. data/lib/active_record/postgresql_extensions/materialized_views.rb +272 -0
  17. data/lib/active_record/postgresql_extensions/permissions.rb +60 -22
  18. data/lib/active_record/postgresql_extensions/roles.rb +18 -7
  19. data/lib/active_record/postgresql_extensions/rules.rb +5 -0
  20. data/lib/active_record/postgresql_extensions/schemas.rb +39 -3
  21. data/lib/active_record/postgresql_extensions/sequences.rb +6 -3
  22. data/lib/active_record/postgresql_extensions/tables.rb +47 -19
  23. data/lib/active_record/postgresql_extensions/tablespaces.rb +1 -1
  24. data/lib/active_record/postgresql_extensions/text_search.rb +3 -3
  25. data/lib/active_record/postgresql_extensions/triggers.rb +3 -3
  26. data/lib/active_record/postgresql_extensions/types.rb +104 -1
  27. data/lib/active_record/postgresql_extensions/utils.rb +35 -13
  28. data/lib/active_record/postgresql_extensions/vacuum.rb +1 -1
  29. data/lib/active_record/postgresql_extensions/version.rb +1 -1
  30. data/lib/active_record/postgresql_extensions/views.rb +137 -6
  31. data/lib/activerecord-postgresql-extensions.rb +13 -11
  32. data/test/{adapter_tests.rb → adapter_extensions_tests.rb} +96 -3
  33. data/test/constraints_tests.rb +216 -104
  34. data/test/event_triggers_tests.rb +109 -0
  35. data/test/extensions_tests.rb +47 -39
  36. data/test/functions_tests.rb +47 -38
  37. data/test/geometry_tests.rb +268 -135
  38. data/test/{index_tests.rb → indexes_tests.rb} +16 -16
  39. data/test/languages_tests.rb +26 -9
  40. data/test/materialized_views_tests.rb +174 -0
  41. data/test/permissions_tests.rb +159 -45
  42. data/test/roles_tests.rb +17 -7
  43. data/test/rules_tests.rb +14 -6
  44. data/test/schemas_tests.rb +35 -9
  45. data/test/sequences_tests.rb +9 -11
  46. data/test/tables_tests.rb +132 -42
  47. data/test/tablespace_tests.rb +21 -15
  48. data/test/test_helper.rb +56 -10
  49. data/test/text_search_tests.rb +42 -44
  50. data/test/trigger_tests.rb +1 -3
  51. data/test/types_tests.rb +95 -0
  52. data/test/vacuum_tests.rb +1 -3
  53. data/test/views_tests.rb +203 -0
  54. metadata +22 -16
@@ -0,0 +1,109 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class EventTriggerTests < PostgreSQLExtensionsTestCase
6
+ def skip_unless_supported
7
+ skip unless ActiveRecord::PostgreSQLExtensions::Features.event_triggers?
8
+ end
9
+
10
+ def test_create_event_trigger
11
+ skip_unless_supported
12
+
13
+ Mig.create_event_trigger(:foo_trg, :ddl_command_start, :foo_trg_function)
14
+
15
+ assert_equal([
16
+ %{CREATE EVENT TRIGGER "foo_trg" ON "ddl_command_start" EXECUTE PROCEDURE "foo_trg_function"();}
17
+ ], statements)
18
+ end
19
+
20
+ def test_create_event_trigger_bad_event
21
+ skip_unless_supported
22
+
23
+ assert_raises(ActiveRecord::InvalidEventTriggerEventType) do
24
+ Mig.create_event_trigger(:foo_trg, :blort, :foo_trg_function)
25
+ end
26
+ end
27
+
28
+ def test_create_event_trigger_with_when_option
29
+ skip_unless_supported
30
+
31
+ Mig.create_event_trigger(:foo_trg, :ddl_command_start, :foo_trg_function,
32
+ :when => {
33
+ :tag => 'CREATE TABLE',
34
+ :toplevel => 'FOOS'
35
+ }
36
+ )
37
+
38
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
39
+ CREATE EVENT TRIGGER "foo_trg" ON "ddl_command_start"
40
+ WHEN "tag" IN ('CREATE TABLE')
41
+ AND "toplevel" IN ('FOOS')
42
+ EXECUTE PROCEDURE "foo_trg_function"();
43
+ SQL
44
+ end
45
+
46
+ def test_drop_event_trigger
47
+ skip_unless_supported
48
+
49
+ ARBC.drop_event_trigger(:foo)
50
+ ARBC.drop_event_trigger(:foo, :if_exists => true, :cascade => true)
51
+
52
+ assert_equal([
53
+ %{DROP EVENT TRIGGER "foo";},
54
+ %{DROP EVENT TRIGGER IF EXISTS "foo" CASCADE;}
55
+ ], statements)
56
+ end
57
+
58
+ def test_rename_event_trigger
59
+ skip_unless_supported
60
+
61
+ ARBC.rename_event_trigger(:foo, :bar)
62
+
63
+ assert_equal([
64
+ %{ALTER EVENT TRIGGER "foo" RENAME TO "bar";}
65
+ ], statements)
66
+ end
67
+
68
+ def test_alter_event_trigger_owner
69
+ skip_unless_supported
70
+
71
+ ARBC.alter_event_trigger_owner(:foo, :bar)
72
+
73
+ assert_equal([
74
+ %{ALTER EVENT TRIGGER "foo" OWNER TO "bar";}
75
+ ], statements)
76
+ end
77
+
78
+ def test_enable_event_trigger
79
+ skip_unless_supported
80
+
81
+ ARBC.enable_event_trigger(:foo)
82
+ ARBC.enable_event_trigger(:foo, :always => true)
83
+ ARBC.enable_event_trigger(:foo, :replica => true)
84
+
85
+ assert_equal([
86
+ %{ALTER EVENT TRIGGER "foo" ENABLE;},
87
+ %{ALTER EVENT TRIGGER "foo" ENABLE ALWAYS;},
88
+ %{ALTER EVENT TRIGGER "foo" ENABLE REPLICA;}
89
+ ], statements)
90
+ end
91
+
92
+ def test_enable_event_trigger_with_replica_and_always
93
+ skip_unless_supported
94
+
95
+ assert_raises(ArgumentError) do
96
+ ARBC.enable_event_trigger(:foo, :always => true, :replica => true)
97
+ end
98
+ end
99
+
100
+ def test_disable_event_trigger
101
+ skip_unless_supported
102
+
103
+ ARBC.disable_event_trigger(:foo)
104
+
105
+ assert_equal([
106
+ %{ALTER EVENT TRIGGER "foo" DISABLE;}
107
+ ], statements)
108
+ end
109
+ end
@@ -2,9 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class ExtensionsTests < MiniTest::Unit::TestCase
6
- include PostgreSQLExtensionsTestHelper
7
-
5
+ class ExtensionsTests < PostgreSQLExtensionsTestCase
8
6
  def test_create_extension
9
7
  skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
10
8
 
@@ -194,11 +192,11 @@ class ExtensionsTests < MiniTest::Unit::TestCase
194
192
  e.domain :bar
195
193
  end
196
194
 
197
- assert_equal([
198
- %{ALTER EXTENSION "foo" DROP COLLATION "bar";
199
- ALTER EXTENSION "foo" ADD CONVERSION "bar";
200
- ALTER EXTENSION "foo" ADD DOMAIN "bar";}
201
- ], statements)
195
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
196
+ ALTER EXTENSION "foo" DROP COLLATION "bar";
197
+ ALTER EXTENSION "foo" ADD CONVERSION "bar";
198
+ ALTER EXTENSION "foo" ADD DOMAIN "bar";
199
+ SQL
202
200
  end
203
201
 
204
202
  def test_alter_extension_cast_option
@@ -210,11 +208,11 @@ ALTER EXTENSION "foo" ADD DOMAIN "bar";}
210
208
  e.cast :source => :hello, :target => :world
211
209
  end
212
210
 
213
- assert_equal([
214
- %{ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");
215
- ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");
216
- ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");}
217
- ], statements)
211
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
212
+ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");
213
+ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");
214
+ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");
215
+ SQL
218
216
  end
219
217
 
220
218
  def test_alter_extension_aggregate_option
@@ -225,10 +223,10 @@ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");}
225
223
  e.aggregate :bar, :type_a, :type_b, :type_c
226
224
  end
227
225
 
228
- assert_equal([
229
- %{ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");
230
- ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");}
231
- ], statements)
226
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
227
+ ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");
228
+ ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");
229
+ SQL
232
230
  end
233
231
 
234
232
  def test_alter_extension_operator_option
@@ -240,11 +238,11 @@ ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");}
240
238
  e.operator :name => :bar, :left_type => :hello, :right_type => :world
241
239
  end
242
240
 
243
- assert_equal([
244
- %{ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");
245
- ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");
246
- ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");}
247
- ], statements)
241
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
242
+ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");
243
+ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");
244
+ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");
245
+ SQL
248
246
  end
249
247
 
250
248
  def test_alter_extension_operator_class_option
@@ -257,12 +255,12 @@ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");}
257
255
  e.operator_class :name => :hello, :indexing_method => :world
258
256
  end
259
257
 
260
- assert_equal([
261
- %{ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
262
- ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
263
- ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
264
- ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");}
265
- ], statements)
258
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
259
+ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
260
+ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
261
+ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
262
+ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
263
+ SQL
266
264
  end
267
265
 
268
266
  def test_alter_extension_operator_family_option
@@ -275,12 +273,12 @@ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");}
275
273
  e.operator_family :name => :hello, :indexing_method => :world
276
274
  end
277
275
 
278
- assert_equal([
279
- %{ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
280
- ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
281
- ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
282
- ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");}
283
- ], statements)
276
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
277
+ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
278
+ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
279
+ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
280
+ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
281
+ SQL
284
282
  end
285
283
 
286
284
  def test_alter_extension_function_option
@@ -292,10 +290,20 @@ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");}
292
290
  e.function :name => :bar, :arguments => "VARIADIC hello world"
293
291
  end
294
292
 
295
- assert_equal([
296
- %{ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);
297
- ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);
298
- ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);}
299
- ], statements)
293
+ assert_equal([ strip_heredoc(<<-SQL) ], statements)
294
+ ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);
295
+ ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);
296
+ ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);
297
+ SQL
298
+ end
299
+
300
+ def test_alter_extension_bad_action
301
+ skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
302
+
303
+ assert_raises(ArgumentError) do
304
+ ARBC.alter_extension(:foo, {
305
+ :blort_collation => :bar
306
+ })
307
+ end
300
308
  end
301
309
  end
@@ -2,9 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class FunctionsTests < MiniTest::Unit::TestCase
6
- include PostgreSQLExtensionsTestHelper
7
-
5
+ class FunctionsTests < PostgreSQLExtensionsTestCase
8
6
  def test_create_function
9
7
  ARBC.create_function(:test, :integer, :integer, :sql) do
10
8
  "select 10;"
@@ -24,22 +22,28 @@ class FunctionsTests < MiniTest::Unit::TestCase
24
22
  "return 10;"
25
23
  end
26
24
 
27
- assert_equal([
28
- %{CREATE FUNCTION "test"(integer) RETURNS integer AS $$
29
- select 10;
30
- $$
31
- LANGUAGE "sql";},
32
-
33
- %{CREATE OR REPLACE FUNCTION "test"(integer) RETURNS integer AS $__$
34
- return 10;
35
- $__$
36
- LANGUAGE "sql"
37
- IMMUTABLE
38
- STRICT
39
- COST 1
40
- ROWS 10
41
- SET TIME ZONE "America/Halifax";}
42
- ], statements)
25
+ expected = []
26
+
27
+ expected << strip_heredoc(<<-SQL)
28
+ CREATE FUNCTION "test"(integer) RETURNS integer AS $$
29
+ select 10;
30
+ $$
31
+ LANGUAGE "sql";
32
+ SQL
33
+
34
+ expected << strip_heredoc(<<-SQL)
35
+ CREATE OR REPLACE FUNCTION "test"(integer) RETURNS integer AS $__$
36
+ return 10;
37
+ $__$
38
+ LANGUAGE "sql"
39
+ IMMUTABLE
40
+ STRICT
41
+ COST 1
42
+ ROWS 10
43
+ SET TIME ZONE "America/Halifax";
44
+ SQL
45
+
46
+ assert_equal(expected, statements)
43
47
  end
44
48
 
45
49
  def test_drop_function
@@ -47,8 +51,8 @@ LANGUAGE "sql"
47
51
  ARBC.drop_function(:test, :integer, :if_exists => true, :cascade => true)
48
52
 
49
53
  assert_equal([
50
- "DROP FUNCTION \"test\"(integer);",
51
- "DROP FUNCTION IF EXISTS \"test\"(integer) CASCADE;"
54
+ %{DROP FUNCTION "test"(integer);},
55
+ %{DROP FUNCTION IF EXISTS "test"(integer) CASCADE;}
52
56
  ], statements)
53
57
  end
54
58
 
@@ -56,7 +60,7 @@ LANGUAGE "sql"
56
60
  ARBC.rename_function(:test, 'integer, text', :foo)
57
61
 
58
62
  assert_equal([
59
- "ALTER FUNCTION \"test\"(integer, text) RENAME TO \"foo\";"
63
+ %{ALTER FUNCTION "test"(integer, text) RENAME TO "foo";}
60
64
  ], statements)
61
65
  end
62
66
 
@@ -64,7 +68,7 @@ LANGUAGE "sql"
64
68
  ARBC.alter_function_owner(:test, 'integer, text', :admin)
65
69
 
66
70
  assert_equal([
67
- "ALTER FUNCTION \"test\"(integer, text) OWNER TO \"admin\";"
71
+ %{ALTER FUNCTION "test"(integer, text) OWNER TO "admin";}
68
72
  ], statements)
69
73
  end
70
74
 
@@ -72,7 +76,7 @@ LANGUAGE "sql"
72
76
  ARBC.alter_function_schema(:test, 'integer, text', :geospatial)
73
77
 
74
78
  assert_equal([
75
- "ALTER FUNCTION \"test\"(integer, text) SET SCHEMA \"geospatial\";"
79
+ %{ALTER FUNCTION "test"(integer, text) SET SCHEMA "geospatial";}
76
80
  ], statements)
77
81
  end
78
82
 
@@ -94,19 +98,24 @@ LANGUAGE "sql"
94
98
  f.reset %w{ debug_assertions trace_notify }
95
99
  end
96
100
 
97
- assert_equal([
98
- %{ALTER FUNCTION "my_function"(integer) RENAME TO "another_function";},
99
- %{ALTER FUNCTION "another_function"(integer) OWNER TO "jdoe";},
100
- %{ALTER FUNCTION "my_function"(integer) RENAME TO "another_function";
101
- ALTER FUNCTION "another_function"(integer) OWNER TO "jdoe";
102
- ALTER FUNCTION "another_function"(integer) SET SCHEMA "foo";
103
- ALTER FUNCTION "another_function"(integer) IMMUTABLE;
104
- ALTER FUNCTION "another_function"(integer) SECURITY INVOKER;
105
- ALTER FUNCTION "another_function"(integer) COST 10;
106
- ALTER FUNCTION "another_function"(integer) ROWS 10;
107
- ALTER FUNCTION "another_function"(integer) SET "log_duration" TO "0.4";
108
- ALTER FUNCTION "another_function"(integer) RESET ALL;
109
- ALTER FUNCTION "another_function"(integer) RESET "debug_assertions" RESET "trace_notify";}
110
- ], statements)
101
+ expected = [
102
+ %{ALTER FUNCTION "my_function"(integer) RENAME TO "another_function";},
103
+ %{ALTER FUNCTION "another_function"(integer) OWNER TO "jdoe";}
104
+ ]
105
+
106
+ expected << strip_heredoc(<<-SQL)
107
+ ALTER FUNCTION "my_function"(integer) RENAME TO "another_function";
108
+ ALTER FUNCTION "another_function"(integer) OWNER TO "jdoe";
109
+ ALTER FUNCTION "another_function"(integer) SET SCHEMA "foo";
110
+ ALTER FUNCTION "another_function"(integer) IMMUTABLE;
111
+ ALTER FUNCTION "another_function"(integer) SECURITY INVOKER;
112
+ ALTER FUNCTION "another_function"(integer) COST 10;
113
+ ALTER FUNCTION "another_function"(integer) ROWS 10;
114
+ ALTER FUNCTION "another_function"(integer) SET "log_duration" TO "0.4";
115
+ ALTER FUNCTION "another_function"(integer) RESET ALL;
116
+ ALTER FUNCTION "another_function"(integer) RESET "debug_assertions" RESET "trace_notify";
117
+ SQL
118
+
119
+ assert_equal(expected, statements)
111
120
  end
112
121
  end
@@ -3,9 +3,7 @@ $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
5
  if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0'
6
- class GeometryTests < MiniTest::Unit::TestCase
7
- include PostgreSQLExtensionsTestHelper
8
-
6
+ class GeometryTests < PostgreSQLExtensionsTestCase
9
7
  def test_create_geometry
10
8
  skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
11
9
 
@@ -13,13 +11,20 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
13
11
  t.geometry :the_geom, :srid => 4326
14
12
  end
15
13
 
16
- assert_equal([
17
- %{CREATE TABLE "foo" (
18
- "id" serial primary key,
19
- "the_geom" geometry(GEOMETRY, 4326)
20
- );},
21
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
22
- ], statements)
14
+ expected = []
15
+
16
+ expected << strip_heredoc(<<-SQL)
17
+ CREATE TABLE "foo" (
18
+ "id" serial primary key,
19
+ "the_geom" geometry(GEOMETRY, 4326)
20
+ );
21
+ SQL
22
+
23
+ expected << strip_heredoc(<<-SQL)
24
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
25
+ SQL
26
+
27
+ assert_equal(expected, statements)
23
28
  end
24
29
 
25
30
  def test_create_geometry_with_spatial
@@ -29,13 +34,20 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
29
34
  t.spatial :the_geom, :srid => 4326
30
35
  end
31
36
 
32
- assert_equal([
33
- %{CREATE TABLE "foo" (
34
- "id" serial primary key,
35
- "the_geom" geometry(GEOMETRY, 4326)
36
- );},
37
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
38
- ], statements)
37
+ expected = []
38
+
39
+ expected << strip_heredoc(<<-SQL)
40
+ CREATE TABLE "foo" (
41
+ "id" serial primary key,
42
+ "the_geom" geometry(GEOMETRY, 4326)
43
+ );
44
+ SQL
45
+
46
+ expected << strip_heredoc(<<-SQL)
47
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
48
+ SQL
49
+
50
+ assert_equal(expected, statements)
39
51
  end
40
52
 
41
53
  def test_create_geometry_with_spatial_and_spatial_column_type
@@ -45,13 +57,20 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
45
57
  t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
46
58
  end
47
59
 
48
- assert_equal([
49
- %{CREATE TABLE "foo" (
50
- "id" serial primary key,
51
- "the_geom" geography(GEOMETRY, 4326)
52
- );},
53
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
54
- ], statements)
60
+ expected = []
61
+
62
+ expected << strip_heredoc(<<-SQL)
63
+ CREATE TABLE "foo" (
64
+ "id" serial primary key,
65
+ "the_geom" geography(GEOMETRY, 4326)
66
+ );
67
+ SQL
68
+
69
+ expected << strip_heredoc(<<-SQL)
70
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
71
+ SQL
72
+
73
+ assert_equal(expected, statements)
55
74
  end
56
75
 
57
76
  def test_create_geography
@@ -61,13 +80,20 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
61
80
  t.geography :the_geom, :srid => 4326
62
81
  end
63
82
 
64
- assert_equal([
65
- %{CREATE TABLE "foo" (
66
- "id" serial primary key,
67
- "the_geom" geography(GEOMETRY, 4326)
68
- );},
69
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
70
- ], statements)
83
+ expected = []
84
+
85
+ expected << strip_heredoc(<<-SQL)
86
+ CREATE TABLE "foo" (
87
+ "id" serial primary key,
88
+ "the_geom" geography(GEOMETRY, 4326)
89
+ );
90
+ SQL
91
+
92
+ expected << strip_heredoc(<<-SQL)
93
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
94
+ SQL
95
+
96
+ assert_equal(expected, statements)
71
97
  end
72
98
 
73
99
  def test_create_geometry_with_force_constraints
@@ -77,15 +103,22 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
77
103
  t.geometry :the_geom, :srid => 4326, :force_constraints => true
78
104
  end
79
105
 
80
- assert_equal([
81
- %{CREATE TABLE "foo" (
82
- "id" serial primary key,
83
- "the_geom" geometry(GEOMETRY, 4326),
84
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
85
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
86
- );},
87
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
88
- ], statements)
106
+ expected = []
107
+
108
+ expected << strip_heredoc(<<-SQL)
109
+ CREATE TABLE "foo" (
110
+ "id" serial primary key,
111
+ "the_geom" geometry(GEOMETRY, 4326),
112
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
113
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
114
+ );
115
+ SQL
116
+
117
+ expected << strip_heredoc(<<-SQL)
118
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
119
+ SQL
120
+
121
+ assert_equal(expected, statements)
89
122
  end
90
123
 
91
124
  def test_create_geometry_with_schema
@@ -93,13 +126,20 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
93
126
  t.geometry :the_geom, :srid => 4326
94
127
  end
95
128
 
96
- assert_equal([
97
- %{CREATE TABLE "shabba"."foo" (
98
- "id" serial primary key,
99
- "the_geom" geometry(GEOMETRY, 4326)
100
- );},
101
- %{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
102
- ], statements)
129
+ expected = []
130
+
131
+ expected << strip_heredoc(<<-SQL)
132
+ CREATE TABLE "shabba"."foo" (
133
+ "id" serial primary key,
134
+ "the_geom" geometry(GEOMETRY, 4326)
135
+ );
136
+ SQL
137
+
138
+ expected << strip_heredoc(<<-SQL)
139
+ CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");
140
+ SQL
141
+
142
+ assert_equal(expected, statements)
103
143
  end
104
144
 
105
145
  def test_create_geometry_with_not_null
@@ -109,13 +149,20 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
109
149
  t.geometry :the_geom, :srid => 4326, :null => false
110
150
  end
111
151
 
112
- assert_equal([
113
- %{CREATE TABLE "foo" (
114
- "id" serial primary key,
115
- "the_geom" geometry(GEOMETRY, 4326) NOT NULL
116
- );},
117
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
118
- ], statements)
152
+ expected = []
153
+
154
+ expected << strip_heredoc(<<-SQL)
155
+ CREATE TABLE "foo" (
156
+ "id" serial primary key,
157
+ "the_geom" geometry(GEOMETRY, 4326) NOT NULL
158
+ );
159
+ SQL
160
+
161
+ expected << strip_heredoc(<<-SQL)
162
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
163
+ SQL
164
+
165
+ assert_equal(expected, statements)
119
166
  end
120
167
 
121
168
  def test_create_geometry_with_null_and_type
@@ -125,13 +172,20 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
125
172
  t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
126
173
  end
127
174
 
128
- assert_equal([
129
- %{CREATE TABLE "foo" (
130
- "id" serial primary key,
131
- "the_geom" geometry(POLYGON, 4326)
132
- );},
133
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
134
- ], statements)
175
+ expected = []
176
+
177
+ expected << strip_heredoc(<<-SQL)
178
+ CREATE TABLE "foo" (
179
+ "id" serial primary key,
180
+ "the_geom" geometry(POLYGON, 4326)
181
+ );
182
+ SQL
183
+
184
+ expected << strip_heredoc(<<-SQL)
185
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
186
+ SQL
187
+
188
+ assert_equal(expected, statements)
135
189
  end
136
190
  end
137
191
  else
@@ -145,17 +199,30 @@ else
145
199
  t.geometry :the_geom, :srid => 4326
146
200
  end
147
201
 
148
- assert_equal([
149
- %{CREATE TABLE "foo" (
150
- "id" serial primary key,
151
- "the_geom" geometry,
152
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
153
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
154
- );},
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)
202
+ expected = []
203
+
204
+ expected << strip_heredoc(<<-SQL)
205
+ CREATE TABLE "foo" (
206
+ "id" serial primary key,
207
+ "the_geom" geometry,
208
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
209
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
210
+ );
211
+ SQL
212
+
213
+ expected << strip_heredoc(<<-SQL)
214
+ DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
215
+ SQL
216
+
217
+ expected << strip_heredoc(<<-SQL)
218
+ INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
219
+ SQL
220
+
221
+ expected << strip_heredoc(<<-SQL)
222
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
223
+ SQL
224
+
225
+ assert_equal(expected, statements)
159
226
  end
160
227
 
161
228
  def test_create_geometry_with_spatial
@@ -165,17 +232,30 @@ else
165
232
  t.spatial :the_geom, :srid => 4326
166
233
  end
167
234
 
168
- assert_equal([
169
- %{CREATE TABLE "foo" (
170
- "id" serial primary key,
171
- "the_geom" geometry,
172
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
173
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
174
- );},
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)
235
+ expected = []
236
+
237
+ expected << strip_heredoc(<<-SQL)
238
+ CREATE TABLE "foo" (
239
+ "id" serial primary key,
240
+ "the_geom" geometry,
241
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
242
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
243
+ );
244
+ SQL
245
+
246
+ expected << strip_heredoc(<<-SQL)
247
+ DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
248
+ SQL
249
+
250
+ expected << strip_heredoc(<<-SQL)
251
+ INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
252
+ SQL
253
+
254
+ expected << strip_heredoc(<<-SQL)
255
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
256
+ SQL
257
+
258
+ assert_equal(expected, statements)
179
259
  end
180
260
 
181
261
  def test_create_geometry_with_spatial_and_spatial_column_type
@@ -185,15 +265,22 @@ else
185
265
  t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
186
266
  end
187
267
 
188
- assert_equal([
189
- %{CREATE TABLE "foo" (
190
- "id" serial primary key,
191
- "the_geom" geography,
192
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
193
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
194
- );},
195
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
196
- ], statements)
268
+ expected = []
269
+
270
+ expected << strip_heredoc(<<-SQL)
271
+ CREATE TABLE "foo" (
272
+ "id" serial primary key,
273
+ "the_geom" geography,
274
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
275
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
276
+ );
277
+ SQL
278
+
279
+ expected << strip_heredoc(<<-SQL)
280
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
281
+ SQL
282
+
283
+ assert_equal(expected, statements)
197
284
  end
198
285
 
199
286
  def test_create_geography
@@ -203,15 +290,22 @@ else
203
290
  t.geography :the_geom, :srid => 4326
204
291
  end
205
292
 
206
- assert_equal([
207
- %{CREATE TABLE "foo" (
208
- "id" serial primary key,
209
- "the_geom" geography,
210
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
211
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
212
- );},
213
- %{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
214
- ], statements)
293
+ expected = []
294
+
295
+ expected << strip_heredoc(<<-SQL)
296
+ CREATE TABLE "foo" (
297
+ "id" serial primary key,
298
+ "the_geom" geography,
299
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
300
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
301
+ );
302
+ SQL
303
+
304
+ expected << strip_heredoc(<<-SQL)
305
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
306
+ SQL
307
+
308
+ assert_equal(expected, statements)
215
309
  end
216
310
 
217
311
  def test_create_geometry_with_schema
@@ -221,17 +315,30 @@ else
221
315
  t.geometry :the_geom, :srid => 4326
222
316
  end
223
317
 
224
- assert_equal([
225
- %{CREATE TABLE "shabba"."foo" (
226
- "id" serial primary key,
227
- "the_geom" geometry,
228
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
229
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
230
- );},
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)
318
+ expected = []
319
+
320
+ expected << strip_heredoc(<<-SQL)
321
+ CREATE TABLE "shabba"."foo" (
322
+ "id" serial primary key,
323
+ "the_geom" geometry,
324
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
325
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
326
+ );
327
+ SQL
328
+
329
+ expected << strip_heredoc(<<-SQL)
330
+ DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'shabba' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
331
+ SQL
332
+
333
+ expected << strip_heredoc(<<-SQL)
334
+ INSERT INTO "geometry_columns" VALUES ('', 'shabba', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
335
+ SQL
336
+
337
+ expected << strip_heredoc(<<-SQL)
338
+ CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");
339
+ SQL
340
+
341
+ assert_equal(expected, statements)
235
342
  end
236
343
 
237
344
  def test_create_geometry_with_not_null
@@ -241,17 +348,30 @@ else
241
348
  t.geometry :the_geom, :srid => 4326, :null => false
242
349
  end
243
350
 
244
- assert_equal([
245
- %{CREATE TABLE "foo" (
246
- "id" serial primary key,
247
- "the_geom" geometry NOT NULL,
248
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
249
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
250
- );},
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)
351
+ expected = []
352
+
353
+ expected << strip_heredoc(<<-SQL)
354
+ CREATE TABLE "foo" (
355
+ "id" serial primary key,
356
+ "the_geom" geometry NOT NULL,
357
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
358
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
359
+ );
360
+ SQL
361
+
362
+ expected << strip_heredoc(<<-SQL)
363
+ DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
364
+ SQL
365
+
366
+ expected << strip_heredoc(<<-SQL)
367
+ INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
368
+ SQL
369
+
370
+ expected << strip_heredoc(<<-SQL)
371
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
372
+ SQL
373
+
374
+ assert_equal(expected, statements)
255
375
  end
256
376
 
257
377
  def test_create_geometry_with_null_and_type
@@ -261,18 +381,31 @@ else
261
381
  t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
262
382
  end
263
383
 
264
- assert_equal([
265
- %{CREATE TABLE "foo" (
266
- "id" serial primary key,
267
- "the_geom" geometry,
268
- CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
269
- CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2),
270
- CONSTRAINT "enforce_geotype_the_geom" CHECK (geometrytype("the_geom") = 'POLYGON'::text OR "the_geom" IS NULL)
271
- );},
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)
384
+ expected = []
385
+
386
+ expected << strip_heredoc(<<-SQL)
387
+ CREATE TABLE "foo" (
388
+ "id" serial primary key,
389
+ "the_geom" geometry,
390
+ CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
391
+ CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2),
392
+ CONSTRAINT "enforce_geotype_the_geom" CHECK (geometrytype("the_geom") = 'POLYGON'::text OR "the_geom" IS NULL)
393
+ );
394
+ SQL
395
+
396
+ expected << strip_heredoc(<<-SQL)
397
+ DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
398
+ SQL
399
+
400
+ expected << strip_heredoc(<<-SQL)
401
+ INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'POLYGON');
402
+ SQL
403
+
404
+ expected << strip_heredoc(<<-SQL)
405
+ CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
406
+ SQL
407
+
408
+ assert_equal(expected, statements)
276
409
  end
277
410
  end
278
411
  end