flextures 1.0.8 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +0 -2
- data/README.ja.rdoc +1 -0
- data/README.rdoc +1 -0
- data/VERSION +1 -1
- data/flextures.gemspec +2 -5
- data/lib/flextures/flextures.rake +31 -6
- data/lib/flextures/flextures.rb +33 -18
- data/lib/flextures/rspec_flextures_support.rb +17 -2
- data/lib/flextures/testunit_flextures_support.rb +2 -2
- metadata +9 -20
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "shoulda", ">= 0"
|
9
|
+
#gem "shoulda", ">= 0"
|
10
10
|
gem "bundler", "~> 1.0.0"
|
11
11
|
gem "jeweler", "~> 1.6.4"
|
12
12
|
gem "rcov", ">= 0"
|
data/Gemfile.lock
CHANGED
data/README.ja.rdoc
CHANGED
@@ -53,6 +53,7 @@ Usersモデルのfixture(users.csvか users.yml)をロードする
|
|
53
53
|
MODEL : モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能
|
54
54
|
DIR : フィクスチャをロード&ダンプするディレクトリを指定する
|
55
55
|
FIXTURES : ロード、ダンプをするファイル名をRails標準以外のもので直接指定(Userモデルのusers.csv以外を指定)
|
56
|
+
FORMAT : yml,yaml 等の文字列を指定するとロード、ダンプをするフォーマットを変更できる(ymlload,ymldumpと同じ)
|
56
57
|
T : TABLEのエイリアス
|
57
58
|
M : モデル名指定のエイリアス
|
58
59
|
D : ディレクトリ指定のエイリアス
|
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
1.0
|
1
|
+
1.9.0
|
2
2
|
|
data/flextures.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{flextures}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.9.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 = %q{2012-
|
12
|
+
s.date = %q{2012-02-14}
|
13
13
|
s.description = %q{load and dump fixtures}
|
14
14
|
s.email = %q{babanba.n@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -49,18 +49,15 @@ Gem::Specification.new do |s|
|
|
49
49
|
s.specification_version = 3
|
50
50
|
|
51
51
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
53
52
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
55
54
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
55
|
else
|
57
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
58
56
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
57
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
60
58
|
s.add_dependency(%q<rcov>, [">= 0"])
|
61
59
|
end
|
62
60
|
else
|
63
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
61
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
62
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
66
63
|
s.add_dependency(%q<rcov>, [">= 0"])
|
@@ -6,32 +6,57 @@ namespace :db do
|
|
6
6
|
namespace :flextures do
|
7
7
|
desc "Dump data to csv format"
|
8
8
|
task :dump => :environment do
|
9
|
-
Flextures::ARGS.parse
|
9
|
+
table_names = Flextures::ARGS.parse
|
10
|
+
Flextures::init_load
|
11
|
+
puts "dumping..."
|
12
|
+
if ["yml","yaml"].include? ENV["FORMAT"]
|
13
|
+
table_names.each { |fmt| Flextures::Dumper::yml(fmt) }
|
14
|
+
else
|
15
|
+
table_names.each { |fmt| Flextures::Dumper::csv(fmt) }
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
desc "Dump data to prefer csv format"
|
13
20
|
task :csvdump => :environment do
|
14
|
-
Flextures::ARGS.parse
|
21
|
+
table_names = Flextures::ARGS.parse
|
22
|
+
Flextures::init_load
|
23
|
+
table_names.each { |fmt| Flextures::Dumper::csv(fmt) }
|
15
24
|
end
|
16
25
|
|
17
26
|
desc "Dump data to yaml format"
|
18
27
|
task :ymldump => :environment do
|
19
|
-
Flextures::ARGS.parse
|
28
|
+
table_names = Flextures::ARGS.parse
|
29
|
+
Flextures::init_load
|
30
|
+
table_names.each { |fmt| Flextures::Dumper::yml(fmt) }
|
20
31
|
end
|
21
32
|
|
22
33
|
desc "load fixture data csv format"
|
23
34
|
task :load => :environment do
|
24
|
-
Flextures::ARGS.parse
|
35
|
+
table_names = Flextures::ARGS.parse
|
36
|
+
Flextures::init_load
|
37
|
+
Flextures::init_tables
|
38
|
+
puts "loading..."
|
39
|
+
if ["yml","yaml"].include? ENV["FORMAT"]
|
40
|
+
table_names.each { |fmt| Flextures::Loader::yml(fmt) }
|
41
|
+
else
|
42
|
+
table_names.each { |fmt| Flextures::Loader::csv(fmt) }
|
43
|
+
end
|
25
44
|
end
|
26
45
|
|
27
46
|
desc "load fixture data only csv format files"
|
28
47
|
task :csvload => :environment do
|
29
|
-
Flextures::ARGS.parse
|
48
|
+
table_names = Flextures::ARGS.parse
|
49
|
+
Flextures::init_load
|
50
|
+
Flextures::init_tables
|
51
|
+
table_names.each { |fmt| Flextures::Loader::csv(fmt) }
|
30
52
|
end
|
31
53
|
|
32
54
|
desc "load fixture files only yaml format"
|
33
55
|
task :ymlload => :environment do
|
34
|
-
Flextures::ARGS::parse
|
56
|
+
table_names = Flextures::ARGS::parse
|
57
|
+
Flextures::init_load
|
58
|
+
Flextures::init_tables
|
59
|
+
table_names.each { |fmt| Flextures::Loader::yml(fmt) }
|
35
60
|
end
|
36
61
|
end
|
37
62
|
end
|
data/lib/flextures/flextures.rb
CHANGED
@@ -36,18 +36,27 @@ module Flextures
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
# テーブル情報の初期化
|
40
|
+
def self.init_tables
|
41
|
+
tables = ActiveRecord::Base.connection.tables
|
42
|
+
tables.delete "schema_migrations"
|
43
|
+
tables.each{ |name| Class.new(ActiveRecord::Base){ |o| o.table_name=name }.delete_all }
|
44
|
+
end
|
45
|
+
|
39
46
|
# 引数解析
|
40
47
|
module ARGS
|
41
48
|
# 書き出し 、読み込み すべきファイルとオプションを書きだす
|
42
49
|
def self.parse option={}
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
table_names = []
|
51
|
+
if ENV["T"] or ENV["TABLE"]
|
52
|
+
table_names = (ENV["T"] or ENV["TABLE"]).split(',').map{ |name| { table: name } }
|
53
|
+
end
|
54
|
+
if ENV["M"] or ENV["MODEL"]
|
55
|
+
table_names = (ENV["M"] or ENV["MODEL"]).split(',').map{ |name| { table: name.constantize.table_name } }
|
56
|
+
end
|
57
|
+
if table_names.empty?
|
58
|
+
table_names = ActiveRecord::Base.connection.tables.map{ |name| { table: name } }
|
59
|
+
end
|
51
60
|
# ENV["FIXTURES"]の中身を解析
|
52
61
|
fixtures_args_parser =->(s){
|
53
62
|
names = s.split(',')
|
@@ -84,27 +93,26 @@ module Flextures
|
|
84
93
|
|
85
94
|
# csv で fixtures を dump
|
86
95
|
def self.csv format
|
87
|
-
|
88
|
-
file_name = format[:file] || table_name
|
96
|
+
file_name = format[:file] || format[:table]
|
89
97
|
dir_name = format[:dir] || DUMP_DIR
|
90
98
|
outfile = "#{dir_name}#{file_name}.csv"
|
99
|
+
table_name = format[:table]
|
91
100
|
klass = PARENT.create_model(table_name)
|
92
101
|
attributes = klass.columns.map { |colum| colum.name }
|
93
|
-
|
94
102
|
CSV.open(outfile,'w') do |csv|
|
95
103
|
csv<< attributes
|
96
104
|
klass.all.each do |row|
|
97
|
-
csv<< attributes.map { |column| trans(row.send(column))}
|
105
|
+
csv<< attributes.map { |column| trans(row.send(column)) }
|
98
106
|
end
|
99
107
|
end
|
100
108
|
end
|
101
109
|
|
102
110
|
# yaml で fixtures を dump
|
103
111
|
def self.yml format
|
104
|
-
|
105
|
-
file_name = format[:file] || table_name
|
112
|
+
file_name = format[:file] || format[:table]
|
106
113
|
dir_name = format[:dir] || DUMP_DIR
|
107
114
|
outfile = "#{dir_name}#{file_name}.yml"
|
115
|
+
table_name = format[:table]
|
108
116
|
klass = PARENT::create_model(table_name)
|
109
117
|
attributes = klass.columns.map { |colum| colum.name }
|
110
118
|
File.open(outfile,"w") do |f|
|
@@ -164,8 +172,14 @@ module Flextures
|
|
164
172
|
end
|
165
173
|
|
166
174
|
# fixturesをまとめてロード、主にテストtest/unit, rspec で使用する
|
175
|
+
#
|
176
|
+
# 全テーブルが対象
|
177
|
+
# fixtures :all
|
178
|
+
# テーブル名で一覧する
|
179
|
+
# fixtures :users, :items
|
180
|
+
# ハッシュで指定
|
181
|
+
# fixtures :users => :users2
|
167
182
|
def self.flextures *fixtures
|
168
|
-
PARENT::init_load
|
169
183
|
# :allですべてのfixtureを反映
|
170
184
|
fixtures = ActiveRecord::Base.connection.tables if fixtures.size== 1 and :all == fixtures.first
|
171
185
|
|
@@ -184,13 +198,13 @@ module Flextures
|
|
184
198
|
klass = PARENT::create_model table_name
|
185
199
|
attributes = klass.columns.map &:name
|
186
200
|
filter = create_filter klass, Factory[table_name]
|
187
|
-
klass.delete_all
|
188
201
|
CSV.open( inpfile ) do |csv|
|
189
202
|
keys = csv.shift # keyの設定
|
190
203
|
warning "CSV", attributes, keys
|
191
204
|
csv.each do |values|
|
192
205
|
h = values.extend(Extensions::Array).to_hash(keys)
|
193
|
-
|
206
|
+
args = [h, file_name]
|
207
|
+
o = filter.call *args[0,filter.arity]
|
194
208
|
o.save
|
195
209
|
end
|
196
210
|
end
|
@@ -208,7 +222,8 @@ module Flextures
|
|
208
222
|
klass.delete_all
|
209
223
|
YAML.load(File.open(inpfile)).each do |k,h|
|
210
224
|
warning "YAML", attributes, h.keys
|
211
|
-
|
225
|
+
args = [h, file_name]
|
226
|
+
o = filter.call *args[0,filter.arity]
|
212
227
|
o.save
|
213
228
|
end
|
214
229
|
end
|
@@ -4,10 +4,25 @@
|
|
4
4
|
module RSpec
|
5
5
|
module Core
|
6
6
|
module Hooks
|
7
|
-
def flextures *
|
8
|
-
Flextures::Loader::flextures *
|
7
|
+
def flextures *_
|
8
|
+
before { Flextures::Loader::flextures *_ }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
module Rails
|
14
|
+
module FlextureSupport
|
15
|
+
@@configs={ load_count: 0 }
|
16
|
+
def self.included(m)
|
17
|
+
# 一番外側のdescribeにだけ追加
|
18
|
+
m.before { Flextures::init_load } if @@configs[:load_count]==0
|
19
|
+
@@configs[:load_count] += 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.configure do |c|
|
25
|
+
c.include RSpec::Rails::FlextureSupport
|
26
|
+
end
|
12
27
|
end
|
13
28
|
|
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: 1.0
|
4
|
+
version: 1.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,23 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-14 00:00:00.000000000 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: shoulda
|
17
|
-
requirement: &80302920 !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
23
|
-
type: :development
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: *80302920
|
26
15
|
- !ruby/object:Gem::Dependency
|
27
16
|
name: bundler
|
28
|
-
requirement: &
|
17
|
+
requirement: &86821870 !ruby/object:Gem::Requirement
|
29
18
|
none: false
|
30
19
|
requirements:
|
31
20
|
- - ~>
|
@@ -33,10 +22,10 @@ dependencies:
|
|
33
22
|
version: 1.0.0
|
34
23
|
type: :development
|
35
24
|
prerelease: false
|
36
|
-
version_requirements: *
|
25
|
+
version_requirements: *86821870
|
37
26
|
- !ruby/object:Gem::Dependency
|
38
27
|
name: jeweler
|
39
|
-
requirement: &
|
28
|
+
requirement: &86821630 !ruby/object:Gem::Requirement
|
40
29
|
none: false
|
41
30
|
requirements:
|
42
31
|
- - ~>
|
@@ -44,10 +33,10 @@ dependencies:
|
|
44
33
|
version: 1.6.4
|
45
34
|
type: :development
|
46
35
|
prerelease: false
|
47
|
-
version_requirements: *
|
36
|
+
version_requirements: *86821630
|
48
37
|
- !ruby/object:Gem::Dependency
|
49
38
|
name: rcov
|
50
|
-
requirement: &
|
39
|
+
requirement: &86821330 !ruby/object:Gem::Requirement
|
51
40
|
none: false
|
52
41
|
requirements:
|
53
42
|
- - ! '>='
|
@@ -55,7 +44,7 @@ dependencies:
|
|
55
44
|
version: '0'
|
56
45
|
type: :development
|
57
46
|
prerelease: false
|
58
|
-
version_requirements: *
|
47
|
+
version_requirements: *86821330
|
59
48
|
description: load and dump fixtures
|
60
49
|
email: babanba.n@gmail.com
|
61
50
|
executables: []
|
@@ -101,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
90
|
version: '0'
|
102
91
|
segments:
|
103
92
|
- 0
|
104
|
-
hash: -
|
93
|
+
hash: -236599985
|
105
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
95
|
none: false
|
107
96
|
requirements:
|