schema_comments 0.1.2 → 0.1.3

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/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.log
2
2
  *~
3
+ /coverage
3
4
  /pkg
4
5
  /selectable_attr_test.sqlite3.db
data/README.rdoc CHANGED
@@ -8,14 +8,12 @@ SchemaComments
8
8
 
9
9
  === as a gem
10
10
  insert following line to config/environment.rb
11
- config.gem 'schema_comments', :version => '0.1.1'
11
+ config.gem 'schema_comments', :version => '0.1.3'
12
12
  and
13
13
  $ sudo rake gems:install
14
14
 
15
15
  Or install gem manually
16
16
 
17
- $ sudo gem install gemcutter
18
- $ sudo gem tumble
19
17
  $ sudo gem install schema_comments
20
18
 
21
19
  And make lib/tasks/schema_comments.rake
data/Rakefile CHANGED
@@ -28,6 +28,9 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
28
  spec.libs << 'lib' << 'spec'
29
29
  spec.pattern = 'spec/**/*_spec.rb'
30
30
  spec.rcov = true
31
+ spec.rcov_opts = lambda do
32
+ IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
33
+ end
31
34
  end
32
35
 
33
36
  task :spec => :check_dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -0,0 +1,23 @@
1
+ module HashKeyOrderable
2
+ attr_accessor :key_order
3
+
4
+ def each_with_key_order(&block)
5
+ if @key_order.nil? || @key_order.empty?
6
+ each_without_key_order(&block)
7
+ return self
8
+ end
9
+ unexist_keys = @key_order - self.keys
10
+ actual_order = (@key_order - unexist_keys) | self.keys
11
+ actual_order.each do |key|
12
+ yield(key, self[key])
13
+ end
14
+ self
15
+ end
16
+
17
+ def self.extended(obj)
18
+ obj.instance_eval do
19
+ alias :each_without_key_order :each
20
+ alias :each :each_with_key_order
21
+ end
22
+ end
23
+ end
@@ -5,14 +5,14 @@ module SchemaComments
5
5
  module Column
6
6
  attr_accessor :comment
7
7
  end
8
-
8
+
9
9
  module ColumnDefinition
10
10
  attr_accessor :comment
11
11
  end
12
-
12
+
13
13
  module TableDefinition
14
14
  def self.included(mod)
15
- mod.module_eval do
15
+ mod.module_eval do
16
16
  alias_method_chain(:column, :schema_comments)
17
17
  end
18
18
  end
@@ -25,7 +25,7 @@ module SchemaComments
25
25
  self
26
26
  end
27
27
  end
28
-
28
+
29
29
  module Adapter
30
30
  def column_comment(table_name, column_name, comment = nil) #:nodoc:
31
31
  if comment
@@ -35,23 +35,23 @@ module SchemaComments
35
35
  SchemaComment.column_comment(table_name, column_name)
36
36
  end
37
37
  end
38
-
38
+
39
39
  # Mass assignment of comments in the form of a hash. Example:
40
- # column_comments {
41
- # :users => {:first_name => "User's given name", :last_name => "Family name"},
42
- # :tags => {:id => "Tag IDentifier"}}
43
- def column_comments(contents)
44
- if contents.is_a?(Hash)
45
- contents.each_pair do |table, cols|
46
- cols.each_pair do |col, comment|
47
- column_comment(table, col, comment) unless SchemaComments.quiet
48
- end
40
+ # column_comments(:users, {:first_name => "User's given name", :last_name => "Family name"})
41
+ # column_comments(:tags , {:id => "Tag IDentifier"})
42
+ def column_comments(*args)
43
+ if (args.length == 2) && args.last.is_a?(Hash)
44
+ # マイグレーションからActiveRecord関係を経由して呼び出されます。
45
+ table_name = args.first.to_s
46
+ args.last.each do |col, comment|
47
+ column_comment(table_name, col, comment) unless SchemaComments.quiet
49
48
  end
50
49
  else
51
- SchemaComment.column_comments(contents)
50
+ # こっちはSchemaComments::Base::ClassMethods#columns_with_schema_commentsから呼び出されます。
51
+ SchemaComment.column_comments(args)
52
52
  end
53
53
  end
54
-
54
+
55
55
  def table_comment(table_name, comment = nil) #:nodoc:
56
56
  if comment
57
57
  comment = (comment[:comment] || comment['comment']) if comment.is_a?(Hash)
