flextures 4.2.6 → 4.2.7
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.
- checksums.yaml +5 -5
- data/.document +5 -5
- data/.gitignore +50 -48
- data/CHANGELOG +2 -2
- data/Gemfile +15 -15
- data/Gemfile.lock +59 -58
- data/LICENSE.txt +20 -20
- data/README.ja.md +215 -215
- data/README.md +205 -205
- data/Rakefile +6 -6
- data/flextures.gemspec +25 -25
- data/lib/flextures/active_record_test_fixtures.rb +138 -138
- data/lib/flextures/flextures.rake +20 -20
- data/lib/flextures/flextures_loader.rb +31 -8
- data/lib/flextures/version.rb +3 -3
- data/lib/generators/flextures/initializer_generator.rb +17 -17
- data/lib/generators/flextures/templates/flextures.factory.rb +8 -8
- data/lib/generators/flextures/templates/flextures.rb +6 -6
- data/test/models/flextures_test.rb +8 -8
- data/test/test_helper.rb +13 -13
- data/test/unit/flextures_args_test.rb +127 -127
- data/test/unit/flextures_dumper_test.rb +232 -232
- data/test/unit/flextures_hooks_test.rb +111 -111
- data/test/unit/flextures_loader_test.rb +313 -313
- metadata +3 -3
data/README.md
CHANGED
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
# flextures
|
|
2
|
-
|
|
3
|
-
* [日本語版ドキュメント(Japanese Document)](https://github.com/baban/flextures/blob/master/README.ja.md)
|
|
4
|
-
|
|
5
|
-

|
|
8
|
-
|
|
9
|
-
## Description
|
|
10
|
-
|
|
11
|
-
This plug-in aim to resolve many problems, durling rails developping about fixtures.
|
|
12
|
-
Basic commands is simple.
|
|
13
|
-
Each commands load or dump fixtures.
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
rake db:flextures:load
|
|
17
|
-
rake db:flextures:dump
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Major different point is four.
|
|
21
|
-
|
|
22
|
-
1. Fixture file prefered CSV to YAML.
|
|
23
|
-
2. Even if, not match column's structure, loading don't stop and auto padding data.
|
|
24
|
-
3. Fixture file name can change, if file name is not equal table name.
|
|
25
|
-
4. Fixture data can translate to use filter, like factory girl.
|
|
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.
|
|
43
|
-
|
|
44
|
-
<a name="usage"></a>
|
|
45
|
-
## Usage
|
|
46
|
-
|
|
47
|
-
<a name="how_to_install"></a>
|
|
48
|
-
## How to install
|
|
49
|
-
|
|
50
|
-
This program is implemented Rails Plug-in.
|
|
51
|
-
If You want to install this plug-in.
|
|
52
|
-
Please use bundler.
|
|
53
|
-
|
|
54
|
-
In `Gemfile`
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
gem "flextures"
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
And execute below commands.
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
bundle install
|
|
64
|
-
bundle exec rails generate flextures:initializer
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
(Development emnvoriment must be ruby2.1 higer and rails3 higher)
|
|
68
|
-
|
|
69
|
-
<a name="commandline_support"></a>
|
|
70
|
-
### rake command
|
|
71
|
-
|
|
72
|
-
load command input fixtures file under "spec/fixtures/".
|
|
73
|
-
(Loading directory can change configuration file)
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
rake db:flextures:load
|
|
77
|
-
rake db:flextures:dump
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
rake command can set options.
|
|
81
|
-
For example, this option set dump file name.
|
|
82
|
-
(Option dump only "users.csv")
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
rake db:flextures:dump TABLE=users
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Other options...
|
|
89
|
-
|
|
90
|
-
| option | description |
|
|
91
|
-
---------|--------------------------------------
|
|
92
|
-
| TABLE | set table name |
|
|
93
|
-
| MODEL | set model name |
|
|
94
|
-
| DIR | set directory name |
|
|
95
|
-
| FILE | set fixture file name |
|
|
96
|
-
| FORMAT | change dump file format(csv or yml) |
|
|
97
|
-
| OPTION | other options |
|
|
98
|
-
| T | alias TABLE option |
|
|
99
|
-
| D | alias DIR option |
|
|
100
|
-
| F | alias FIXTURES option |
|
|
101
|
-
|
|
102
|
-
if you change table colum information
|
|
103
|
-
next comannd regenerate (load fixture and dump) fixtures
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
rake db:flextures:generate T=users
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Other information please see [wiki](https://github.com/baban/flextures/wiki/Rake-command-option) ...
|
|
110
|
-
|
|
111
|
-
<a name="unittest_support"></a>
|
|
112
|
-
### Unit test support
|
|
113
|
-
|
|
114
|
-
Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda).
|
|
115
|
-
|
|
116
|
-
```ruby
|
|
117
|
-
describe ItemShopController do
|
|
118
|
-
flextures :users, :items
|
|
119
|
-
end
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
flexture function can write like a "fixture" function, implemented in RSpec.
|
|
123
|
-
But, "flexture" function ignore columns change.
|
|
124
|
-
|
|
125
|
-
Flextures function can change load file name.
|
|
126
|
-
|
|
127
|
-
```ruby
|
|
128
|
-
describe ItemShopController do
|
|
129
|
-
flextures :items, :users => :users_for_itemshop # load "users_for_itemshop.csv"
|
|
130
|
-
end
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Other option information
|
|
134
|
-
Please see [wiki](https://github.com/baban/flextures/wiki/Unittestsupport) ...
|
|
135
|
-
|
|
136
|
-
<a name="flextures_filter"></a>
|
|
137
|
-
### Flextures load & dump filter
|
|
138
|
-
|
|
139
|
-
#### load filter
|
|
140
|
-
|
|
141
|
-
In `config/flextures.factory.rb`
|
|
142
|
-
|
|
143
|
-
Factory filter translate fixture data and set database.
|
|
144
|
-
|
|
145
|
-
For example, this code set current time to last_login_date column.
|
|
146
|
-
|
|
147
|
-
```ruby
|
|
148
|
-
Flextures::Factory.define :users do |f|
|
|
149
|
-
f.last_login_date = DateTime.now
|
|
150
|
-
end
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
This sample, generate name and sex automatically, and other tables data generate
|
|
154
|
-
|
|
155
|
-
```ruby
|
|
156
|
-
require 'faker'
|
|
157
|
-
Flextures::Factory.define :users do |f|
|
|
158
|
-
f.name= Faker::Name.name if !f.name # gemerate name
|
|
159
|
-
f.sex= [0,1].shuffle.first if !f.sex # generate sex
|
|
160
|
-
# factory filter can generate data, use has_many association
|
|
161
|
-
f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
|
|
162
|
-
end
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### dump filter
|
|
166
|
-
|
|
167
|
-
if you need to convert table data into other data format, you use dump filter.
|
|
168
|
-
(dump filter is same file as load filter)
|
|
169
|
-
|
|
170
|
-
dump filter has hash arguments, it is formatted colum name key and convert method, proc, lambda value
|
|
171
|
-
|
|
172
|
-
file is `config/flextures.factory.rb`
|
|
173
|
-
|
|
174
|
-
```ruby
|
|
175
|
-
Flextures::DumpFilter.define :users, {
|
|
176
|
-
:encrypted_password => lambda { |v| Base64.encode64(v) }
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
Other options please see [wiki](https://github.com/baban/flextures/wiki/Factoryfilter) ...
|
|
181
|
-
|
|
182
|
-
<a name="configuration"></a>
|
|
183
|
-
### Configuration file
|
|
184
|
-
|
|
185
|
-
In `config/initializers/flextures.rb`, configuration file can change load and dump directory
|
|
186
|
-
|
|
187
|
-
```ruby
|
|
188
|
-
Flextures::Configuration.configure do |config|
|
|
189
|
-
# Load and dump directory change "spec/fixtures/" to "test/fixtures/"
|
|
190
|
-
config.load_directory = "test/fixtures/"
|
|
191
|
-
config.dump_directory = "test/fixtures/"
|
|
192
|
-
end
|
|
193
|
-
```
|
|
194
|
-
|
|
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).
|
|
1
|
+
# flextures
|
|
2
|
+
|
|
3
|
+
* [日本語版ドキュメント(Japanese Document)](https://github.com/baban/flextures/blob/master/README.ja.md)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
This plug-in aim to resolve many problems, durling rails developping about fixtures.
|
|
12
|
+
Basic commands is simple.
|
|
13
|
+
Each commands load or dump fixtures.
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
rake db:flextures:load
|
|
17
|
+
rake db:flextures:dump
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Major different point is four.
|
|
21
|
+
|
|
22
|
+
1. Fixture file prefered CSV to YAML.
|
|
23
|
+
2. Even if, not match column's structure, loading don't stop and auto padding data.
|
|
24
|
+
3. Fixture file name can change, if file name is not equal table name.
|
|
25
|
+
4. Fixture data can translate to use filter, like factory girl.
|
|
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.3 higher
|
|
43
|
+
|
|
44
|
+
<a name="usage"></a>
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
<a name="how_to_install"></a>
|
|
48
|
+
## How to install
|
|
49
|
+
|
|
50
|
+
This program is implemented Rails Plug-in.
|
|
51
|
+
If You want to install this plug-in.
|
|
52
|
+
Please use bundler.
|
|
53
|
+
|
|
54
|
+
In `Gemfile`
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
gem "flextures"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
And execute below commands.
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
bundle install
|
|
64
|
+
bundle exec rails generate flextures:initializer
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
(Development emnvoriment must be ruby2.1 higer and rails3 higher)
|
|
68
|
+
|
|
69
|
+
<a name="commandline_support"></a>
|
|
70
|
+
### rake command
|
|
71
|
+
|
|
72
|
+
load command input fixtures file under "spec/fixtures/".
|
|
73
|
+
(Loading directory can change configuration file)
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
rake db:flextures:load
|
|
77
|
+
rake db:flextures:dump
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
rake command can set options.
|
|
81
|
+
For example, this option set dump file name.
|
|
82
|
+
(Option dump only "users.csv")
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
rake db:flextures:dump TABLE=users
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Other options...
|
|
89
|
+
|
|
90
|
+
| option | description |
|
|
91
|
+
---------|--------------------------------------
|
|
92
|
+
| TABLE | set table name |
|
|
93
|
+
| MODEL | set model name |
|
|
94
|
+
| DIR | set directory name |
|
|
95
|
+
| FILE | set fixture file name |
|
|
96
|
+
| FORMAT | change dump file format(csv or yml) |
|
|
97
|
+
| OPTION | other options |
|
|
98
|
+
| T | alias TABLE option |
|
|
99
|
+
| D | alias DIR option |
|
|
100
|
+
| F | alias FIXTURES option |
|
|
101
|
+
|
|
102
|
+
if you change table colum information
|
|
103
|
+
next comannd regenerate (load fixture and dump) fixtures
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
rake db:flextures:generate T=users
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Other information please see [wiki](https://github.com/baban/flextures/wiki/Rake-command-option) ...
|
|
110
|
+
|
|
111
|
+
<a name="unittest_support"></a>
|
|
112
|
+
### Unit test support
|
|
113
|
+
|
|
114
|
+
Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda).
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
describe ItemShopController do
|
|
118
|
+
flextures :users, :items
|
|
119
|
+
end
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
flexture function can write like a "fixture" function, implemented in RSpec.
|
|
123
|
+
But, "flexture" function ignore columns change.
|
|
124
|
+
|
|
125
|
+
Flextures function can change load file name.
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
describe ItemShopController do
|
|
129
|
+
flextures :items, :users => :users_for_itemshop # load "users_for_itemshop.csv"
|
|
130
|
+
end
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Other option information
|
|
134
|
+
Please see [wiki](https://github.com/baban/flextures/wiki/Unittestsupport) ...
|
|
135
|
+
|
|
136
|
+
<a name="flextures_filter"></a>
|
|
137
|
+
### Flextures load & dump filter
|
|
138
|
+
|
|
139
|
+
#### load filter
|
|
140
|
+
|
|
141
|
+
In `config/flextures.factory.rb`
|
|
142
|
+
|
|
143
|
+
Factory filter translate fixture data and set database.
|
|
144
|
+
|
|
145
|
+
For example, this code set current time to last_login_date column.
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
Flextures::Factory.define :users do |f|
|
|
149
|
+
f.last_login_date = DateTime.now
|
|
150
|
+
end
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
This sample, generate name and sex automatically, and other tables data generate
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
require 'faker'
|
|
157
|
+
Flextures::Factory.define :users do |f|
|
|
158
|
+
f.name= Faker::Name.name if !f.name # gemerate name
|
|
159
|
+
f.sex= [0,1].shuffle.first if !f.sex # generate sex
|
|
160
|
+
# factory filter can generate data, use has_many association
|
|
161
|
+
f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
|
|
162
|
+
end
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### dump filter
|
|
166
|
+
|
|
167
|
+
if you need to convert table data into other data format, you use dump filter.
|
|
168
|
+
(dump filter is same file as load filter)
|
|
169
|
+
|
|
170
|
+
dump filter has hash arguments, it is formatted colum name key and convert method, proc, lambda value
|
|
171
|
+
|
|
172
|
+
file is `config/flextures.factory.rb`
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
Flextures::DumpFilter.define :users, {
|
|
176
|
+
:encrypted_password => lambda { |v| Base64.encode64(v) }
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Other options please see [wiki](https://github.com/baban/flextures/wiki/Factoryfilter) ...
|
|
181
|
+
|
|
182
|
+
<a name="configuration"></a>
|
|
183
|
+
### Configuration file
|
|
184
|
+
|
|
185
|
+
In `config/initializers/flextures.rb`, configuration file can change load and dump directory
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
Flextures::Configuration.configure do |config|
|
|
189
|
+
# Load and dump directory change "spec/fixtures/" to "test/fixtures/"
|
|
190
|
+
config.load_directory = "test/fixtures/"
|
|
191
|
+
config.dump_directory = "test/fixtures/"
|
|
192
|
+
end
|
|
193
|
+
```
|
|
194
|
+
|
|
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/Rakefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require "bundler/gem_tasks"
|
|
2
|
-
require 'rake/testtask'
|
|
3
|
-
|
|
4
|
-
Rake::TestTask.new do |t|
|
|
5
|
-
t.pattern = "test/**/*_test.rb"
|
|
6
|
-
end
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
|
|
4
|
+
Rake::TestTask.new do |t|
|
|
5
|
+
t.pattern = "test/**/*_test.rb"
|
|
6
|
+
end
|
data/flextures.gemspec
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require 'flextures/version'
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "flextures"
|
|
7
|
-
spec.version = Flextures::VERSION
|
|
8
|
-
spec.authors = ["baban"]
|
|
9
|
-
spec.email = ["babanba.n@gmail.com"]
|
|
10
|
-
spec.summary = %q{load and dump fixtures.}
|
|
11
|
-
spec.description = %q{load and dump fixtures.}
|
|
12
|
-
spec.homepage = "http://github.com/baban/flextures"
|
|
13
|
-
spec.license = "MIT"
|
|
14
|
-
|
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
|
16
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
17
|
-
spec.test_files = ["test/unit/flextures_args_test.rb"]
|
|
18
|
-
spec.require_paths = ["lib"]
|
|
19
|
-
|
|
20
|
-
spec.add_dependency "activerecord"
|
|
21
|
-
spec.add_dependency "activesupport"
|
|
22
|
-
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
|
24
|
-
spec.add_development_dependency "rake"
|
|
25
|
-
end
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require 'flextures/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "flextures"
|
|
7
|
+
spec.version = Flextures::VERSION
|
|
8
|
+
spec.authors = ["baban"]
|
|
9
|
+
spec.email = ["babanba.n@gmail.com"]
|
|
10
|
+
spec.summary = %q{load and dump fixtures.}
|
|
11
|
+
spec.description = %q{load and dump fixtures.}
|
|
12
|
+
spec.homepage = "http://github.com/baban/flextures"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
|
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
17
|
+
spec.test_files = ["test/unit/flextures_args_test.rb"]
|
|
18
|
+
spec.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
spec.add_dependency "activerecord"
|
|
21
|
+
spec.add_dependency "activesupport"
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
24
|
+
spec.add_development_dependency "rake"
|
|
25
|
+
end
|