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.
data/test/index_tests.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class IndexTests < Test::Unit::TestCase
5
+ class IndexTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_index
@@ -57,12 +57,22 @@ class IndexTests < Test::Unit::TestCase
57
57
  Mig.drop_index(:foo_names_idx)
58
58
  Mig.drop_index(:foo_names_idx, :if_exists => true)
59
59
  Mig.drop_index(:foo_names_idx, :cascade => true)
60
+ Mig.drop_index(:foo_names_idx, :concurrently => true)
60
61
 
61
62
  assert_equal([
62
63
  "DROP INDEX \"foo_names_idx\";",
63
64
  "DROP INDEX IF EXISTS \"foo_names_idx\";",
64
- "DROP INDEX \"foo_names_idx\" CASCADE;"
65
+ "DROP INDEX \"foo_names_idx\" CASCADE;",
66
+ "DROP INDEX CONCURRENTLY \"foo_names_idx\";"
65
67
  ], statements)
68
+
69
+ assert_raises(ArgumentError) do
70
+ ARBC.drop_index([ :foo_idx, :bar_idx ], :concurrently => true)
71
+ end
72
+
73
+ assert_raises(ArgumentError) do
74
+ Mig.drop_index(:foo_idx, :concurrently => true, :cascade => true)
75
+ end
66
76
  end
67
77
 
68
78
  def test_rename_index
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class LanguagesTests < Test::Unit::TestCase
5
+ class LanguagesTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_language
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class PermissionsTests < Test::Unit::TestCase
5
+ class PermissionsTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_grant_table_privileges
@@ -11,13 +11,15 @@ class PermissionsTests < Test::Unit::TestCase
11
11
  Mig.grant_table_privileges(:foo, :select, :nobody, :with_grant_option => true)
12
12
  Mig.grant_table_privileges(:foo, :select, :nobody, :cascade => true)
13
13
  Mig.grant_table_privileges(:foo, :select, :public, :cascade => true)
14
+ Mig.grant_table_privileges(:foo, :select, :nobody, :all => true)
14
15
 
15
16
  assert_equal([
16
17
  "GRANT SELECT ON TABLE \"foo\" TO \"nobody\";",
17
18
  "GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE \"foo\" TO \"nobody\", \"somebody\";",
18
19
  "GRANT SELECT ON TABLE \"foo\" TO \"nobody\" WITH GRANT OPTION;",
19
20
  "GRANT SELECT ON TABLE \"foo\" TO \"nobody\";",
20
- "GRANT SELECT ON TABLE \"foo\" TO PUBLIC;"
21
+ "GRANT SELECT ON TABLE \"foo\" TO PUBLIC;",
22
+ "GRANT SELECT ON ALL TABLES IN SCHEMA \"foo\" TO \"nobody\";"
21
23
  ], statements)
22
24
  end
23
25
 
@@ -27,53 +29,63 @@ class PermissionsTests < Test::Unit::TestCase
27
29
  Mig.revoke_table_privileges(:foo, :select, :nobody, :with_grant_option => true)
28
30
  Mig.revoke_table_privileges(:foo, :select, :nobody, :cascade => true)
29
31
  Mig.revoke_table_privileges(:foo, :select, :public, :cascade => true)
32
+ Mig.revoke_table_privileges(:foo, :select, :nobody, :all => true)
30
33
 
31
34
  assert_equal([
32
35
  "REVOKE SELECT ON TABLE \"foo\" FROM \"nobody\";",
33
36
  "REVOKE SELECT, UPDATE, DELETE, INSERT ON TABLE \"foo\" FROM \"nobody\", \"somebody\";",
34
37
  "REVOKE SELECT ON TABLE \"foo\" FROM \"nobody\";",
35
38
  "REVOKE SELECT ON TABLE \"foo\" FROM \"nobody\" CASCADE;",
36
- "REVOKE SELECT ON TABLE \"foo\" FROM PUBLIC CASCADE;"
39
+ "REVOKE SELECT ON TABLE \"foo\" FROM PUBLIC CASCADE;",
40
+ "REVOKE SELECT ON ALL TABLES IN SCHEMA \"foo\" FROM \"nobody\";"
37
41
  ], statements)
38
42
  end
39
43
 
40
44
  def test_grant_sequence_privileges
41
45
  Mig.grant_sequence_privileges(:foo, :select, :nobody)
42
46
  Mig.grant_sequence_privileges(:foo, [ :select, :update ], [ :nobody, :somebody ])