@@ -61,23 +61,23 @@ module SchemaComments
61
61
  SchemaComment.table_comment(table_name)
62
62
  end
63
63
  end
64
-
64
+
65
65
  def delete_schema_comments(table_name, column_name = nil)
66
66
  SchemaComment.destroy_of(table_name, column_name) unless SchemaComments.quiet
67
67
  end
68
-
68
+
69
69
  def update_schema_comments_table_name(table_name, new_name)
70
70
  SchemaComment.update_table_name(table_name, new_name) unless SchemaComments.quiet
71
71
  end
72
-
72
+
73
73
  def update_schema_comments_column_name(table_name, column_name, new_name)
74
74
  SchemaComment.update_column_name(table_name, column_name, new_name) unless SchemaComments.quiet
75
75
  end
76
76
  end
77
-
77
+
78
78
  module ConcreteAdapter
79
79
  def self.included(mod)
80
- mod.module_eval do
80
+ mod.module_eval do
81
81
  alias_method_chain :columns, :schema_comments
82
82
  alias_method_chain :create_table, :schema_comments
83
83
  alias_method_chain :drop_table, :schema_comments
@@ -88,7 +88,7 @@ module SchemaComments
88
88
  alias_method_chain :rename_column, :schema_comments
89
89
  end
90
90
  end
91
-
91
+
92
92
  def columns_with_schema_comments(table_name, name = nil, &block)
93
93
  result = columns_without_schema_comments(table_name, name, &block)
94
94
  column_comment_hash = column_comments(table_name)
@@ -97,7 +97,7 @@ module SchemaComments
97
97
  end
98
98
  result
99
99
  end
100
-
100
+
101
101
  def create_table_with_schema_comments(table_name, options = {}, &block)
102
102
  table_def = nil
103
103
  result = create_table_without_schema_comments(table_name, options) do |t|
@@ -110,19 +110,19 @@ module SchemaComments
110
110
  end
111
111
  result
112
112
  end
113
-
113
+
114
114
  def drop_table_with_schema_comments(table_name, options = {}, &block)
115
115
  result = drop_table_without_schema_comments(table_name, options)
116
116
  delete_schema_comments(table_name) unless @ignore_drop_table
117
117
  result
118
118
  end
119
-
119
+
120
120
  def rename_table_with_schema_comments(table_name, new_name)
121
121
  result = rename_table_without_schema_comments(table_name, new_name)
122
122
  update_schema_comments_table_name(table_name, new_name)
123
123
  result
124
124
  end
125
-
125
+
126
126
  def remove_column_with_schema_comments(table_name, *column_names)
127
127
  # sqlite3ではremove_columnがないので、以下のフローでスキーマ更新します。
128
128
  # 1. CREATE TEMPORARY TABLE "altered_xxxxxx" (・・・)
@@ -131,7 +131,7 @@ module SchemaComments
131
131
  # 4. CREATE TABLE "xxxxxx"
132
132
  # 5. PRAGMA index_list("altered_xxxxxx")
133
133
  # 6. DROP TABLE "altered_xxxxxx"
134
- #
134
+ #
135
135
  # このdrop tableの際に、schema_commentsを変更しないようにフラグを立てています。
136
136
  @ignore_drop_table = true
137
137
  remove_column_without_schema_comments(table_name, *column_names)
@@ -141,14 +141,14 @@ module SchemaComments
141
141
  ensure
142
142
  @ignore_drop_table = false
143
143
  end
144
-
144
+
145
145
  def add_column_with_schema_comments(table_name, column_name, type, options = {})
146
146
  comment = options.delete(:comment)
147
147
  result = add_column_without_schema_comments(table_name, column_name, type, options)
148
148
  column_comment(table_name, column_name, comment) if comment
149
149
  result
150
150
  end
151
-
151
+
152
152
  def change_column_with_schema_comments(table_name, column_name, type, options = {})
153
153
  comment = options.delete(:comment)
154
154
  @ignore_drop_table = true
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'yaml/store'
3
+ require 'hash_key_orderable'
3
4
 
4
5
  module SchemaComments
5
6
  # 現在はActiveRecord::Baseを継承していますが、将来移行が完全に終了した
@@ -120,14 +121,6 @@ module SchemaComments
120
121
  end
121
122
 
122
123
  class SortedStore < YAML::Store
