flextures 0.9.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.ja.rdoc +113 -0
- data/README.rdoc +55 -44
- data/VERSION +1 -1
- data/flextures.gemspec +4 -2
- data/lib/flextures.rb +2 -2
- data/lib/flextures/flextures.rb +4 -3
- data/lib/flextures/testunit_flextures_support.rb +3 -3
- metadata +13 -11
data/README.ja.rdoc
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
= flextures
|
2
|
+
|
3
|
+
== Abstruct
|
4
|
+
|
5
|
+
このplug-inは、これまで開発中で溜まっていた
|
6
|
+
Rails標準のfixtureの不満点を解消するために作成しました
|
7
|
+
基本的な操作は単純で次のコマンドで
|
8
|
+
それぞれfixtureのロードとダンプを行います
|
9
|
+
|
10
|
+
rake db:flextures:load
|
11
|
+
rake db:flextures:dump
|
12
|
+
|
13
|
+
通常のfixtureとの主な違いは次の4点です
|
14
|
+
|
15
|
+
1. yamlよりもcsvを優先する
|
16
|
+
2. migrationでテーブル構成が変わっても、ロードを停止しないで、カラムの変更点を検知して値を補完する
|
17
|
+
3. テーブル名と、fixtureのファイル名を一致させないでも自由なロード&ダンプが出来る機能
|
18
|
+
4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
|
19
|
+
|
20
|
+
== インストール方法
|
21
|
+
|
22
|
+
RailsのPlug-inとして使われることを想定しています
|
23
|
+
gem化されているので、bundlerで次のように記述して、普通にbundle install してください
|
24
|
+
|
25
|
+
gem "flextures"
|
26
|
+
|
27
|
+
ちなみに開発環境はruby1.9系、rails3環境を想定しています
|
28
|
+
|
29
|
+
== 使い方
|
30
|
+
|
31
|
+
=== rakeコマンド
|
32
|
+
|
33
|
+
次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
|
34
|
+
(ディレクトリは設定ファイルで変更可能)
|
35
|
+
|
36
|
+
rake db:flextures:load
|
37
|
+
rake db:flextures:dump
|
38
|
+
|
39
|
+
rake コマンドには以下の様な書式でオプションを指定することができます
|
40
|
+
指摘出来るオプションは、ロードとダンプで共通です
|
41
|
+
|
42
|
+
テーブル名で吐き出し(Userモデルusers)
|
43
|
+
|
44
|
+
rake db:flextures:dump TABLE=users
|
45
|
+
|
46
|
+
Usersモデルのfixture(users.csvか users.yml)をロードする
|
47
|
+
|
48
|
+
rake db:flextures:load MODEL=User
|
49
|
+
|
50
|
+
その他オプションは以下のとおりな感じです:
|
51
|
+
|
52
|
+
TABLE : テーブル名を指定してロード。テーブル名はカンマ切りで複数指定が可能
|
53
|
+
MODEL : モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能
|
54
|
+
DIR : フィクスチャをロード&ダンプするディレクトリを指定する
|
55
|
+
FIXTURES : ロード、ダンプをするファイル名をRails標準以外のもので直接指定(Userモデルのusers.csv以外を指定)
|
56
|
+
T : TABLEのエイリアス
|
57
|
+
M : モデル名指定のエイリアス
|
58
|
+
D : ディレクトリ指定のエイリアス
|
59
|
+
F : ファイル名指定のエイリアス
|
60
|
+
|
61
|
+
yamlのファイルはロードしたいけどcsvはロードをしたくない
|
62
|
+
またはその逆の場合は、以下のコマンドでそれが可能です
|
63
|
+
|
64
|
+
rake db:flextures:csvload
|
65
|
+
rake db:flextures:ymlload
|
66
|
+
rake db:flextures:csvdump
|
67
|
+
rake db:flextures:ymldump
|
68
|
+
|
69
|
+
通常の load や dump で使えるオプションはこちらでも使用可能です
|
70
|
+
|
71
|
+
=== RSpec flexture support
|
72
|
+
|
73
|
+
RSpec中でfixtures関数の代わりにfixtureのロード機能を使えます
|
74
|
+
基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
|
75
|
+
|
76
|
+
describe ItemShopController do
|
77
|
+
flextures :users, :items
|
78
|
+
|
79
|
+
基本的な違いは、yamlよりcsvを優先する、カラムの変更点を検知して警告を出しながらもロードを行う等ですが
|
80
|
+
もう一つ、ハッシュ引数で指定する事で、テーブル名、ファイル名を一致させなくても フィクスチャ を読み込ませることができます
|
81
|
+
そのため、すべてのテストケースで依存関係を気にしながら共通のfixtureを使わなくても良い様に出来ます
|
82
|
+
|
83
|
+
describe ItemShopController do
|
84
|
+
flextures :items, :users => :users_for_itmshop # users_for_itemshop.csv をロードする
|
85
|
+
|
86
|
+
=== Flextures factory filter
|
87
|
+
|
88
|
+
Railsのプロジェクトに config/flextures.factory.rb というファイルを作成して、そこにフィルタを記述することによって
|
89
|
+
フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
|
90
|
+
例えば、次の様に記述するとusersテーブルのlast_login_dateの値を、常に現在の時間として設定できます
|
91
|
+
|
92
|
+
Flextures::Factory.define :users do |f|
|
93
|
+
f.last_login_date = DateTime.now
|
94
|
+
end
|
95
|
+
|
96
|
+
テーブルにdefaultとか設定していなくても
|
97
|
+
カラムのデータとかを、適当に補完する機能があるので
|
98
|
+
Faker等のデータ生成系のライブラリと組み合わせて必要なデータだけ自動生成すると
|
99
|
+
今までより若干捗るかもしれません
|
100
|
+
|
101
|
+
=== 設定ファイル
|
102
|
+
|
103
|
+
config/flextures.config.rb で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
|
104
|
+
|
105
|
+
# config/flextures.config.rb
|
106
|
+
module Flextures
|
107
|
+
# test/fixtures/ のフィクスチャを読み出したい場合は吐き出しディレクトリの値を上書きする
|
108
|
+
Config.fixture_load_directory = "test/fixtures/"
|
109
|
+
Config.fixture_dump_directory = "test/fixtures/"
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
|
data/README.rdoc
CHANGED
@@ -2,94 +2,105 @@
|
|
2
2
|
|
3
3
|
== Abstruct
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
それぞれfixtureのロードとダンプを行います
|
5
|
+
This plug-in aim to resolve many problems, durling rails developping about fixtures.
|
6
|
+
Basic commands is simple.
|
7
|
+
Each commands load or dump fixtures.
|
9
8
|
|
10
9
|
rake db:flextures:load
|
11
10
|
rake db:flextures:dump
|
12
11
|
|
13
|
-
|
12
|
+
Major different point is four.
|
14
13
|
|
15
|
-
1.
|
16
|
-
2.
|
17
|
-
3.
|
18
|
-
4.
|
14
|
+
1. Fixture file is prefered CSV to YAML.
|
15
|
+
2. Don't stop load if table colums are'nt match fixture file's column.
|
16
|
+
3. Fixture file name can change if file name is not equal table name.
|
17
|
+
4. Fixture data translate to use filter like factory girl.
|
19
18
|
|
20
|
-
==
|
19
|
+
== How to install
|
21
20
|
|
22
|
-
Rails
|
23
|
-
|
21
|
+
This program is implemented Rails Plug-in.
|
22
|
+
You want to install this plug-in.
|
23
|
+
Please use bundler.
|
24
24
|
|
25
25
|
gem "flextures"
|
26
26
|
|
27
|
-
|
27
|
+
(Development emnvoriment must be ruby1.9 and rails3)
|
28
28
|
|
29
|
-
==
|
29
|
+
== How to use
|
30
30
|
|
31
|
-
=== rake
|
31
|
+
=== rake command
|
32
32
|
|
33
|
-
|
34
|
-
(
|
33
|
+
load command input fixtures file under "spec/fixtures/".
|
34
|
+
(Loading directory can change configuration file)
|
35
35
|
|
36
36
|
rake db:flextures:load
|
37
37
|
rake db:flextures:dump
|
38
38
|
|
39
|
-
rake
|
40
|
-
|
41
|
-
|
42
|
-
テーブル名で吐き出し(Userモデルusers)
|
39
|
+
rake command can set options.
|
40
|
+
For example, this option set dump file name.
|
41
|
+
(Option dump only "users.csv")
|
43
42
|
|
44
43
|
rake db:flextures:dump TABLE=users
|
45
44
|
|
46
|
-
|
45
|
+
If you use this option load command.
|
46
|
+
Option set load file name.
|
47
|
+
(loading "users.csv" or "users.yml")
|
47
48
|
|
48
49
|
rake db:flextures:load MODEL=User
|
49
50
|
|
50
|
-
|
51
|
+
Other options...
|
51
52
|
|
52
|
-
TABLE :
|
53
|
-
MODEL :
|
54
|
-
DIR :
|
55
|
-
|
56
|
-
T : TABLE
|
57
|
-
M :
|
58
|
-
D :
|
59
|
-
F :
|
53
|
+
TABLE : set table name
|
54
|
+
MODEL : set model name
|
55
|
+
DIR : set directory name
|
56
|
+
FIXTURES : set fixture file name
|
57
|
+
T : alias TABLE option
|
58
|
+
M : alias MODEL option
|
59
|
+
D : alias DIR option
|
60
|
+
F : alias FIXTURES option
|
60
61
|
|
61
|
-
|
62
|
-
またはその逆の場合は、以下のコマンドでそれが可能です
|
62
|
+
if you only load CSV file or YAML file, next command can load.
|
63
63
|
|
64
64
|
rake db:flextures:csvload
|
65
65
|
rake db:flextures:ymlload
|
66
66
|
rake db:flextures:csvdump
|
67
67
|
rake db:flextures:ymldump
|
68
68
|
|
69
|
-
通常の load や dump で使えるオプションはこちらでも使用可能です
|
70
|
-
|
71
69
|
=== RSpec flexture support
|
72
70
|
|
73
|
-
RSpec
|
74
|
-
基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
|
71
|
+
Fixture load function implemented for RSpec.
|
75
72
|
|
76
73
|
describe ItemShopController do
|
77
74
|
flextures :users, :items
|
78
75
|
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
flexture function can write like a "fixture" function, implemented in RSpec.
|
77
|
+
But, "flexture" function ignore columns change.
|
78
|
+
|
79
|
+
Flextures function can change load file name.
|
82
80
|
|
83
81
|
describe ItemShopController do
|
84
|
-
flextures :items, :users => :users_for_itmshop # users_for_itemshop.csv
|
82
|
+
flextures :items, :users => :users_for_itmshop # load "users_for_itemshop.csv"
|
85
83
|
|
86
84
|
=== Flextures factory filter
|
87
85
|
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
If you create filter file.(File name is "config/flextures.factory.rb")
|
87
|
+
Factory filter translate fixture data and set database.
|
88
|
+
|
89
|
+
For example, this code set current time to last_login_date column.
|
91
90
|
|
92
91
|
Flextures::Factory.define :users do |f|
|
93
92
|
f.last_login_date = DateTime.now
|
94
93
|
end
|
95
94
|
|
95
|
+
=== Configuration file
|
96
|
+
|
97
|
+
Configuration file can change load and dump directory
|
98
|
+
(file is confi/flextures.config.rb)
|
99
|
+
|
100
|
+
# config/flextures.config.rb
|
101
|
+
module Flextures
|
102
|
+
# Load and dump directory change "spec/fixtures/" to "test/fixtures/"
|
103
|
+
Config.fixture_load_directory = "test/fixtures/"
|
104
|
+
Config.fixture_dump_directory = "test/fixtures/"
|
105
|
+
end
|
106
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.1
|
data/flextures.gemspec
CHANGED
@@ -5,15 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{flextures}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.1"
|
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 = %q{2011-11-
|
12
|
+
s.date = %q{2011-11-24}
|
13
13
|
s.description = %q{load and dump fixtures}
|
14
14
|
s.email = %q{babanba.n@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
+
"README.ja.rdoc",
|
17
18
|
"README.rdoc"
|
18
19
|
]
|
19
20
|
s.files = [
|
@@ -23,6 +24,7 @@ Gem::Specification.new do |s|
|
|
23
24
|
"Gemfile.lock",
|
24
25
|
"History.txt",
|
25
26
|
"LICENSE.txt",
|
27
|
+
"README.ja.rdoc",
|
26
28
|
"README.rdoc",
|
27
29
|
"Rakefile",
|
28
30
|
"VERSION",
|
data/lib/flextures.rb
CHANGED
@@ -5,6 +5,6 @@ require 'flextures/flextures_extension_modules'
|
|
5
5
|
require 'flextures/flextures'
|
6
6
|
require 'flextures/flextures_factory'
|
7
7
|
require 'flextures/flextures_railtie' if defined? Rails
|
8
|
-
require 'flextures/rspec_flextures_support'
|
9
|
-
require 'flextures/testunit_flextures_support'
|
8
|
+
require 'flextures/rspec_flextures_support' if defined? RSpec
|
9
|
+
require 'flextures/testunit_flextures_support' if defined? Test::Unit::TestCase
|
10
10
|
|
data/lib/flextures/flextures.rb
CHANGED
@@ -40,8 +40,8 @@ module Flextures
|
|
40
40
|
table_names = ActiveRecord::Base.connection.tables if ""==table_names
|
41
41
|
table_names = table_names.map{ |name| { table: name } }
|
42
42
|
table_names = table_names.map{ |option| option.merge dir: ENV["DIR"] } if ENV["DIR"]
|
43
|
-
table_names.first[:file]= ENV["
|
44
|
-
table_names.first[:file]= ENV["F"] if ENV["F"]
|
43
|
+
table_names.first[:file] = ENV["FIXTURES"] if ENV["FIXTURES"] # ファイル名は最初のものしか指定できない
|
44
|
+
table_names.first[:file] = ENV["F"] if ENV["F"]
|
45
45
|
# read mode だとcsvもyaml存在しないファイルは返さない
|
46
46
|
table_names.select! &exist if option[:mode] && option[:mode].to_sym == :read
|
47
47
|
table_names
|
@@ -53,6 +53,7 @@ module Flextures
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
# データを吐き出す処理をまとめる
|
56
57
|
module Dumper
|
57
58
|
PARENT = Flextures
|
58
59
|
|
@@ -103,6 +104,7 @@ module Flextures
|
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
107
|
+
# Dumperと違ってデータの吐き出し処理をまとめたクラス
|
106
108
|
module Loader
|
107
109
|
PARENT = Flextures
|
108
110
|
|
@@ -222,7 +224,6 @@ module Flextures
|
|
222
224
|
h
|
223
225
|
}
|
224
226
|
end
|
225
|
-
|
226
227
|
end
|
227
228
|
end
|
228
229
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flextures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-24 00:00:00.000000000 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
17
|
-
requirement: &
|
17
|
+
requirement: &90095980 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *90095980
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &90095740 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *90095740
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &90095500 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.6.4
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *90095500
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rcov
|
50
|
-
requirement: &
|
50
|
+
requirement: &90095260 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,13 +55,14 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *90095260
|
59
59
|
description: load and dump fixtures
|
60
60
|
email: babanba.n@gmail.com
|
61
61
|
executables: []
|
62
62
|
extensions: []
|
63
63
|
extra_rdoc_files:
|
64
64
|
- LICENSE.txt
|
65
|
+
- README.ja.rdoc
|
65
66
|
- README.rdoc
|
66
67
|
files:
|
67
68
|
- .document
|
@@ -70,6 +71,7 @@ files:
|
|
70
71
|
- Gemfile.lock
|
71
72
|
- History.txt
|
72
73
|
- LICENSE.txt
|
74
|
+
- README.ja.rdoc
|
73
75
|
- README.rdoc
|
74
76
|
- Rakefile
|
75
77
|
- VERSION
|
@@ -101,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
103
|
version: '0'
|
102
104
|
segments:
|
103
105
|
- 0
|
104
|
-
hash:
|
106
|
+
hash: -767338093
|
105
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
108
|
none: false
|
107
109
|
requirements:
|