migration_comments 0.1.3 → 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.
@@ -1,53 +1,37 @@
1
- require 'test_helper'
2
- gem 'annotate'
3
- require 'annotate/annotate_models'
4
-
5
- class Sample < ActiveRecord::Base
6
- self.table_name = 'sample'
7
- end
8
-
9
- class AnnotateModelsTest < Test::Unit::TestCase
10
- include TestHelper
11
-
12
- TEST_PREFIX = "== Schema Information"
13
-
14
- def test_annotate_includes_comments
15
- db_type = :default
16
- ActiveRecord::Schema.define do
17
- db_type = :mysql if connection.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter) rescue false
18
-
19
- set_table_comment :sample, "a table comment"
20
- set_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
21
- add_column :sample, :field3, :string, :null => false, :default => '', :comment => "third column comment"
22
- end
23
-
24
- result = AnnotateModels.get_schema_info(Sample, TEST_PREFIX)
25
- default_expected = <<EOS
26
- # #{TEST_PREFIX}
27
- #
28
- # Table name: sample # a table comment
29
- #
30
- # id :integer not null, primary key
31
- # field1 :string(255) # a "comment" \\ that ' needs; escaping''
32
- # field2 :integer
33
- # field3 :string(255) default(""), not null # third column comment
34
- #
35
-
36
- EOS
37
- mysql_expected = <<EOS
38
- # #{TEST_PREFIX}
39
- #
40
- # Table name: sample # a table comment
41
- #
42
- # id :integer(4) not null, primary key
43
- # field1 :string(255) # a "comment" \\ that ' needs; escaping''
44
- # field2 :integer(4)
45
- # field3 :string(255) default(""), not null # third column comment
46
- #
47
-
48
- EOS
49
- expected = instance_eval "#{db_type}_expected"
50
- assert_equal expected, result
51
- end
52
- end
53
-
1
+ require './test_helper'
2
+ gem 'annotate'
3
+ require 'annotate/annotate_models'
4
+
5
+ class Sample < ActiveRecord::Base
6
+ self.table_name = 'sample'
7
+ end
8
+
9
+ class AnnotateModelsTest < Test::Unit::TestCase
10
+ include TestHelper
11
+
12
+ TEST_PREFIX = "== Schema Information"
13
+
14
+ def test_annotate_includes_comments
15
+ ActiveRecord::Schema.define do
16
+ set_table_comment :sample, "a table comment"
17
+ set_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
18
+ add_column :sample, :field3, :string, :null => false, :default => '', :comment => "third column comment"
19
+ end
20
+
21
+ result = AnnotateModels.get_schema_info(Sample, TEST_PREFIX)
22
+ expected = <<EOS
23
+ # #{TEST_PREFIX}
24
+ #
25
+ # Table name: sample # a table comment
26
+ #
27
+ # id :integer not null, primary key
28
+ # field1 :string(255) # a "comment" \\ that ' needs; escaping''
29
+ # field2 :integer
30
+ # field3 :string(255) default(""), not null # third column comment
31
+ #
32
+
33
+ EOS
34
+ assert_equal expected, result
35
+ end
36
+ end
37
+
@@ -0,0 +1,50 @@
1
+ require './test_helper'
2
+
3
+ class Sample < ActiveRecord::Base
4
+ self.table_name = 'sample'
5
+ end
6
+
7
+ class AutoIncrementTest < Test::Unit::TestCase
8
+ include TestHelper
9
+
10
+ def test_basic_table_creation
11
+ assert_auto_increments
12
+ end
13
+
14
+ def test_modified_primary_key
15
+ comment_text = "a comment on the sample table in the primary_key field"
16
+ result_comment = nil
17
+ ActiveRecord::Schema.define do
18
+ set_column_comment :sample, :id, comment_text
19
+ result_comment = retrieve_column_comment :sample, :id
20
+ end
21
+ assert_auto_increments
22
+ assert_equal comment_text, result_comment
23
+ end
24
+
25
+ private
26
+ def assert_auto_increments
27
+ if ENV['DB'] == 'mysql'
28
+ extra = nil
29
+ ActiveRecord::Base.connection.instance_eval do
30
+ execute_and_free("SHOW FULL FIELDS FROM #{quote_table_name :sample}") do |result|
31
+ extra = each_hash(result).detect{|field| field[:Field] == 'id'}[:Extra]
32
+ end
33
+ end
34
+ assert_match /auto_increment/i, extra
35
+ end
36
+
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
44
+ end
45
+ end
46
+ assert_equal [1,2,3], ids
47
+
48
+ assert_equal Sample.count, 3
49
+ end
50
+ end
@@ -1,18 +1,18 @@
1
- postgres:
2
- adapter: postgresql
3
- database: migration_comments_test
4
- host: 127.0.0.1
5
- username: postgres
6
- password: postgres
7
-
8
- mysql:
9
- adapter: mysql # mysql2
10
- database: migration_comments_test
11
- user: root
12
- password: password
13
-
14
- sqlite:
15
- adapter: sqlite3
16
- database: db/migration_comments_test
17
- pool: 5
1
+ postgres:
2
+ adapter: postgresql
3
+ database: migration_comments_test
4
+ host: 127.0.0.1
5
+ username: postgres
6
+ password: postgres
7
+
8
+ mysql:
9
+ adapter: mysql # mysql2
10
+ database: migration_comments_test
11
+ user: root
12
+ password: password
13
+
14
+ sqlite:
15
+ adapter: sqlite3
16
+ database: db/migration_comments_test
17
+ pool: 5
18
18
  timeout: 5000
