flextures 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -29
- data/README.ja.md +168 -168
- data/README.md +156 -156
- data/Rakefile +1 -1
- data/flextures.gemspec +23 -23
- data/lib/flextures/flextures_dumper.rb +5 -3
- data/lib/flextures/version.rb +3 -3
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e1475921d9e2497f5f3e27ab528d2e94a6fc973
|
4
|
+
data.tar.gz: 53a38f7501809ea48dc837e6a494f9ea1887299f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5da565b171cdfeca142e93f1c43783ec8f836abbf0a6b60be0cce3c96d412e708a8463b96691e9c35ef5b79cb24dd3b688a03d50683b956a9c50b180e07f98
|
7
|
+
data.tar.gz: d400b6c54c592af58dd3a7962bee1c7519006474f5cc515180ba4d1d9eff7bcd977a38c1c494f768b379a060b1ba860c110abe8f519a605f62d869c6b6729ff1
|
data/Gemfile.lock
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
flextures (3.1.
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activesupport (3.2.8)
|
10
|
-
i18n (~> 0.6)
|
11
|
-
multi_json (~> 1.0)
|
12
|
-
i18n (0.6.0)
|
13
|
-
multi_json (1.3.6)
|
14
|
-
rake (0.9.2.2)
|
15
|
-
shoulda (3.1.1)
|
16
|
-
shoulda-context (~> 1.0)
|
17
|
-
shoulda-matchers (~> 1.2)
|
18
|
-
shoulda-context (1.0.0)
|
19
|
-
shoulda-matchers (1.2.0)
|
20
|
-
activesupport (>= 3.0.0)
|
21
|
-
|
22
|
-
PLATFORMS
|
23
|
-
ruby
|
24
|
-
|
25
|
-
DEPENDENCIES
|
26
|
-
bundler (~> 1.6)
|
27
|
-
flextures!
|
28
|
-
rake
|
29
|
-
shoulda
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flextures (3.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (3.2.8)
|
10
|
+
i18n (~> 0.6)
|
11
|
+
multi_json (~> 1.0)
|
12
|
+
i18n (0.6.0)
|
13
|
+
multi_json (1.3.6)
|
14
|
+
rake (0.9.2.2)
|
15
|
+
shoulda (3.1.1)
|
16
|
+
shoulda-context (~> 1.0)
|
17
|
+
shoulda-matchers (~> 1.2)
|
18
|
+
shoulda-context (1.0.0)
|
19
|
+
shoulda-matchers (1.2.0)
|
20
|
+
activesupport (>= 3.0.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
bundler (~> 1.6)
|
27
|
+
flextures!
|
28
|
+
rake
|
29
|
+
shoulda
|
data/README.ja.md
CHANGED
@@ -1,168 +1,168 @@
|
|
1
|
-
# flextures
|
2
|
-
|
3
|
-
* [ENGLISH DOCUMENT](https://github.com/baban/flextures/blob/master/README.rdoc)
|
4
|
-
|
5
|
-
## Abstruct
|
6
|
-
|
7
|
-
このplug-inは、これまで開発中で溜まっていた
|
8
|
-
Rails標準のfixtureの不満点を解消するために作成しました
|
9
|
-
基本的な操作は単純で次のコマンドで
|
10
|
-
それぞれfixtureのロードとダンプを行います
|
11
|
-
|
12
|
-
```
|
13
|
-
rake db:flextures:load
|
14
|
-
rake db:flextures:dump
|
15
|
-
```
|
16
|
-
|
17
|
-
通常のfixtureとの主な違いは次の4点です
|
18
|
-
|
19
|
-
1. yamlよりもcsvを優先する
|
20
|
-
2. migrationでテーブル構成が変わっても、カラムの変更点を無視、補完してロードを行う
|
21
|
-
3. テーブル名とfixtureのファイル名を一致させないでも、自由なロード&ダンプが出来るオプション
|
22
|
-
4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
|
23
|
-
|
24
|
-
## インストール方法
|
25
|
-
|
26
|
-
RailsのPlug-inとして使われることを想定しています
|
27
|
-
gem化されているので、bundlerで次のように記述して、普通にbundle install してください
|
28
|
-
|
29
|
-
```
|
30
|
-
gem "flextures"
|
31
|
-
|
32
|
-
```
|
33
|
-
|
34
|
-
ちなみに開発環境はruby1.9以上のバージョン、rails3以上、もしくはPadrinoを想定しています
|
35
|
-
|
36
|
-
## 使い方
|
37
|
-
|
38
|
-
### rakeコマンド
|
39
|
-
|
40
|
-
次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
|
41
|
-
(読み込む基本のディレクトリは設定ファイルで変更可能)
|
42
|
-
|
43
|
-
```
|
44
|
-
rake db:flextures:load
|
45
|
-
rake db:flextures:dump
|
46
|
-
```
|
47
|
-
|
48
|
-
rake コマンドには以下の様な書式でオプションを指定することができます
|
49
|
-
指摘出来るオプションは、ロードとダンプで共通です
|
50
|
-
|
51
|
-
テーブル名で吐き出し(Userモデルusers)
|
52
|
-
|
53
|
-
```
|
54
|
-
rake db:flextures:dump TABLE=users
|
55
|
-
```
|
56
|
-
|
57
|
-
Usersモデルのfixture(users.csvか users.yml)をロードする
|
58
|
-
|
59
|
-
```
|
60
|
-
rake db:flextures:load MODEL=User
|
61
|
-
```
|
62
|
-
|
63
|
-
その他オプションは以下の通りです:
|
64
|
-
|
65
|
-
| オプション | 役割 |
|
66
|
-
------------|--------------------------------------------------------------------
|
67
|
-
| TABLE | テーブル名を指定してロード。テーブル名はカンマ切りで複数指定が可能 |
|
68
|
-
| MODEL | モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能 |
|
69
|
-
| DIR | フィクスチャをロード&ダンプするディレクトリを指定する |
|
70
|
-
| FILE | loadまたはdumpするファイル名を直接指定(Userモデルのusers.csv以外を指定) |
|
71
|
-
| FORMAT | ダンプ、またはロードするデータの種類を指定できる(csvかyml) |
|
72
|
-
| OPTION | その他の細かい読み込みオプションはここで指定出来ます |
|
73
|
-
| T | TABLEのエイリアス |
|
74
|
-
| D | ディレクトリ指定のエイリアス |
|
75
|
-
| F | ファイル名指定のエイリアス |
|
76
|
-
|
77
|
-
migration等でテーブルの構成が変わった時には
|
78
|
-
generateコマンドを実行すると、テーブル情報のloadとdumpをセットで行なってくれるので便利です
|
79
|
-
|
80
|
-
```
|
81
|
-
rake db:flextures:generate T=users
|
82
|
-
```
|
83
|
-
|
84
|
-
さらに詳しい説明に関しては [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)を参照して下さい
|
85
|
-
|
86
|
-
### Unit test flexture support
|
87
|
-
|
88
|
-
ユニットテスト中でデータの読み込みが行いたくなったときのために
|
89
|
-
fixtureのロード機能を使えます
|
90
|
-
|
91
|
-
次の例はRSpecからの読み込みですが
|
92
|
-
基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
describe ItemShopController do
|
96
|
-
flextures :users, :items
|
97
|
-
```
|
98
|
-
|
99
|
-
基本的な違いは、yamlよりcsvを優先する、カラムの変更点を検知して警告を出しながらもロードを行う等ですが
|
100
|
-
もう一つ、ハッシュ引数で指定する事で、テーブル名、ファイル名を一致させなくても フィクスチャ を読み込ませることができます
|
101
|
-
そのため、すべてのテストケースで依存関係を気にしながら共通のfixtureを使わなくても良い様に出来ます
|
102
|
-
|
103
|
-
```ruby
|
104
|
-
describe ItemShopController do
|
105
|
-
flextures :items, :users => :users_for_itmshop # users_for_itemshop.csv をロードする
|
106
|
-
```
|
107
|
-
|
108
|
-
その他現在はShouldからの呼び出しや様々なオプションを載せていますが
|
109
|
-
さらに詳しい使い方に関しては [Wiki:Unit Test Supportの説明](https://github.com/baban/flextures/wiki/Unit-test-support%E3%81%AE%E8%AA%AC%E6%98%8E) を参照して下さい
|
110
|
-
|
111
|
-
### Flextures load filter (and dump filter)
|
112
|
-
|
113
|
-
#### load filer
|
114
|
-
|
115
|
-
Railsのプロジェクトに config/flextures.factory.rb というファイルを作成して、そこにフィルタを記述することによって
|
116
|
-
(Padrinoでも設置場所は同じです)
|
117
|
-
フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
|
118
|
-
例えば、次の様に記述するとusersテーブルのlast_login_dateの値を、常に現在の時間として設定できます
|
119
|
-
|
120
|
-
```ruby
|
121
|
-
Flextures::Factory.define :users do |f|
|
122
|
-
f.last_login_date = DateTime.now
|
123
|
-
end
|
124
|
-
```
|
125
|
-
|
126
|
-
テーブルにdefaultの値を設定していなくても
|
127
|
-
カラムのデータを適当に補完する機能があるので
|
128
|
-
大量のデータを生成したい時は次のように[faker](https://github.com/stympy/faker)等と組み合わせて
|
129
|
-
必要な分だけ生成をさせると、今までより若干捗るかもしれません
|
130
|
-
|
131
|
-
```ruby
|
132
|
-
require 'faker'
|
133
|
-
Flextures::Factory.define :users do |f|
|
134
|
-
f.name= Faker::Name.name if !f.name # ランダムで名前を生成(ただしUS仕様
|
135
|
-
f.sex= [0,1].shuffle.first if !f.sex # 性別を設定
|
136
|
-
# Factory Girlの様にhas_manyな感じのデータも生成できます。(初期設定でアイテムを2個持たせる)
|
137
|
-
f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
|
138
|
-
end
|
139
|
-
```
|
140
|
-
|
141
|
-
* [wiki:has_manyな感じのデータの精製法](https://github.com/baban/flextures/wiki/Has-many%E3%81%AA%E6%84%9F%E3%81%98%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E7%B2%BE%E8%A3%BD%E6%96%B9%E6%B3%95)
|
142
|
-
|
143
|
-
#### dump filer
|
144
|
-
|
145
|
-
データのdump時に加工が必要になった時には、ダンプフィルターにテーブル名と、加工したい値をキーに、処理をラムダで渡してやることで可能です
|
146
|
-
|
147
|
-
```ruby
|
148
|
-
Flextures::DumpFilter.define :users, {
|
149
|
-
:encrypted_password => lambda { |v| Base64.encode64(v) }
|
150
|
-
}
|
151
|
-
```
|
152
|
-
|
153
|
-
さらに細かい使い方に関しては [Wiki:FactoryFilterについて](https://github.com/baban/flextures/wiki/Factoryfilter%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) を参照して下さい
|
154
|
-
|
155
|
-
### 設定ファイル
|
156
|
-
|
157
|
-
config/flextures.config.rb で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
|
158
|
-
|
159
|
-
```ruby
|
160
|
-
# config/flextures.config.rb
|
161
|
-
module Flextures
|
162
|
-
# test/fixtures/ のフィクスチャを読み出したい場合は吐き出しディレクトリの値を上書きする
|
163
|
-
Config.fixture_load_directory = "test/fixtures/"
|
164
|
-
Config.fixture_dump_directory = "test/fixtures/"
|
165
|
-
end
|
166
|
-
```
|
167
|
-
|
168
|
-
その他の情報は [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)を参照して下さい
|
1
|
+
# flextures
|
2
|
+
|
3
|
+
* [ENGLISH DOCUMENT](https://github.com/baban/flextures/blob/master/README.rdoc)
|
4
|
+
|
5
|
+
## Abstruct
|
6
|
+
|
7
|
+
このplug-inは、これまで開発中で溜まっていた
|
8
|
+
Rails標準のfixtureの不満点を解消するために作成しました
|
9
|
+
基本的な操作は単純で次のコマンドで
|
10
|
+
それぞれfixtureのロードとダンプを行います
|
11
|
+
|
12
|
+
```
|
13
|
+
rake db:flextures:load
|
14
|
+
rake db:flextures:dump
|
15
|
+
```
|
16
|
+
|
17
|
+
通常のfixtureとの主な違いは次の4点です
|
18
|
+
|
19
|
+
1. yamlよりもcsvを優先する
|
20
|
+
2. migrationでテーブル構成が変わっても、カラムの変更点を無視、補完してロードを行う
|
21
|
+
3. テーブル名とfixtureのファイル名を一致させないでも、自由なロード&ダンプが出来るオプション
|
22
|
+
4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
|
23
|
+
|
24
|
+
## インストール方法
|
25
|
+
|
26
|
+
RailsのPlug-inとして使われることを想定しています
|
27
|
+
gem化されているので、bundlerで次のように記述して、普通にbundle install してください
|
28
|
+
|
29
|
+
```
|
30
|
+
gem "flextures"
|
31
|
+
|
32
|
+
```
|
33
|
+
|
34
|
+
ちなみに開発環境はruby1.9以上のバージョン、rails3以上、もしくはPadrinoを想定しています
|
35
|
+
|
36
|
+
## 使い方
|
37
|
+
|
38
|
+
### rakeコマンド
|
39
|
+
|
40
|
+
次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
|
41
|
+
(読み込む基本のディレクトリは設定ファイルで変更可能)
|
42
|
+
|
43
|
+
```
|
44
|
+
rake db:flextures:load
|
45
|
+
rake db:flextures:dump
|
46
|
+
```
|
47
|
+
|
48
|
+
rake コマンドには以下の様な書式でオプションを指定することができます
|
49
|
+
指摘出来るオプションは、ロードとダンプで共通です
|
50
|
+
|
51
|
+
テーブル名で吐き出し(Userモデルusers)
|
52
|
+
|
53
|
+
```
|
54
|
+
rake db:flextures:dump TABLE=users
|
55
|
+
```
|
56
|
+
|
57
|
+
Usersモデルのfixture(users.csvか users.yml)をロードする
|
58
|
+
|
59
|
+
```
|
60
|
+
rake db:flextures:load MODEL=User
|
61
|
+
```
|
62
|
+
|
63
|
+
その他オプションは以下の通りです:
|
64
|
+
|
65
|
+
| オプション | 役割 |
|
66
|
+
------------|--------------------------------------------------------------------
|
67
|
+
| TABLE | テーブル名を指定してロード。テーブル名はカンマ切りで複数指定が可能 |
|
68
|
+
| MODEL | モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能 |
|
69
|
+
| DIR | フィクスチャをロード&ダンプするディレクトリを指定する |
|
70
|
+
| FILE | loadまたはdumpするファイル名を直接指定(Userモデルのusers.csv以外を指定) |
|
71
|
+
| FORMAT | ダンプ、またはロードするデータの種類を指定できる(csvかyml) |
|
72
|
+
| OPTION | その他の細かい読み込みオプションはここで指定出来ます |
|
73
|
+
| T | TABLEのエイリアス |
|
74
|
+
| D | ディレクトリ指定のエイリアス |
|
75
|
+
| F | ファイル名指定のエイリアス |
|
76
|
+
|
77
|
+
migration等でテーブルの構成が変わった時には
|
78
|
+
generateコマンドを実行すると、テーブル情報のloadとdumpをセットで行なってくれるので便利です
|
79
|
+
|
80
|
+
```
|
81
|
+
rake db:flextures:generate T=users
|
82
|
+
```
|
83
|
+
|
84
|
+
さらに詳しい説明に関しては [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)を参照して下さい
|
85
|
+
|
86
|
+
### Unit test flexture support
|
87
|
+
|
88
|
+
ユニットテスト中でデータの読み込みが行いたくなったときのために
|
89
|
+
fixtureのロード機能を使えます
|
90
|
+
|
91
|
+
次の例はRSpecからの読み込みですが
|
92
|
+
基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
describe ItemShopController do
|
96
|
+
flextures :users, :items
|
97
|
+
```
|
98
|
+
|
99
|
+
基本的な違いは、yamlよりcsvを優先する、カラムの変更点を検知して警告を出しながらもロードを行う等ですが
|
100
|
+
もう一つ、ハッシュ引数で指定する事で、テーブル名、ファイル名を一致させなくても フィクスチャ を読み込ませることができます
|
101
|
+
そのため、すべてのテストケースで依存関係を気にしながら共通のfixtureを使わなくても良い様に出来ます
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
describe ItemShopController do
|
105
|
+
flextures :items, :users => :users_for_itmshop # users_for_itemshop.csv をロードする
|
106
|
+
```
|
107
|
+
|
108
|
+
その他現在はShouldからの呼び出しや様々なオプションを載せていますが
|
109
|
+
さらに詳しい使い方に関しては [Wiki:Unit Test Supportの説明](https://github.com/baban/flextures/wiki/Unit-test-support%E3%81%AE%E8%AA%AC%E6%98%8E) を参照して下さい
|
110
|
+
|
111
|
+
### Flextures load filter (and dump filter)
|
112
|
+
|
113
|
+
#### load filer
|
114
|
+
|
115
|
+
Railsのプロジェクトに config/flextures.factory.rb というファイルを作成して、そこにフィルタを記述することによって
|
116
|
+
(Padrinoでも設置場所は同じです)
|
117
|
+
フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
|
118
|
+
例えば、次の様に記述するとusersテーブルのlast_login_dateの値を、常に現在の時間として設定できます
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
Flextures::Factory.define :users do |f|
|
122
|
+
f.last_login_date = DateTime.now
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
テーブルにdefaultの値を設定していなくても
|
127
|
+
カラムのデータを適当に補完する機能があるので
|
128
|
+
大量のデータを生成したい時は次のように[faker](https://github.com/stympy/faker)等と組み合わせて
|
129
|
+
必要な分だけ生成をさせると、今までより若干捗るかもしれません
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
require 'faker'
|
133
|
+
Flextures::Factory.define :users do |f|
|
134
|
+
f.name= Faker::Name.name if !f.name # ランダムで名前を生成(ただしUS仕様
|
135
|
+
f.sex= [0,1].shuffle.first if !f.sex # 性別を設定
|
136
|
+
# Factory Girlの様にhas_manyな感じのデータも生成できます。(初期設定でアイテムを2個持たせる)
|
137
|
+
f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
* [wiki:has_manyな感じのデータの精製法](https://github.com/baban/flextures/wiki/Has-many%E3%81%AA%E6%84%9F%E3%81%98%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E7%B2%BE%E8%A3%BD%E6%96%B9%E6%B3%95)
|
142
|
+
|
143
|
+
#### dump filer
|
144
|
+
|
145
|
+
データのdump時に加工が必要になった時には、ダンプフィルターにテーブル名と、加工したい値をキーに、処理をラムダで渡してやることで可能です
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
Flextures::DumpFilter.define :users, {
|
149
|
+
:encrypted_password => lambda { |v| Base64.encode64(v) }
|
150
|
+
}
|
151
|
+
```
|
152
|
+
|
153
|
+
さらに細かい使い方に関しては [Wiki:FactoryFilterについて](https://github.com/baban/flextures/wiki/Factoryfilter%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) を参照して下さい
|
154
|
+
|
155
|
+
### 設定ファイル
|
156
|
+
|
157
|
+
config/flextures.config.rb で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
# config/flextures.config.rb
|
161
|
+
module Flextures
|
162
|
+
# test/fixtures/ のフィクスチャを読み出したい場合は吐き出しディレクトリの値を上書きする
|
163
|
+
Config.fixture_load_directory = "test/fixtures/"
|
164
|
+
Config.fixture_dump_directory = "test/fixtures/"
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
その他の情報は [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)を参照して下さい
|
data/README.md
CHANGED
@@ -1,156 +1,156 @@
|
|
1
|
-
# flextures
|
2
|
-
|
3
|
-
* [日本語版ドキュメント(Japanese Document)](https://github.com/baban/flextures/blob/master/README.ja.md)
|
4
|
-
|
5
|
-
## Abstruct
|
6
|
-
|
7
|
-
This plug-in aim to resolve many problems, durling rails developping about fixtures.
|
8
|
-
Basic commands is simple.
|
9
|
-
Each commands load or dump fixtures.
|
10
|
-
|
11
|
-
```
|
12
|
-
rake db:flextures:load
|
13
|
-
rake db:flextures:dump
|
14
|
-
```
|
15
|
-
|
16
|
-
Major different point is four.
|
17
|
-
|
18
|
-
1. Fixture file prefered CSV to YAML.
|
19
|
-
2. loading don't stop, if table columns are not match fixture file's column
|
20
|
-
3. Fixture file name can change, if file name is not equal table name.
|
21
|
-
4. Fixture data can translate to use filter, like factory girl.
|
22
|
-
|
23
|
-
## How to install
|
24
|
-
|
25
|
-
This program is implemented Rails Plug-in.
|
26
|
-
You want to install this plug-in.
|
27
|
-
Please use bundler.
|
28
|
-
|
29
|
-
```
|
30
|
-
gem "flextures"
|
31
|
-
```
|
32
|
-
|
33
|
-
(Development emnvoriment must be ruby1.9 higer and rails3 higher)
|
34
|
-
|
35
|
-
## How to use
|
36
|
-
|
37
|
-
### rake command
|
38
|
-
|
39
|
-
load command input fixtures file under "spec/fixtures/".
|
40
|
-
(Loading directory can change configuration file)
|
41
|
-
|
42
|
-
```
|
43
|
-
rake db:flextures:load
|
44
|
-
rake db:flextures:dump
|
45
|
-
```
|
46
|
-
|
47
|
-
rake command can set options.
|
48
|
-
For example, this option set dump file name.
|
49
|
-
(Option dump only "users.csv")
|
50
|
-
|
51
|
-
```
|
52
|
-
rake db:flextures:dump TABLE=users
|
53
|
-
```
|
54
|
-
|
55
|
-
Other options...
|
56
|
-
|
57
|
-
| option | description |
|
58
|
-
---------|--------------------------------------
|
59
|
-
| TABLE | set table name |
|
60
|
-
| MODEL | set model name |
|
61
|
-
| DIR | set directory name |
|
62
|
-
| FILE | set fixture file name |
|
63
|
-
| FORMAT | change dump file format(csv or yml) |
|
64
|
-
| OPTION | other options |
|
65
|
-
| T | alias TABLE option |
|
66
|
-
| D | alias DIR option |
|
67
|
-
| F | alias FIXTURES option |
|
68
|
-
|
69
|
-
if you change table colum information
|
70
|
-
next comannd regenerate (load fixture and dump) fixtures
|
71
|
-
|
72
|
-
```
|
73
|
-
rake db:flextures:generate T=users
|
74
|
-
```
|
75
|
-
|
76
|
-
Other information please see [wiki](https://github.com/baban/flextures/wiki/Rake-command-option) ...
|
77
|
-
|
78
|
-
### Unit test flexture support
|
79
|
-
|
80
|
-
Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda).
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
describe ItemShopController do
|
84
|
-
flextures :users, :items
|
85
|
-
```
|
86
|
-
|
87
|
-
flexture function can write like a "fixture" function, implemented in RSpec.
|
88
|
-
But, "flexture" function ignore columns change.
|
89
|
-
|
90
|
-
Flextures function can change load file name.
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
describe ItemShopController do
|
94
|
-
flextures :items, :users => :users_for_itmshop # load "users_for_itemshop.csv"
|
95
|
-
```
|
96
|
-
|
97
|
-
Other option information
|
98
|
-
Please see [wiki](https://github.com/baban/flextures/wiki/Unittestsupport) ...
|
99
|
-
|
100
|
-
### Flextures load & dump filter
|
101
|
-
|
102
|
-
#### load filter
|
103
|
-
|
104
|
-
If you create filter file.(File name is "config/flextures.factory.rb")
|
105
|
-
Factory filter translate fixture data and set database.
|
106
|
-
|
107
|
-
For example, this code set current time to last_login_date column.
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
Flextures::Factory.define :users do |f|
|
111
|
-
f.last_login_date = DateTime.now
|
112
|
-
end
|
113
|
-
```
|
114
|
-
|
115
|
-
This sample, generate name and sex automatically, and other tables data generate
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
require 'faker'
|
119
|
-
Flextures::Factory.define :users do |f|
|
120
|
-
f.name= Faker::Name.name if !f.name # gemerate name
|
121
|
-
f.sex= [0,1].shuffle.first if !f.sex # generate sex
|
122
|
-
# factory filter can generate data, use has_many association
|
123
|
-
f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
|
124
|
-
end
|
125
|
-
```
|
126
|
-
|
127
|
-
### dump filter
|
128
|
-
|
129
|
-
if you need to convert table data into other data format, you use dump filter.
|
130
|
-
(dump filter is same file as load filter)
|
131
|
-
|
132
|
-
dump filter has hash argumtne, it is formatted colum name key and convert method, proc, lambda value
|
133
|
-
|
134
|
-
```ruby
|
135
|
-
Flextures::DumpFilter.define :users, {
|
136
|
-
:encrypted_password => lambda { |v| Base64.encode64(v) }
|
137
|
-
}
|
138
|
-
```
|
139
|
-
|
140
|
-
Other options please see [wiki](https://github.com/baban/flextures/wiki/Factoryfilter) ...
|
141
|
-
|
142
|
-
### Configuration file
|
143
|
-
|
144
|
-
Configuration file can change load and dump directory
|
145
|
-
(file is config/flextures.config.rb)
|
146
|
-
|
147
|
-
```ruby
|
148
|
-
# config/flextures.config.rb
|
149
|
-
module Flextures
|
150
|
-
# Load and dump directory change "spec/fixtures/" to "test/fixtures/"
|
151
|
-
Config.fixture_load_directory = "test/fixtures/"
|
152
|
-
Config.fixture_dump_directory = "test/fixtures/"
|
153
|
-
end
|
154
|
-
```
|
155
|
-
|
156
|
-
Other options please see [wiki](https://github.com/baban/flextures/wiki/Configuration-file) ...
|
1
|
+
# flextures
|
2
|
+
|
3
|
+
* [日本語版ドキュメント(Japanese Document)](https://github.com/baban/flextures/blob/master/README.ja.md)
|
4
|
+
|
5
|
+
## Abstruct
|
6
|
+
|
7
|
+
This plug-in aim to resolve many problems, durling rails developping about fixtures.
|
8
|
+
Basic commands is simple.
|
9
|
+
Each commands load or dump fixtures.
|
10
|
+
|
11
|
+
```
|
12
|
+
rake db:flextures:load
|
13
|
+
rake db:flextures:dump
|
14
|
+
```
|
15
|
+
|
16
|
+
Major different point is four.
|
17
|
+
|
18
|
+
1. Fixture file prefered CSV to YAML.
|
19
|
+
2. loading don't stop, if table columns are not match fixture file's column
|
20
|
+
3. Fixture file name can change, if file name is not equal table name.
|
21
|
+
4. Fixture data can translate to use filter, like factory girl.
|
22
|
+
|
23
|
+
## How to install
|
24
|
+
|
25
|
+
This program is implemented Rails Plug-in.
|
26
|
+
You want to install this plug-in.
|
27
|
+
Please use bundler.
|
28
|
+
|
29
|
+
```
|
30
|
+
gem "flextures"
|
31
|
+
```
|
32
|
+
|
33
|
+
(Development emnvoriment must be ruby1.9 higer and rails3 higher)
|
34
|
+
|
35
|
+
## How to use
|
36
|
+
|
37
|
+
### rake command
|
38
|
+
|
39
|
+
load command input fixtures file under "spec/fixtures/".
|
40
|
+
(Loading directory can change configuration file)
|
41
|
+
|
42
|
+
```
|
43
|
+
rake db:flextures:load
|
44
|
+
rake db:flextures:dump
|
45
|
+
```
|
46
|
+
|
47
|
+
rake command can set options.
|
48
|
+
For example, this option set dump file name.
|
49
|
+
(Option dump only "users.csv")
|
50
|
+
|
51
|
+
```
|
52
|
+
rake db:flextures:dump TABLE=users
|
53
|
+
```
|
54
|
+
|
55
|
+
Other options...
|
56
|
+
|
57
|
+
| option | description |
|
58
|
+
---------|--------------------------------------
|
59
|
+
| TABLE | set table name |
|
60
|
+
| MODEL | set model name |
|
61
|
+
| DIR | set directory name |
|
62
|
+
| FILE | set fixture file name |
|
63
|
+
| FORMAT | change dump file format(csv or yml) |
|
64
|
+
| OPTION | other options |
|
65
|
+
| T | alias TABLE option |
|
66
|
+
| D | alias DIR option |
|
67
|
+
| F | alias FIXTURES option |
|
68
|
+
|
69
|
+
if you change table colum information
|
70
|
+
next comannd regenerate (load fixture and dump) fixtures
|
71
|
+
|
72
|
+
```
|
73
|
+
rake db:flextures:generate T=users
|
74
|
+
```
|
75
|
+
|
76
|
+
Other information please see [wiki](https://github.com/baban/flextures/wiki/Rake-command-option) ...
|
77
|
+
|
78
|
+
### Unit test flexture support
|
79
|
+
|
80
|
+
Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda).
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
describe ItemShopController do
|
84
|
+
flextures :users, :items
|
85
|
+
```
|
86
|
+
|
87
|
+
flexture function can write like a "fixture" function, implemented in RSpec.
|
88
|
+
But, "flexture" function ignore columns change.
|
89
|
+
|
90
|
+
Flextures function can change load file name.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
describe ItemShopController do
|
94
|
+
flextures :items, :users => :users_for_itmshop # load "users_for_itemshop.csv"
|
95
|
+
```
|
96
|
+
|
97
|
+
Other option information
|
98
|
+
Please see [wiki](https://github.com/baban/flextures/wiki/Unittestsupport) ...
|
99
|
+
|
100
|
+
### Flextures load & dump filter
|
101
|
+
|
102
|
+
#### load filter
|
103
|
+
|
104
|
+
If you create filter file.(File name is "config/flextures.factory.rb")
|
105
|
+
Factory filter translate fixture data and set database.
|
106
|
+
|
107
|
+
For example, this code set current time to last_login_date column.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
Flextures::Factory.define :users do |f|
|
111
|
+
f.last_login_date = DateTime.now
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
This sample, generate name and sex automatically, and other tables data generate
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
require 'faker'
|
119
|
+
Flextures::Factory.define :users do |f|
|
120
|
+
f.name= Faker::Name.name if !f.name # gemerate name
|
121
|
+
f.sex= [0,1].shuffle.first if !f.sex # generate sex
|
122
|
+
# factory filter can generate data, use has_many association
|
123
|
+
f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
### dump filter
|
128
|
+
|
129
|
+
if you need to convert table data into other data format, you use dump filter.
|
130
|
+
(dump filter is same file as load filter)
|
131
|
+
|
132
|
+
dump filter has hash argumtne, it is formatted colum name key and convert method, proc, lambda value
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
Flextures::DumpFilter.define :users, {
|
136
|
+
:encrypted_password => lambda { |v| Base64.encode64(v) }
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
Other options please see [wiki](https://github.com/baban/flextures/wiki/Factoryfilter) ...
|
141
|
+
|
142
|
+
### Configuration file
|
143
|
+
|
144
|
+
Configuration file can change load and dump directory
|
145
|
+
(file is config/flextures.config.rb)
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
# config/flextures.config.rb
|
149
|
+
module Flextures
|
150
|
+
# Load and dump directory change "spec/fixtures/" to "test/fixtures/"
|
151
|
+
Config.fixture_load_directory = "test/fixtures/"
|
152
|
+
Config.fixture_dump_directory = "test/fixtures/"
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
156
|
+
Other options please see [wiki](https://github.com/baban/flextures/wiki/Configuration-file) ...
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
data/flextures.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'flextures/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "flextures"
|
8
|
-
spec.version = Flextures::VERSION
|
9
|
-
spec.authors = ["baban"]
|
10
|
-
spec.email = ["babanba.n@gmail.com"]
|
11
|
-
spec.summary = %q{load and dump fixtures.}
|
12
|
-
spec.description = %q{load and dump fixtures.}
|
13
|
-
spec.homepage = "http://github.com/baban/flextures"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flextures/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flextures"
|
8
|
+
spec.version = Flextures::VERSION
|
9
|
+
spec.authors = ["baban"]
|
10
|
+
spec.email = ["babanba.n@gmail.com"]
|
11
|
+
spec.summary = %q{load and dump fixtures.}
|
12
|
+
spec.description = %q{load and dump fixtures.}
|
13
|
+
spec.homepage = "http://github.com/baban/flextures"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -102,7 +102,7 @@ module Flextures
|
|
102
102
|
},
|
103
103
|
datetime:->( d, format ){
|
104
104
|
procs = (format == :yml) ?
|
105
|
-
[:nullstr, :blank2null, :false2nullstr, proc { |d| d.to_s }] :
|
105
|
+
[:nullstr, :blank2null, :false2nullstr, proc { |d| d.try(:strftime,"%F %T").to_s }] :
|
106
106
|
[proc { |d| d.to_s }]
|
107
107
|
self.translate_creater d, procs
|
108
108
|
},
|
@@ -137,14 +137,16 @@ module Flextures
|
|
137
137
|
self.translate_creater d, procs
|
138
138
|
},
|
139
139
|
time:->( d, format ){
|
140
|
+
p d
|
140
141
|
procs = (format == :yml) ?
|
141
|
-
[:ymlnulltime, proc { |d| d.to_s }] :
|
142
|
+
[:ymlnulltime, proc { |d| d.try(:strftime,"%F %T").to_s }] :
|
142
143
|
[proc { |d| d.to_s }]
|
143
144
|
self.translate_creater d, procs
|
144
145
|
},
|
145
146
|
timestamp:->( d, format ){
|
147
|
+
p d
|
146
148
|
procs = (format == :yml) ?
|
147
|
-
[:ymlnulltime, proc { |d| d.to_s }] :
|
149
|
+
[:ymlnulltime, proc { |d| d.try(:strftime,"%F %T").to_s }] :
|
148
150
|
[proc { |d| d.to_s }]
|
149
151
|
self.translate_creater d, procs
|
150
152
|
},
|
data/lib/flextures/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Flextures
|
2
|
-
VERSION="3.1.
|
3
|
-
end
|
1
|
+
module Flextures
|
2
|
+
VERSION="3.1.1"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flextures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- baban
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: load and dump fixtures.
|
@@ -45,8 +45,8 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .document
|
49
|
-
- .gitignore
|
48
|
+
- ".document"
|
49
|
+
- ".gitignore"
|
50
50
|
- CHANGELOG
|
51
51
|
- Gemfile
|
52
52
|
- Gemfile.lock
|
@@ -86,17 +86,17 @@ require_paths:
|
|
86
86
|
- lib
|
87
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.1
|
99
|
+
rubygems_version: 2.2.0.rc.1
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: load and dump fixtures.
|