flextures 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +48 -0
- data/Gemfile +8 -13
- data/Gemfile.lock +9 -12
- data/{README.ja.rdoc → README.ja.md} +81 -56
- data/README.md +156 -0
- data/Rakefile +1 -57
- data/flextures.gemspec +19 -71
- data/lib/flextures/flextures.rb +22 -24
- data/lib/flextures/flextures_base_config.rb +1 -2
- data/lib/flextures/flextures_command.rb +0 -1
- data/lib/flextures/flextures_dumper.rb +14 -15
- data/lib/flextures/flextures_extension_modules.rb +3 -5
- data/lib/flextures/flextures_factory.rb +5 -6
- data/lib/flextures/flextures_loader.rb +117 -85
- data/lib/flextures/rspec_flextures_support.rb +49 -13
- data/lib/flextures/testunit_flextures_support.rb +16 -8
- data/lib/flextures/version.rb +1 -2
- metadata +41 -35
- data/History.txt +0 -9
- data/README.rdoc +0 -133
- data/VERSION +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99504d8a772565a2297207af2206bfc18cb82c73
|
4
|
+
data.tar.gz: 707211a620654b6711d760e9ef6ca89f58ae17e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be828a61867a9f864890d8372d171d79affe797f41a851607015dd54ee2516c094197ebac46452ce22e21c201a2cf25f34a2e19415dd414aaec276953299483d
|
7
|
+
data.tar.gz: 028002915fb72150b3a618ca6efd128d502c942463f8dd0e3b40cdc66bf6f3db3e0dd36be97f54b76f5b016a5355a17b22fd83c58fa7c2ca882256ed2dd8ed2c
|
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
.DS_Store
|
31
|
+
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
|
36
|
+
# For emacs:
|
37
|
+
*~
|
38
|
+
\#*
|
39
|
+
.\#*
|
40
|
+
|
41
|
+
# For vim:
|
42
|
+
*.swp
|
43
|
+
|
44
|
+
# For redcar:
|
45
|
+
#.redcar
|
46
|
+
|
47
|
+
# For rubinius:
|
48
|
+
#*.rbc
|
data/Gemfile
CHANGED
@@ -1,13 +1,8 @@
|
|
1
|
-
source
|
2
|
-
|
3
|
-
#gem
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
gem "
|
8
|
-
end
|
9
|
-
|
10
|
-
group :text do
|
11
|
-
gem "shoulda", ">= 0"
|
12
|
-
end
|
13
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in flextures.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem "shoulda", ">= 0"
|
8
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,17 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flextures (3.1.0)
|
5
|
+
|
1
6
|
GEM
|
2
|
-
remote:
|
7
|
+
remote: https://rubygems.org/
|
3
8
|
specs:
|
4
9
|
activesupport (3.2.8)
|
5
10
|
i18n (~> 0.6)
|
6
11
|
multi_json (~> 1.0)
|
7
|
-
git (1.2.5)
|
8
12
|
i18n (0.6.0)
|
9
|
-
jeweler (1.8.3)
|
10
|
-
bundler (~> 1.0)
|
11
|
-
git (>= 1.2.5)
|
12
|
-
rake
|
13
|
-
rdoc
|
14
|
-
json (1.6.6)
|
15
13
|
multi_json (1.3.6)
|
16
14
|
rake (0.9.2.2)
|
17
|
-
rdoc (3.12)
|
18
|
-
json (~> 1.4)
|
19
15
|
shoulda (3.1.1)
|
20
16
|
shoulda-context (~> 1.0)
|
21
17
|
shoulda-matchers (~> 1.2)
|
@@ -27,6 +23,7 @@ PLATFORMS
|
|
27
23
|
ruby
|
28
24
|
|
29
25
|
DEPENDENCIES
|
30
|
-
bundler (
|
31
|
-
|
26
|
+
bundler (~> 1.6)
|
27
|
+
flextures!
|
28
|
+
rake
|
32
29
|
shoulda
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
# flextures
|
2
2
|
|
3
|
-
*
|
3
|
+
* [ENGLISH DOCUMENT](https://github.com/baban/flextures/blob/master/README.rdoc)
|
4
4
|
|
5
|
-
|
5
|
+
## Abstruct
|
6
6
|
|
7
7
|
このplug-inは、これまで開発中で溜まっていた
|
8
8
|
Rails標準のfixtureの不満点を解消するために作成しました
|
9
9
|
基本的な操作は単純で次のコマンドで
|
10
10
|
それぞれfixtureのロードとダンプを行います
|
11
11
|
|
12
|
+
```
|
12
13
|
rake db:flextures:load
|
13
14
|
rake db:flextures:dump
|
15
|
+
```
|
14
16
|
|
15
17
|
通常のfixtureとの主な違いは次の4点です
|
16
18
|
|
@@ -19,56 +21,69 @@ Rails標準のfixtureの不満点を解消するために作成しました
|
|
19
21
|
3. テーブル名とfixtureのファイル名を一致させないでも、自由なロード&ダンプが出来るオプション
|
20
22
|
4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
|
21
23
|
|
22
|
-
|
24
|
+
## インストール方法
|
23
25
|
|
24
26
|
RailsのPlug-inとして使われることを想定しています
|
25
27
|
gem化されているので、bundlerで次のように記述して、普通にbundle install してください
|
26
28
|
|
29
|
+
```
|
27
30
|
gem "flextures"
|
28
31
|
|
32
|
+
```
|
33
|
+
|
29
34
|
ちなみに開発環境はruby1.9以上のバージョン、rails3以上、もしくはPadrinoを想定しています
|
30
35
|
|
31
|
-
|
36
|
+
## 使い方
|
32
37
|
|
33
|
-
|
38
|
+
### rakeコマンド
|
34
39
|
|
35
40
|
次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
|
36
41
|
(読み込む基本のディレクトリは設定ファイルで変更可能)
|
37
42
|
|
38
|
-
|
39
|
-
|
43
|
+
```
|
44
|
+
rake db:flextures:load
|
45
|
+
rake db:flextures:dump
|
46
|
+
```
|
40
47
|
|
41
48
|
rake コマンドには以下の様な書式でオプションを指定することができます
|
42
49
|
指摘出来るオプションは、ロードとダンプで共通です
|
43
50
|
|
44
51
|
テーブル名で吐き出し(Userモデルusers)
|
45
52
|
|
46
|
-
|
53
|
+
```
|
54
|
+
rake db:flextures:dump TABLE=users
|
55
|
+
```
|
47
56
|
|
48
57
|
Usersモデルのfixture(users.csvか users.yml)をロードする
|
49
58
|
|
50
|
-
|
59
|
+
```
|
60
|
+
rake db:flextures:load MODEL=User
|
61
|
+
```
|
51
62
|
|
52
63
|
その他オプションは以下の通りです:
|
53
64
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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 | ファイル名指定のエイリアス |
|
63
76
|
|
64
77
|
migration等でテーブルの構成が変わった時には
|
65
78
|
generateコマンドを実行すると、テーブル情報のloadとdumpをセットで行なってくれるので便利です
|
66
79
|
|
67
|
-
|
80
|
+
```
|
81
|
+
rake db:flextures:generate T=users
|
82
|
+
```
|
68
83
|
|
69
|
-
さらに詳しい説明に関しては
|
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)を参照して下さい
|
70
85
|
|
71
|
-
|
86
|
+
### Unit test flexture support
|
72
87
|
|
73
88
|
ユニットテスト中でデータの読み込みが行いたくなったときのために
|
74
89
|
fixtureのロード機能を使えます
|
@@ -76,68 +91,78 @@ fixtureのロード機能を使えます
|
|
76
91
|
次の例はRSpecからの読み込みですが
|
77
92
|
基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
|
78
93
|
|
79
|
-
|
80
|
-
|
94
|
+
```ruby
|
95
|
+
describe ItemShopController do
|
96
|
+
flextures :users, :items
|
97
|
+
```
|
81
98
|
|
82
99
|
基本的な違いは、yamlよりcsvを優先する、カラムの変更点を検知して警告を出しながらもロードを行う等ですが
|
83
100
|
もう一つ、ハッシュ引数で指定する事で、テーブル名、ファイル名を一致させなくても フィクスチャ を読み込ませることができます
|
84
101
|
そのため、すべてのテストケースで依存関係を気にしながら共通のfixtureを使わなくても良い様に出来ます
|
85
102
|
|
86
|
-
|
87
|
-
|
103
|
+
```ruby
|
104
|
+
describe ItemShopController do
|
105
|
+
flextures :items, :users => :users_for_itmshop # users_for_itemshop.csv をロードする
|
106
|
+
```
|
88
107
|
|
89
108
|
その他現在はShouldからの呼び出しや様々なオプションを載せていますが
|
90
|
-
さらに詳しい使い方に関しては
|
109
|
+
さらに詳しい使い方に関しては [Wiki:Unit Test Supportの説明](https://github.com/baban/flextures/wiki/Unit-test-support%E3%81%AE%E8%AA%AC%E6%98%8E) を参照して下さい
|
91
110
|
|
92
|
-
|
111
|
+
### Flextures load filter (and dump filter)
|
93
112
|
|
94
|
-
|
113
|
+
#### load filer
|
95
114
|
|
96
115
|
Railsのプロジェクトに config/flextures.factory.rb というファイルを作成して、そこにフィルタを記述することによって
|
97
116
|
(Padrinoでも設置場所は同じです)
|
98
117
|
フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
|
99
118
|
例えば、次の様に記述するとusersテーブルのlast_login_dateの値を、常に現在の時間として設定できます
|
100
119
|
|
101
|
-
|
102
|
-
|
103
|
-
|
120
|
+
```ruby
|
121
|
+
Flextures::Factory.define :users do |f|
|
122
|
+
f.last_login_date = DateTime.now
|
123
|
+
end
|
124
|
+
```
|
104
125
|
|
105
126
|
テーブルにdefaultの値を設定していなくても
|
106
127
|
カラムのデータを適当に補完する機能があるので
|
107
|
-
大量のデータを生成したい時は次のように
|
128
|
+
大量のデータを生成したい時は次のように[faker](https://github.com/stympy/faker)等と組み合わせて
|
108
129
|
必要な分だけ生成をさせると、今までより若干捗るかもしれません
|
109
130
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
+
```
|
117
140
|
|
118
|
-
*
|
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)
|
119
142
|
|
120
|
-
|
143
|
+
#### dump filer
|
121
144
|
|
122
145
|
データのdump時に加工が必要になった時には、ダンプフィルターにテーブル名と、加工したい値をキーに、処理をラムダで渡してやることで可能です
|
123
146
|
|
124
|
-
|
125
|
-
|
126
|
-
}
|
147
|
+
```ruby
|
148
|
+
Flextures::DumpFilter.define :users, {
|
149
|
+
:encrypted_password => lambda { |v| Base64.encode64(v) }
|
150
|
+
}
|
151
|
+
```
|
127
152
|
|
153
|
+
さらに細かい使い方に関しては [Wiki:FactoryFilterについて](https://github.com/baban/flextures/wiki/Factoryfilter%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) を参照して下さい
|
128
154
|
|
129
|
-
|
130
|
-
|
131
|
-
=== 設定ファイル
|
155
|
+
### 設定ファイル
|
132
156
|
|
133
157
|
config/flextures.config.rb で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
|
134
158
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
+
```
|
143
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
ADDED
@@ -0,0 +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) ...
|