schema_comments 0.1.4 → 0.2.0.alpha1
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.
- data/Gemfile +23 -0
- data/Gemfile.lock +125 -0
- data/README.rdoc +9 -10
- data/Rakefile +31 -37
- data/VERSION +1 -1
- data/lib/annotate_models.rb +27 -25
- data/lib/hash_key_orderable.rb +1 -1
- data/lib/schema_comments/base.rb +9 -9
- data/lib/schema_comments/connection_adapters.rb +13 -8
- data/lib/schema_comments/migration.rb +2 -2
- data/lib/schema_comments/migrator.rb +2 -2
- data/lib/schema_comments/schema.rb +1 -1
- data/lib/schema_comments/schema_comment.rb +10 -10
- data/lib/schema_comments/schema_dumper.rb +15 -15
- data/lib/schema_comments.rb +9 -7
- data/schema_comments.gemspec +94 -98
- data/spec/annotate_models_spec.rb +3 -3
- data/spec/fake_app.rb +17 -0
- data/spec/hash_key_orderable_spec.rb +1 -1
- data/spec/i18n_export_spec.rb +7 -7
- data/spec/migrations/valid/001_create_products.rb +1 -1
- data/spec/schema_comments/connection_adapters_spec.rb +7 -7
- data/spec/schema_comments/schema_comment_spec.rb +4 -4
- data/spec/schema_comments/schema_comments.yml +3 -2
- data/spec/schema_comments/schema_dumper_spec.rb +11 -9
- data/spec/spec_helper.rb +27 -38
- data/spec/yaml_export_spec.rb +10 -10
- metadata +134 -52
- data/.gitignore +0 -5
@@ -3,18 +3,18 @@ module SchemaComments
|
|
3
3
|
module SchemaDumper
|
4
4
|
def self.included(mod)
|
5
5
|
# mod.extend(ClassMethods)
|
6
|
-
# mod.instance_eval do
|
6
|
+
# mod.instance_eval do
|
7
7
|
# alias :ignore_tables_without_schema_comments :ignore_tables
|
8
|
-
# alias :ignore_tables :ignore_tables_with_schema_comments
|
8
|
+
# alias :ignore_tables :ignore_tables_with_schema_comments
|
9
9
|
# end
|
10
|
-
mod.module_eval do
|
10
|
+
mod.module_eval do
|
11
11
|
alias_method_chain :tables, :schema_comments
|
12
12
|
alias_method_chain :table, :schema_comments
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
IGNORED_TABLE = 'schema_comments'
|
17
|
-
|
17
|
+
|
18
18
|
# module ClassMethods
|
19
19
|
# def ignore_tables_with_schema_comments
|
20
20
|
# result = ignore_tables_without_schema_comments
|
@@ -22,7 +22,7 @@ module SchemaComments
|
|
22
22
|
# result
|
23
23
|
# end
|
24
24
|
# end
|
25
|
-
|
25
|
+
|
26
26
|
private
|
27
27
|
def tables_with_schema_comments(stream)
|
28
28
|
tables_without_schema_comments(stream)
|
@@ -36,7 +36,7 @@ module SchemaComments
|
|
36
36
|
return if IGNORED_TABLE == table.downcase
|
37
37
|
# MySQLは、ビューもテーブルとして扱うので、一個一個チェックします。
|
38
38
|
if adapter_name == 'mysql'
|
39
|
-
config = ActiveRecord::Base.configurations[
|
39
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
40
40
|
match_count = @connection.select_value(
|
41
41
|
"select count(*) from information_schema.TABLES where TABLE_TYPE = 'VIEW' AND TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'" % [
|
42
42
|
config["database"], table])
|
@@ -60,10 +60,10 @@ module SchemaComments
|
|
60
60
|
tbl.print ", :id => false"
|
61
61
|
end
|
62
62
|
tbl.print ", :force => true"
|
63
|
-
|
63
|
+
|
64
64
|
table_comment = @connection.table_comment(table)
|
65
65
|
tbl.print ", :comment => '#{table_comment}'" unless table_comment.blank?
|
66
|
-
|
66
|
+
|
67
67
|
tbl.puts " do |t|"
|
68
68
|
|
69
69
|
column_specs = columns.map do |column|
|
@@ -110,7 +110,7 @@ module SchemaComments
|
|
110
110
|
|
111
111
|
tbl.puts " end"
|
112
112
|
tbl.puts
|
113
|
-
|
113
|
+
|
114
114
|
indexes(table, tbl)
|
115
115
|
|
116
116
|
tbl.rewind
|
@@ -120,24 +120,24 @@ module SchemaComments
|
|
120
120
|
stream.puts "# #{e.message}"
|
121
121
|
stream.puts
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
stream
|
125
125
|
end
|
126
126
|
|
127
127
|
def adapter_name
|
128
|
-
config = ActiveRecord::Base.configurations[
|
128
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
129
129
|
config ? config['adapter'] : ActiveRecord::Base.connection.adapter_name
|
130
130
|
end
|
131
131
|
|
132
132
|
def mysql_views(stream)
|
133
|
-
config = ActiveRecord::Base.configurations[
|
133
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
134
134
|
view_names = @connection.select_values(
|
135
135
|
"select TABLE_NAME from information_schema.TABLES where TABLE_TYPE = 'VIEW' AND TABLE_SCHEMA = '%s'" % config["database"])
|
136
136
|
view_names.each do |view_name|
|
137
137
|
mysql_view(view_name, stream)
|
138
138
|
end
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
def mysql_view(view_name, stream)
|
142
142
|
ddl = @connection.select_value("show create view #{view_name}")
|
143
143
|
ddl.gsub!(/^CREATE .+? VIEW /i, "CREATE OR REPLACE VIEW ")
|
@@ -157,6 +157,6 @@ module SchemaComments
|
|
157
157
|
stream.print(ddl.split(/\n/).map{|line| ' ' << line.strip}.join("\n"))
|
158
158
|
stream.print("\n EOS\n")
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
end
|
162
162
|
end
|
data/lib/schema_comments.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'active_support/core_ext/module'
|
2
|
+
|
1
3
|
module SchemaComments
|
2
4
|
VERSION = '0.1.0'
|
3
|
-
|
5
|
+
|
4
6
|
autoload :Base, 'schema_comments/base'
|
5
7
|
autoload :ConnectionAdapters, 'schema_comments/connection_adapters'
|
6
8
|
autoload :Migration, 'schema_comments/migration'
|
@@ -9,10 +11,10 @@ module SchemaComments
|
|
9
11
|
autoload :SchemaComment, 'schema_comments/schema_comment'
|
10
12
|
autoload :SchemaDumper, 'schema_comments/schema_dumper'
|
11
13
|
|
12
|
-
DEFAULT_YAML_PATH = File.expand_path(File.join(RAILS_ROOT, 'db/schema_comments.yml'))
|
14
|
+
# DEFAULT_YAML_PATH = File.expand_path(File.join(RAILS_ROOT, 'db/schema_comments.yml'))
|
13
15
|
|
14
16
|
mattr_accessor :yaml_path
|
15
|
-
self.yaml_path = DEFAULT_YAML_PATH
|
17
|
+
# self.yaml_path = DEFAULT_YAML_PATH
|
16
18
|
|
17
19
|
mattr_accessor :quiet
|
18
20
|
|
@@ -23,7 +25,7 @@ module SchemaComments
|
|
23
25
|
def setup
|
24
26
|
base_names = %w(Base Migration Migrator Schema SchemaDumper) +
|
25
27
|
%w(Column ColumnDefinition TableDefinition).map{|name| "ConnectionAdapters::#{name}"}
|
26
|
-
|
28
|
+
|
27
29
|
base_names.each do |base_name|
|
28
30
|
ar_class = "ActiveRecord::#{base_name}".constantize
|
29
31
|
sc_class = "SchemaComments::#{base_name}".constantize
|
@@ -31,13 +33,13 @@ module SchemaComments
|
|
31
33
|
ar_class.__send__(:include, sc_class)
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
36
|
+
|
35
37
|
unless ActiveRecord::ConnectionAdapters::AbstractAdapter.ancestors.include?(SchemaComments::ConnectionAdapters::Adapter)
|
36
38
|
ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
|
37
39
|
include SchemaComments::ConnectionAdapters::Adapter
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
# %w(Mysql PostgreSQL SQLite3 SQLite Firebird DB2 Oracle Sybase Openbase Frontbase)
|
42
44
|
%w(Mysql PostgreSQL SQLite3 SQLite).each do |adapter|
|
43
45
|
begin
|
@@ -50,7 +52,7 @@ module SchemaComments
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
53
|
-
|
55
|
+
|
54
56
|
end
|
55
57
|
|
56
58
|
end
|
data/schema_comments.gemspec
CHANGED
@@ -1,121 +1,117 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "schema_comments"
|
8
|
+
s.version = "0.2.0.alpha1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["akimatter"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-04-16"
|
13
|
+
s.description = "schema_comments generates extra methods dynamically for attribute which has options"
|
14
|
+
s.email = "akm2000@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
"spec/database.yml",
|
42
|
-
"spec/fixtures/.gitignore",
|
43
|
-
"spec/hash_key_orderable_spec.rb",
|
44
|
-
"spec/i18n_export_spec.rb",
|
45
|
-
"spec/migration_spec.rb",
|
46
|
-
"spec/migrations/valid/001_create_products.rb",
|
47
|
-
"spec/migrations/valid/002_rename_products.rb",
|
48
|
-
"spec/migrations/valid/003_rename_products_again.rb",
|
49
|
-
"spec/migrations/valid/004_remove_price.rb",
|
50
|
-
"spec/migrations/valid/005_change_products_name.rb",
|
51
|
-
"spec/migrations/valid/006_change_products_name_with_comment.rb",
|
52
|
-
"spec/migrations/valid/007_change_comments.rb",
|
53
|
-
"spec/migrations/valid/008_create_users_without_comment.rb",
|
54
|
-
"spec/rcov.opts",
|
55
|
-
"spec/resources/models/product.rb",
|
56
|
-
"spec/resources/models/product_name.rb",
|
57
|
-
"spec/schema.rb",
|
58
|
-
"spec/schema_comments/.gitignore",
|
59
|
-
"spec/schema_comments/connection_adapters_spec.rb",
|
60
|
-
"spec/schema_comments/schema_comment_spec.rb",
|
61
|
-
"spec/schema_comments/schema_comments_broken_column_comments.yml",
|
62
|
-
"spec/schema_comments/schema_comments_broken_column_hash.yml",
|
63
|
-
"spec/schema_comments/schema_comments_broken_table_comments.yml",
|
64
|
-
"spec/schema_comments/schema_comments_users_without_column_hash.yml",
|
65
|
-
"spec/schema_comments/schema_dumper_spec.rb",
|
66
|
-
"spec/spec.opts",
|
67
|
-
"spec/spec_helper.rb",
|
68
|
-
"spec/yaml_export_spec.rb",
|
69
|
-
"tasks/annotate_models_tasks.rake",
|
70
|
-
"tasks/schema_comments.rake"
|
71
|
-
]
|
72
|
-
s.homepage = %q{http://github.com/akm/schema_comments}
|
73
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
74
|
-
s.require_paths = ["lib"]
|
75
|
-
s.rubygems_version = %q{1.3.6}
|
76
|
-
s.summary = %q{schema_comments generates extra methods dynamically}
|
77
|
-
s.test_files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"autotest/discover.rb",
|
27
|
+
"init.rb",
|
28
|
+
"lib/annotate_models.rb",
|
29
|
+
"lib/hash_key_orderable.rb",
|
30
|
+
"lib/schema_comments.rb",
|
31
|
+
"lib/schema_comments/base.rb",
|
32
|
+
"lib/schema_comments/connection_adapters.rb",
|
33
|
+
"lib/schema_comments/migration.rb",
|
34
|
+
"lib/schema_comments/migrator.rb",
|
35
|
+
"lib/schema_comments/schema.rb",
|
36
|
+
"lib/schema_comments/schema_comment.rb",
|
37
|
+
"lib/schema_comments/schema_dumper.rb",
|
38
|
+
"lib/schema_comments/task.rb",
|
39
|
+
"schema_comments.gemspec",
|
40
|
+
"spec/.gitignore",
|
78
41
|
"spec/annotate_models_spec.rb",
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
42
|
+
"spec/database.yml",
|
43
|
+
"spec/fake_app.rb",
|
44
|
+
"spec/fixtures/.gitignore",
|
45
|
+
"spec/hash_key_orderable_spec.rb",
|
46
|
+
"spec/i18n_export_spec.rb",
|
47
|
+
"spec/migration_spec.rb",
|
48
|
+
"spec/migrations/valid/001_create_products.rb",
|
49
|
+
"spec/migrations/valid/002_rename_products.rb",
|
50
|
+
"spec/migrations/valid/003_rename_products_again.rb",
|
51
|
+
"spec/migrations/valid/004_remove_price.rb",
|
52
|
+
"spec/migrations/valid/005_change_products_name.rb",
|
53
|
+
"spec/migrations/valid/006_change_products_name_with_comment.rb",
|
54
|
+
"spec/migrations/valid/007_change_comments.rb",
|
55
|
+
"spec/migrations/valid/008_create_users_without_comment.rb",
|
56
|
+
"spec/rcov.opts",
|
57
|
+
"spec/resources/models/product.rb",
|
58
|
+
"spec/resources/models/product_name.rb",
|
59
|
+
"spec/schema.rb",
|
60
|
+
"spec/schema_comments/.gitignore",
|
61
|
+
"spec/schema_comments/connection_adapters_spec.rb",
|
62
|
+
"spec/schema_comments/schema_comment_spec.rb",
|
63
|
+
"spec/schema_comments/schema_comments_broken_column_comments.yml",
|
64
|
+
"spec/schema_comments/schema_comments_broken_column_hash.yml",
|
65
|
+
"spec/schema_comments/schema_comments_broken_table_comments.yml",
|
66
|
+
"spec/schema_comments/schema_comments_users_without_column_hash.yml",
|
67
|
+
"spec/schema_comments/schema_dumper_spec.rb",
|
68
|
+
"spec/spec.opts",
|
69
|
+
"spec/spec_helper.rb",
|
70
|
+
"spec/yaml_export_spec.rb",
|
71
|
+
"tasks/annotate_models_tasks.rake",
|
72
|
+
"tasks/schema_comments.rake"
|
106
73
|
]
|
74
|
+
s.homepage = "http://github.com/akm/schema_comments"
|
75
|
+
s.licenses = ["Ruby License"]
|
76
|
+
s.require_paths = ["lib"]
|
77
|
+
s.rubygems_version = "1.8.15"
|
78
|
+
s.summary = "schema_comments generates extra methods dynamically"
|
79
|
+
s.test_files = ["spec/annotate_models_spec.rb", "spec/fake_app.rb", "spec/hash_key_orderable_spec.rb", "spec/i18n_export_spec.rb", "spec/migration_spec.rb", "spec/migrations/valid/001_create_products.rb", "spec/migrations/valid/002_rename_products.rb", "spec/migrations/valid/003_rename_products_again.rb", "spec/migrations/valid/004_remove_price.rb", "spec/migrations/valid/005_change_products_name.rb", "spec/migrations/valid/006_change_products_name_with_comment.rb", "spec/migrations/valid/007_change_comments.rb", "spec/migrations/valid/008_create_users_without_comment.rb", "spec/resources/models/product.rb", "spec/resources/models/product_name.rb", "spec/schema.rb", "spec/schema_comments/connection_adapters_spec.rb", "spec/schema_comments/schema_comment_spec.rb", "spec/schema_comments/schema_dumper_spec.rb", "spec/spec_helper.rb", "spec/yaml_export_spec.rb", "spec/database.yml", "spec/human_readable_schema_comments.yml", "spec/schema_comments/schema_comments.yml", "spec/schema_comments/schema_comments_broken_column_comments.yml", "spec/schema_comments/schema_comments_broken_column_hash.yml", "spec/schema_comments/schema_comments_broken_table_comments.yml", "spec/schema_comments/schema_comments_users_without_column_hash.yml", "spec/schema_comments.yml"]
|
107
80
|
|
108
81
|
if s.respond_to? :specification_version then
|
109
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
110
82
|
s.specification_version = 3
|
111
83
|
|
112
|
-
if Gem::Version.new(Gem::
|
113
|
-
s.
|
84
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
85
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.1.0"])
|
86
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 3.1.0"])
|
87
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
88
|
+
s.add_development_dependency(%q<rspec-rails>, ["~> 2.8.1"])
|
89
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
90
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
91
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
92
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
93
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
114
94
|
else
|
115
|
-
s.add_dependency(%q<
|
95
|
+
s.add_dependency(%q<activesupport>, ["~> 3.1.0"])
|
96
|
+
s.add_dependency(%q<activerecord>, ["~> 3.1.0"])
|
97
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
98
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.8.1"])
|
99
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
100
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
101
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
102
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
103
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
116
104
|
end
|
117
105
|
else
|
118
|
-
s.add_dependency(%q<
|
106
|
+
s.add_dependency(%q<activesupport>, ["~> 3.1.0"])
|
107
|
+
s.add_dependency(%q<activerecord>, ["~> 3.1.0"])
|
108
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
109
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.8.1"])
|
110
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
111
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
112
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
113
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
114
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
119
115
|
end
|
120
116
|
end
|
121
117
|
|
@@ -15,10 +15,10 @@ describe AnnotateModels do
|
|
15
15
|
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
16
16
|
ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "get_schema_info" do
|
20
20
|
(ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
|
21
|
-
|
21
|
+
|
22
22
|
ActiveRecord::Schema.define(:version => "20090721185959") do
|
23
23
|
drop_table("books") rescue nil
|
24
24
|
|
@@ -52,5 +52,5 @@ describe AnnotateModels do
|
|
52
52
|
#
|
53
53
|
}
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
end
|
data/spec/fake_app.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
# see https://github.com/amatsuda/kaminari/blob/master/spec/fake_app.rb
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
require 'action_controller/railtie'
|
6
|
+
require 'action_view/railtie'
|
7
|
+
|
8
|
+
# database
|
9
|
+
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
|
10
|
+
ActiveRecord::Base.establish_connection('test')
|
11
|
+
|
12
|
+
# config
|
13
|
+
app = Class.new(Rails::Application)
|
14
|
+
app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
|
15
|
+
app.config.session_store :cookie_store, :key => "_myapp_session"
|
16
|
+
app.config.active_support.deprecation = :log
|
17
|
+
app.initialize!
|
data/spec/i18n_export_spec.rb
CHANGED
@@ -13,32 +13,32 @@ describe SchemaComments::Base do
|
|
13
13
|
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
14
14
|
ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "test_valid_migration" do
|
18
18
|
(ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
|
19
|
-
|
19
|
+
|
20
20
|
migration_path = File.join(MIGRATIONS_ROOT, 'valid')
|
21
21
|
Dir.glob('*.rb').each do |file|
|
22
22
|
require(file) if /^\d+?_.*/ =~ file
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
Product.reset_table_comments
|
26
26
|
Product.reset_column_comments
|
27
27
|
|
28
28
|
ActiveRecord::Migrator.up(migration_path, 1)
|
29
29
|
ActiveRecord::Migrator.current_version.should == 1
|
30
|
-
|
30
|
+
|
31
31
|
ActiveRecord::Base.export_i18n_models.keys.include?('product').should == true
|
32
32
|
ActiveRecord::Base.export_i18n_models['product'].should == '商品'
|
33
|
-
|
33
|
+
|
34
34
|
ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
|
35
35
|
ActiveRecord::Base.export_i18n_attributes['product'].should == {
|
36
|
-
'product_type_cd' => '種別コード',
|
36
|
+
'product_type_cd' => '種別コード',
|
37
37
|
"price" => "価格",
|
38
38
|
"name" => "商品名",
|
39
39
|
"created_at" => "登録日時",
|
40
40
|
"updated_at" => "更新日時"
|
41
41
|
}
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
end
|
@@ -8,7 +8,7 @@ describe SchemaComments::ConnectionAdapters do
|
|
8
8
|
before(:each) do
|
9
9
|
SchemaComments.yaml_path = File.expand_path(File.join(File.dirname(__FILE__), 'schema_comments.yml'))
|
10
10
|
FileUtils.rm(SchemaComments.yaml_path, :verbose => true) if File.exist?(SchemaComments.yaml_path)
|
11
|
-
|
11
|
+
|
12
12
|
(ActiveRecord::Base.connection.tables - IGNORED_TABLES).each do |t|
|
13
13
|
ActiveRecord::Base.connection.drop_table(t) rescue nil
|
14
14
|
end
|
@@ -16,31 +16,31 @@ describe SchemaComments::ConnectionAdapters do
|
|
16
16
|
ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
|
17
17
|
|
18
18
|
(ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
|
19
|
-
|
19
|
+
|
20
20
|
migration_path = File.join(MIGRATIONS_ROOT, 'valid')
|
21
21
|
Dir.glob('*.rb').each do |file|
|
22
22
|
require(file) if /^\d+?_.*/ =~ file
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
Product.reset_table_comments
|
26
26
|
Product.reset_column_comments
|
27
|
-
|
27
|
+
|
28
28
|
ActiveRecord::Migrator.up(migration_path, 1)
|
29
29
|
ActiveRecord::Migrator.current_version.should == 1
|
30
30
|
|
31
31
|
ActiveRecord::Base.export_i18n_models.keys.include?('product').should == true
|
32
32
|
ActiveRecord::Base.export_i18n_models['product'].should == '商品'
|
33
|
-
|
33
|
+
|
34
34
|
ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
|
35
35
|
ActiveRecord::Base.export_i18n_attributes['product'].should == {
|
36
|
-
'product_type_cd' => '種別コード',
|
36
|
+
'product_type_cd' => '種別コード',
|
37
37
|
"price" => "価格",
|
38
38
|
"name" => "商品名",
|
39
39
|
"created_at" => "登録日時",
|
40
40
|
"updated_at" => "更新日時"
|
41
41
|
}
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
describe SchemaComments::ConnectionAdapters::Column do
|
45
45
|
describe :comment do
|
46
46
|
it "should return comment" do
|
@@ -8,7 +8,7 @@ describe SchemaComments::SchemaComment do
|
|
8
8
|
before(:each) do
|
9
9
|
SchemaComments.yaml_path = File.expand_path(File.join(File.dirname(__FILE__), 'schema_comments.yml'))
|
10
10
|
FileUtils.rm(SchemaComments.yaml_path, :verbose => true) if File.exist?(SchemaComments.yaml_path)
|
11
|
-
|
11
|
+
|
12
12
|
(ActiveRecord::Base.connection.tables - IGNORED_TABLES).each do |t|
|
13
13
|
ActiveRecord::Base.connection.drop_table(t) rescue nil
|
14
14
|
end
|
@@ -45,7 +45,7 @@ describe SchemaComments::SchemaComment do
|
|
45
45
|
ActiveRecord::Migrator.up(migration_path, 8)
|
46
46
|
ActiveRecord::Migrator.current_version.should == 8
|
47
47
|
|
48
|
-
SchemaComments.yaml_path =
|
48
|
+
SchemaComments.yaml_path =
|
49
49
|
File.expand_path(File.join(
|
50
50
|
File.dirname(__FILE__), "schema_comments_users_without_column_hash.yml"))
|
51
51
|
SchemaComments::SchemaComment.yaml_access do |db|
|
@@ -64,7 +64,7 @@ describe SchemaComments::SchemaComment do
|
|
64
64
|
ActiveRecord::Migrator.up(migration_path, 8)
|
65
65
|
ActiveRecord::Migrator.current_version.should == 8
|
66
66
|
|
67
|
-
SchemaComments.yaml_path =
|
67
|
+
SchemaComments.yaml_path =
|
68
68
|
File.expand_path(File.join(
|
69
69
|
File.dirname(__FILE__), "schema_comments_broken_#{broken_type}.yml"))
|
70
70
|
lambda{
|
@@ -72,7 +72,7 @@ describe SchemaComments::SchemaComment do
|
|
72
72
|
}.should raise_error(SchemaComments::YamlError)
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
end
|
77
77
|
|
78
78
|
end
|
@@ -8,14 +8,14 @@ describe ActiveRecord::SchemaDumper do
|
|
8
8
|
before(:each) do
|
9
9
|
SchemaComments.yaml_path = File.expand_path(File.join(File.dirname(__FILE__), 'schema_comments.yml'))
|
10
10
|
FileUtils.rm(SchemaComments.yaml_path, :verbose => true) if File.exist?(SchemaComments.yaml_path)
|
11
|
-
|
11
|
+
|
12
12
|
(ActiveRecord::Base.connection.tables - IGNORED_TABLES).each do |t|
|
13
13
|
ActiveRecord::Base.connection.drop_table(t) rescue nil
|
14
14
|
end
|
15
15
|
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
16
16
|
ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
describe :dump do
|
20
20
|
it "products" do
|
21
21
|
(ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
|
@@ -34,7 +34,7 @@ describe ActiveRecord::SchemaDumper do
|
|
34
34
|
|
35
35
|
ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
|
36
36
|
ActiveRecord::Base.export_i18n_attributes['product'].should == {
|
37
|
-
'product_type_cd' => '種別コード',
|
37
|
+
'product_type_cd' => '種別コード',
|
38
38
|
"price" => "価格",
|
39
39
|
"name" => "商品名",
|
40
40
|
"created_at" => "登録日時",
|
@@ -45,13 +45,15 @@ describe ActiveRecord::SchemaDumper do
|
|
45
45
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, dest)
|
46
46
|
dest.rewind
|
47
47
|
dest.read.should == <<EOS
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
48
|
+
# encoding: UTF-8
|
49
|
+
# This file is auto-generated from the current state of the database. Instead
|
50
|
+
# of editing this file, please use the migrations feature of Active Record to
|
51
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
51
52
|
#
|
52
|
-
# Note that this schema.rb definition is the authoritative source for your
|
53
|
-
# to create the application database on another
|
54
|
-
#
|
53
|
+
# Note that this schema.rb definition is the authoritative source for your
|
54
|
+
# database schema. If you need to create the application database on another
|
55
|
+
# system, you should be using db:schema:load, not running all the migrations
|
56
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
55
57
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
56
58
|
#
|
57
59
|
# It's strongly recommended to check this file into your version control system.
|