123
- module ColumnNamedHash
124
- def each
125
- @column_names.each do |column_name|
126
- yield(column_name, self[column_name])
127
- end
128
- end
129
- end
130
-
131
124
  def dump(table)
132
125
  root = nil
133
126
  StringIO.open do |io|
@@ -135,7 +128,6 @@ module SchemaComments
135
128
  io.rewind
136
129
  root = YAML.load(io)
137
130
  end
138
-
139
131
  table_comments = root['table_comments']
140
132
  column_comments = root['column_comments']
141
133
  # 大元は
@@ -146,34 +138,15 @@ module SchemaComments
146
138
  # その他
147
139
  # ...
148
140
  # の順番です。
149
- root.instance_eval do
150
- def each
151
- yield('table_comments', self['table_comments'])
152
- yield('column_comments', self['column_comments'])
153
- (self.keys - ['table_comments', 'column_comments']).each do |key|
154
- yield(key, self[key])
155
- end
156
- end
157
- end
141
+ root.extend(HashKeyOrderable)
142
+ root.key_order = %w(table_comments column_comments)
158
143
  # table_comments はテーブル名のアルファベット順
159
144
  table_names = ActiveRecord::Base.connection.tables.sort - ['schema_migrations']
160
- table_comments.instance_variable_set(:@table_names, table_names)
161
- table_comments.instance_eval do
162
- def each
163
- @table_names.each do |key|
164
- yield(key, self[key])
165
- end
166
- end
167
- end
145
+ table_comments.extend(HashKeyOrderable)
146
+ table_comments.key_order = table_names
168
147
  # column_comments もテーブル名のアルファベット順
169
- column_comments.instance_variable_set(:@table_names, table_names)
170
- column_comments.instance_eval do
171
- def each
172
- @table_names.each do |key|
173
- yield(key, self[key])
174
- end
175
- end
176
- end
148
+ column_comments.extend(HashKeyOrderable)
149
+ column_comments.key_order = table_names
177
150
  # column_comments の各値はテーブルのカラム順
178
151
  column_comments.each do |table_name, column_hash|
179
152
  column_names = nil
@@ -184,8 +157,8 @@ module SchemaComments
184
157
  column_names = column_hash.keys.sort
185
158
  end
186
159
  column_names.delete('id')
187
- column_hash.instance_variable_set(:@column_names, column_names)
188
- column_hash.extend(ColumnNamedHash)
160
+ column_hash.extend(HashKeyOrderable)
161
+ column_hash.key_order = column_names
189
162
  end
190
163
  root.to_yaml(@opt)
191
164
  end
@@ -77,7 +77,7 @@ module SchemaComments
77
77
  spec[:scale] = column.scale.inspect if !column.scale.nil?
78
78
  spec[:null] = 'false' if !column.null
79
79
  spec[:default] = default_string(column.default) if !column.default.nil?
