migration_comments 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 766b7ebfb9c64bc9b8a4bc03e4c943d0276c6f49
4
+ data.tar.gz: c33c766bd47e849dc07d5c5b454eddeb1ce3278c
5
+ SHA512:
6
+ metadata.gz: 5be5b935f97b70922631c45519bff6083fec3a9bc8fd6104c2f7f391aa888d0ac57fc413cb8a4ce3310eae1c15fa4bded524f9cc10a74ba20e5c1e85285a11a7
7
+ data.tar.gz: 22b2a9ec4daaa59bf52b7a4c53969cb4d98340844857f564e9dda63d4ed598145cf052696e6529ac70c739f11db879587c378f2933b3ddb939a9db4faf1498f4
@@ -19,10 +19,16 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
19
19
  false
20
20
  end
21
21
 
22
+ # SQLite style - embedded comments
22
23
  def inline_comments?
23
24
  false
24
25
  end
25
26
 
27
+ # PostgreSQL style - comment specific commands
28
+ def independent_comments?
29
+ false
30
+ end
31
+
26
32
  # Remove a comment on a table (if set)
27
33
  def remove_table_comment(table_name)
28
34
  set_table_comment(table_name, nil)
@@ -3,6 +3,7 @@ module MigrationComments::ActiveRecord::ConnectionAdapters::AbstractAdapter
3
3
  def self.included(base)
4
4
  base.class_eval do
5
5
  alias_method_chain :column_options, :migration_comments
6
+ alias_method_chain :add_column_options!, :migration_comments
6
7
  alias_method_chain :visit_TableDefinition, :migration_comments
7
8
  alias_method_chain :visit_ColumnDefinition, :migration_comments
8
9
  end
@@ -14,6 +15,14 @@ module MigrationComments::ActiveRecord::ConnectionAdapters::AbstractAdapter
14
15
  column_options
15
16
  end
16
17
 
18
+ def add_column_options_with_migration_comments!(sql, options)
19
+ sql = add_column_options_without_migration_comments!(sql, options)
20
+ if options.keys.include?(:comment) && !@conn.independent_comments?
21
+ sql << MigrationComments::ActiveRecord::ConnectionAdapters::CommentDefinition.new(@conn, nil, nil, options[:comment]).to_sql
22
+ end
23
+ sql
24
+ end
25
+
17
26
  def visit_TableDefinition_with_migration_comments(o)
18
27
  if @conn.inline_comments?
19
28
  create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE "
@@ -61,10 +61,14 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
61
61
  def add_column_options!(sql, options)
62
62
  super(sql, options)
63
63
  if options.keys.include?(:comment)
64
- sql << " COMMENT #{escaped_comment(options[:comment])}"
64
+ sql << CommentDefinition.new(self, nil, nil, options[:comment]).to_sql
65
65
  end
66
66
  end
67
67
 
68
+ def comment_sql(comment_definition)
69
+ " COMMENT #{escaped_comment(comment_definition.comment_text)}"
70
+ end
71
+
68
72
  def execute_comment(comment_definition)
69
73
  if comment_definition.table_comment?
70
74
  set_table_comment comment_definition.table_name, comment_definition.comment_text
@@ -12,6 +12,10 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
12
12
  true
13
13
  end
14
14
 
15
+ def independent_comments?
16
+ true
17
+ end
18
+
15
19
  # Set a comment on a table
16
20
  def set_table_comment(table_name, comment_text)
17
21
  execute CommentDefinition.new(self, table_name, nil, comment_text).to_sql
@@ -13,7 +13,7 @@ module MigrationComments
13
13
  end
14
14
 
15
15
  def render_value(value)
