flextures 4.2.0 → 4.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +5 -5
- data/.gitignore +48 -48
- data/CHANGELOG +2 -2
- data/Gemfile.lock +11 -14
- data/LICENSE.txt +20 -20
- data/README.ja.md +58 -16
- data/README.md +43 -6
- data/lib/flextures.rb +1 -0
- data/lib/flextures/active_record_test_fixtures.rb +138 -0
- data/lib/flextures/rspec_flextures_support.rb +0 -139
- data/lib/flextures/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9726d311d7a8e2ea0e476d87c3aa2c6f55e499aa
|
4
|
+
data.tar.gz: 5d698420575a089d9752e8a8059cf4502539815f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91f20fc07082d3fd1216109dcc6be7adfe6ab56ce014a828d3907aed6e9e957926130eb73dd5189b45c63bd5d55a5e547455fcbdf989179f8e6054c8d78a2123
|
7
|
+
data.tar.gz: f5142e6bc66c4b4e889304c616627900e3865651252b7380e9c292335b25c453c5bf09b2fcb1eb9146a781b61edfd273232174652a00267921c728a5b042163a
|
data/.document
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
lib/**/*.rb
|
2
|
-
bin/*
|
3
|
-
-
|
4
|
-
features/**/*.feature
|
5
|
-
LICENSE.txt
|
1
|
+
lib/**/*.rb
|
2
|
+
bin/*
|
3
|
+
-
|
4
|
+
features/**/*.feature
|
5
|
+
LICENSE.txt
|
data/.gitignore
CHANGED
@@ -1,48 +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
|
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/CHANGELOG
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
2011/10/03 Release
|
2
|
-
|
1
|
+
2011/10/03 Release
|
2
|
+
|
data/Gemfile.lock
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
flextures (4.2.
|
4
|
+
flextures (4.2.2)
|
5
5
|
activerecord
|
6
6
|
activesupport
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (
|
12
|
-
activesupport (=
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
activemodel (5.0.0.1)
|
12
|
+
activesupport (= 5.0.0.1)
|
13
|
+
activerecord (5.0.0.1)
|
14
|
+
activemodel (= 5.0.0.1)
|
15
|
+
activesupport (= 5.0.0.1)
|
16
|
+
arel (~> 7.0)
|
17
|
+
activesupport (5.0.0.1)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
19
|
i18n (~> 0.7)
|
20
|
-
json (~> 1.7, >= 1.7.7)
|
21
20
|
minitest (~> 5.1)
|
22
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
23
21
|
tzinfo (~> 1.1)
|
24
|
-
arel (
|
25
|
-
|
22
|
+
arel (7.1.4)
|
23
|
+
concurrent-ruby (1.0.4)
|
26
24
|
i18n (0.7.0)
|
27
|
-
json (1.8.3)
|
28
25
|
minitest (5.4.0)
|
29
26
|
minitest-bang (0.1.1)
|
30
27
|
minitest (>= 4.7.5, <= 5.4.0)
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2011 baban
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2011 baban
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.ja.md
CHANGED
@@ -2,26 +2,58 @@
|
|
2
2
|
|
3
3
|
* [ENGLISH DOCUMENT](https://github.com/baban/flextures/blob/master/README.md)
|
4
4
|
|
5
|
-
|
5
|
+
![Ruby 2.1 higher](https://img.shields.io/badge/ruby-v2.1-red.svg)
|
6
|
+
![Rails 4.0 higher](https://img.shields.io/badge/rails-v4.0-red.svg)
|
7
|
+
![MIT Licence](https://img.shields.io/badge/licence-MIT-blue.svg)
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
## 要約
|
10
|
+
|
11
|
+
このplug-inは、これまで開発中で溜まっていた Rails標準のfixtureの不満点を解消するために作成しました。
|
12
|
+
基本的な操作は単純で次のコマンドで、それぞれfixtureのロードとダンプを行います。
|
11
13
|
|
12
14
|
```
|
13
15
|
rake db:flextures:load
|
14
16
|
rake db:flextures:dump
|
15
17
|
```
|
16
18
|
|
17
|
-
|
19
|
+
また、rspecやminitest中でテストデータを読み込むのにも使用できます。
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
describe ItemShopController do
|
23
|
+
flextures :users, :items
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
通常のfixtureとの主な違いは次の4点です。
|
18
28
|
|
19
29
|
1. yamlよりもcsvを優先する
|
20
30
|
2. migrationでテーブル構成が変わっても、カラムの変更点を無視、補完してロードを行う
|
21
31
|
3. テーブル名とfixtureのファイル名を一致させないでも、自由なロード&ダンプが出来るオプション
|
22
32
|
4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
|
23
33
|
|
24
|
-
|
34
|
+
<a name="table_of_contents"></a>
|
35
|
+
## 目次
|
36
|
+
|
37
|
+
* [必要条件](#requirements)
|
38
|
+
* [使い方](#usage)
|
39
|
+
* [インストール方法](#how_to_install)
|
40
|
+
* [rakeコマンドでの呼び出し方](#commandline_support)
|
41
|
+
* [ユニットテストでの使い方](#unittest_support)
|
42
|
+
* [読み込み・書き出しフィルター](#flextures_filter)
|
43
|
+
* [設定ファイル](#configuration)
|
44
|
+
* [貢献](#contributing)
|
45
|
+
* [ライセンス](#licence)
|
46
|
+
|
47
|
+
<a name="requirements"></a>
|
48
|
+
## 必要条件
|
49
|
+
|
50
|
+
* ruby2.1以上
|
51
|
+
|
52
|
+
<a name="usage"></a>
|
53
|
+
## 使い方
|
54
|
+
|
55
|
+
<a name="how_to_install"></a>
|
56
|
+
### インストール方法
|
25
57
|
|
26
58
|
RailsのPlug-inとして使われることを想定しています
|
27
59
|
gem化されているので、bundlerで次のように記述して、普通にbundle install してください
|
@@ -32,13 +64,10 @@ gem化されているので、bundlerで次のように記述して、普通にb
|
|
32
64
|
|
33
65
|
```
|
34
66
|
bundle install
|
35
|
-
bundle exec rails
|
67
|
+
bundle exec rails generate flextures:initializer
|
36
68
|
```
|
37
69
|
|
38
|
-
|
39
|
-
|
40
|
-
## 使い方
|
41
|
-
|
70
|
+
<a name="commandline_support"></a>
|
42
71
|
### rakeコマンド
|
43
72
|
|
44
73
|
次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
|
@@ -87,7 +116,8 @@ rake db:flextures:generate T=users
|
|
87
116
|
|
88
117
|
さらに詳しい説明に関しては [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)を参照して下さい
|
89
118
|
|
90
|
-
|
119
|
+
<a name="unittest_support"></a>
|
120
|
+
### ユニットテストでの使い方
|
91
121
|
|
92
122
|
ユニットテスト中でデータの読み込みが行いたくなったときのために
|
93
123
|
fixtureのロード機能を使えます
|
@@ -114,9 +144,10 @@ end
|
|
114
144
|
その他現在はShouldからの呼び出しや様々なオプションを載せていますが
|
115
145
|
さらに詳しい使い方に関しては [Wiki:Unit Test Supportの説明](https://github.com/baban/flextures/wiki/Unit-test-support%E3%81%AE%E8%AA%AC%E6%98%8E) を参照して下さい
|
116
146
|
|
117
|
-
|
147
|
+
<a name="flextures_filter"></a>
|
148
|
+
### 読み込み・書き出しフィルター
|
118
149
|
|
119
|
-
####
|
150
|
+
#### 読み込みフィルター
|
120
151
|
|
121
152
|
Railsのプロジェクトに `config/flextures.factory.rb` というファイルを作成して、そこにフィルタを記述することによって
|
122
153
|
フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
|
@@ -145,7 +176,7 @@ end
|
|
145
176
|
|
146
177
|
* [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)
|
147
178
|
|
148
|
-
####
|
179
|
+
#### 書き出しフィルター
|
149
180
|
|
150
181
|
データのdump時に加工が必要になった時には、同じく`config/flextures.factory.rb`に
|
151
182
|
テーブル名と、加工したい値をキーに、処理をラムダで渡してやることで可能です
|
@@ -158,6 +189,7 @@ Flextures::DumpFilter.define :users, {
|
|
158
189
|
|
159
190
|
さらに細かい使い方に関しては [Wiki:FactoryFilterについて](https://github.com/baban/flextures/wiki/Factoryfilter%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) を参照して下さい
|
160
191
|
|
192
|
+
<a name="configuration"></a>
|
161
193
|
### 設定ファイル
|
162
194
|
|
163
195
|
`config/initializers/flextures.rb` で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
|
@@ -171,3 +203,13 @@ end
|
|
171
203
|
```
|
172
204
|
|
173
205
|
その他の情報は [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)を参照して下さい
|
206
|
+
|
207
|
+
<a name="contributing"></a>
|
208
|
+
## 貢献
|
209
|
+
|
210
|
+
https://github.com/baban/flextures/graphs/contributors
|
211
|
+
|
212
|
+
<a name="licence"></a>
|
213
|
+
## ライセンス
|
214
|
+
|
215
|
+
このソフトウェアは [MIT ライセンス](http://www.opensource.org/licenses/MIT)によってライセンスされています。
|
data/README.md
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
* [日本語版ドキュメント(Japanese Document)](https://github.com/baban/flextures/blob/master/README.ja.md)
|
4
4
|
|
5
|
-
|
5
|
+
![Ruby 2.1 higher](https://img.shields.io/badge/ruby-v2.1-red.svg)
|
6
|
+
![Rails 4.0 higher](https://img.shields.io/badge/rails-v4.0-red.svg)
|
7
|
+
![MIT Licence](https://img.shields.io/badge/licence-MIT-blue.svg)
|
8
|
+
|
9
|
+
## Description
|
6
10
|
|
7
11
|
This plug-in aim to resolve many problems, durling rails developping about fixtures.
|
8
12
|
Basic commands is simple.
|
@@ -16,10 +20,31 @@ rake db:flextures:dump
|
|
16
20
|
Major different point is four.
|
17
21
|
|
18
22
|
1. Fixture file prefered CSV to YAML.
|
19
|
-
2. loading don't stop
|
23
|
+
2. Even if, not match column's structure, loading don't stop and auto padding data.
|
20
24
|
3. Fixture file name can change, if file name is not equal table name.
|
21
25
|
4. Fixture data can translate to use filter, like factory girl.
|
22
26
|
|
27
|
+
## Table of Contents
|
28
|
+
|
29
|
+
* [Requirements](#requirements)
|
30
|
+
* [Usage](#usage)
|
31
|
+
* [How to install](#how_to_install)
|
32
|
+
* [rake command](#commandline_support)
|
33
|
+
* [Unit test support](#unittest_support)
|
34
|
+
* [Flextures load & dump filter](#flextures_filter)
|
35
|
+
* [Configuration file](#configuration)
|
36
|
+
* [Contributing](#contributing)
|
37
|
+
* [License](#licence)
|
38
|
+
|
39
|
+
<a name="requirements"></a>
|
40
|
+
## Requirements
|
41
|
+
|
42
|
+
* ruby2.1 higher
|
43
|
+
|
44
|
+
<a name="usage"></a>
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
<a name="how_to_install"></a>
|
23
48
|
## How to install
|
24
49
|
|
25
50
|
This program is implemented Rails Plug-in.
|
@@ -36,13 +61,12 @@ And execute below commands.
|
|
36
61
|
|
37
62
|
```
|
38
63
|
bundle install
|
39
|
-
bundle exec rails
|
64
|
+
bundle exec rails generate flextures:initializer
|
40
65
|
```
|
41
66
|
|
42
67
|
(Development emnvoriment must be ruby2.1 higer and rails3 higher)
|
43
68
|
|
44
|
-
|
45
|
-
|
69
|
+
<a name="commandline_support"></a>
|
46
70
|
### rake command
|
47
71
|
|
48
72
|
load command input fixtures file under "spec/fixtures/".
|
@@ -84,7 +108,8 @@ rake db:flextures:generate T=users
|
|
84
108
|
|
85
109
|
Other information please see [wiki](https://github.com/baban/flextures/wiki/Rake-command-option) ...
|
86
110
|
|
87
|
-
|
111
|
+
<a name="unittest_support"></a>
|
112
|
+
### Unit test support
|
88
113
|
|
89
114
|
Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda).
|
90
115
|
|
@@ -108,6 +133,7 @@ end
|
|
108
133
|
Other option information
|
109
134
|
Please see [wiki](https://github.com/baban/flextures/wiki/Unittestsupport) ...
|
110
135
|
|
136
|
+
<a name="flextures_filter"></a>
|
111
137
|
### Flextures load & dump filter
|
112
138
|
|
113
139
|
#### load filter
|
@@ -153,6 +179,7 @@ Flextures::DumpFilter.define :users, {
|
|
153
179
|
|
154
180
|
Other options please see [wiki](https://github.com/baban/flextures/wiki/Factoryfilter) ...
|
155
181
|
|
182
|
+
<a name="configuration"></a>
|
156
183
|
### Configuration file
|
157
184
|
|
158
185
|
In `config/initializers/flextures.rb`, configuration file can change load and dump directory
|
@@ -166,3 +193,13 @@ end
|
|
166
193
|
```
|
167
194
|
|
168
195
|
Other options please see [wiki](https://github.com/baban/flextures/wiki/Configuration-file) ...
|
196
|
+
|
197
|
+
<a name="contributing"></a>
|
198
|
+
## Contributing
|
199
|
+
|
200
|
+
https://github.com/baban/flextures/graphs/contributors
|
201
|
+
|
202
|
+
<a name="licence"></a>
|
203
|
+
## Licence
|
204
|
+
|
205
|
+
This software is released under the [MIT Licence](http://www.opensource.org/licenses/MIT).
|
data/lib/flextures.rb
CHANGED
@@ -7,5 +7,6 @@ require 'flextures/flextures_factory'
|
|
7
7
|
require 'flextures/flextures_loader'
|
8
8
|
require 'flextures/flextures_dumper'
|
9
9
|
require 'flextures/flextures_command'
|
10
|
+
require 'flextures/active_record_test_fixtures' if defined? ActiveRecord
|
10
11
|
require 'flextures/flextures_railtie' if defined? Rails
|
11
12
|
require 'flextures/rspec_flextures_support' if defined? RSpec
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# override setup_fixtures function
|
2
|
+
module ActiveRecord
|
3
|
+
module TestFixtures
|
4
|
+
PARENT = self
|
5
|
+
@@flextures_loader = Flextures::Loader.new
|
6
|
+
@@all_cached_flextures = {}
|
7
|
+
@@already_loaded_flextures = {}
|
8
|
+
|
9
|
+
alias :setup_fixtures_bkup :setup_fixtures
|
10
|
+
def setup_fixtures
|
11
|
+
Flextures::load_configurations
|
12
|
+
setup_fixtures_bkup
|
13
|
+
end
|
14
|
+
|
15
|
+
alias :teardown_fixtures_bkup :teardown_fixtures
|
16
|
+
def teardown_fixtures
|
17
|
+
teardown_fixtures_bkup
|
18
|
+
end
|
19
|
+
|
20
|
+
# load initial fixtures
|
21
|
+
# There is fixtures load before start rspec
|
22
|
+
def self.init_load_should_cache_fixtures(table_load_settings)
|
23
|
+
table_load_settings.each do |load_setting|
|
24
|
+
if should_cache_setting?(load_setting) and !cached_table?(load_setting)
|
25
|
+
@@flextures_loader.load(load_setting)
|
26
|
+
set_cached_settng_list(load_setting)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Usually, fixture is cached when is exist under "spec/fixture/" directly.
|
32
|
+
def self.should_cache_setting?(load_setting)
|
33
|
+
load_setting.keys.sort == %i[table file loader].sort &&
|
34
|
+
load_setting[:file].to_s == load_setting[:table].to_s &&
|
35
|
+
load_setting[:loader] == :fun
|
36
|
+
end
|
37
|
+
|
38
|
+
# check: same data is exist in DB.
|
39
|
+
def self.cached_table?(load_setting)
|
40
|
+
flextures_cached?(load_setting) || fixture_cached?(load_setting)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.flextures_cached?(load_setting)
|
44
|
+
config = @@all_cached_flextures[load_setting[:table]]
|
45
|
+
config && config == load_setting
|
46
|
+
end
|
47
|
+
|
48
|
+
# flextures check fixture function already loaded data.
|
49
|
+
def self.fixture_cached?(load_setting)
|
50
|
+
default_file_path = File.join(Flextures::Configuration.load_directory, "#{load_setting[:table]}.yml")
|
51
|
+
|
52
|
+
load_setting[:file] == default_file_path &&
|
53
|
+
yml_fixture_cached?(load_setting[:table])
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.yml_fixture_cached?(table_name)
|
57
|
+
connection = ActiveRecord::Base.connection
|
58
|
+
!!ActiveRecord::FixtureSet.fixture_is_cached?(connection, table_name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.set_cached_settng_list(load_setting)
|
62
|
+
@@all_cached_flextures[load_setting[:table]] = load_setting
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_not_cached_fixtures(table_load_settings)
|
66
|
+
table_load_settings.each do |load_setting|
|
67
|
+
if PARENT.cached_table?(load_setting) and load_setting[:cache] != false
|
68
|
+
next
|
69
|
+
else
|
70
|
+
@@flextures_loader.load(load_setting)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def load_all_fixtures(table_load_settings)
|
76
|
+
table_load_settings.each do |load_setting|
|
77
|
+
@@flextures_loader.load(load_setting)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
module ClassMethods
|
82
|
+
def get_or_initialize_flextures_loader_options
|
83
|
+
@flextures_loader_options ||= {}
|
84
|
+
end
|
85
|
+
|
86
|
+
def flextures_loader_options
|
87
|
+
get_or_initialize_flextures_loader_options
|
88
|
+
end
|
89
|
+
|
90
|
+
def flextures_loader
|
91
|
+
PARENT.class_variable_get(:@@flextures_loader)
|
92
|
+
end
|
93
|
+
|
94
|
+
def flextures(*fixtures)
|
95
|
+
loads_use_cache_fixtures(*fixtures)
|
96
|
+
end
|
97
|
+
|
98
|
+
def loads_use_cache_fixtures(*fixtures)
|
99
|
+
table_load_settings = Flextures::Loader.parse_flextures_options(flextures_loader_options, *fixtures)
|
100
|
+
|
101
|
+
if (respond_to?(:use_transactional_fixtures) && use_transactional_fixtures) || (respond_to?(:use_transactional_tests) && use_transactional_tests)
|
102
|
+
PARENT.init_load_should_cache_fixtures(table_load_settings)
|
103
|
+
before do
|
104
|
+
load_not_cached_fixtures(table_load_settings)
|
105
|
+
end
|
106
|
+
else
|
107
|
+
before do
|
108
|
+
load_all_fixtures(table_load_settings)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# delete table data
|
114
|
+
# @params [Array] _ table names
|
115
|
+
def flextures_delete(*_)
|
116
|
+
before do
|
117
|
+
if _.empty?
|
118
|
+
Flextures::init_tables
|
119
|
+
else
|
120
|
+
Flextures::delete_tables(*_)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def flextures_set_options(options)
|
126
|
+
get_or_initialize_flextures_loader_options.merge!(options)
|
127
|
+
end
|
128
|
+
|
129
|
+
def flextures_instance
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
def flextures_options
|
134
|
+
@flextures_loader_options
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -20,142 +20,3 @@ module RSpec
|
|
20
20
|
c.include RSpec::Rails::FlextureSupport
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
|
-
# override setup_fixtures function
|
25
|
-
module ActiveRecord
|
26
|
-
module TestFixtures
|
27
|
-
PARENT = self
|
28
|
-
@@flextures_loader = Flextures::Loader.new
|
29
|
-
@@all_cached_flextures = {}
|
30
|
-
@@already_loaded_flextures = {}
|
31
|
-
|
32
|
-
alias :setup_fixtures_bkup :setup_fixtures
|
33
|
-
def setup_fixtures
|
34
|
-
Flextures::load_configurations
|
35
|
-
setup_fixtures_bkup
|
36
|
-
end
|
37
|
-
|
38
|
-
alias :teardown_fixtures_bkup :teardown_fixtures
|
39
|
-
def teardown_fixtures
|
40
|
-
teardown_fixtures_bkup
|
41
|
-
end
|
42
|
-
|
43
|
-
# load initial fixtures
|
44
|
-
# There is fixtures load before start rspec
|
45
|
-
def self.init_load_should_cache_fixtures(table_load_settings)
|
46
|
-
table_load_settings.each do |load_setting|
|
47
|
-
if should_cache_setting?(load_setting) and !cached_table?(load_setting)
|
48
|
-
@@flextures_loader.load(load_setting)
|
49
|
-
set_cached_settng_list(load_setting)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Usually, fixture is cached when is exist under "spec/fixture/" directly.
|
55
|
-
def self.should_cache_setting?(load_setting)
|
56
|
-
load_setting.keys.sort == %i[table file loader].sort &&
|
57
|
-
load_setting[:file].to_s == load_setting[:table].to_s &&
|
58
|
-
load_setting[:loader] == :fun
|
59
|
-
end
|
60
|
-
|
61
|
-
# check: same data is exist in DB.
|
62
|
-
def self.cached_table?(load_setting)
|
63
|
-
flextures_cached?(load_setting) || fixture_cached?(load_setting)
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.flextures_cached?(load_setting)
|
67
|
-
config = @@all_cached_flextures[load_setting[:table]]
|
68
|
-
config && config == load_setting
|
69
|
-
end
|
70
|
-
|
71
|
-
# flextures check fixture function already loaded data.
|
72
|
-
def self.fixture_cached?(load_setting)
|
73
|
-
default_file_path = File.join(Flextures::Configuration.load_directory, "#{load_setting[:table]}.yml")
|
74
|
-
|
75
|
-
load_setting[:file] == default_file_path &&
|
76
|
-
yml_fixture_cached?(load_setting[:table])
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.yml_fixture_cached?(table_name)
|
80
|
-
connection = ActiveRecord::Base.connection
|
81
|
-
!!ActiveRecord::FixtureSet.fixture_is_cached?(connection, table_name)
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.set_cached_settng_list(load_setting)
|
85
|
-
@@all_cached_flextures[load_setting[:table]] = load_setting
|
86
|
-
end
|
87
|
-
|
88
|
-
def load_not_cached_fixtures(table_load_settings)
|
89
|
-
table_load_settings.each do |load_setting|
|
90
|
-
if PARENT.cached_table?(load_setting) and load_setting[:cache] != false
|
91
|
-
next
|
92
|
-
else
|
93
|
-
@@flextures_loader.load(load_setting)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def load_all_fixtures(table_load_settings)
|
99
|
-
table_load_settings.each do |load_setting|
|
100
|
-
@@flextures_loader.load(load_setting)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
module ClassMethods
|
105
|
-
def get_or_initialize_flextures_loader_options
|
106
|
-
@flextures_loader_options ||= {}
|
107
|
-
end
|
108
|
-
|
109
|
-
def flextures_loader_options
|
110
|
-
get_or_initialize_flextures_loader_options
|
111
|
-
end
|
112
|
-
|
113
|
-
def flextures_loader
|
114
|
-
PARENT.class_variable_get(:@@flextures_loader)
|
115
|
-
end
|
116
|
-
|
117
|
-
def flextures(*fixtures)
|
118
|
-
loads_use_cache_fixtures(*fixtures)
|
119
|
-
end
|
120
|
-
|
121
|
-
def loads_use_cache_fixtures(*fixtures)
|
122
|
-
table_load_settings = Flextures::Loader.parse_flextures_options(flextures_loader_options, *fixtures)
|
123
|
-
|
124
|
-
if use_transactional_fixtures
|
125
|
-
PARENT.init_load_should_cache_fixtures(table_load_settings)
|
126
|
-
before do
|
127
|
-
load_not_cached_fixtures(table_load_settings)
|
128
|
-
end
|
129
|
-
else
|
130
|
-
before do
|
131
|
-
load_all_fixtures(table_load_settings)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# delete table data
|
137
|
-
# @params [Array] _ table names
|
138
|
-
def flextures_delete(*_)
|
139
|
-
before do
|
140
|
-
if _.empty?
|
141
|
-
Flextures::init_tables
|
142
|
-
else
|
143
|
-
Flextures::delete_tables(*_)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def flextures_set_options(options)
|
149
|
-
get_or_initialize_flextures_loader_options.merge!(options)
|
150
|
-
end
|
151
|
-
|
152
|
-
def flextures_instance
|
153
|
-
self
|
154
|
-
end
|
155
|
-
|
156
|
-
def flextures_options
|
157
|
-
@flextures_loader_options
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
data/lib/flextures/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flextures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- baban
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- Rakefile
|
85
85
|
- flextures.gemspec
|
86
86
|
- lib/flextures.rb
|
87
|
+
- lib/flextures/active_record_test_fixtures.rb
|
87
88
|
- lib/flextures/flextures.rake
|
88
89
|
- lib/flextures/flextures.rb
|
89
90
|
- lib/flextures/flextures_base_config.rb
|