schema_comments 0.2.0 → 0.3.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.
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,2 +0,0 @@
1
- class Product < ActiveRecord::Base
2
- end
@@ -1,2 +0,0 @@
1
- class ProductName < ActiveRecord::Base
2
- end
data/spec/schema.rb DELETED
@@ -1,2 +0,0 @@
1
- ActiveRecord::Schema.define(:version => 0) do
2
- end
@@ -1,54 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), '../spec_helper')
3
-
4
- describe SchemaComments::ConnectionAdapters 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
-
16
- (ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
17
-
18
- migration_path = File.join(MIGRATIONS_ROOT, 'valid')
19
- Dir.glob('*.rb').each do |file|
20
- require(file) if /^\d+?_.*/ =~ file
21
- end
22
-
23
- Product.reset_table_comments
24
- Product.reset_column_comments
25
-
26
- ActiveRecord::Migrator.up(migration_path, 1)
27
- ActiveRecord::Migrator.current_version.should == 1
28
-
29
- ActiveRecord::Base.export_i18n_models.keys.include?('product').should == true
30
- ActiveRecord::Base.export_i18n_models['product'].should == '商品'
31
-
32
- ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
33
- ActiveRecord::Base.export_i18n_attributes['product'].should == {
34
- 'product_type_cd' => '種別コード',
35
- "price" => "価格",
36
- "name" => "商品名",
37
- "created_at" => "登録日時",
38
- "updated_at" => "更新日時"
39
- }
40
- end
41
-
42
- describe SchemaComments::ConnectionAdapters::Column do
43
- describe :comment do
44
- it "should return comment" do
45
- Product.columns.detect{|c| c.name == "product_type_cd"}.comment.should == '種別コード'
46
- Product.columns.detect{|c| c.name == "price"}.comment.should == '価格'
47
- Product.columns.detect{|c| c.name == "name"}.comment.should == '商品名'
48
- Product.columns.detect{|c| c.name == "created_at"}.comment.should == '登録日時'
49
- Product.columns.detect{|c| c.name == "updated_at"}.comment.should == '更新日時'
50
- end
51
- end
52
-
53
- end
54
- end
@@ -1,76 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), '../spec_helper')
3
-
4
- describe SchemaComments::SchemaComment 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
- describe :yaml_access do
18
- before{@original_yaml_path = SchemaComments.yaml_path}
19
- after {SchemaComments.yaml_path = @original_yaml_path}
20
-
21
- # http://d.hatena.ne.jp/akm/20091213#c1271134505
22
- # プラグインの更新ご苦労さまです。
23
- # とても便利に使わせていただいてます。
24
- #
25
- # ところが本日更新してみたら0.1.3になっていて、
26
- # コメントの生成に失敗するようになってしまいました。
27
- #
28
- # 原因を探ってみましたところ、
29
- # コメントを一個も書いていないマイグレーションでは、
30
- # nilにHashKeyOrderableをextendしようとして落ちていました。
31
- #
32
- # プラグインによって自動で作られるマイグレーションがあるのですが、
33
- # 必ずしもコメントを書くとは限らないので、
34
- # コメントがないときは無視?もしくはそのままカラム名をいれるのがいいのかなと思いました。
35
- #
36
- # # schema_comment.rb:154-164 あたり
37
- #
38
- # よろしければ対応していただけたらと思います。
39
- it "dump without column comment" do
40
- migration_path = File.join(MIGRATIONS_ROOT, 'valid')
41
- Dir.glob('*.rb').each{|file| require(file) if /^\d+?_.*/ =~ file}
42
-
43
- ActiveRecord::Migrator.up(migration_path, 8)
44
- ActiveRecord::Migrator.current_version.should == 8
45
-
46
- SchemaComments.yaml_path =
47
- File.expand_path(File.join(
48
- File.dirname(__FILE__), "schema_comments_users_without_column_hash.yml"))
49
- SchemaComments::SchemaComment.yaml_access do |db|
50
- db['column_comments']['products']['name'] = "商品名"
51
- end
52
- end
53
- {
54
- "table_comments" => lambda{|db| db['column_comments']['users']['login'] = "ログイン"},
55
- "column_comments" => lambda{|db| db['table_comments']['users'] = "物品"},
56
- "column_hash" => lambda{|db| db['column_comments']['users']['login'] = "ログイン"}
57
- }.each do |broken_type, proc|
58
- it "raise SchemaComments::YamlError with broken #{broken_type}" do
59
- migration_path = File.join(MIGRATIONS_ROOT, 'valid')
60
- Dir.glob('*.rb').each{|file| require(file) if /^\d+?_.*/ =~ file}
61
-
62
- ActiveRecord::Migrator.up(migration_path, 8)
63
- ActiveRecord::Migrator.current_version.should == 8
64
-
65
- SchemaComments.yaml_path =
66
- File.expand_path(File.join(
67
- File.dirname(__FILE__), "schema_comments_broken_#{broken_type}.yml"))
68
- lambda{
69
- SchemaComments::SchemaComment.yaml_access(&proc)
70
- }.should raise_error(SchemaComments::YamlError)
71
- end
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,10 +0,0 @@
1
- ---
2
- table_comments:
3
- products: 商品
4
- column_comments:
5
- products:
6
- product_type_cd: 種別コード
7
- price: 価格
8
- name: 商品名
9
- created_at: 登録日時
10
- updated_at: 更新日時
@@ -1,7 +0,0 @@
1
- ---
2
- table_comments:
3
- products: "商品"
4
- column_comments:
5
- - "ここには"
6
- - "配列ではなく"
7
- - "Hashを期待しています"
@@ -1,10 +0,0 @@
1
- ---
2
- table_comments:
3
- products: "商品"
4
- column_comments:
5
- products:
6
- - "ここには"
7
- - "配列ではなく"
8
- - "Hashを期待しています"
9
- users:
10
- login: "ログインID"
@@ -1,13 +0,0 @@
1
- ---
2
- table_comments:
3
- - "ここには"
4
- - "配列ではなく"
5
- - "Hashを期待しています"
6
- column_comments:
7
- products:
8
- product_type_cd: "カテゴリコード"
9
- name: "商品名称"
10
- created_at: "登録日時"
11
- updated_at: "更新日時"
12
- users:
13
- login: "ログインID"
@@ -1,10 +0,0 @@
1
- ---
2
- table_comments:
3
- products: 商品
4
- column_comments:
5
- products:
6
- product_type_cd: カテゴリコード
7
- name: 商品名
8
- created_at: 登録日時
9
- updated_at: 更新日時
10
- users:
@@ -1,92 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), '../spec_helper')
3
-
4
- describe ActiveRecord::SchemaDumper 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
- describe :dump do
18
- it "products" do
19
- (ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
20
-
21
- migration_path = File.join(MIGRATIONS_ROOT, 'valid')
22
- Dir.glob('*.rb').each{|file| require(file) if /^\d+?_.*/ =~ file}
23
-
24
- Product.reset_table_comments
25
- Product.reset_column_comments
26
-
27
- ActiveRecord::Migrator.up(migration_path, 1)
28
- ActiveRecord::Migrator.current_version.should == 1
29
-
30
- ActiveRecord::Base.export_i18n_models.keys.include?('product').should == true
31
- ActiveRecord::Base.export_i18n_models['product'].should == '商品'
32
-
33
- ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
34
- ActiveRecord::Base.export_i18n_attributes['product'].should == {
35
- 'product_type_cd' => '種別コード',
36
- "price" => "価格",
37
- "name" => "商品名",
38
- "created_at" => "登録日時",
39
- "updated_at" => "更新日時"
40
- }
41
-
42
- dest = StringIO.new
43
- # ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, dest)
44
- SchemaComments::SchemaDumper.dump(ActiveRecord::Base.connection, dest)
45
- dest.rewind
46
- s = <<EOS
47
- # encoding: UTF-8
48
- # This file is auto-generated from the current state of the database. Instead
49
- # of editing this file, please use the migrations feature of Active Record to
50
- # incrementally modify your database, and then regenerate this schema definition.
51
- #
52
- # Note that this schema.rb definition is the authoritative source for your
53
- # database schema. If you need to create the application database on another
54
- # system, you should be using db:schema:load, not running all the migrations
55
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
56
- # you'll amass, the slower it'll run and the greater likelihood for issues).
57
- #
58
- # It's strongly recommended to check this file into your version control system.
59
-
60
- ActiveRecord::Schema.define(:version => 1) do
61
-
62
- create_table "products", :force => true, :comment => '商品' do |t|
63
- EOS
64
-
65
- if ENV['DB'] =~ /mysql/i
66
- s << <<EOS
67
- #t.column "id", "int(11)", :null => false, :comment => "AUTO_INCREMENT PRIMARY KEY by rails"
68
- t.column "product_type_cd", "varchar(255)", :comment => "種別コード"
69
- t.column "price", "int(11)", :comment => "価格"
70
- t.column "name", "varchar(255)", :comment => "商品名"
71
- t.column "created_at", "datetime", :comment => "登録日時"
72
- t.column "updated_at", "datetime", :comment => "更新日時"
73
- EOS
74
- else
75
- s << <<EOS
76
- t.string "product_type_cd", :comment => "種別コード"
77
- t.integer "price", :comment => "価格"
78
- t.string "name", :comment => "商品名"
79
- t.datetime "created_at", :comment => "登録日時"
80
- t.datetime "updated_at", :comment => "更新日時"
81
- EOS
82
- end
83
- s << <<EOS
84
- end
85
-
86
- end
87
- EOS
88
- dest.read.should == s
89
- end
90
-
91
- end
92
- end
@@ -1,9 +0,0 @@
1
- ---
2
- table_comments:
3
- products: 商品
4
- column_comments:
5
- products:
6
- product_type_cd: カテゴリコード
7
- name: 商品名称
8
- created_at: 登録日時
9
- updated_at: 更新日時
data/spec/spec_helper.rb DELETED
@@ -1,53 +0,0 @@
1
- if ENV["COVERAGE"] and not(ENV["COVERAGE"].empty?)
2
- require "simplecov"
3
- SimpleCov.start
4
- end
5
-
6
- ENV['DB'] ||= 'sqlite3'
7
-
8
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
- $LOAD_PATH.unshift(File.dirname(__FILE__))
10
-
11
- require 'rails'
12
- require 'schema_comments'
13
- # require 'database_cleaner'
14
- SchemaComments.yaml_path = File.expand_path("schema_comments.yml", File.dirname(__FILE__))
15
-
16
- # Ensure we use 'syck' instead of 'psych' in 1.9.2
17
- # RubyGems >= 1.5.0 uses 'psych' on 1.9.2, but
18
- # Psych does not yet support YAML 1.1 merge keys.
19
- # Merge keys is often used in mongoid.yml
20
- # See: http://redmine.ruby-lang.org/issues/show/4300
21
- # if RUBY_VERSION >= '1.9.2'
22
-
23
- # if defined?(YAML::ENGINE) && YAML::ENGINE.respond_to?(:yamler=)
24
- # YAML::ENGINE.yamler = 'syck'
25
- # end
26
-
27
- # require 'yaml_waml'
28
-
29
- require 'fake_app'
30
-
31
- require 'rspec/rails'
32
-
33
- # Requires supporting files with custom matchers and macros, etc,
34
- # in ./support/ and its subdirectories.
35
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
36
-
37
-
38
- RSpec.configure do |config|
39
-
40
- %w(resources/models).each do |path|
41
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), path)
42
- ActiveSupport::Dependencies.autoload_paths << File.join(File.dirname(__FILE__), path)
43
- end
44
- Dir.glob("resources/**/*.rb") do |filename|
45
- require filename
46
- end
47
-
48
- SchemaComments.setup
49
- end
50
-
51
- MIGRATIONS_ROOT = File.join(File.dirname(__FILE__), 'migrations')
52
-
53
- IGNORED_TABLES = %w(schema_migrations)
@@ -1,52 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
3
-
4
- describe SchemaComments::SchemaComment do
5
-
6
- before(:each) do
7
- SchemaComments.yaml_path = File.join(File.dirname(__FILE__), 'human_readable_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 "should export human readable yaml" do
18
- ActiveRecord::Schema.define(:version => 0) do
19
- create_table(:person, :comment => '人') do |t|
20
- t.string :name, :comment => '名前'
21
- end
22
-
23
- create_table(:addresses, :comment => '住所') do |t|
24
- t.integer :person_id, :comment => '人'
25
- t.text :descriptions, :comment => '記述'
26
- end
27
-
28
- create_table(:emails, :comment => 'メール') do |t|
29
- t.integer :person_id, :comment => '人'
30
- t.string :address, :comment => 'アドレス'
31
- end
32
- end
33
-
34
- File.read(SchemaComments.yaml_path).split(/$/).map(&:strip).should == %{
35
- ---
36
- table_comments:
37
- addresses: 住所
38
- emails: メール
39
- person: 人
40
- column_comments:
41
- addresses:
42
- person_id: 人
43
- descriptions: 記述
44
- emails:
45
- person_id: 人
46
- address: アドレス
47
- person:
48
- name: 名前
49
- }.split(/$/).map(&:strip)
50
- end
51
-
52
- end