flextures 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.ja.rdoc +33 -22
- data/README.rdoc +29 -22
- data/VERSION +1 -1
- data/flextures.gemspec +7 -6
- data/lib/flextures/flextures.rake +28 -4
- data/lib/flextures/flextures.rb +33 -28
- data/lib/flextures/flextures_base_config.rb +17 -6
- data/lib/flextures/flextures_command.rb +25 -27
- data/lib/flextures/flextures_dumper.rb +82 -55
- data/lib/flextures/flextures_extension_modules.rb +12 -8
- data/lib/flextures/flextures_factory.rb +13 -11
- data/lib/flextures/flextures_loader.rb +208 -132
- data/lib/flextures/rspec_flextures_support.rb +13 -7
- data/lib/flextures/testunit_flextures_support.rb +30 -4
- data/lib/flextures/version.rb +1 -1
- data/test/unit/test_flextures.rb +1 -1
- data/test/unit/test_flextures_args.rb +70 -17
- data/test/unit/test_flextures_dumper.rb +48 -37
- data/test/unit/test_flextures_extention_modules.rb +37 -0
- data/test/unit/test_flextures_hooks.rb +66 -17
- data/test/unit/test_flextures_loader.rb +89 -14
- data/test/unit/test_simple.rb +1 -1
- metadata +12 -21
@@ -1,15 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
#
|
3
|
+
# flextures function use like fixtures method in RSpec
|
4
4
|
module RSpec
|
5
5
|
module Core
|
6
6
|
module Hooks
|
7
|
-
#
|
7
|
+
# load fixtture data
|
8
|
+
# @params [Array] _ fixture file names
|
8
9
|
def flextures *_
|
9
10
|
before { Flextures::Loader::flextures *_ }
|
10
11
|
end
|
11
12
|
|
12
|
-
#
|
13
|
+
# delete table data
|
14
|
+
# @params [Array] _ table names
|
13
15
|
def flextures_delete *_
|
14
16
|
before {
|
15
17
|
if _.empty?
|
@@ -20,8 +22,13 @@ module RSpec
|
|
20
22
|
}
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
24
|
-
|
25
|
+
def flextures_set_options options
|
26
|
+
before do
|
27
|
+
Flextures::Loader::set_options options
|
28
|
+
end
|
29
|
+
after do
|
30
|
+
Flextures::Loader::delete_options
|
31
|
+
end
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
@@ -29,7 +36,6 @@ module RSpec
|
|
29
36
|
module Rails
|
30
37
|
module FlextureSupport
|
31
38
|
def self.included(m)
|
32
|
-
# 実行前にテーブルの初期化
|
33
39
|
Flextures::init_tables
|
34
40
|
end
|
35
41
|
end
|
@@ -40,7 +46,7 @@ module RSpec
|
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
43
|
-
#
|
49
|
+
# override setup_fixtures function
|
44
50
|
module ActiveRecord
|
45
51
|
module TestFixtures
|
46
52
|
alias :setup_fixtures_bkup :setup_fixtures
|
@@ -1,9 +1,35 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# shouda
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# flxtures function shouda support
|
4
|
+
module Shoulda
|
5
|
+
module Context
|
6
|
+
module ClassMethods
|
7
|
+
def flextures *_
|
8
|
+
context = Shoulda::Context.current_context
|
9
|
+
context.setup_blocks<< ->{ Flextures::Loader::flextures *_ }
|
10
|
+
end
|
11
|
+
|
12
|
+
def flextures_delete *_
|
13
|
+
context = Shoulda::Context.current_context
|
14
|
+
context.setup_blocks<< -> {
|
15
|
+
if _.empty?
|
16
|
+
Flextures::init_tables
|
17
|
+
else
|
18
|
+
Flextures::delete_tables *_
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def flextures_set_options options={}
|
24
|
+
context = Shoulda::Context.current_context
|
25
|
+
context.setup_blocks<< -> {
|
26
|
+
Flextures::Loader::set_options options
|
27
|
+
}
|
28
|
+
context.teardown_blocks<< -> {
|
29
|
+
Flextures::Loader::delete_options
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
7
33
|
end
|
8
34
|
end
|
9
35
|
|
data/lib/flextures/version.rb
CHANGED
data/test/unit/test_flextures.rb
CHANGED
@@ -2,49 +2,49 @@
|
|
2
2
|
|
3
3
|
class FlexturesArgsTest < Test::Unit::TestCase
|
4
4
|
context Flextures::ARGS do
|
5
|
-
context " TABLE
|
5
|
+
context "if set TABLE='table_name' option " do
|
6
6
|
setup do
|
7
7
|
ENV["TABLE"] = "users"
|
8
8
|
@format = Flextures::ARGS.parse
|
9
9
|
end
|
10
|
-
should "
|
10
|
+
should "return table_name" do
|
11
11
|
assert_equal "users", @format.first[:table]
|
12
12
|
end
|
13
|
-
should "
|
13
|
+
should "filename is same table_name" do
|
14
14
|
assert_equal "users", @format.first[:file]
|
15
15
|
end
|
16
16
|
teardown do
|
17
17
|
ENV.delete("TABLE")
|
18
18
|
end
|
19
19
|
end
|
20
|
-
context " T
|
20
|
+
context "if set T=table_name option " do
|
21
21
|
setup do
|
22
22
|
ENV["T"] = "s_user"
|
23
23
|
@format = Flextures::ARGS.parse
|
24
24
|
end
|
25
|
-
should "
|
25
|
+
should "retrun table_name" do
|
26
26
|
assert_equal "s_user", @format.first[:table]
|
27
27
|
end
|
28
|
-
should "
|
28
|
+
should "filename is same table_name" do
|
29
29
|
assert_equal "s_user", @format.first[:file]
|
30
30
|
end
|
31
31
|
teardown do
|
32
32
|
ENV.delete("T")
|
33
33
|
end
|
34
34
|
end
|
35
|
-
context " DIR
|
35
|
+
context " DIR=option " do
|
36
36
|
setup do
|
37
37
|
ENV["T"] = "users"
|
38
38
|
ENV["DIR"] = "test/fixtures/"
|
39
39
|
@format = Flextures::ARGS.parse
|
40
40
|
end
|
41
|
-
should "
|
41
|
+
should "directory name is exist" do
|
42
42
|
assert_equal "test/fixtures/", @format.first[:dir]
|
43
43
|
end
|
44
|
-
should "
|
44
|
+
should "set table name" do
|
45
45
|
assert_equal "users", @format.first[:table]
|
46
46
|
end
|
47
|
-
should "
|
47
|
+
should "file name is equal table name" do
|
48
48
|
assert_equal "users", @format.first[:file]
|
49
49
|
end
|
50
50
|
teardown do
|
@@ -52,19 +52,19 @@ class FlexturesArgsTest < Test::Unit::TestCase
|
|
52
52
|
ENV.delete("DIR")
|
53
53
|
end
|
54
54
|
end
|
55
|
-
context " D
|
55
|
+
context " D=option " do
|
56
56
|
setup do
|
57
57
|
ENV["T"] = "users"
|
58
58
|
ENV["D"] = "test/fixtures/"
|
59
59
|
@format = Flextures::ARGS.parse
|
60
60
|
end
|
61
|
-
should "
|
61
|
+
should "directory name" do
|
62
62
|
assert_equal "test/fixtures/", @format.first[:dir]
|
63
63
|
end
|
64
|
-
should "
|
64
|
+
should "table name is exist" do
|
65
65
|
assert_equal "users", @format.first[:table]
|
66
66
|
end
|
67
|
-
should "
|
67
|
+
should "file name is equal table name" do
|
68
68
|
assert_equal "users", @format.first[:file]
|
69
69
|
end
|
70
70
|
teardown do
|
@@ -72,16 +72,16 @@ class FlexturesArgsTest < Test::Unit::TestCase
|
|
72
72
|
ENV.delete("D")
|
73
73
|
end
|
74
74
|
end
|
75
|
-
context " FIXTURES
|
75
|
+
context " FIXTURES=option " do
|
76
76
|
setup do
|
77
77
|
ENV["T"] = "users"
|
78
78
|
ENV["FIXTURES"] = "user_another"
|
79
79
|
@format = Flextures::ARGS.parse
|
80
80
|
end
|
81
|
-
should "
|
81
|
+
should "table name is exist" do
|
82
82
|
assert_equal "users", @format.first[:table]
|
83
83
|
end
|
84
|
-
should "
|
84
|
+
should " file name is changed by option's name " do
|
85
85
|
assert_equal "user_another", @format.first[:file]
|
86
86
|
end
|
87
87
|
teardown do
|
@@ -89,6 +89,59 @@ class FlexturesArgsTest < Test::Unit::TestCase
|
|
89
89
|
ENV.delete("FIXTURES")
|
90
90
|
end
|
91
91
|
end
|
92
|
+
context " MINUS option " do
|
93
|
+
context "only one columns" do
|
94
|
+
setup do
|
95
|
+
ENV["T"]="users"
|
96
|
+
ENV["MINUS"]="id"
|
97
|
+
@format = Flextures::ARGS.parse
|
98
|
+
end
|
99
|
+
should " option contain 'minus' parameters" do
|
100
|
+
assert_equal ["id"], @format.first[:minus]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
context "many columns" do
|
104
|
+
setup do
|
105
|
+
ENV["T"]="users"
|
106
|
+
ENV["MINUS"]="id,created_at,updated_at"
|
107
|
+
@format = Flextures::ARGS.parse
|
108
|
+
end
|
109
|
+
should " option contain 'minus' parameters" do
|
110
|
+
assert_equal ["id","created_at","updated_at"], @format.first[:minus]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
teardown do
|
114
|
+
ENV.delete("T")
|
115
|
+
ENV.delete("MINUS")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
context " PLUS options " do
|
119
|
+
setup do
|
120
|
+
ENV["T"]="users"
|
121
|
+
end
|
122
|
+
context "only one columns" do
|
123
|
+
setup do
|
124
|
+
ENV["PLUS"]="hoge"
|
125
|
+
@format = Flextures::ARGS.parse
|
126
|
+
end
|
127
|
+
should " option contain 'plus' parameters" do
|
128
|
+
assert_equal ["hoge"], @format.first[:plus]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
context "many columns" do
|
132
|
+
setup do
|
133
|
+
ENV["PLUS"]="hoge,mage"
|
134
|
+
@format = Flextures::ARGS.parse
|
135
|
+
end
|
136
|
+
should " option contain 'plus' parameters" do
|
137
|
+
assert_equal ["hoge","mage"], @format.first[:plus]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
teardown do
|
141
|
+
ENV.delete("T")
|
142
|
+
ENV.delete("MINUS")
|
143
|
+
end
|
144
|
+
end
|
92
145
|
end
|
93
146
|
end
|
94
147
|
|
@@ -1,21 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# ruby -I"lib:lib:test" -I"/Users/matsubaramasanao/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib" "/Users/matsubaramasanao/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" test/**/test_*.rb
|
4
|
-
# ruby -I"lib:lib:test" "/Users/matsubaramasanao/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" test/**/test_*.rb
|
5
|
-
|
6
3
|
class FlexturesDumperTest < Test::Unit::TestCase
|
7
4
|
context Flextures::Dumper do
|
8
|
-
|
9
|
-
assert_equal Module, Flextures::Dumper.class
|
10
|
-
end
|
11
|
-
|
12
|
-
context "データ型を以下のフォーマットに変換" do
|
5
|
+
context "TRANSLATE function rules" do
|
13
6
|
context :binary do
|
14
7
|
context :yml do
|
15
8
|
setup do
|
16
9
|
@trans = Flextures::Dumper::TRANSLATER[:binary]
|
17
10
|
end
|
18
|
-
should "
|
11
|
+
should "nil translate 'null' string" do
|
19
12
|
assert_equal "null", @trans.call( nil, :yml )
|
20
13
|
end
|
21
14
|
end
|
@@ -30,19 +23,19 @@ class FlexturesDumperTest < Test::Unit::TestCase
|
|
30
23
|
setup do
|
31
24
|
@trans = Flextures::Dumper::TRANSLATER[:boolean]
|
32
25
|
end
|
33
|
-
should "
|
26
|
+
should "nil translate 'null' string" do
|
34
27
|
assert_equal "null", @trans.call( nil, :yml )
|
35
28
|
end
|
36
|
-
should "
|
29
|
+
should "0 translate false" do
|
37
30
|
assert_equal false, @trans.call( 0, :yml )
|
38
31
|
end
|
39
|
-
should "
|
32
|
+
should "natural number translat true" do
|
40
33
|
assert_equal true, @trans.call( 1, :yml )
|
41
34
|
end
|
42
|
-
should "
|
35
|
+
should " empty string translate dalse" do
|
43
36
|
assert_equal false, @trans.call( "", :yml )
|
44
37
|
end
|
45
|
-
should "
|
38
|
+
should "string translate true" do
|
46
39
|
assert_equal true, @trans.call( "Hello", :yml )
|
47
40
|
end
|
48
41
|
end
|
@@ -57,13 +50,13 @@ class FlexturesDumperTest < Test::Unit::TestCase
|
|
57
50
|
setup do
|
58
51
|
@trans = Flextures::Dumper::TRANSLATER[:date]
|
59
52
|
end
|
60
|
-
should "
|
53
|
+
should "nil translate 'null' string" do
|
61
54
|
assert_equal "null", @trans.call( nil, :yml )
|
62
55
|
end
|
63
|
-
should "
|
56
|
+
should "empty string translate 'null' string" do
|
64
57
|
assert_equal "null", @trans.call( "", :yml )
|
65
58
|
end
|
66
|
-
should "
|
59
|
+
should "false translate 'null' string" do
|
67
60
|
assert_equal "null", @trans.call( false, :yml )
|
68
61
|
end
|
69
62
|
end
|
@@ -78,13 +71,13 @@ class FlexturesDumperTest < Test::Unit::TestCase
|
|
78
71
|
setup do
|
79
72
|
@trans = Flextures::Dumper::TRANSLATER[:datetime]
|
80
73
|
end
|
81
|
-
should "
|
74
|
+
should "nil translate 'null' string" do
|
82
75
|
assert_equal "null", @trans.call( nil, :yml )
|
83
76
|
end
|
84
|
-
should "
|
77
|
+
should "empty string translate 'null' string" do
|
85
78
|
assert_equal "null", @trans.call( "", :yml )
|
86
79
|
end
|
87
|
-
should "
|
80
|
+
should "false translate 'null' string" do
|
88
81
|
assert_equal "null", @trans.call( false, :yml )
|
89
82
|
end
|
90
83
|
end
|
@@ -96,19 +89,19 @@ class FlexturesDumperTest < Test::Unit::TestCase
|
|
96
89
|
setup do
|
97
90
|
@trans = Flextures::Dumper::TRANSLATER[:float]
|
98
91
|
end
|
99
|
-
should "
|
92
|
+
should "integral number don't translate" do
|
100
93
|
assert_equal 10, @trans.call( 10, :yml )
|
101
94
|
end
|
102
|
-
should "
|
95
|
+
should "floating number don't translate" do
|
103
96
|
assert_equal 1.5, @trans.call( 1.5, :yml )
|
104
97
|
end
|
105
|
-
should "
|
98
|
+
should "nil translate 'null' string" do
|
106
99
|
assert_equal "null", @trans.call( nil, :yml )
|
107
100
|
end
|
108
|
-
should "
|
101
|
+
should "0 don't translate" do
|
109
102
|
assert_equal "null", @trans.call( nil, :yml )
|
110
103
|
end
|
111
|
-
should "
|
104
|
+
should "false don't translate" do
|
112
105
|
assert_equal "null", @trans.call( nil, :yml )
|
113
106
|
end
|
114
107
|
end
|
@@ -120,22 +113,22 @@ class FlexturesDumperTest < Test::Unit::TestCase
|
|
120
113
|
setup do
|
121
114
|
@trans = Flextures::Dumper::TRANSLATER[:integer]
|
122
115
|
end
|
123
|
-
should "
|
116
|
+
should "integral number don't translate" do
|
124
117
|
assert_equal 10, @trans.call( 10, :yml )
|
125
118
|
end
|
126
|
-
should "
|
119
|
+
should "float number is floored" do
|
127
120
|
assert_equal 1, @trans.call( 1.5, :yml )
|
128
121
|
end
|
129
|
-
should "
|
122
|
+
should "nil translate 'null' string" do
|
130
123
|
assert_equal "null", @trans.call( nil, :yml )
|
131
124
|
end
|
132
|
-
should "
|
125
|
+
should "0 don't translate" do
|
133
126
|
assert_equal 0, @trans.call( 0, :yml )
|
134
127
|
end
|
135
|
-
should "
|
128
|
+
should "false translate 0" do
|
136
129
|
assert_equal 0, @trans.call( false, :yml )
|
137
130
|
end
|
138
|
-
should "
|
131
|
+
should "true translate 1" do
|
139
132
|
assert_equal 1, @trans.call( true, :yml )
|
140
133
|
end
|
141
134
|
end
|
@@ -143,10 +136,10 @@ class FlexturesDumperTest < Test::Unit::TestCase
|
|
143
136
|
setup do
|
144
137
|
@trans = Flextures::Dumper::TRANSLATER[:integer]
|
145
138
|
end
|
146
|
-
should "
|
139
|
+
should "integral number don't translate" do
|
147
140
|
assert_equal 10, @trans.call( 10, :csv )
|
148
141
|
end
|
149
|
-
should '
|
142
|
+
should 'nil translate empty string' do
|
150
143
|
assert_equal "", @trans.call( nil, :csv )
|
151
144
|
end
|
152
145
|
end
|
@@ -156,20 +149,38 @@ class FlexturesDumperTest < Test::Unit::TestCase
|
|
156
149
|
setup do
|
157
150
|
@trans = Flextures::Dumper::TRANSLATER[:string]
|
158
151
|
end
|
159
|
-
should "
|
152
|
+
should "nil translate 'null' string" do
|
160
153
|
assert_equal "null", @trans.call( nil, :yml )
|
161
154
|
end
|
162
|
-
should "
|
155
|
+
should "empty string don't translate" do
|
163
156
|
assert_equal "null", @trans.call( nil, :yml )
|
164
157
|
end
|
165
|
-
should "
|
158
|
+
should "false don't translate" do
|
166
159
|
assert_equal false, @trans.call( false, :yml )
|
167
160
|
end
|
168
|
-
should "
|
161
|
+
should "true don't translate" do
|
169
162
|
assert_equal true, @trans.call( true, :yml )
|
170
163
|
end
|
171
164
|
end
|
172
165
|
end
|
166
|
+
context :null do
|
167
|
+
context :yml do
|
168
|
+
setup do
|
169
|
+
@trans = Flextures::Dumper::TRANSLATER[:null]
|
170
|
+
end
|
171
|
+
should "values is 'null' string" do
|
172
|
+
assert_equal "null", @trans.call( nil, :yml )
|
173
|
+
end
|
174
|
+
end
|
175
|
+
context :csv do
|
176
|
+
setup do
|
177
|
+
@trans = Flextures::Dumper::TRANSLATER[:null]
|
178
|
+
end
|
179
|
+
should "values is empty string" do
|
180
|
+
assert_equal "", @trans.call( nil, :csv )
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
173
184
|
end
|
174
185
|
end
|
175
186
|
end
|