80
- spec[:comment] = (column.comment || '').inspect
80
+ spec[:comment] = '"' << (column.comment || '').gsub(/\"/, '\"') << '"' # ここでinspectを使うと最後の文字だけ文字化け(UTF-8のコード)になっちゃう
81
81
  (spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k.inspect} => ")}
82
82
  spec
83
83
  end.compact
@@ -86,10 +86,12 @@ module SchemaComments
86
86
  keys = [:name, :limit, :precision, :scale, :default, :null, :comment] & column_specs.map(&:keys).flatten
87
87
 
88
88
  # figure out the lengths for each column based on above keys
89
- lengths = keys.map{ |key| column_specs.map{ |spec| spec[key] ? spec[key].length + 2 : 0 }.max }
89
+ lengths = keys.map{ |key|
90
+ column_specs.map{ |spec| spec[key] ? spec[key].length + 2 : 0 }.max
91
+ }
90
92
 
91
93
  # the string we're going to sprintf our values against, with standardized column widths
92
- format_string = lengths.map{ |len| "%-#{len}s" }
94
+ format_string = lengths.map{|len| len ? "%-#{len}s" : "%s" }
93
95
 
94
96
  # find the max length for the 'type' column, which is special
95
97
  type_length = column_specs.map{ |column| column[:type].length }.max
@@ -5,26 +5,27 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{schema_comments}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["akimatter"]
12
- s.date = %q{2009-12-13}
12
+ s.date = %q{2010-04-13}
13
13
  s.description = %q{schema_comments generates extra methods dynamically for attribute which has options}
14
14
  s.email = %q{akm2000@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".gitignore",
21
21
  "LICENSE.txt",
22
- "README",
22
+ "README.rdoc",
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "autotest/discover.rb",
26
26
  "init.rb",
27
27
  "lib/annotate_models.rb",
28
+ "lib/hash_key_orderable.rb",
28
29
  "lib/schema_comments.rb",
29
30
  "lib/schema_comments/base.rb",
30
31
  "lib/schema_comments/connection_adapters.rb",
@@ -39,6 +40,7 @@ Gem::Specification.new do |s|
39
40
  "spec/annotate_models_spec.rb",
40
41
  "spec/database.yml",
41
42
  "spec/fixtures/.gitignore",
43
+ "spec/hash_key_orderable_spec.rb",
42
44
  "spec/i18n_export_spec.rb",
43
45
  "spec/migration_spec.rb",
44
46
  "spec/migrations/valid/001_create_products.rb",
@@ -47,10 +49,14 @@ Gem::Specification.new do |s|
47
49
  "spec/migrations/valid/004_remove_price.rb",
48
50
  "spec/migrations/valid/005_change_products_name.rb",
49
51
  "spec/migrations/valid/006_change_products_name_with_comment.rb",
52
+ "spec/migrations/valid/007_change_comments.rb",
53
+ "spec/rcov.opts",
50
54
  "spec/resources/models/product.rb",
51
55
  "spec/resources/models/product_name.rb",
52
56
  "spec/schema.rb",
53
- "spec/schema_dumper_spec.rb",
57
+ "spec/schema_comments/.gitignore",
58
+ "spec/schema_comments/connection_adapters_spec.rb",
59
+ "spec/schema_comments/schema_dumper_spec.rb",
54
60
  "spec/spec.opts",
55
61
  "spec/spec_helper.rb",
56
62
  "spec/yaml_export_spec.rb",
@@ -60,10 +66,11 @@ Gem::Specification.new do |s|
60
66
  s.homepage = %q{http://github.com/akm/schema_comments}
61
67
  s.rdoc_options = ["--charset=UTF-8"]
62
68
  s.require_paths = ["lib"]
63
- s.rubygems_version = %q{1.3.5}
69
+ s.rubygems_version = %q{1.3.6}
64
70
  s.summary = %q{schema_comments generates extra methods dynamically}
65
71
  s.test_files = [
66
72
  "spec/annotate_models_spec.rb",
73
+ "spec/hash_key_orderable_spec.rb",
67
74
  "spec/i18n_export_spec.rb",
68
75
  "spec/migration_spec.rb",
69
76
  "spec/migrations/valid/001_create_products.rb",
@@ -72,10 +79,12 @@ Gem::Specification.new do |s|
72
79
  "spec/migrations/valid/004_remove_price.rb",
73
80
  "spec/migrations/valid/005_change_products_name.rb",
74
81
  "spec/migrations/valid/006_change_products_name_with_comment.rb",
82
+ "spec/migrations/valid/007_change_comments.rb",
75
83
  "spec/resources/models/product.rb",
76
84
  "spec/resources/models/product_name.rb",
77
85
  "spec/schema.rb",
78
- "spec/schema_dumper_spec.rb",
86
+ "spec/schema_comments/connection_adapters_spec.rb",
87
+ "spec/schema_comments/schema_dumper_spec.rb",
79
88
  "spec/spec_helper.rb",
80
89
  "spec/yaml_export_spec.rb"
81
90
  ]
@@ -0,0 +1,50 @@
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
@@ -91,6 +91,19 @@ describe ActiveRecord::Migrator do
91
91
  ActiveRecord::Migrator.current_version.should == 6
92
92
  Product.reset_column_comments
93
93
  Product.columns.detect{|c| c.name == 'name'}.comment.should == '名称'
94
+
95
+ # Bug report from Ishikawa, Thanks!
96
+ # schema_commentsのcolumn_commentsがうまく動かないみたいです。
97
+ # カラムを定義するついでにコメントを付加するのは動くのですが、
98
+ # コメントだけあとから付けようとすると、カラムへのコメントが付きません。
99
+ #
100
+ # column_comments(:table_name => {:column_name => "name"})
101
+ # 上記のようにメソッドを呼び出しても、なぜか引数がHashではなくStringで取れてしまうみたいです。
102
+ ActiveRecord::Migrator.up(migration_path, 7)
103
+ ActiveRecord::Migrator.current_version.should == 7
104
+ Product.reset_column_comments
105
+ Product.columns.detect{|c| c.name == 'name'}.comment.should == '商品名称'
106
+ Product.columns.detect{|c| c.name == 'product_type_cd'}.comment.should == 'カテゴリコード'
94
107
  end
95
108
 
96
109
  end
@@ -0,0 +1,12 @@
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
data/spec/rcov.opts ADDED
@@ -0,0 +1 @@
1
+ --exclude "spec/*,gems/*"
@@ -0,0 +1,2 @@
1
+ /human_readable_schema_comments.yml
2
+ /schema_comments.yml
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), '../spec_helper')
3
+
4
+ describe SchemaComments::ConnectionAdapters do
5
+
6
+ IGNORED_TABLES = %w(schema_migrations)
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
+
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
+ describe SchemaComments::ConnectionAdapters::Column do
45
+ describe :comment do
46
+ it "should return comment" do
47
+ Product.columns.detect{|c| c.name == "product_type_cd"}.comment.should == '種別コード'
48
+ Product.columns.detect{|c| c.name == "price"}.comment.should == '価格'
49
+ Product.columns.detect{|c| c.name == "name"}.comment.should == '商品名'
50
+ Product.columns.detect{|c| c.name == "created_at"}.comment.should == '登録日時'
51
+ Product.columns.detect{|c| c.name == "updated_at"}.comment.should == '更新日時'
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require File.join(File.dirname(__FILE__), '../spec_helper')
3
3
 
4
4
  describe ActiveRecord::SchemaDumper do
5
5
 
@@ -16,36 +16,37 @@ describe ActiveRecord::SchemaDumper do
16
16
  ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
17
17
  end
18
18
 
19
- it "dump" do
20
- (ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
21
-
22
- migration_path = File.join(MIGRATIONS_ROOT, 'valid')
23
- Dir.glob('*.rb').each do |file|
24
- require(file) if /^\d+?_.*/ =~ file
25
- end
26
-
27
- Product.reset_table_comments
28
- Product.reset_column_comments
19
+ describe :dump do
20
+ it "products" do
21
+ (ActiveRecord::Base.connection.tables - %w(schema_migrations)).should == []
29
22
 
30
- ActiveRecord::Migrator.up(migration_path, 1)
31
- ActiveRecord::Migrator.current_version.should == 1
32
-
33
- ActiveRecord::Base.export_i18n_models.keys.include?('product').should == true
34
- ActiveRecord::Base.export_i18n_models['product'].should == '商品'
35
-
36
- ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
37
- ActiveRecord::Base.export_i18n_attributes['product'].should == {
38
- 'product_type_cd' => '種別コード',
39
- "price" => "価格",
40
- "name" => "商品名",
41
- "created_at" => "登録日時",
42
- "updated_at" => "更新日時"
43
- }
23
+ migration_path = File.join(MIGRATIONS_ROOT, 'valid')
24
+ Dir.glob('*.rb').each do |file|
25
+ require(file) if /^\d+?_.*/ =~ file
26
+ end
27
+
28
+ Product.reset_table_comments
29
+ Product.reset_column_comments
44
30
 
45
- dest = StringIO.new
46
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, dest)
47
- dest.rewind
48
- dest.read.should == <<EOS
31
+ ActiveRecord::Migrator.up(migration_path, 1)
32
+ ActiveRecord::Migrator.current_version.should == 1
33
+
34
+ ActiveRecord::Base.export_i18n_models.keys.include?('product').should == true
35
+ ActiveRecord::Base.export_i18n_models['product'].should == '商品'
36
+
37
+ ActiveRecord::Base.export_i18n_attributes.keys.include?('product').should == true
38
+ ActiveRecord::Base.export_i18n_attributes['product'].should == {
39
+ 'product_type_cd' => '種別コード',
40
+ "price" => "価格",
41
+ "name" => "商品名",
42
+ "created_at" => "登録日時",
43
+ "updated_at" => "更新日時"
44
+ }
45
+
46
+ dest = StringIO.new
47
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, dest)
48
+ dest.rewind
49
+ dest.read.should == <<EOS
49
50
  # This file is auto-generated from the current state of the database. Instead of editing this file,
