flextures 3.1.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,43 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # flxtures function shouda support
4
- module Shoulda
5
- module Context
6
- module ClassMethods
7
- def create_or_get_flextures_loader
8
- @flextures_loader ||= Flextures::Loader.new
9
- end
10
-
11
- def flextures( *_ )
12
- flextures_loader = create_or_get_flextures_loader
13
-
14
- context = Shoulda::Context.current_context
15
- context.setup_blocks<< ->{ flextures_loader.flextures(*_) }
16
- end
17
-
18
- def flextures_delete( *_ )
19
- context = Shoulda::Context.current_context
20
-
21
- context.setup_blocks<< -> {
22
- if _.empty?
23
- Flextures::init_tables
24
- else
25
- Flextures::delete_tables(*_)
26
- end
27
- }
28
- end
29
-
30
- def flextures_set_options( options={} )
31
- flextures_loader = create_or_get_flextures_loader
32
-
33
- context = Shoulda::Context.current_context
34
- context.setup_blocks<< -> {
35
- flextures_loader.set_options(options)
36
- }
37
- context.teardown_blocks<< -> {
38
- flextures_loader.delete_options
39
- }
40
- end
41
- end
42
- end
43
- end
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class FlexturesTest < Test::Unit::TestCase
4
- should "data type test" do
5
- assert_equal Module, Flextures.class
6
- end
7
- end
8
-
@@ -1,147 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class FlexturesArgsTest < Test::Unit::TestCase
4
- context Flextures::ARGS do
5
- context "if set TABLE='table_name' option " do
6
- setup do
7
- ENV["TABLE"] = "users"
8
- @format = Flextures::ARGS.parse
9
- end
10
- should "return table_name" do
11
- assert_equal "users", @format.first[:table]
12
- end
13
- should "filename is same table_name" do
14
- assert_equal "users", @format.first[:file]
15
- end
16
- teardown do
17
- ENV.delete("TABLE")
18
- end
19
- end
20
- context "if set T=table_name option " do
21
- setup do
22
- ENV["T"] = "s_user"
23
- @format = Flextures::ARGS.parse
24
- end
25
- should "retrun table_name" do
26
- assert_equal "s_user", @format.first[:table]
27
- end
28
- should "filename is same table_name" do
29
- assert_equal "s_user", @format.first[:file]
30
- end
31
- teardown do
32
- ENV.delete("T")
33
- end
34
- end
35
- context " DIR=option " do
36
- setup do
37
- ENV["T"] = "users"
38
- ENV["DIR"] = "test/fixtures/"
39
- @format = Flextures::ARGS.parse
40
- end
41
- should "directory name is exist" do
42
- assert_equal "test/fixtures/", @format.first[:dir]
43
- end
44
- should "set table name" do
45
- assert_equal "users", @format.first[:table]
46
- end
47
- should "file name is equal table name" do
48
- assert_equal "users", @format.first[:file]
49
- end
50
- teardown do
51
- ENV.delete("T")
52
- ENV.delete("DIR")
53
- end
54
- end
55
- context " D=option " do
56
- setup do
57
- ENV["T"] = "users"
58
- ENV["D"] = "test/fixtures/"
59
- @format = Flextures::ARGS.parse
60
- end
61
- should "directory name" do
62
- assert_equal "test/fixtures/", @format.first[:dir]
63
- end
64
- should "table name is exist" do
65
- assert_equal "users", @format.first[:table]
66
- end
67
- should "file name is equal table name" do
68
- assert_equal "users", @format.first[:file]
69
- end
70
- teardown do
71
- ENV.delete("T")
72
- ENV.delete("D")
73
- end
74
- end
75
- context " FIXTURES=option " do
76
- setup do
77
- ENV["T"] = "users"
78
- ENV["FIXTURES"] = "user_another"
79
- @format = Flextures::ARGS.parse
80
- end
81
- should "table name is exist" do
82
- assert_equal "users", @format.first[:table]
83
- end
84
- should " file name is changed by option's name " do
85
- assert_equal "user_another", @format.first[:file]
86
- end
87
- teardown do
88
- ENV.delete("T")
89
- ENV.delete("FIXTURES")
90
- end
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
145
- end
146
- end
147
-
@@ -1,187 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class FlexturesDumperTest < Test::Unit::TestCase
4
- context Flextures::Dumper do
5
- context "TRANSLATE function rules" do
6
- context :binary do
7
- context :yml do
8
- setup do
9
- @trans = Flextures::Dumper::TRANSLATER[:binary]
10
- end
11
- should "nil translate 'null' string" do
12
- assert_equal "null", @trans.call( nil, :yml )
13
- end
14
- end
15
- context :csv do
16
- setup do
17
- @trans = Flextures::Dumper::TRANSLATER[:binary]
18
- end
19
- end
20
- end
21
- context :boolean do
22
- context :yml do
23
- setup do
24
- @trans = Flextures::Dumper::TRANSLATER[:boolean]
25
- end
26
- should "nil translate 'null' string" do
27
- assert_equal "null", @trans.call( nil, :yml )
28
- end
29
- should "0 translate false" do
30
- assert_equal false, @trans.call( 0, :yml )
31
- end
32
- should "natural number translat true" do
33
- assert_equal true, @trans.call( 1, :yml )
34
- end
35
- should " empty string translate dalse" do
36
- assert_equal false, @trans.call( "", :yml )
37
- end
38
- should "string translate true" do
39
- assert_equal true, @trans.call( "Hello", :yml )
40
- end
41
- end
42
- context :csv do
43
- setup do
44
- @trans = Flextures::Dumper::TRANSLATER[:boolean]
45
- end
46
- end
47
- end
48
- context :date do
49
- context :yml do
50
- setup do
51
- @trans = Flextures::Dumper::TRANSLATER[:date]
52
- end
53
- should "nil translate 'null' string" do
54
- assert_equal "null", @trans.call( nil, :yml )
55
- end
56
- should "empty string translate 'null' string" do
57
- assert_equal "null", @trans.call( "", :yml )
58
- end
59
- should "false translate 'null' string" do
60
- assert_equal "null", @trans.call( false, :yml )
61
- end
62
- end
63
- context :csv do
64
- setup do
65
- @trans = Flextures::Dumper::TRANSLATER[:date]
66
- end
67
- end
68
- end
69
- context :datetime do
70
- context :yml do
71
- setup do
72
- @trans = Flextures::Dumper::TRANSLATER[:datetime]
73
- end
74
- should "nil translate 'null' string" do
75
- assert_equal "null", @trans.call( nil, :yml )
76
- end
77
- should "empty string translate 'null' string" do
78
- assert_equal "null", @trans.call( "", :yml )
79
- end
80
- should "false translate 'null' string" do
81
- assert_equal "null", @trans.call( false, :yml )
82
- end
83
- end
84
- context :csv do
85
- end
86
- end
87
- context :float do
88
- context :yml do
89
- setup do
90
- @trans = Flextures::Dumper::TRANSLATER[:float]
91
- end
92
- should "integral number don't translate" do
93
- assert_equal 10, @trans.call( 10, :yml )
94
- end
95
- should "floating number don't translate" do
96
- assert_equal 1.5, @trans.call( 1.5, :yml )
97
- end
98
- should "nil translate 'null' string" do
99
- assert_equal "null", @trans.call( nil, :yml )
100
- end
101
- should "0 don't translate" do
102
- assert_equal "null", @trans.call( nil, :yml )
103
- end
104
- should "false don't translate" do
105
- assert_equal "null", @trans.call( nil, :yml )
106
- end
107
- end
108
- context :csv do
109
- end
110
- end
111
- context :integer do
112
- context :yml do
113
- setup do
114
- @trans = Flextures::Dumper::TRANSLATER[:integer]
115
- end
116
- should "integral number don't translate" do
117
- assert_equal 10, @trans.call( 10, :yml )
118
- end
119
- should "float number is floored" do
120
- assert_equal 1, @trans.call( 1.5, :yml )
121
- end
122
- should "nil translate 'null' string" do
123
- assert_equal "null", @trans.call( nil, :yml )
124
- end
125
- should "0 don't translate" do
126
- assert_equal 0, @trans.call( 0, :yml )
127
- end
128
- should "false translate 0" do
129
- assert_equal 0, @trans.call( false, :yml )
130
- end
131
- should "true translate 1" do
132
- assert_equal 1, @trans.call( true, :yml )
133
- end
134
- end
135
- context :csv do
136
- setup do
137
- @trans = Flextures::Dumper::TRANSLATER[:integer]
138
- end
139
- should "integral number don't translate" do
140
- assert_equal 10, @trans.call( 10, :csv )
141
- end
142
- should 'nil translate empty string' do
143
- assert_equal "", @trans.call( nil, :csv )
144
- end
145
- end
146
- end
147
- context :string do
148
- context :yml do
149
- setup do
150
- @trans = Flextures::Dumper::TRANSLATER[:string]
151
- end
152
- should "nil translate 'null' string" do
153
- assert_equal "null", @trans.call( nil, :yml )
154
- end
155
- should "empty string don't translate" do
156
- assert_equal "null", @trans.call( nil, :yml )
157
- end
158
- should "false don't translate" do
159
- assert_equal false, @trans.call( false, :yml )
160
- end
161
- should "true don't translate" do
162
- assert_equal true, @trans.call( true, :yml )
163
- end
164
- end
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
184
- end
185
- end
186
- end
187
-
@@ -1,90 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class FlexturesHookTest < Test::Unit::TestCase
4
- context Flextures::Loader do
5
- context ".parse_flextures_options" do
6
- context "set one table" do
7
- setup do
8
- @list = Flextures::Loader.parse_flextures_options(:users)
9
- end
10
- should "return table is Array" do
11
- assert_equal true, @list.is_a?(Array)
12
- end
13
- should "return table is only one" do
14
- assert_equal 1, @list.size
15
- end
16
- should "return data is content Hash data" do
17
- assert_equal true, @list.first.is_a?(Hash)
18
- end
19
- should "return data is contain loading table infomation" do
20
- h = { table: :users, file: "users", loader: :fun }
21
- assert_equal h, @list.first
22
- end
23
- end
24
- context "if set file name option" do
25
- setup do
26
- @list = Flextures::Loader.parse_flextures_options( :users => :users_another3 )
27
- end
28
- should "returned data size is only one" do
29
- assert_equal 1, @list.size
30
- end
31
- should " 'file' option is changed setted file name" do
32
- assert_equal :users_another3, @list.first[:file]
33
- end
34
- should "returned data include data" do
35
- h = { table: :users, file: :users_another3, loader: :fun }
36
- assert_equal h, @list.first
37
- end
38
- end
39
- context "if set 'cache' option" do
40
- setup do
41
- @list = Flextures::Loader.parse_flextures_options( { cache: true }, :users )
42
- end
43
- should "setted cache option" do
44
- assert_equal true, @list.first[:cache]
45
- end
46
- end
47
- context " if set 'dir' option " do
48
- setup do
49
- @list = Flextures::Loader.parse_flextures_options( { dir: "a/b/c" }, :users )
50
- end
51
- should "setted cache option" do
52
- assert_equal "a/b/c", @list.first[:dir]
53
- end
54
- end
55
- context " if set 'controller' option " do
56
- setup do
57
- @list = Flextures::Loader.parse_flextures_options( { controller: "top" }, :users )
58
- end
59
- should "setted cache option" do
60
- assert_equal "controllers/top", @list.first[:dir]
61
- end
62
- end
63
- context " if set 'controller' and 'action' option " do
64
- setup do
65
- @list = Flextures::Loader.parse_flextures_options( { controller: "top", action:"index" }, :users )
66
- end
67
- should "setted cache option" do
68
- assert_equal "controllers/top/index", @list.first[:dir]
69
- end
70
- end
71
- context " if set 'model' option " do
72
- setup do
73
- @list = Flextures::Loader.parse_flextures_options( { model: "users" }, :users )
74
- end
75
- should "setted cache option" do
76
- assert_equal "models/users", @list.first[:dir]
77
- end
78
- end
79
- context " if set 'model' and 'method' option " do
80
- setup do
81
- @list = Flextures::Loader.parse_flextures_options( { model: "users", method:"login" }, :users )
82
- end
83
- should "setted cache option" do
84
- assert_equal "models/users/login", @list.first[:dir]
85
- end
86
- end
87
- end
88
- end
89
- end
90
-