activerecord-postgresql-extensions 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/MIT-LICENSE +23 -0
  2. data/README.rdoc +32 -0
  3. data/Rakefile +42 -0
  4. data/VERSION +1 -0
  5. data/lib/activerecord-postgresql-extensions.rb +30 -0
  6. data/lib/postgresql_extensions/foreign_key_associations.rb +367 -0
  7. data/lib/postgresql_extensions/postgresql_adapter_extensions.rb +646 -0
  8. data/lib/postgresql_extensions/postgresql_constraints.rb +579 -0
  9. data/lib/postgresql_extensions/postgresql_functions.rb +345 -0
  10. data/lib/postgresql_extensions/postgresql_geometry.rb +212 -0
  11. data/lib/postgresql_extensions/postgresql_indexes.rb +219 -0
  12. data/lib/postgresql_extensions/postgresql_languages.rb +80 -0
  13. data/lib/postgresql_extensions/postgresql_permissions.rb +322 -0
  14. data/lib/postgresql_extensions/postgresql_rules.rb +112 -0
  15. data/lib/postgresql_extensions/postgresql_schemas.rb +49 -0
  16. data/lib/postgresql_extensions/postgresql_sequences.rb +222 -0
  17. data/lib/postgresql_extensions/postgresql_tables.rb +308 -0
  18. data/lib/postgresql_extensions/postgresql_triggers.rb +131 -0
  19. data/lib/postgresql_extensions/postgresql_types.rb +17 -0
  20. data/lib/postgresql_extensions/postgresql_views.rb +103 -0
  21. data/postgresql-extensions.gemspec +50 -0
  22. data/test/adapter_test.rb +45 -0
  23. data/test/constraints_test.rb +98 -0
  24. data/test/functions_test.rb +112 -0
  25. data/test/geometry_test.rb +43 -0
  26. data/test/index_test.rb +68 -0
  27. data/test/languages_test.rb +48 -0
  28. data/test/permissions_test.rb +163 -0
  29. data/test/rules_test.rb +32 -0
  30. data/test/schemas_test.rb +43 -0
  31. data/test/sequences_test.rb +90 -0
  32. data/test/tables_test.rb +49 -0
  33. data/test/test_helper.rb +64 -0
  34. metadata +97 -0