50
51
  # please use the migrations feature of Active Record to incrementally modify your database, and
51
52
  # then regenerate this schema definition.
@@ -69,6 +70,7 @@ ActiveRecord::Schema.define(:version => 1) do
69
70
 
70
71
  end
71
72
  EOS
73
+ end
74
+
72
75
  end
73
-
74
76
  end
data/spec/spec_helper.rb CHANGED
@@ -21,7 +21,7 @@ unless defined?(RAILS_ENV)
21
21
  begin
22
22
  require 'yaml_waml'
23
23
  rescue
24
- $stderr.puts "yaml_waml not found. You should [sudo] gem install kakutani-yaml_waml"
24
+ $stderr.puts "yaml_waml not found. You should [sudo] gem install yaml_waml"
25
25
  end
26
26
 
27
27
  config = YAML.load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 3
9
+ version: 0.1.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - akimatter
@@ -9,19 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-14 00:00:00 +09:00
17
+ date: 2010-04-13 00:00:00 +09:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
23
31
  version: 1.2.9
24
- version:
32
+ type: :development
33
+ version_requirements: *id001
25
34
  description: schema_comments generates extra methods dynamically for attribute which has options
26
35
  email: akm2000@gmail.com
27
36
  executables: []
@@ -40,6 +49,7 @@ files:
40
49
  - autotest/discover.rb