47
+ Mig.grant_sequence_privileges(:foo, :select, :nobody, :all => true)
43
48
 
44
49
  assert_equal([
45
50
  "GRANT SELECT ON SEQUENCE \"foo\" TO \"nobody\";",
46
- "GRANT SELECT, UPDATE ON SEQUENCE \"foo\" TO \"nobody\", \"somebody\";"
51
+ "GRANT SELECT, UPDATE ON SEQUENCE \"foo\" TO \"nobody\", \"somebody\";",
52
+ "GRANT SELECT ON ALL SEQUENCES IN SCHEMA \"foo\" TO \"nobody\";"
47
53
  ], statements)
48
54
  end
49
55
 
50
56
  def test_revoke_sequence_privileges
51
57
  Mig.revoke_sequence_privileges(:foo, :select, :nobody)
52
58
  Mig.revoke_sequence_privileges(:foo, [ :select, :update ], [ :nobody, :somebody ])
59
+ Mig.revoke_sequence_privileges(:foo, :select, :nobody, :all => true)
53
60
 
54
61
  assert_equal([
55
62
  "REVOKE SELECT ON SEQUENCE \"foo\" FROM \"nobody\";",
56
- "REVOKE SELECT, UPDATE ON SEQUENCE \"foo\" FROM \"nobody\", \"somebody\";"
63
+ "REVOKE SELECT, UPDATE ON SEQUENCE \"foo\" FROM \"nobody\", \"somebody\";",
64
+ "REVOKE SELECT ON ALL SEQUENCES IN SCHEMA \"foo\" FROM \"nobody\";"
57
65
  ], statements)
58
66
  end
59
67
 
60
68
  def test_grant_function_privileges
61
69
  Mig.grant_function_privileges('test(text, integer)', :execute, :nobody)
62
70
  Mig.grant_function_privileges('test(text, integer)', :all, [ :nobody, :somebody ])
71
+ Mig.grant_function_privileges(:foo, :execute, :nobody, :all => true)
63
72
 
64
73
  assert_equal([
65
74
  "GRANT EXECUTE ON FUNCTION test(text, integer) TO \"nobody\";",
66
- "GRANT ALL ON FUNCTION test(text, integer) TO \"nobody\", \"somebody\";"
75
+ "GRANT ALL ON FUNCTION test(text, integer) TO \"nobody\", \"somebody\";",
76
+ "GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA \"foo\" TO \"nobody\";",
67
77
  ], statements)
68
78
  end
69
79
 
70
80
  def test_revoke_function_privileges
71
81
  Mig.revoke_function_privileges('test(text, integer)', :execute, :nobody)
72
82
  Mig.revoke_function_privileges('test(text, integer)', :all, [ :nobody, :somebody ])
83
+ Mig.revoke_function_privileges(:foo, :execute, :nobody, :all => true)
73
84
 
74
85
  assert_equal([
75
86
  "REVOKE EXECUTE ON FUNCTION test(text, integer) FROM \"nobody\";",
76
- "REVOKE ALL ON FUNCTION test(text, integer) FROM \"nobody\", \"somebody\";"
87
+ "REVOKE ALL ON FUNCTION test(text, integer) FROM \"nobody\", \"somebody\";",
88
+ "REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA \"foo\" FROM \"nobody\";",
77
89
  ], statements)
78
90
  end
79
91
 
data/test/roles_tests.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class RolesTests < Test::Unit::TestCase
5
+ class RolesTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_role
data/test/rules_tests.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class RulesTests < Test::Unit::TestCase
5
+ class RulesTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_rule
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class SchemasTests < Test::Unit::TestCase
5
+ class SchemasTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_schema
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class SequenceTests < Test::Unit::TestCase
5
+ class SequenceTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_sequence
data/test/tables_tests.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class TablesTests < Test::Unit::TestCase
5
+ class TablesTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_default_with_expression
@@ -99,8 +99,22 @@ class TablesTests < Test::Unit::TestCase
99
99
  Mig.create_table('foo', :of_type => 'bar')
100
100
 
101
101
  assert_equal([
102
- %{CREATE TABLE "foo" OF "bar" (\n "id" serial primary key\n);}
102
+ %{CREATE TABLE "foo" OF "bar";}
103
103
  ], statements)