@@ -1,33 +1,33 @@
1
- require 'test_helper'
2
-
3
- class SchemaDumperTest < Test::Unit::TestCase
4
- include TestHelper
5
-
6
- def test_dump
7
- db_type = :default
8
- ActiveRecord::Schema.define do
9
- db_type = :sqlite if connection.is_a?(ActiveRecord::ConnectionAdapters::SQLiteAdapter) rescue false
10
-
11
- set_table_comment :sample, "a table comment"
12
- set_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
13
- add_column :sample, :field3, :string, :null => false, :default => "", :comment => "third column comment"
14
- end
15
- dest = StringIO.new
16
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, dest)
17
- dest.rewind
18
- result = dest.read
19
- expected = <<EOS
20
- ActiveRecord::Schema.define(:version => 1) do
21
-
22
- create_table "sample", :force => true, :comment => "a table comment" do |t|
23
- t.string "field1", :comment => "a \"comment\" \\ that ' needs; escaping''"
24
- t.integer "field2"
25
- t.string "field3", :default => "", :null => false, :comment => "third column comment"
26
- end
27
-
28
- end
29
- EOS
30
-
31
- assert_match /#{Regexp.escape expected}/, result
32
- end
33
- end
1
+ require './test_helper'
2
+
3
+ class SchemaDumperTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ def test_dump
7
+ db_type = :default
8
+ ActiveRecord::Schema.define do
9
+ db_type = :sqlite if connection.is_a?(ActiveRecord::ConnectionAdapters::SQLiteAdapter) rescue false
10
+
11
+ set_table_comment :sample, "a table comment"
12
+ set_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
13
+ add_column :sample, :field3, :string, :null => false, :default => "", :comment => "third column comment"
14
+ end
15
+ dest = StringIO.new
16
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, dest)
17
+ dest.rewind
18
+ result = dest.read
19
+ expected = <<EOS
20
+ ActiveRecord::Schema.define(:version => 1) do
21
+
22
+ create_table "sample", :force => true, :comment => "a table comment" do |t|
23
+ t.string "field1", :comment => "a \"comment\" \\ that ' needs; escaping''"
24
+ t.integer "field2"
25
+ t.string "field3", :default => "", :null => false, :comment => "third column comment"
26
+ end
27
+
28
+ end
29
+ EOS
30
+
31
+ assert_match /#{Regexp.escape expected}/, result
32
+ end
33
+ end
@@ -1,32 +1,32 @@
1
- require 'test/unit'
2
-
3
- require 'rubygems'
4
- gem 'rails', '>= 2.3.2'
5
- require 'active_record'
6
- require 'yaml'
7
-
8
- CONFIGURATIONS = YAML::load(IO.read('config/database.yml'))
9
-
10
- ENV['DB'] ||= 'postgres' # override as needed
11
-
12
- ActiveRecord::Base.establish_connection(CONFIGURATIONS[ENV['DB']])
13
-
14
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
15
- require 'migration_comments'
16
-
17
- module TestHelper
18
- def setup
19
- ActiveRecord::Schema.define(:version => 1) do
20
- create_table :sample do |t|
21
- t.string :field1
22
- t.integer :field2
23
- end
24
- end
25
- end
26
-
27
- def teardown
28
- ActiveRecord::Schema.define do
29
- drop_table :sample
30
- end
31
- end
32
- end
1
+ require 'test/unit'
2
+
3
+ require 'rubygems'
4
+ gem 'rails', '>= 2.3.2'
5
+ require 'active_record'
6
+ require 'yaml'
7
+
8
+ CONFIGURATIONS = YAML::load(IO.read('config/database.yml'))
9
+
10
+ ENV['DB'] ||= 'postgres' # override as needed
11
+
12
+ ActiveRecord::Base.establish_connection(CONFIGURATIONS[ENV['DB']])
13
+
14
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
15
+ require 'migration_comments'
16
+
17
+ module TestHelper
18
+ def setup
19
+ ActiveRecord::Schema.define(:version => 1) do
20
+ create_table :sample do |t|
21
+ t.string :field1
22
+ t.integer :field2
23
+ end
24
+ end
25
+ end
26
+
27
+ def teardown
28
+ ActiveRecord::Schema.define do
29
+ drop_table :sample
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,79 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: migration_comments
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Pinny
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-02-22 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 2
32
- - 3
33
- - 2
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 2.3.2
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: annotate
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: annotate
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.5.0
49
38
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: pg
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: pg
48
+ requirement: !ruby/object:Gem::Requirement
55
49
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
63
54
  type: :development