41
50
  - init.rb
42
51
  - lib/annotate_models.rb
52
+ - lib/hash_key_orderable.rb
43
53
  - lib/schema_comments.rb
44
54
  - lib/schema_comments/base.rb
45
55
  - lib/schema_comments/connection_adapters.rb
@@ -54,6 +64,7 @@ files:
54
64
  - spec/annotate_models_spec.rb
55
65
  - spec/database.yml
56
66
  - spec/fixtures/.gitignore
67
+ - spec/hash_key_orderable_spec.rb
57
68
  - spec/i18n_export_spec.rb
58
69
  - spec/migration_spec.rb
59
70
  - spec/migrations/valid/001_create_products.rb
@@ -62,10 +73,14 @@ files:
62
73
  - spec/migrations/valid/004_remove_price.rb
63
74
  - spec/migrations/valid/005_change_products_name.rb
64
75
  - spec/migrations/valid/006_change_products_name_with_comment.rb
76
+ - spec/migrations/valid/007_change_comments.rb
77
+ - spec/rcov.opts
65
78
  - spec/resources/models/product.rb
66
79
  - spec/resources/models/product_name.rb
67
80
  - spec/schema.rb
68
- - spec/schema_dumper_spec.rb
81
+ - spec/schema_comments/.gitignore
82
+ - spec/schema_comments/connection_adapters_spec.rb
83
+ - spec/schema_comments/schema_dumper_spec.rb
69
84
  - spec/spec.opts
70
85
  - spec/spec_helper.rb
71
86
  - spec/yaml_export_spec.rb
@@ -84,23 +99,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
99
  requirements:
85
100
  - - ">="
86
101
  - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
87
104
  version: "0"
88
- version:
89
105
  required_rubygems_version: !ruby/object:Gem::Requirement
90
106
  requirements:
91
107
  - - ">="
92
108
  - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
93
111
  version: "0"
94
- version:
95
112
  requirements: []
96
113
 
97
114
  rubyforge_project:
98
- rubygems_version: 1.3.5
115
+ rubygems_version: 1.3.6
99
116
  signing_key:
100
117
  specification_version: 3
101
118
  summary: schema_comments generates extra methods dynamically
102
119
  test_files:
103
120
  - spec/annotate_models_spec.rb
121
+ - spec/hash_key_orderable_spec.rb
104
122
  - spec/i18n_export_spec.rb
105
123
  - spec/migration_spec.rb
106
124
  - spec/migrations/valid/001_create_products.rb
@@ -109,9 +127,11 @@ test_files:
109
127
  - spec/migrations/valid/004_remove_price.rb
110
128
  - spec/migrations/valid/005_change_products_name.rb
111
129
  - spec/migrations/valid/006_change_products_name_with_comment.rb
130
+ - spec/migrations/valid/007_change_comments.rb
112
131
  - spec/resources/models/product.rb
113
132
  - spec/resources/models/product_name.rb
114
133
  - spec/schema.rb
115
- - spec/schema_dumper_spec.rb
134
+ - spec/schema_comments/connection_adapters_spec.rb
135
+ - spec/schema_comments/schema_dumper_spec.rb
116
136
  - spec/spec_helper.rb
117
137
  - spec/yaml_export_spec.rb