@@ -0,0 +1,43 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class SchemasTests < Test::Unit::TestCase
6
+ include PostgreSQLExtensionsTestHelper
7
+
8
+ def test_create_schema
9
+ Mig.create_schema(:foo)
10
+ Mig.create_schema(:foo, :authorization => 'bar')
11
+
12
+ assert_equal([
13
+ "CREATE SCHEMA \"foo\"",
14
+ "CREATE SCHEMA \"foo\" AUTHORIZATION \"bar\""
15
+ ], statements)
16
+ end
17
+
18
+ def test_drop_schema
19
+ Mig.drop_schema(:foo)
20
+ Mig.drop_schema(:foo, :if_exists => true, :cascade => true)
21
+
22
+ assert_equal([
23
+ "DROP SCHEMA \"foo\"",
24
+ "DROP SCHEMA IF EXISTS \"foo\" CASCADE"
25
+ ], statements)
26
+ end
27
+
28
+ def test_alter_schema_name
29
+ Mig.alter_schema_name(:foo, :bar)
30
+
31
+ assert_equal([
32
+ "ALTER SCHEMA \"foo\" RENAME TO \"bar\""
33
+ ], statements)
34
+ end
35
+
36
+ def test_alter_schema_owner
37
+ Mig.alter_schema_owner(:foo, :bar)
38
+
39
+ assert_equal([
40
+ "ALTER SCHEMA \"foo\" OWNER TO \"bar\""
41
+ ], statements)
42
+ end
43
+ end
@@ -0,0 +1,90 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class SequenceTests < Test::Unit::TestCase
6
+ include PostgreSQLExtensionsTestHelper
7
+
8
+ def test_create_sequence
9
+ Mig.create_sequence(
10
+ 'what_a_sequence_of_events',
11
+ :start => 10
12
+ )
13
+
14
+ Mig.create_sequence(
15
+ 'what_a_sequence_of_events',
16
+ :increment => 2,
17
+ :cache => 2,
18
+ :min_value => nil,
19
+ :max_value => 10,
20
+ :owned_by => [ :foo, :id ]
21
+ )
22
+
23
+ assert_equal([
24
+ "CREATE SEQUENCE \"what_a_sequence_of_events\" START WITH 10",
25
+ "CREATE SEQUENCE \"what_a_sequence_of_events\" INCREMENT BY 2 NO MINVALUE MAXVALUE 10 CACHE 2 OWNED BY \"foo\".\"id\""
26
+ ], statements)
27
+ end
28
+
29
+ def test_drop_sequence
30
+ Mig.drop_sequence(
31
+ :foo_id_seq,
32
+ :if_exists => true,
33
+ :cascade => true
34
+ )
35
+
36
+ assert_equal([
37
+ "DROP SEQUENCE IF EXISTS \"foo_id_seq\" CASCADE"
38
+ ], statements)
39
+ end
40
+
41
+ def test_rename_sequence
42
+ Mig.rename_sequence(:foo, :bar)
43
+
44
+ assert_equal([
45
+ 'ALTER SEQUENCE "foo" RENAME TO "bar"'
46
+ ], statements)
47
+ end
48
+
49
+ def test_alter_sequence_schema
50
+ Mig.alter_sequence_schema(:foo, :bar)
51
+ Mig.alter_sequence_schema(:foo, :public)
52
+
53
+ assert_equal([
54
+ 'ALTER SEQUENCE "foo" SET SCHEMA "bar"',
55
+ 'ALTER SEQUENCE "foo" SET SCHEMA PUBLIC',
56
+ ], statements)
57
+ end
58
+
59
+ def test_set_sequence_value
60
+ Mig.set_sequence_value(:foo, 42)
61
+ Mig.set_sequence_value(:foo, 42, :is_called => false)
62
+
63
+ assert_equal([
64
+ "SELECT setval('foo', 42, true)",
65
+ "SELECT setval('foo', 42, false)"
66
+ ], statements)
67
+ end
68
+
69
+ def test_create_sequence
70
+ Mig.alter_sequence(
71
+ 'what_a_sequence_of_events',
72
+ :restart_with => 10
73
+ )
74
+
75
+ Mig.alter_sequence(
76
+ 'what_a_sequence_of_events',
77
+ :start => 10,
78
+ :increment => 2,
79
+ :cache => 2,
80
+ :min_value => nil,
81
+ :max_value => 10,
82
+ :owned_by => [ :foo, :id ]
83
+ )
84
+
85
+ assert_equal([
86
+ "ALTER SEQUENCE \"what_a_sequence_of_events\" RESTART WITH 10",
87
+ "ALTER SEQUENCE \"what_a_sequence_of_events\" INCREMENT BY 2 NO MINVALUE MAXVALUE 10 START WITH 10 CACHE 2 OWNED BY \"foo\".\"id\""
88
+ ], statements)
89
+ end
90
+ end
@@ -0,0 +1,49 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class TablesTests < Test::Unit::TestCase
6
+ include PostgreSQLExtensionsTestHelper
7
+
8
+ def test_foreign_key_in_column_definition
9
+ Mig.create_table('foo') do |t|
10
+ t.integer :foo_id, :references => {
11
+ :table => :foo,
12
+ :on_delete => :set_null,
13
+ :on_update => :cascade
14
+ }
15
+
16
+ t.integer :bar_id, :references => :bar
17
+
18
+ t.integer :baz_id, :references => [ :baz ]
19
+
20
+ t.foreign_key [ :schabba_id, :doo_id ], :bar, [ :schabba_id, :doo_id ]
21
+ end
22
+
23
+ assert_equal([
24
+ %{CREATE TABLE "foo" (
25
+ "id" serial primary key,
26
+ "foo_id" integer,
27
+ "bar_id" integer,
28
+ "baz_id" integer,
29
+ FOREIGN KEY ("foo_id") REFERENCES "foo" ON DELETE SET NULL ON UPDATE CASCADE,
30
+ FOREIGN KEY ("bar_id") REFERENCES "bar",
31
+ FOREIGN KEY ("baz_id") REFERENCES "baz",
32
+ FOREIGN KEY ("schabba_id", "doo_id") REFERENCES "bar" ("schabba_id", "doo_id")
33
+ )} ], statements)
34
+ end
35
+
36
+ def test_default_with_expression
37
+ Mig.create_table('foo') do |t|
38
+ t.integer :foo_id, :default => { :expression => '1 + 1' }
39
+ t.integer :bar_id, :default => '1 + 1'
40
+ end
41
+
42
+ assert_equal([
43
+ %{CREATE TABLE "foo" (
44
+ "id" serial primary key,
45
+ "foo_id" integer DEFAULT 1 + 1,
46
+ "bar_id" integer DEFAULT '1 + 1'
47
+ )} ], statements)
48
+ end
49
+ end
@@ -0,0 +1,64 @@
1
+
2
+ ACTIVERECORD_GEM_VERSION = ENV['ACTIVERECORD_GEM_VERSION'] || '~> 3.0.3'
3
+
4
+ require 'rubygems'
5
+ gem 'activerecord', ACTIVERECORD_GEM_VERSION
6
+
7
+ require 'active_record'
8
+ require 'test/unit'
9
+ require File.join(File.dirname(__FILE__), *%w{ .. lib activerecord-postgresql-extensions })
10
+
11
+ puts "Testing against ActiveRecord #{Gem.loaded_specs['activerecord'].version.to_s}"
12
+
13
+ ActiveRecord::Base.configurations = {
14
+ 'arunit' => {
15
+ :adapter => 'postgresql',
16
+ :database => 'postgresql_extensions_unit_tests',
17
+ :min_messages => 'warning'
18
+ }
19
+ }
20
+
21
+ ActiveRecord::Base.establish_connection 'arunit'
22
+ #ActiveRecord::Base.connection.drop_database('postgresql_extensions_unit_tests')
23
+ #ActiveRecord::Base.connection.create_database('postgresql_extensions_unit_tests')
24
+
25
+ ARBC = ActiveRecord::Base.connection
26
+
27
+ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
28
+ def statements
29
+ @statements ||= []
30
+ end
31
+
32
+ def execute_with_statement_capture(sql, name = nil)
33
+ statements << sql
34
+ #execute_without_statement_capture(sql, name)
35
+ end
36
+ alias_method_chain :execute, :statement_capture
37
+
38
+ def query_with_statement_capture(sql, name = nil)
39
+ statements << sql
40
+ #query_without_statement_capture(sql, name)
41
+ end
42
+ alias_method_chain :query, :statement_capture
43
+
44
+ def clear_statements!
45
+ @statements = []
46
+ end
47
+ end
48
+
49
+ module PostgreSQLExtensionsTestHelper
50
+ def clear_statements!
51
+ ActiveRecord::Base.connection.clear_statements!
52
+ end
53
+
54
+ def statements
55
+ ActiveRecord::Base.connection.statements
56
+ end
57
+
58
+ def setup
59
+ clear_statements!
60
+ end
61
+ end
62
+
63
+ class Mig < ActiveRecord::Migration
64
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-postgresql-extensions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 7
10
+ version: 0.0.7
11
+ platform: ruby
12
+ authors:
13
+ - J Smith
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-28 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: A whole bunch of extensions the ActiveRecord PostgreSQL adapter.
22
+ email: code@zoocasa.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ files:
30
+ - MIT-LICENSE
31
+ - README.rdoc
32
+ - Rakefile
33
+ - VERSION
34
+ - lib/activerecord-postgresql-extensions.rb
35
+ - lib/postgresql_extensions/foreign_key_associations.rb
36
+ - lib/postgresql_extensions/postgresql_adapter_extensions.rb
37
+ - lib/postgresql_extensions/postgresql_constraints.rb
38
+ - lib/postgresql_extensions/postgresql_functions.rb
39
+ - lib/postgresql_extensions/postgresql_geometry.rb
40
+ - lib/postgresql_extensions/postgresql_indexes.rb
41
+ - lib/postgresql_extensions/postgresql_languages.rb
42
+ - lib/postgresql_extensions/postgresql_permissions.rb
43
+ - lib/postgresql_extensions/postgresql_rules.rb
44
+ - lib/postgresql_extensions/postgresql_schemas.rb
45
+ - lib/postgresql_extensions/postgresql_sequences.rb
46
+ - lib/postgresql_extensions/postgresql_tables.rb
47
+ - lib/postgresql_extensions/postgresql_triggers.rb
48
+ - lib/postgresql_extensions/postgresql_types.rb
49
+ - lib/postgresql_extensions/postgresql_views.rb
50
+ - postgresql-extensions.gemspec
51
+ - test/adapter_test.rb
52
+ - test/constraints_test.rb
53
+ - test/functions_test.rb
54
+ - test/geometry_test.rb
55
+ - test/index_test.rb
56
+ - test/languages_test.rb
57
+ - test/permissions_test.rb
58
+ - test/rules_test.rb
59
+ - test/schemas_test.rb
60
+ - test/sequences_test.rb
61
+ - test/tables_test.rb
62
+ - test/test_helper.rb
63
+ homepage: http://github.com/zoocasa/activerecord-postgresql-extensions
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.7.2
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A whole bunch of extensions the ActiveRecord PostgreSQL adapter.
96
+ test_files: []
97
+