64
- version_requirements: *id003
65
- description: Add schema comments in your migrations, see them in model annotations and db/schema.rb dump
66
- email:
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Add schema comments in your migrations, see them in model annotations
63
+ and db/schema.rb dump
64
+ email:
67
65
  - pinny@medwiztech.com
68
66
  executables: []
69
-
70
67
  extensions: []
71
-
72
68
  extra_rdoc_files: []
73
-
74
- files:
69
+ files:
75
70
  - .gitignore
76
71
  - Gemfile
72
+ - MIT-LICENSE
77
73
  - README.rdoc
78
74
  - Rakefile
79
75
  - lib/migration_comments.rb
@@ -93,42 +89,32 @@ files:
93
89
  - migration_comments.gemspec
94
90
  - test/add_comments_test.rb
95
91
  - test/annotate_models_test.rb
92
+ - test/auto_increment_test.rb
96
93
  - test/config/database.yml
97
94
  - test/schema_dumper_test.rb
98
95
  - test/test_helper.rb
99
- has_rdoc: true
100
96
  homepage: https://github.com/pinnymz/migration_comments
101
97
  licenses: []
102
-
103
98
  post_install_message:
104
99
  rdoc_options: []
105
-
106
- require_paths:
100
+ require_paths:
107
101
  - lib
108
- required_ruby_version: !ruby/object:Gem::Requirement
102
+ required_ruby_version: !ruby/object:Gem::Requirement
109
103
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- hash: 3
114
- segments:
115
- - 0
116
- version: "0"
117
- required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
109
  none: false
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- hash: 3
123
- segments:
124
- - 0
125
- version: "0"
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
126
114
  requirements: []
127
-
128
115
  rubyforge_project: migration_comments
129
- rubygems_version: 1.4.2
116
+ rubygems_version: 1.8.24
130
117
  signing_key:
131
118
  specification_version: 3
132
119
  summary: Comments for your migrations
133
120
  test_files: []
134
-