pg_comment 0.1.2 → 0.2.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.
- checksums.yaml +15 -0
- data/.gitignore +5 -1
- data/.rspec +2 -0
- data/README.markdown +16 -13
- data/Rakefile +37 -5
- data/lib/pg_comment/connection_adapters/abstract/schema_statements.rb +10 -0
- data/lib/pg_comment/connection_adapters/postgresql_adapter.rb +24 -0
- data/lib/pg_comment/migration/command_recorder.rb +15 -2
- data/lib/pg_comment/schema_dumper.rb +6 -0
- data/lib/pg_comment/version.rb +1 -1
- data/pg_comment.gemspec +3 -1
- data/spec/comments_spec.rb +42 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +60 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +12 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20130502030557_create_vegetables.rb +23 -0
- data/spec/dummy/db/schema.rb +31 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/lib/pg_comment/connection_adapters/abstract/schema_definitions_spec.rb +46 -0
- data/spec/lib/pg_comment/connection_adapters/abstract/schema_statements_spec.rb +25 -0
- data/spec/lib/pg_comment/connection_adapters/postgresql_adapter_spec.rb +63 -0
- data/spec/lib/pg_comment/migration/command_recorder_spec.rb +40 -0
- data/spec/lib/pg_comment/schema_dumper_spec.rb +23 -0
- data/spec/spec_helper.rb +16 -0
- metadata +75 -16
- data/test/fake_connection.rb +0 -9
- data/test/postgre_sql_adapter_test.rb +0 -91
- data/test/schema_dumper_test.rb +0 -42
- data/test/test_helper.rb +0 -16
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PostgreSQLAdapterTest < Test::Unit::TestCase
|
4
|
-
class Adapter
|
5
|
-
attr_reader :buffer
|
6
|
-
def select_results=(val)
|
7
|
-
@select_results = val
|
8
|
-
end
|
9
|
-
|
10
|
-
def select_all(*args)
|
11
|
-
@select_results
|
12
|
-
end
|
13
|
-
|
14
|
-
def quote_table_name(table_name)
|
15
|
-
table_name
|
16
|
-
end
|
17
|
-
|
18
|
-
def quote_column_name(column_name)
|
19
|
-
column_name
|
20
|
-
end
|
21
|
-
|
22
|
-
def execute(sql)
|
23
|
-
@buffer ||= []
|
24
|
-
@buffer << sql
|
25
|
-
end
|
26
|
-
|
27
|
-
include PgComment::ConnectionAdapters::PostgreSQLAdapter
|
28
|
-
end
|
29
|
-
|
30
|
-
def setup
|
31
|
-
@adapter = Adapter.new
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_table_comments_sql
|
35
|
-
expected = [ "COMMENT ON TABLE my_table IS $$table comment$$;",
|
36
|
-
"COMMENT ON TABLE my_table IS NULL;" ]
|
37
|
-
@adapter.set_table_comment :my_table, 'table comment'
|
38
|
-
@adapter.remove_table_comment :my_table
|
39
|
-
assert_equal expected, @adapter.buffer
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_column_comment_sql
|
43
|
-
expected = [ "COMMENT ON COLUMN my_table.my_column IS $$column comment$$;",
|
44
|
-
"COMMENT ON COLUMN my_table.my_column IS NULL;" ]
|
45
|
-
@adapter.set_column_comment :my_table, :my_column, 'column comment'
|
46
|
-
@adapter.remove_column_comment :my_table, :my_column
|
47
|
-
assert_equal expected, @adapter.buffer
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_column_comments_sql
|
51
|
-
expected = [ "COMMENT ON COLUMN my_table.column1 IS $$column comment 1$$;",
|
52
|
-
"COMMENT ON COLUMN my_table.column2 IS $$column comment 2$$;" ]
|
53
|
-
|
54
|
-
@adapter.set_column_comments :my_table, :column1 => 'column comment 1', :column2 => 'column comment 2'
|
55
|
-
assert_equal expected, @adapter.buffer
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_sql_generation
|
59
|
-
expected = [ "COMMENT ON TABLE my_table IS $$table comment$$;",
|
60
|
-
"COMMENT ON COLUMN my_table.my_column IS $$column comment$$;",
|
61
|
-
"COMMENT ON TABLE my_table IS NULL;",
|
62
|
-
"COMMENT ON COLUMN my_table.my_column IS NULL;" ]
|
63
|
-
|
64
|
-
@adapter.set_table_comment :my_table, 'table comment'
|
65
|
-
@adapter.set_column_comment :my_table, :my_column, 'column comment'
|
66
|
-
@adapter.remove_table_comment :my_table
|
67
|
-
@adapter.remove_column_comment :my_table, :my_column
|
68
|
-
assert_equal expected, @adapter.buffer
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_comments
|
72
|
-
expected = [ { 'column_name' => nil, 'comment' => 'table comment' },
|
73
|
-
{ 'column_name' => 'column1', 'comment' => 'column comment 1' },
|
74
|
-
{ 'column_name' => 'column2', 'comment' => 'column comment 2' } ]
|
75
|
-
@adapter.select_results = expected
|
76
|
-
results = @adapter.comments( nil )
|
77
|
-
assert_not_nil results
|
78
|
-
assert_equal 3, results.size, "Should have three comment rows."
|
79
|
-
results.each_with_index do |comment_row, index|
|
80
|
-
column_name = comment_row[0]
|
81
|
-
comment = comment_row[1]
|
82
|
-
assert_equal expected[index]['column_name'], column_name
|
83
|
-
assert_equal expected[index]['comment'], comment
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_supports_comments
|
88
|
-
assert_true @adapter.supports_comments?
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
data/test/schema_dumper_test.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SchemaDumperTest < Test::Unit::TestCase
|
4
|
-
class SchemaDumpContainer
|
5
|
-
def initialize
|
6
|
-
@connection = FakeConnection.new( :comments => [[nil, 'table\'s comment'],
|
7
|
-
['c1', 'column1 comment'],
|
8
|
-
['c2', 'column\'s comment']] )
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.alias_method_chain(*args)
|
12
|
-
#Does nothing
|
13
|
-
end
|
14
|
-
|
15
|
-
include PgComment::SchemaDumper
|
16
|
-
|
17
|
-
public :dump_comments
|
18
|
-
end
|
19
|
-
|
20
|
-
class Stream
|
21
|
-
attr_reader :stream_results
|
22
|
-
|
23
|
-
def puts(str = nil)
|
24
|
-
@stream_results ||= []
|
25
|
-
@stream_results << str unless str.nil?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def setup
|
30
|
-
@fake_table = 'my_table'
|
31
|
-
@expected = [" set_table_comment '#{@fake_table}', 'table\\'s comment'",
|
32
|
-
" set_column_comment '#{@fake_table}', 'c1', 'column1 comment'",
|
33
|
-
" set_column_comment '#{@fake_table}', 'c2', 'column\\'s comment'"].join("\n")
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_dump_comments
|
37
|
-
sd = SchemaDumpContainer.new
|
38
|
-
stream = Stream.new
|
39
|
-
sd.dump_comments @fake_table, stream
|
40
|
-
assert_equal @expected, stream.stream_results[0]
|
41
|
-
end
|
42
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#require 'rubygems'
|
2
|
-
gem 'test-unit'
|
3
|
-
|
4
|
-
if require 'simplecov'
|
5
|
-
SimpleCov.start do
|
6
|
-
add_filter 'test/'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'active_record'
|
12
|
-
|
13
|
-
|
14
|
-
require 'pg_comment/connection_adapters/postgresql_adapter'
|
15
|
-
require 'fake_connection'
|
16
|
-
require 'pg_comment/schema_dumper'
|