schema_comments 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +13 -0
  4. data/Gemfile +11 -8
  5. data/README.md +187 -0
  6. data/Rakefile +6 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +7 -0
  9. data/gemfiles/.gitignore +1 -0
  10. data/gemfiles/Gemfile.rails-4.0 +15 -0
  11. data/gemfiles/Gemfile.rails-4.1 +12 -0
  12. data/gemfiles/Gemfile.rails-4.2 +12 -0
  13. data/lib/annotate_models.rb +12 -4
  14. data/lib/schema_comments/connection_adapters.rb +2 -1
  15. data/lib/schema_comments/railtie.rb +11 -0
  16. data/lib/schema_comments/schema_comment.rb +1 -1
  17. data/lib/schema_comments/schema_dumper/mysql.rb +2 -2
  18. data/lib/schema_comments/version.rb +3 -0
  19. data/lib/schema_comments.rb +2 -0
  20. data/schema_comments.gemspec +28 -0
  21. metadata +52 -194
  22. data/Gemfile.lock +0 -106
  23. data/README.rdoc +0 -150
  24. data/spec/annotate_models_spec.rb +0 -63
  25. data/spec/database.yml +0 -15
  26. data/spec/fake_app.rb +0 -38
  27. data/spec/hash_key_orderable_spec.rb +0 -50
  28. data/spec/human_readable_schema_comments.yml +0 -14
  29. data/spec/i18n_export_spec.rb +0 -44
  30. data/spec/migration_spec.rb +0 -108
  31. data/spec/migrations/valid/001_create_products.rb +0 -17
  32. data/spec/migrations/valid/002_rename_products.rb +0 -10
  33. data/spec/migrations/valid/003_rename_products_again.rb +0 -10
  34. data/spec/migrations/valid/004_remove_price.rb +0 -10
  35. data/spec/migrations/valid/005_change_products_name.rb +0 -10
  36. data/spec/migrations/valid/006_change_products_name_with_comment.rb +0 -10
  37. data/spec/migrations/valid/007_change_comments.rb +0 -12
  38. data/spec/migrations/valid/008_create_users_without_comment.rb +0 -19
  39. data/spec/resources/models/product.rb +0 -2
  40. data/spec/resources/models/product_name.rb +0 -2
  41. data/spec/schema.rb +0 -2
  42. data/spec/schema_comments/connection_adapters_spec.rb +0 -54
  43. data/spec/schema_comments/schema_comment_spec.rb +0 -76
  44. data/spec/schema_comments/schema_comments.yml +0 -10
  45. data/spec/schema_comments/schema_comments_broken_column_comments.yml +0 -7
  46. data/spec/schema_comments/schema_comments_broken_column_hash.yml +0 -10
  47. data/spec/schema_comments/schema_comments_broken_table_comments.yml +0 -13
  48. data/spec/schema_comments/schema_comments_users_without_column_hash.yml +0 -10
  49. data/spec/schema_comments/schema_dumper_spec.rb +0 -92
  50. data/spec/schema_comments.yml +0 -9
  51. data/spec/spec_helper.rb +0 -53
  52. data/spec/yaml_export_spec.rb +0 -52