104
+
105
+ assert_raises(ArgumentError) do
106
+ Mig.create_table('foo', :of_type => 'bar') do |t|
107
+ t.integer :what
108
+ end
109
+ end
110
+
111
+ assert_raises(ArgumentError) do
112
+ Mig.create_table('foo', :of_type => 'bar', :like => :something)
113
+ end
114
+
115
+ assert_raises(ArgumentError) do
116
+ Mig.create_table('foo', :of_type => 'bar', :inherits => :something)
117
+ end
104
118
  end
105
119
 
106
120
  def test_exclude_constraint
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class TablespaceTests < Test::Unit::TestCase
5
+ class TablespaceTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_tablespace
data/test/test_helper.rb CHANGED
@@ -5,7 +5,8 @@ require 'rubygems'
5
5
  gem 'activerecord', ACTIVERECORD_GEM_VERSION
6
6
 
7
7
  require 'active_record'
8
- require 'test/unit'
8
+ require 'minitest/autorun'
9
+ require 'turn'
9
10
  require 'logger'
10
11
  require File.join(File.dirname(__FILE__), *%w{ .. lib activerecord-postgresql-extensions })
11
12
 
@@ -37,8 +38,8 @@ ActiveRecord::Base.establish_connection 'arunit'
37
38
  ARBC = ActiveRecord::Base.connection
38
39
 
39
40
  puts "Testing against ActiveRecord #{Gem.loaded_specs['activerecord'].version.to_s}"
40
- if postgresql_version = ARBC.select_rows('SELECT version()').first.first
41
- puts "PostgreSQL info from version(): #{postgresql_version}"
41
+ if postgresql_version = ActiveRecord::PostgreSQLExtensions.SERVER_VERSION
42
+ puts "PostgreSQL info from pg_catalog.version(): #{postgresql_version}"
42
43
  end
43
44
 
44
45
  if postgis_version = ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib]
@@ -110,8 +111,22 @@ module PostgreSQLExtensionsTestHelper
110
111
  end
111
112
  end
112
113
 
114
+ class ActiveRecord::Migration
115
+ def say(*args)
116
+ # no-op -- we just want it to be quiet.
117
+ end
118
+ end
119
+
113
120
  class Mig < ActiveRecord::Migration
114
121
  end
115
122
 
116
123
  class Foo < ActiveRecord::Base
117
124
  end
125
+
126
+ if ENV['autotest']
127
+ module Turn::Colorize
128
+ def self.color_supported?
129
+ true
130
+ end
131
+ end
132
+ end
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class TextSearchTests < Test::Unit::TestCase
5
+ class TextSearchTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_create_text_search_configuration
@@ -16,11 +16,11 @@ class TextSearchTests < Test::Unit::TestCase
16
16
  "CREATE TEXT SEARCH CONFIGURATION \"foo\" (COPY = \"pg_catalog\".\"english\");"
17
17
  ], statements)
18
18
 
19
- assert_raise(ArgumentError) do
19
+ assert_raises(ArgumentError) do
20
20
  ARBC.create_text_search_configuration(:foo)
21
21
  end
22
22
 
23
- assert_raise(ArgumentError) do
23
+ assert_raises(ArgumentError) do
24
24
  ARBC.create_text_search_configuration(:foo, :parser_name => 'bar', :source_config => 'lolwut')
25
25
  end
26
26
  end
@@ -74,11 +74,11 @@ class TextSearchTests < Test::Unit::TestCase
74
74
  "ALTER TEXT SEARCH CONFIGURATION \"foo\" DROP MAPPING IF EXISTS FOR \"bar\";"
75
75
  ], statements)
76
76
 
77
- assert_raise(ArgumentError) do
77
+ assert_raises(ArgumentError) do
78
78
  ARBC.drop_text_search_configuration_mapping(:foo)
79
79
  end
80
80
 
81
- assert_raise(ArgumentError) do
81
+ assert_raises(ArgumentError) do
82
82
  ARBC.drop_text_search_configuration_mapping(:foo, :if_exists => true)
83
83
  end
84
84
  end
@@ -174,7 +174,7 @@ class TextSearchTests < Test::Unit::TestCase
174
174
  "CREATE TEXT SEARCH TEMPLATE \"foo\" (INIT = \"lol\", LEXIZE = \"bar\");"
175
175
  ], statements)
176
176
 
177
- assert_raise(ArgumentError) do
177
+ assert_raises(ArgumentError) do
178
178
  ARBC.create_text_search_template(:foo)
179
179
  end
180
180
  end