16
- value.is_a?(String) ? "\"#{value}\"" : value
16
+ value.is_a?(String) ? %Q[#{value}].inspect : value
17
17
  end
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module MigrationComments
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class AddCommentsTest < Test::Unit::TestCase
3
+ class AddCommentsTest < Minitest::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def test_adding_a_table_comment
@@ -6,7 +6,7 @@ class Sample < ActiveRecord::Base
6
6
  self.table_name = 'sample'
7
7
  end
8
8
 
9
- class AnnotateModelsTest < Test::Unit::TestCase
9
+ class AnnotateModelsTest < Minitest::Unit::TestCase
10
10
  include TestHelper
11
11
 
12
12
  TEST_PREFIX = "== Schema Information"
@@ -4,7 +4,7 @@ class Sample < ActiveRecord::Base
4
4
  self.table_name = 'sample'
5
5
  end
6
6
 
7
- class AutoIncrementTest < Test::Unit::TestCase
7
+ class AutoIncrementTest < Minitest::Unit::TestCase
8
8
  include TestHelper
9
9
 
10
10
  def test_basic_table_creation
@@ -35,13 +35,11 @@ class AutoIncrementTest < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  ids = []
38
- assert_nothing_raised ActiveRecord::StatementInvalid do
39
- ActiveRecord::Base.connection.instance_eval do
40
- 3.times do |n|
41
- execute "INSERT INTO #{quote_table_name :sample} (#{quote_column_name :field1}, #{quote_column_name :field2}) VALUES ('text#{n}', #{n})"
42
- end
43
- ids = select_rows("SELECT #{quote_column_name :id} FROM #{quote_table_name :sample}").map{|r| r.first.to_i }.sort
38
+ ActiveRecord::Base.connection.instance_eval do
39
+ 3.times do |n|
40
+ execute "INSERT INTO #{quote_table_name :sample} (#{quote_column_name :field1}, #{quote_column_name :field2}) VALUES ('text#{n}', #{n})"
44
41
  end
42
+ ids = select_rows("SELECT #{quote_column_name :id} FROM #{quote_table_name :sample}").map{|r| r.first.to_i }.sort
45
43
  end
46
44
  assert_equal [1,2,3], ids
47
45
 
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class SchemaDumperTest < Test::Unit::TestCase
3
+ class SchemaDumperTest < Minitest::Unit::TestCase
4
4
  include TestHelper
5
5
  include MigrationComments::SchemaFormatter
6
6
 
@@ -15,15 +15,11 @@ class SchemaDumperTest < Test::Unit::TestCase
15
15
  dest.rewind
16
16
  result = dest.read
17
17
  expected = <<EOS
18
- ActiveRecord::Schema.define(#{render_kv_pair(:version, 1)}) do
19
-
20
18
  create_table "sample", #{render_kv_pair(:force, true)}, #{render_kv_pair(:comment, "a table comment")} do |t|
21
19
  t.string "field1", __SPACES__#{render_kv_pair(:comment, %{a \"comment\" \\ that ' needs; escaping''})}
22
20
  t.integer "field2"
23
21
  t.string "field3", #{render_kv_pair(:default, "")}, #{render_kv_pair(:null, false)}, #{render_kv_pair(:comment, "third column comment")}
24
22
  end
25
-
26
- end
27
23
  EOS
28
24
  assert_match /#{Regexp.escape(expected).gsub(/__SPACES__/, " +")}/, result
29
25
  end
@@ -39,12 +35,8 @@ EOS
39
35
  dest.rewind
40
36
  result = dest.read
41
37
  expected = <<EOS
42
- ActiveRecord::Schema.define(#{render_kv_pair(:version, 1)}) do
43
-
44
38
  create_table "sample", #{render_kv_pair(:force, true)}, #{render_kv_pair(:comment, "a table comment")} do |t|
45
39
  end
46
-
47
- end
48
40
  EOS
49
41
 
50
42
  assert_match /#{Regexp.escape expected}/, result
@@ -66,12 +58,8 @@ EOS
66
58
  result = dest.read
67
59
 
68
60
  expected = <<EOS
69
- ActiveRecord::Schema.define(#{render_kv_pair(:version, 1)}) do
70
-
71
61
  # Could not dump table "sample" because of following StandardError
72
62
  # Unknown type 'my_custom_type' for column 'field2'
73
-
74
- end
75
63
  EOS
76
64
 
77
65
  assert_match /#{Regexp.escape expected}/, result
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
 
3
3
  require 'rubygems'
4
4
  gem 'activerecord', '>= 2.3.2'
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 0.3.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Pinny
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-08 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.3.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.3.2
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: annotate
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: 2.5.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: 2.5.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: pg
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: mysql2
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: sqlite3
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: Add schema comments in your migrations, see them in model annotations
@@ -99,7 +88,7 @@ executables: []
99
88
  extensions: []
100
89
  extra_rdoc_files: []
101
90
  files:
102
- - .gitignore
91
+ - ".gitignore"
103
92
  - Gemfile
104
93
  - MIT-LICENSE
105
94
  - README.rdoc
@@ -132,32 +121,25 @@ files:
132
121
  - test/test_helper.rb
133
122
  homepage: https://github.com/pinnymz/migration_comments
134
123
  licenses: []
124
+ metadata: {}
135
125
  post_install_message:
136
126
  rdoc_options: []
137
127
  require_paths:
138
128
  - lib
139
129
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
130
  requirements:
142
- - - ! '>='
131
+ - - ">="
143
132
  - !ruby/object:Gem::Version
144
133
  version: '0'
145
- segments:
146
- - 0
147
- hash: -3400320072112058526
148
134
  required_rubygems_version: !ruby/object:Gem::Requirement
149
- none: false
150
135
  requirements:
151
- - - ! '>='
136
+ - - ">="
152
137
  - !ruby/object:Gem::Version
153
138
  version: '0'
154
- segments:
155
- - 0
156
- hash: -3400320072112058526
157
139
  requirements: []
158
140
  rubyforge_project: migration_comments
159
- rubygems_version: 1.8.25
141
+ rubygems_version: 2.2.2
160
142
  signing_key:
161
- specification_version: 3
143
+ specification_version: 4
162
144
  summary: Comments for your migrations
163
145
  test_files: []