@@ -1,63 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
3
-
4
- require File.join(File.dirname(__FILE__), '../lib/annotate_models.rb')
5
-
6
- describe AnnotateModels do
7
-
8
- before(:each) do
9
- SchemaComments.yaml_path = File.expand_path(File.join(File.dirname(__FILE__), 'schema_comments.yml'))
10
- FileUtils.rm(SchemaComments.yaml_path, :verbose => true) if File.exist?(SchemaComments.yaml_path)
11
-
12
- (ActiveRecord::Base.connection.tables - IGNORED_TABLES).each do |t|
13
- ActiveRecord::Base.connection.drop_table(t) rescue nil
14
- end
15
- ActiveRecord::Base.connection.initialize_schema_migrations_table
16
- ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
17
- end
18
-
19
- it "get_schema_info" do
20
- (ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
21
-
22
- ActiveRecord::Schema.define(:version => "20090721185959") do
23
- drop_table("books") rescue nil
24
-
25
- create_table "books", :force => true, :comment => '書籍' do |t|
26
- t.string "title", :limit => 100, :null => false, :comment => 'タイトル'
27
- t.integer "size", :null => false, :default => 1, :comment => '判型'
28
- t.decimal "price", :precision => 17, :scale => 14, :default => 0.0, :null => false, :comment => '価格'
29
- t.datetime "created_at", :comment => '登録日時'
30
- t.datetime "updated_at", :comment => '更新日時'
31
- end
32
- end
33
-
34
- class Book < ActiveRecord::Base
35
- end
36
-
37
- puts "ActiveRecord::Base.connection.adapter_name: #{ActiveRecord::Base.connection.adapter_name.inspect}"
38
-
39
- int_expr =
40
- case ActiveRecord::Base.connection.adapter_name
41
- when /mysql/i then ":integer(4)"
42
- else ":integer "
43
- end
44
-
45
- AnnotateModels.get_schema_info(Book).should == %{# == Schema Info ==
46
- #
47
- # Schema version: 20090721185959
48
- #
49
- # Table name: books # 書籍
50
- #
51
- # id #{int_expr} not null, primary key
52
- # title :string(100) not null # タイトル
53
- # size #{int_expr} not null, default(1) # 判型
54
- # price :decimal(17, 14) not null, default(0.0) # 価格
55
- # created_at :datetime # 登録日時
56
- # updated_at :datetime # 更新日時
57
- #
58
- # =================
59
- #
60
- }
61
- end
62
-
63
- end
data/spec/database.yml DELETED
@@ -1,15 +0,0 @@
1
- sqlite3:
2
- :adapter: sqlite3
3
- :database: ":memory:"
4
- mysql:
5
- adapter: mysql
6
- encoding: utf8
7
- username: root
8
- password:
9
- database: schema_comments_mysql_test
10
- mysql2:
11
- adapter: mysql2
12
- encoding: utf8
13
- username: root
14
- password:
15
- database: schema_comments_mysql2_test
data/spec/fake_app.rb DELETED
@@ -1,38 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # see https://github.com/amatsuda/kaminari/blob/master/spec/fake_app.rb
4
-
5
- require 'active_record'
6
- require 'action_controller/railtie'
7
- require 'action_view/railtie'
8
-
9
- # database
10
- db_name = ENV['DB'] || 'sqlite3'
11
- configs = YAML.load_file(File.expand_path("../database.yml", __FILE__))
12
- config = configs[db_name]
13
-
14
- def mysql_creation_options(config)
15
- @charset = ENV['CHARSET'] || 'utf8'
16
- @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
17
- {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
18
- end
19
-
20
- case db_name
21
- when /mysql/ then
22
- ActiveRecord::Base.establish_connection(config.merge('database' => nil))
23
- begin
24
- ActiveRecord::Base.connection.create_database(config['database'], mysql_creation_options(config))
25
- rescue ActiveRecord::StatementInvalid => e
26
- raise e unless e.message =~ /^Mysql2?::Error: Can't create database|^ActiveRecord::JDBCError: Can't create database/
27
- end
28
- end
29
-
30
- ActiveRecord::Base.configurations = configs
31
- ActiveRecord::Base.establish_connection( db_name )
32
-
33
- # config
34
- app = Class.new(Rails::Application)
35
- app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
36
- app.config.session_store :cookie_store, :key => "_myapp_session"
37
- app.config.active_support.deprecation = :log
38
- app.initialize!
@@ -1,50 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require 'hash_key_orderable'
3
-
4
- describe HashKeyOrderable do
5
-
6
- describe :each do
7
- it "should each with key order" do
8
- hash = {'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4}
9
- hash.extend(HashKeyOrderable)
10
- hash.key_order = %w(b d c a)
11
- actuals = []
12
- hash.each do |key, value|
13
- actuals << key
14
- end
15
- actuals.should == hash.key_order
16
- end
17
-
18
- it "should use original each without key_order" do
19
- hash = {'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4}
20
- hash.extend(HashKeyOrderable)
21
- hash.should_receive(:each_without_key_order) # original each method
22
- hash.each{ }
23
- end
24
-
25
- it "should appear remain key after key_order in each" do
26
- hash = {'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}
27
- hash.extend(HashKeyOrderable)
28
- hash.key_order = %w(b e d)
29
- actuals = []
30
- hash.each do |key, value|
31
- actuals << key
32
- end
33
- actuals[0..2].should == hash.key_order
34
- actuals[3..4].sort.should == %w(a c)
35
- end
36
-
37
- it "should ignore unexist key in key_order" do
38
- hash = {'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}
39
- hash.extend(HashKeyOrderable)
40
- hash.key_order = %w(b z x d)
41
- actuals = []
42
- hash.each do |key, value|
43
- actuals << key
44
- end
45
- actuals[0..1].should == %w(b d)
46
- actuals[2..4].sort.should == %w(a c e)
47
- end
48
-
49
- end
50
- end
@@ -1,14 +0,0 @@
1
- ---
2
- table_comments:
3
- addresses: 住所
4
- emails: メール
5
- person: 人
6
- column_comments:
7
- addresses:
8
- person_id: 人
9
- descriptions: 記述
10
- emails:
11
- person_id: 人
12
- address: アドレス
13
- person:
14
- name: 名前
@@ -1,44 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
3
-
4
- describe SchemaComments::Base do
5
-
6
- before(:each) do
7
- SchemaComments.yaml_path = File.expand_path(File.join(File.dirname(__FILE__), 'schema_comments.yml'))
8
- FileUtils.rm(SchemaComments.yaml_path, :verbose => true) if File.exist?(SchemaComments.yaml_path)
9
-
10
- (ActiveRecord::Base.connection.tables - IGNORED_TABLES).each do |t|
11
- ActiveRecord::Base.connection.drop_table(t) rescue nil
12
- end
13
- ActiveRecord::Base.connection.initialize_schema_migrations_table
14
- ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
15
- end
16
-
17
- it "test_valid_migration" do
18
- (ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
19
-
20
- migration_path = File.join(MIGRATIONS_ROOT, 'valid')
21
- Dir.glob('*.rb').each do |file|
22
- require(file) if /^\d+?_.*/ =~ file
23
- end
24
-
25
- Product.reset_table_comments
26
- Product.reset_column_comments
27
-
28
- ActiveRecord::Migrator.up(migration_path, 1)
29
- ActiveRecord::Migrator.current_version.should == 1
30
-
31
- ActiveRecord::Base.export_i18n_models.keys.include?('product').should == true
32
- ActiveRecord::Base.export_i18n_models['product'].should == '商品'
33
-
34
- ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
35
- ActiveRecord::Base.export_i18n_attributes['product'].should == {
36
- 'product_type_cd' => '種別コード',
37
- "price" => "価格",
38
- "name" => "商品名",
39
- "created_at" => "登録日時",
40
- "updated_at" => "更新日時"
41
- }
42
- end
43
-
44
- end
@@ -1,108 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
3
-
4
- describe ActiveRecord::Migrator do
5
-
6
- before(:each) do
7
- SchemaComments.yaml_path = File.expand_path(File.join(File.dirname(__FILE__), 'schema_comments.yml'))
8
- FileUtils.rm(SchemaComments.yaml_path, :verbose => true) if File.exist?(SchemaComments.yaml_path)
9
-
10
- (ActiveRecord::Base.connection.tables - IGNORED_TABLES).each do |t|
11
- ActiveRecord::Base.connection.drop_table(t) rescue nil
12
- end
13
- ActiveRecord::Base.connection.initialize_schema_migrations_table
14
- ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
15
- end
16
-
17
- it "test_valid_migration" do
18
- (ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
19
-
20
- migration_path = File.join(MIGRATIONS_ROOT, 'valid')
21
- Dir.glob('*.rb').each do |file|
22
- require(file) if /^\d+?_.*/ =~ file
23
- end
24
-
25
- Product.reset_table_comments
26
- Product.reset_column_comments
27
-
28
- ActiveRecord::Migrator.up(migration_path, 1)
29
-
30
- ActiveRecord::Migrator.current_version.should == 1
31
- Product.table_comment.should == '商品'
32
- {
33
- 'product_type_cd' => '種別コード',
34
- "price" => "価格",
35
- "name" => "商品名",
36
- "created_at" => "登録日時",
37
- "updated_at" => "更新日時"
38
- }.each do |col_name, comment|
39
- Product.columns.detect{|c| c.name.to_s == col_name}.comment.should == comment
40
- end
41
-
42
- ActiveRecord::Migrator.down(migration_path, 0)
43
- # SchemaComments::SchemaComment.count.should == 0
44
-
45
- ActiveRecord::Migrator.up(migration_path, 1)
46
- ActiveRecord::Migrator.up(migration_path, 2)
47
- ActiveRecord::Migrator.current_version.should == 2
48
-
49
- ProductName.table_comment.should == '商品'
50
- {
51
- 'product_type_cd' => '種別コード',
52
- "price" => "価格",
53
- "name" => "商品名",
54
- "created_at" => "登録日時",
55
- "updated_at" => "更新日時"
56
- }.each do |col_name, comment|
57
- ProductName.columns.detect{|c| c.name == col_name}.comment.should == comment
58
- end
59
-
60
- ActiveRecord::Migrator.down(migration_path, 1)
61
- ActiveRecord::Migrator.current_version.should == 1
62
-
63
- Product.table_comment.should == '商品'
64
- {
65
- 'product_type_cd' => '種別コード',
66
- "price" => "価格",
67
- "name" => "商品名",
68
- "created_at" => "登録日時",
69
- "updated_at" => "更新日時"
70
- }.each do |col_name, comment|
71
- Product.columns.detect{|c| c.name == col_name}.comment.should == comment
72
- end
73
-
74
- ActiveRecord::Migrator.up(migration_path, 4)
75
- ActiveRecord::Migrator.current_version.should == 4
76
- # SchemaComments::SchemaComment.count.should == 5
77
-
78
- ActiveRecord::Migrator.down(migration_path, 3)
79
- ActiveRecord::Migrator.current_version.should == 3
80
- # SchemaComments::SchemaComment.count.should == 6
81
-
82
- ActiveRecord::Migrator.up(migration_path, 5)
83
- ActiveRecord::Migrator.current_version.should == 5
84
- Product.columns.detect{|c| c.name == 'name'}.comment.should == '商品名'
85
-
86
- ActiveRecord::Migrator.up(migration_path, 6)
87
- ActiveRecord::Migrator.current_version.should == 6
88
- Product.reset_column_comments
89
- Product.columns.detect{|c| c.name == 'name'}.comment.should == '名称'
90
-
91
- # Bug report from Ishikawa, Thanks!
92
- # schema_commentsのcolumn_commentsがうまく動かないみたいです。
93
- # カラムを定義するついでにコメントを付加するのは動くのですが、
94
- # コメントだけあとから付けようとすると、カラムへのコメントが付きません。
95
- #
96
- # column_comments(:table_name => {:column_name => "name"})
97
- # 上記のようにメソッドを呼び出しても、なぜか引数がHashではなくStringで取れてしまうみたいです。
98
- ActiveRecord::Migrator.up(migration_path, 7)
99
- ActiveRecord::Migrator.current_version.should == 7
100
- Product.reset_column_comments
101
- Product.columns.detect{|c| c.name == 'name'}.comment.should == '商品名称'
102
- Product.columns.detect{|c| c.name == 'product_type_cd'}.comment.should == 'カテゴリコード'
103
-
104
- ActiveRecord::Migrator.up(migration_path, 8)
105
- ActiveRecord::Migrator.current_version.should == 8
106
- end
107
-
108
- end
@@ -1,17 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class CreateProducts < ActiveRecord::Migration
3
-
4
- def self.up
5
- create_table "products", :comment => '商品' do |t|
6
- t.string "product_type_cd", :comment => '種別コード'
7
- t.integer "price", :comment => "価格"
8
- t.string "name", :comment => "商品名"
9
- t.datetime "created_at", :comment => "登録日時"
10
- t.datetime "updated_at", :comment => "更新日時"
11
- end
12
- end
13
-
14
- def self.down
15
- drop_table "products"
16
- end
17
- end
@@ -1,10 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class RenameProducts < ActiveRecord::Migration
3
- def self.up
4
- rename_table "products", "product_names"
5
- end
6
-
7
- def self.down
8
- rename_table "product_names", "products"
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class RenameProductsAgain < ActiveRecord::Migration
3
- def self.up
4
- rename_table "product_names", "products"
5
- end
6
-
7
- def self.down
8
- rename_table "products", "product_names"
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class RemovePrice < ActiveRecord::Migration
3
- def self.up
4
- remove_column "products", "price"
5
- end
6
-
7
- def self.down
8
- add_column "products", "price", :integer, :comment => "価格"
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class ChangeProductsName < ActiveRecord::Migration
3
- def self.up
4
- change_column "products", 'name', :string, :limit => 50
5
- end
6
-
7
- def self.down
8
- change_column "products", 'name', :string
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class ChangeProductsNameWithComment < ActiveRecord::Migration
3
- def self.up
4
- change_column "products", 'name', :string, :limit => 100, :comment => "名称"
5
- end
6
-
7
- def self.down
8
- change_column "products", 'name', :string, :limit => 50, :comment => "商品名"
9
- end
10
- end
@@ -1,12 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class ChangeComments < ActiveRecord::Migration
3
- def self.up
4
- column_comments(:products, {:name => "商品名称"})
5
- column_comments("products", "product_type_cd" => 'カテゴリコード')
6
- end
7
-
8
- def self.down
9
- column_comments(:products, {:name => "名称"})
10
- column_comments("products", "product_type_cd" => '種別コード')
11
- end
12
- end
@@ -1,19 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class CreateUsersWithoutComment < ActiveRecord::Migration
3
- def self.up
4
- create_table :users do |t|
5
- t.string :login
6
- t.string :email
7
- t.string :crypted_password
8
- t.string :password_salt
9
- t.string :persistence_token
10
- t.string :single_access_token
11
- t.string :perishable_token
12
- t.timestamps
13
- end
14
- end
15
-
16
- def self.down
17
- drop_table :users
18
- end
19
- end