flextures 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  #gem "activerecord"
4
4
 
5
5
  group :development, :test do
6
- gem "bundler", "1.2.0"
6
+ gem "bundler", "1.3.5"
7
7
  gem "jeweler", "1.8.3"
8
8
  end
9
9
 
data/Gemfile.lock CHANGED
@@ -27,6 +27,6 @@ PLATFORMS
27
27
  ruby
28
28
 
29
29
  DEPENDENCIES
30
- bundler (= 1.2.0)
30
+ bundler (= 1.3.5)
31
31
  jeweler (= 1.8.3)
32
32
  shoulda
data/README.ja.rdoc CHANGED
@@ -15,8 +15,8 @@ Rails標準のfixtureの不満点を解消するために作成しました
15
15
  通常のfixtureとの主な違いは次の4点です
16
16
 
17
17
  1. yamlよりもcsvを優先する
18
- 2. migrationでテーブル構成が変わっても、ロードを停止しないで、カラムの変更点を検知して値を補完する
19
- 3. テーブル名と、fixtureのファイル名を一致させないでも自由なロード&ダンプが出来る機能
18
+ 2. migrationでテーブル構成が変わっても、カラムの変更点を無視、補完してロードを行う
19
+ 3. テーブル名とfixtureのファイル名を一致させないでも、自由なロード&ダンプが出来るオプション
20
20
  4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
21
21
 
22
22
  == インストール方法
@@ -26,14 +26,18 @@ gem化されているので、bundlerで次のように記述して、普通にb
26
26
 
27
27
  gem "flextures"
28
28
 
29
- ちなみに開発環境はruby1.9系、rails3環境を想定しています
29
+ 現在flexturesは機能を追加したバージョンアップをした3系への移行作業途中で
30
+ ソースコード、マニュアルは3系のものになっています
31
+ 最新版のソースコードはgithub上に挙げられているのでbundlerにguthubのリポジトリのURLを追加して下さい
32
+
33
+ ちなみに開発環境はruby1.9以上のバージョン、rails3以上、もしくはPadrinoを想定しています
30
34
 
31
35
  == 使い方
32
36
 
33
37
  === rakeコマンド
34
38
 
35
39
  次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
36
- (ディレクトリは設定ファイルで変更可能)
40
+ (読み込む基本のディレクトリは設定ファイルで変更可能)
37
41
 
38
42
  rake db:flextures:load
39
43
  rake db:flextures:dump
@@ -49,31 +53,31 @@ Usersモデルのfixture(users.csvか users.yml)をロードする
49
53
 
50
54
  rake db:flextures:load MODEL=User
51
55
 
52
- その他オプションは以下のとおりな感じです:
56
+ その他オプションは以下の通りです:
53
57
 
54
58
  TABLE : テーブル名を指定してロード。テーブル名はカンマ切りで複数指定が可能
55
59
  MODEL : モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能
56
60
  DIR : フィクスチャをロード&ダンプするディレクトリを指定する
57
- FIXTURES : ロード、ダンプをするファイル名をRails標準以外のもので直接指定(Userモデルのusers.csv以外を指定)
58
- FILE : ロード、ダンプをするファイル名をRails標準以外のもので直接指定(Userモデルのusers.csv以外を指定)
61
+ FILE : loadまたはdumpするファイル名を直接指定(Userモデルのusers.csv以外を指定)
62
+ FORMAT:ダンプ、またはロードするデータの種類を指定できる(csvかyml)
63
+ OPTION:その他の細かい読み込みオプションはここで指定出来ます
59
64
  T : TABLEのエイリアス
60
- M : モデル名指定のエイリアス
61
65
  D : ディレクトリ指定のエイリアス
62
66
  F : ファイル名指定のエイリアス
63
67
 
64
- yamlのファイルはロードしたいけどcsvはロードをしたくない
65
- またはその逆の場合は、以下のコマンドでそれが可能です
66
-
67
- rake db:flextures:csvload
68
- rake db:flextures:ymlload
69
- rake db:flextures:csvdump
70
- rake db:flextures:ymldump
68
+ migration等でテーブルの構成が変わった時には
69
+ generateコマンドを実行すると、テーブル情報のloadとdumpをセットで行なってくれるので便利です
70
+
71
+ rake db:flextures:generate T=users
71
72
 