@@ -228,7 +228,7 @@ class TextSearchTests < Test::Unit::TestCase
228
228
  "CREATE TEXT SEARCH PARSER \"foo\" (START = \"start\", GETTOKEN = \"gettoken\", END = \"end\", LEXTYPES = \"lextypes\", HEADLINE = \"headline\");"
229
229
  ], statements)
230
230
 
231
- assert_raise(ArgumentError) do
231
+ assert_raises(ArgumentError) do
232
232
  ARBC.create_text_search_parser(:foo)
233
233
  end
234
234
  end
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class TriggerTests < Test::Unit::TestCase
5
+ class TriggerTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLExtensionsTestHelper
7
7
 
8
8
  def test_enable_triggers
@@ -0,0 +1,39 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class VacuumTests < MiniTest::Unit::TestCase
6
+ include PostgreSQLExtensionsTestHelper
7
+
8
+ def test_vacuum
9
+ ARBC.vacuum
10
+ ARBC.vacuum(:full => true, :freeze => true, :verbose => true, :analyze => true)
11
+ ARBC.vacuum(:foo, :full => true, :freeze => true, :verbose => true, :analyze => true)
12
+ ARBC.vacuum(:foo, :columns => :bar)
13
+ ARBC.vacuum(:foo, :columns => [ :bar, :baz ])
14
+
15
+ if ActiveRecord::PostgreSQLExtensions.SERVER_VERSION.to_f >= 9.0
16
+ assert_equal([
17
+ %{VACUUM;},
18
+ %{VACUUM (FULL, FREEZE, VERBOSE, ANALYZE);},
19
+ %{VACUUM (FULL, FREEZE, VERBOSE, ANALYZE) "foo";},
20
+ %{VACUUM (ANALYZE) "foo" ("bar");},
21
+ %{VACUUM (ANALYZE) "foo" ("bar", "baz");}
22
+ ], statements)
23
+ else
24
+ assert_equal([
25
+ "VACUUM;",
26
+ %{VACUUM FULL FREEZE VERBOSE ANALYZE;},
27
+ %{VACUUM FULL FREEZE VERBOSE ANALYZE "foo";},
28
+ %{VACUUM ANALYZE "foo" ("bar");},
29
+ %{VACUUM ANALYZE "foo" ("bar", "baz");}
30
+ ], statements)
31
+ end
32
+ end
33
+
34
+ def test_vacuum_with_columns_but_no_table
35
+ assert_raises(ArgumentError) do
36
+ ARBC.vacuum(:columns => :bar)
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgresql-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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-08-16 00:00:00.000000000 Z
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -75,6 +75,38 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0.9'
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: turn
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
78
110
  description: A whole bunch of extensions the ActiveRecord PostgreSQL adapter.
79
111
  email: code@zoocasa.com
80
112
  executables: []
@@ -91,6 +123,7 @@ files:
91
123
  - lib/active_record/postgresql_extensions/adapter_extensions.rb
92
124
  - lib/active_record/postgresql_extensions/constraints.rb
93
125
  - lib/active_record/postgresql_extensions/extensions.rb
126
+ - lib/active_record/postgresql_extensions/features.rb
94
127
  - lib/active_record/postgresql_extensions/foreign_key_associations.rb
95
128
  - lib/active_record/postgresql_extensions/functions.rb
96
129
  - lib/active_record/postgresql_extensions/geometry.rb
@@ -108,6 +141,7 @@ files:
108
141
  - lib/active_record/postgresql_extensions/triggers.rb
109
142
  - lib/active_record/postgresql_extensions/types.rb
110
143
  - lib/active_record/postgresql_extensions/utils.rb
144
+ - lib/active_record/postgresql_extensions/vacuum.rb
111
145
  - lib/active_record/postgresql_extensions/version.rb
112
146
  - lib/active_record/postgresql_extensions/views.rb
113
147
  - lib/activerecord-postgresql-extensions.rb
@@ -129,6 +163,7 @@ files:
129
163
  - test/test_helper.rb
130
164
  - test/text_search_tests.rb
131
165
  - test/trigger_tests.rb
166
+ - test/vacuum_tests.rb
132
167
  homepage: http://github.com/zoocasa/activerecord-postgresql-extensions
133
168
  licenses: []
134
169
  post_install_message:
@@ -172,3 +207,4 @@ test_files:
172
207
  - test/test_helper.rb
173
208
  - test/text_search_tests.rb
174
209
  - test/trigger_tests.rb
210
+ - test/vacuum_tests.rb