72
- 通常の load や dump で使えるオプションはこちらでも使用可能です
73
+ さらに詳しい説明に関しては {Wiki:Rakeコマンドラインオプション}[https://github.com/baban/flextures/wiki/Rake%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3]を参照して下さい
73
74
 
74
- === RSpec flexture support
75
+ === Unit test flexture support
75
76
 
76
- RSpec中でfixtures関数の代わりにfixtureのロード機能を使えます
77
+ ユニットテスト中でデータの読み込みが行いたくなったときのために
78
+ fixtureのロード機能を使えます
79
+
80
+ 次の例はRSpecからの読み込みですが
77
81
  基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
78
82
 
79
83
  describe ItemShopController do
@@ -86,11 +90,15 @@ RSpec中でfixtures関数の代わりにfixtureのロード機能を使えます
86
90
  describe ItemShopController do
87
91
  flextures :items, :users => :users_for_itmshop # users_for_itemshop.csv をロードする
88
92
 
89
- === Flextures load and dump filter
93
+ その他現在はShouldからの呼び出しや様々なオプションを載せていますが
94
+ さらに詳しい使い方に関しては {Wiki:Unit Test Supportの説明}[https://github.com/baban/flextures/wiki/Unit-test-support%E3%81%AE%E8%AA%AC%E6%98%8E] を参照して下さい
95
+
96
+ === Flextures load filter (and dump filter)
90
97
 
91
98
  ==== load filer
92
99
 
93
100
  Railsのプロジェクトに config/flextures.factory.rb というファイルを作成して、そこにフィルタを記述することによって
101
+ (Padrinoでも設置場所は同じです)
94
102
  フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
95
103
  例えば、次の様に記述するとusersテーブルのlast_login_dateの値を、常に現在の時間として設定できます
96
104
 
@@ -98,8 +106,8 @@ Railsのプロジェクトに config/flextures.factory.rb というファイル
98
106
  f.last_login_date = DateTime.now
99
107
  end
100
108
 
101
- テーブルにdefaultとか設定していなくても
102
- カラムのデータとかを、適当に補完する機能があるので
109
+ テーブルにdefaultの値を設定していなくても
110
+ カラムのデータを適当に補完する機能があるので
103
111
  大量のデータを生成したい時は次のように{faker}[https://github.com/stympy/faker]等と組み合わせて
104
112
  必要な分だけ生成をさせると、今までより若干捗るかもしれません
105
113
 
@@ -121,6 +129,9 @@ Railsのプロジェクトに config/flextures.factory.rb というファイル
121
129
  :encrypted_password => lambda { |v| Base64.encode64(v) }
122
130
  }
123
131
 
132
+
133
+ さらに細かい使い方に関しては {Wiki:FactoryFilterについて}[https://github.com/baban/flextures/wiki/Factoryfilter%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6] を参照して下さい
134
+
124
135
  === 設定ファイル
125
136
 
126
137
  config/flextures.config.rb で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
@@ -132,5 +143,5 @@ config/flextures.config.rb で設定ファイルを作成すると、データ
132
143
  Config.fixture_dump_directory = "test/fixtures/"
133
144
  end
134
145
 
135
-
146
+ その他の情報は {Wiki:設定ファイルの書式について}[https://github.com/baban/flextures/wiki/%E8%A8%AD%E5%AE%9A%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E6%9B%B8%E5%BC%8F%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6] を参照して下さい
136
147
 
data/README.rdoc CHANGED
@@ -13,10 +13,10 @@ Each commands load or dump fixtures.
13
13
 
14
14
  Major different point is four.
15
15
 
16
- 1. Fixture file is prefered CSV to YAML.
17
- 2. Don't stop load if table colums are'nt match fixture file's column.
18
- 3. Fixture file name can change if file name is not equal table name.
19
- 4. Fixture data translate to use filter like factory girl.
16
+ 1. Fixture file prefered CSV to YAML.
17
+ 2. loading don't stop, if table columns are not match fixture file's column
18
+ 3. Fixture file name can change, if file name is not equal table name.
19
+ 4. Fixture data can translate to use filter, like factory girl.
20
20
 
21
21
  == How to install
22
22
 
@@ -26,7 +26,15 @@ Please use bundler.
26
26
 
27
27
  gem "flextures"
28
28
 
29
- (Development emnvoriment must be ruby1.9 and rails3)
29
+ curent flextures is developping version3.0
30
+
31
+ This document and sourcecode and documents(readme.rdoc,wiki) write about version flextures 3.0 (current released version is 2.1.0)
32
+ if you want to use flextures3.0
33
+ your Gemfile should set option github url
34
+
35
+ gem "flextures", git:"https://github.com/baban/flextures"
36
+
37
+ (Development emnvoriment must be ruby1.9 higer and rails3 higher)
30
38
 
31
39
  == How to use
32
40
 
@@ -44,34 +52,28 @@ For example, this option set dump file name.
44
52
 
45
53
  rake db:flextures:dump TABLE=users
46
54
 
47
- If you use this option load command.
48
- Option set load file name.
49
- (loading "users.csv" or "users.yml")
50
-
51
- rake db:flextures:load MODEL=User
52
-
53
55
  Other options...
54
56
 
55
57
  TABLE : set table name
56
58
  MODEL : set model name
57
59
  DIR : set directory name
58
- FIXTURES : set fixture file name
59
60
  FILE : set fixture file name
61
+ FORMAT:change dump file format(csv or yml)
62
+ OPTION:other options
60
63
  T : alias TABLE option
61
- M : alias MODEL option
62
64
  D : alias DIR option
63
65
  F : alias FIXTURES option
64
66
 
65
- if you only load CSV file or YAML file, next command can load.
66
-
67
- rake db:flextures:csvload
68
- rake db:flextures:ymlload
69
- rake db:flextures:csvdump
70
- rake db:flextures:ymldump
67
+ if you change table colum information
68
+ next comannd regenerate (load fixture and dump) fixtures
71
69
 
72
- === RSpec flexture support
70
+ rake db:flextures:generate T=users
73
71
 
74
- Fixture load function implemented for RSpec.
72
+ Other information please see {wiki}[https://github.com/baban/flextures/wiki/Rake-command-option] ...
73
+
74
+ === Unit test flexture support
75
+
76
+ Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda).
75
77
 
76
78
  describe ItemShopController do
77
79
  flextures :users, :items
@@ -84,6 +86,9 @@ Flextures function can change load file name.
84
86
  describe ItemShopController do
85
87
  flextures :items, :users => :users_for_itmshop # load "users_for_itemshop.csv"
86
88
 
89
+ Other option information
90
+ Please see {wiki}[https://github.com/baban/flextures/wiki/Unittestsupport] ...
91
+
87
92
  === Flextures load & dump filter
88
93
 
89
94
  ==== load filter
@@ -118,6 +123,8 @@ dump filter has hash argumtne, it is formatted colum name key and convert method
118
123
  :encrypted_password => lambda { |v| Base64.encode64(v) }
119
124
  }
120
125
 
126
+ Other options please see {wiki}[https://github.com/baban/flextures/wiki/Factoryfilter] ...
127
+
121
128
  === Configuration file
122
129
 
123
130
  Configuration file can change load and dump directory
@@ -130,5 +137,5 @@ Configuration file can change load and dump directory
130
137
  Config.fixture_dump_directory = "test/fixtures/"
131
138
  end
132
139
 
133
-
140
+ Other options please see {wiki}[https://github.com/baban/flextures/wiki/Configuration-file] ...
134
141
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 3.0.0
data/flextures.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "flextures"
8
- s.version = "2.1.0"
8
+ s.version = "3.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["baban"]
12
- s.date = "2013-02-03"
12
+ s.date = "2013-06-24"
13
13
  s.description = "load and dump fixtures"
14
14
  s.email = "babanba.n@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
46
46
  "test/unit/test_flextures.rb",
47
47
  "test/unit/test_flextures_args.rb",
48
48
  "test/unit/test_flextures_dumper.rb",
49
+ "test/unit/test_flextures_extention_modules.rb",
49
50
  "test/unit/test_flextures_hooks.rb",
50
51
  "test/unit/test_flextures_loader.rb",
51
52
  "test/unit/test_simple.rb"
@@ -53,21 +54,21 @@ Gem::Specification.new do |s|
53
54
  s.homepage = "http://github.com/baban/flextures"
54
55
  s.licenses = ["MIT"]
55
56
  s.require_paths = ["lib"]
56
- s.rubygems_version = "1.8.25"
57
+ s.rubygems_version = "1.8.10"
57
58
  s.summary = "load and dump fixtures"
58
59
 
59
60
  if s.respond_to? :specification_version then
60
61
  s.specification_version = 3
61
62
 
62
63
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
- s.add_development_dependency(%q<bundler>, ["= 1.2.0"])
64
+ s.add_development_dependency(%q<bundler>, ["= 1.3.5"])
64
65
  s.add_development_dependency(%q<jeweler>, ["= 1.8.3"])
65
66
  else
66
- s.add_dependency(%q<bundler>, ["= 1.2.0"])
67
+ s.add_dependency(%q<bundler>, ["= 1.3.5"])
67
68
  s.add_dependency(%q<jeweler>, ["= 1.8.3"])
68
69
  end
69
70
  else
70
- s.add_dependency(%q<bundler>, ["= 1.2.0"])
71
+ s.add_dependency(%q<bundler>, ["= 1.3.5"])
71
72
  s.add_dependency(%q<jeweler>, ["= 1.8.3"])
72
73
  end
73
74
  end
@@ -11,12 +11,21 @@ namespace :db do
11
11
 
12
12
  desc "Dump data to prefer csv format"
13
13
  task :csvdump => :environment do
14
- Flextures::Rake::Command::csvdump
14
+ puts "This command is deprecated"
15
+ # TODO: deprecated message
16
+ # please use 'FOAMRT=csv' option
17
+ ENV["FORMAT"]="csv"
18
+ Flextures::Rake::Command::dump
15
19
  end
16
20
 
17
21
  desc "Dump data to yaml format"
18
22
  task :ymldump => :environment do
19
- Flextures::Rake::Command::ymldump
23
+ puts "This command is deprecated"
24
+ puts "please use 'rake db:flextures:dump FORMAT='yml''"
25
+ # TODO: deprecated message
26
+ # please use 'FOAMRT=yml' option
27
+ ENV["FORMAT"]="yml"
28
+ Flextures::Rake::Command::dump
20
29
  end
21
30
 
22
31
  desc "load fixture data csv format"
@@ -26,12 +35,27 @@ namespace :db do
26
35
 
27
36
  desc "load fixture data only csv format files"
28
37
  task :csvload => :environment do
29
- Flextures::Rake::Command::csvload
38
+ puts "This command is deprecated"
39
+ puts "please use 'rake db:flextures:load FORMAT='csv''"
40
+ # TODO: deprecated message
41
+ # please use 'FOAMRT=csv' option
42
+ ENV["FORMAT"]="csv"
43
+ Flextures::Rake::Command::load
30
44
  end
31
45
 
32
46
  desc "load fixture files only yaml format"
33
47
  task :ymlload => :environment do
34
- Flextures::Rake::Command::ymlload
48
+ # TODO: deprecated message
49
+ # please use 'FOAMRT=yml' option
50
+ ENV["FORMAT"]="yml"
51
+ puts "This command is deprecated"
52
+ puts "please use 'rake db:flextures:load FORMAT='yml''"
53
+ Flextures::Rake::Command::load
35
54
  end
55
+
56
+ desc "load and dump file (replace) new data file"
57
+ task :generate => :environment do
58
+ Flextures::Rake::Command::generate
59
+ end
36
60
  end
37
61
  end
@@ -8,17 +8,16 @@ require "flextures/flextures_extension_modules"
8
8
  require "flextures/flextures_factory"
9
9
 
10
10
  module Flextures
11
- LOAD_DIR = Config.fixture_load_directory
12
- DUMP_DIR = Config.fixture_dump_directory
13
-
14
- # テーブルモデルの作成
11
+ # ActiveRecord Model is created that guess by table_name
12
+ # @params [String|Symbol] table_name
13
+ # @params [ActiveRecord::Base] model class
15
14
  def self.create_model table_name
16
- # Factoryにオプションで指定があった時
15
+ # when Model is defined in FactoryFilter
17
16
  a = ->{
18
17
  f = Factory::FACTORIES[table_name.to_sym]
19
18
  f && f[:model]
20
19
  }
21
- # テーブル名からモデル名が推測できるとき
20
+ # when program can guess Model name by table_name
22
21
  b = ->{
23
22
  begin
24
23
  table_name.singularize.camelize.constantize
@@ -26,14 +25,14 @@ module Flextures
26
25
  nil
27
26
  end
28
27
  }
29
- # モデル名推測不可能なとき
28
+ # when cannot guess Model name
30
29
  c = ->{
31
30
  Class.new(ActiveRecord::Base){ |o| o.table_name=table_name }
32
31
  }
33
32
  a.call || b.call || c.call
34
33
  end
35
34
 
36
- # 設定ファイルが存在すればロード
35
+ # load configuration file, if file is exist
37
36
  def self.init_load
38
37
  if defined?(Rails) and Rails.root
39
38
  [
@@ -43,20 +42,18 @@ module Flextures
43
42
  end
44
43
  end
45
44
 
46
- # 全テーブル削除のときにほんとうに消去して良いテーブル一覧を返す
45
+ # @return [Array] flextures useable table names
47
46
  def self.deletable_tables
48
47
  tables = ActiveRecord::Base.connection.tables
49
- Flextures::Config.ignore_tables.each do |name|
50
- tables.delete name
51
- end
48
+ Flextures::Config.ignore_tables.each { |name| tables.delete name }
52
49
  tables
53
50
  end
54
51
 
55
- # テーブル情報の初期化
52
+ # initialize table data
56
53
  def self.init_tables
57
54
  tables = Flextures::deletable_tables
58
55
  tables.each do |name|
59
- # テーブルではなくviewを拾って止まる場合があるのでrescueしてしまう
56
+ # if 'name' variable is 'database view', raise error
60
57
  begin
61
58
  Class.new(ActiveRecord::Base){ |o| o.table_name= name }.delete_all
62
59
  rescue => e
@@ -64,41 +61,40 @@ module Flextures
64
61
  end
65
62
  end
66
63
 
67
- # テーブル情報の初期化
68
64
  def self.delete_tables *tables
69
65
  tables.each do |name|
70
- # テーブルではなくviewを拾って止まる場合があるのでrescueしてしまう
66
+ # if 'name' variable is 'database view', raise error
71
67
  begin
72
68
  Class.new(ActiveRecord::Base){ |o| o.table_name= name }.delete_all
73
- rescue => e
69
+ rescue StandaraError => e
74
70
  end
75
71
  end
76
72
  end
77
73
 
78
- # デバッグ用のメソッド、渡されたブロックを実行する
79
- # 主にテーブルの今の中身を覗きたい時に使う
74
+ # It is debug method to use like 'tab' method
75
+ # @params [Proc] dumper write dump information
80
76
  def self.table_tap &dumper
81
77
  tables = Flextures::deletable_tables
82
78
  tables.each do |name|
83
- # テーブルではなくviewを拾って止まる場合があるのでrescueしてしまう
79
+ # if 'name' variable is 'database view', raise error
84
80
  begin
85
81
  klass = Class.new(ActiveRecord::Base){ |o| o.table_name= name; }
86
82
  dumper.call klass
87
- rescue => e
83
+ rescue StandaraError => e
88
84
  end
89
85
  end
90
86
  end
91
87
 
92
88
  # parse arguments functions
93
89
  module ARGS
94
- # 書き出し 、読み込み すべきファイルとオプションを書きだす
90
+ # parse rake ENV parameters
95
91
  def self.parse option={}
96
92
  table_names = []
97
- if ENV["T"] or ENV["TABLE"]
98
- table_names = (ENV["T"] or ENV["TABLE"]).split(',').map{ |name| { table: name, file: name } }
93
+ if v = (ENV["T"] or ENV["TABLE"])
94
+ table_names = v.split(',').map{ |name| { table: name, file: name } }
99
95
  end
100
- if ENV["M"] or ENV["MODEL"]
101
- table_names = (ENV["M"] or ENV["MODEL"]).split(',').map do |name|
96
+ if v = (ENV["M"] or ENV["MODEL"])
97
+ table_names = v.split(',').map do |name|
102
98
  name = name.constantize.table_name
103
99
  { table: name, file: name }
104
100
  end
@@ -122,14 +118,23 @@ module Flextures
122
118
 
123
119
  table_names = table_names.map{ |option| option.merge dir: ENV["DIR"] } if ENV["DIR"]
124
120
  table_names = table_names.map{ |option| option.merge dir: ENV["D"] } if ENV["D"]
125
- # read mode だとcsvもyaml存在しないファイルは返さない
121
+
122
+ table_names = table_names.map{ |option| option.merge minus: ENV["MINUS"].to_s.split(",") } if ENV["MINUS"]
123
+ table_names = table_names.map{ |option| option.merge plus: ENV["PLUS"].to_s.split(",") } if ENV["PLUS"]
124
+
125
+ table_names = table_names.map{ |option| option.merge silent: true } if ENV["OPTION"].to_s.split(",").include?("silent")
126
+ table_names = table_names.map{ |option| option.merge unfilter: true } if ENV["OPTION"].to_s.split(",").include?("unfilter")
127
+ table_names = table_names.map{ |option| option.merge strict: true } if ENV["OPTION"].to_s.split(",").include?("strict")
128
+
129
+ # if mode is 'read mode' and file is not exist value is not return
126
130
  table_names.select! &exist if option[:mode] && option[:mode] == 'read'
127
131
  table_names
128
132
  end
129
133
 
130
134
  # check exist filename block
131
135
  def self.exist
132
- return->(name){ File.exists?("#{LOAD_DIR}#{name}.csv") or File.exists?("#{LOAD_DIR}#{name}.yml") }
136
+ return->(name){ File.exists?( File.join( Config.fixture_load_directory, "#{name}.csv") ) or
137
+ File.exists?( File.join( Config.fixture_load_directory, "#{name}.yml") ) }
133
138
  end
134
139
  end
135
140
  end