fixture_dependencies 1.8.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +119 -0
- data/MIT-LICENSE +1 -1
- data/README.md +89 -42
- data/lib/fixture_dependencies/active_record.rb +1 -1
- data/lib/fixture_dependencies/helper_methods.rb +18 -0
- data/lib/fixture_dependencies/minitest_spec/sequel.rb +1 -1
- data/lib/fixture_dependencies/minitest_spec.rb +2 -14
- data/lib/fixture_dependencies/rspec/sequel.rb +3 -13
- data/lib/fixture_dependencies/test_unit/rails.rb +1 -1
- data/lib/fixture_dependencies/test_unit/sequel.rb +1 -1
- data/lib/fixture_dependencies/test_unit.rb +2 -21
- data/lib/fixture_dependencies.rb +10 -17
- data/lib/fixture_dependencies_test_help.rb +1 -1
- metadata +25 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 844710257301d985c8f60539a30ff1bd9b1819d779da5891ed13ad5753b7966d
|
4
|
+
data.tar.gz: aba7f742f37df3939a391d43bf9ecc462058ba3d54af0ab25e3624d4b14b84e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 381d8c7eac5902496a24f294d2b2e0d7367c8502adc98f0697d34aed92be4e22231bdd9ec332dcb393628dac092b579b21f55a8b2191f64364972091f5320763
|
7
|
+
data.tar.gz: d6b7b5d3bac8327c21caeeb68c1559127f351988b5f88e3f15eaf993586e2eb8e8163fbf15c786eed29d6e5eef8999df0eda467588ecd92fd7745598ed4e0419
|
data/CHANGELOG
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# 1.11.0 (2022-06-30)
|
2
|
+
|
3
|
+
* Drop Ruby 1.8 support (jeremyevans)
|
4
|
+
|
5
|
+
* Do not skip fixtures where attributes are an array instead of a hash (jeremyevans)
|
6
|
+
|
7
|
+
* Drop support for table inheritance when using Sequel <4.24 (jeremyevans)
|
8
|
+
|
9
|
+
* Raise ActiveRecord::RecordInvalid when unable to save an ActiveRecord object (AlecksJohannes) (#33)
|
10
|
+
|
11
|
+
* Handle polymorphic associations in newer versions of ActiveRecord (AlecksJohannes) (#32)
|
12
|
+
|
13
|
+
* Handle recursive relationships correctly when using the class_map feature (rintaun) (#28)
|
14
|
+
|
15
|
+
# 1.10.0 (2018-05-18)
|
16
|
+
|
17
|
+
* Add fixture_dependencies/helper_methods for FixtureDependencies::HelperMethods for the load/load_attributes/build methods (adam12) (#25)
|
18
|
+
|
19
|
+
# 1.9.0 (2017-04-17)
|
20
|
+
|
21
|
+
* Support a custom fixture filename per model via fixture_filename model method (roupen) (#24)
|
22
|
+
|
23
|
+
* Fix polymorphic dependency load for multiple polymorphic fixtures (manuwell) (#18)
|
24
|
+
|
25
|
+
# 1.8.0 (2016-04-25)
|
26
|
+
|
27
|
+
* Support fixture_dependencies/minitest_spec and fixture_dependencies/minitest_spec/sequel helper integration (halostatue, badosu) (#17, #16)
|
28
|
+
|
29
|
+
# 1.7.0 (2016-02-26)
|
30
|
+
|
31
|
+
* Add load_attributes and build methods for instantating objects without persisting them (badosu) (#15)
|
32
|
+
|
33
|
+
# 1.6.0 (2015-08-31)
|
34
|
+
|
35
|
+
* Suport polymorphic associations (rpanachi) (#12)
|
36
|
+
|
37
|
+
# 1.5.0 (2015-07-28)
|
38
|
+
|
39
|
+
* Support Sequel <4.24.0 class table inheritance (brianphillips) (#11)
|
40
|
+
|
41
|
+
# 1.4.0 (2014-09-03)
|
42
|
+
|
43
|
+
* Add support for class_map for custom class mapping (mpalmer, jeremyevans) (#8)
|
44
|
+
|
45
|
+
# 1.3.3 (2014-05-27)
|
46
|
+
|
47
|
+
* Add support for RSpec 2+ to the rspec/sequel integration (jeremyevans)
|
48
|
+
|
49
|
+
* Remove Merb/Webrat integration (jeremyevans)
|
50
|
+
|
51
|
+
# 1.3.2 (2013-08-21)
|
52
|
+
|
53
|
+
* Support for Sequel single table inheritance model_map functionality (brianphillips) (#6)
|
54
|
+
|
55
|
+
# 1.3.1 (2012-06-04)
|
56
|
+
|
57
|
+
* Fix issues on Ruby 1.9 due to lack of String#each (jeremyevans)
|
58
|
+
|
59
|
+
* Require yaml instead of depending on it already being required (jeremyevans)
|
60
|
+
|
61
|
+
# 1.3.0 (2011-04-13)
|
62
|
+
|
63
|
+
* Add composite key support when using Sequel (gditrick, jeremyevans) (#4)
|
64
|
+
|
65
|
+
* Raise errors when unable to save (jeremyevans)
|
66
|
+
|
67
|
+
# 1.2.6 (2011-01-03)
|
68
|
+
|
69
|
+
* Add support for Sequel single_table_inheritance plugin (derdewey) (#3)
|
70
|
+
|
71
|
+
* Add Merb/Webrat integration (derdewey) (#3)
|
72
|
+
|
73
|
+
# 1.2.5 (2010-10-18)
|
74
|
+
|
75
|
+
* Work with Sequel 3.10+ one_to_one associations (jeremyevans)
|
76
|
+
|
77
|
+
# 1.2.4 (2010-10-15)
|
78
|
+
|
79
|
+
* Support preprocessing fixtures with ERB (patcoll) (#1)
|
80
|
+
|
81
|
+
# 1.2.3 (2010-06-29)
|
82
|
+
|
83
|
+
* Fix bogus spec suite failures when using the RSpec/Sequel helper (jeremyevans)
|
84
|
+
|
85
|
+
# 1.2.2 (2009-10-12)
|
86
|
+
|
87
|
+
* Fix false positive when detecting association cycles (jeremyevans)
|
88
|
+
|
89
|
+
# 1.2.1 (2009-05-07)
|
90
|
+
|
91
|
+
* Work with Sequel 3.0.0 (jeremyevans)
|
92
|
+
|
93
|
+
# 1.2.0 (2009-02-09)
|
94
|
+
|
95
|
+
* Support hashes for loading specific fixtures, without double underscore notation (jeremyevans)
|
96
|
+
|
97
|
+
* Add RSpec/Sequel helper (jeremyevans)
|
98
|
+
|
99
|
+
# 1.1.2 (2008-11-17)
|
100
|
+
|
101
|
+
* Better handle fixtures without primary keys by setting saved value in fixture (Matthew Willson)
|
102
|
+
|
103
|
+
# 1.1.1 (2008-10-14)
|
104
|
+
|
105
|
+
* Fix bug when adding associated objects using Sequel (jeremyevans)
|
106
|
+
|
107
|
+
# 1.1.0 (2008-08-25)
|
108
|
+
|
109
|
+
* Allow use of Sequel in addition to ActiveRecord (jeremyevans)
|
110
|
+
|
111
|
+
* Allow customizing fixture path (jeremyevans)
|
112
|
+
|
113
|
+
* Fix singularizing already singular names when dealing with individual fixtures (jeremyevans)
|
114
|
+
|
115
|
+
* Make most FixtureDependencies class methods private (jeremyevans)
|
116
|
+
|
117
|
+
# 1.0.0 (2007-12-06)
|
118
|
+
|
119
|
+
* Initial Release (jeremyevans)
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# fixture_dependencies
|
2
2
|
|
3
|
-
fixture_dependencies is
|
4
|
-
|
3
|
+
fixture_dependencies is a fixture loader, allowing the loading of models
|
4
|
+
from YAML fixtures, along with their entire dependency graph. It has
|
5
5
|
the following features:
|
6
6
|
|
7
7
|
- Fixtures specify association names instead of foreign keys
|
8
|
-
-
|
8
|
+
- Supports both Sequel and ActiveRecord
|
9
9
|
- Supports many_to_one/belongs_to, one_to_many/has_many,
|
10
10
|
many_to_many/has_and_belongs_to_many, and has_one/one_to_one associations
|
11
11
|
- Loads a fixture's dependency graph in such a manner that foreign key
|
12
12
|
constraints aren't violated
|
13
|
-
- Has a
|
13
|
+
- Has a simple API (`FixtureDependencies.load(:model__fixture)`)
|
14
14
|
- Handles almost all cyclic dependencies
|
15
15
|
- Includes Rails and Sequel test helpers for Test::Unit (and a Sequel test
|
16
16
|
helper for RSpec) that load fixtures for every test inside a transaction,
|
@@ -18,29 +18,21 @@ the following features:
|
|
18
18
|
|
19
19
|
## Installation
|
20
20
|
|
21
|
-
|
22
|
-
gem install fixture_dependencies
|
23
|
-
```
|
21
|
+
`gem install fixture_dependencies`
|
24
22
|
|
25
23
|
## Source
|
26
24
|
|
27
25
|
Source is available via github:
|
26
|
+
http://github.com/jeremyevans/fixture_dependencies
|
28
27
|
|
29
28
|
```
|
30
|
-
http://github.com/jeremyevans/fixture_dependencies
|
31
|
-
```
|
32
|
-
|
33
|
-
You can check it out with git:
|
34
|
-
|
35
|
-
```
|
36
|
-
git clone git://github.com/jeremyevans/fixture_dependencies.git
|
37
29
|
```
|
38
30
|
|
39
31
|
## Usage
|
40
32
|
|
41
33
|
### With Rails/ActiveRecord/Test::Unit:
|
42
34
|
|
43
|
-
Add the following to test/test_helper.rb after "require 'test_help'":
|
35
|
+
Add the following to `test/test_helper.rb` after "require 'test_help'":
|
44
36
|
|
45
37
|
```
|
46
38
|
require 'fixture_dependencies/test_unit/rails'
|
@@ -85,6 +77,32 @@ Somewhere before the test code is loaded:
|
|
85
77
|
|
86
78
|
This runs each spec inside a separate Sequel transaction.
|
87
79
|
|
80
|
+
### With Rails and Minitest:
|
81
|
+
|
82
|
+
You can add the following in your `test_helper.rb` file.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
ENV['RAILS_ENV'] ||= 'test'
|
86
|
+
require_relative '../config/environment'
|
87
|
+
require 'rails/test_help'
|
88
|
+
|
89
|
+
require 'fixture_dependencies/helper_methods'
|
90
|
+
|
91
|
+
class ActiveSupport::TestCase # we are monkey-patching.
|
92
|
+
# Run tests in parallel with specified workers
|
93
|
+
parallelize(workers: :number_of_processors)
|
94
|
+
|
95
|
+
# Add more helper methods to be used by all tests here...
|
96
|
+
include FixtureDependencies::HelperMethods
|
97
|
+
|
98
|
+
FixtureDependencies.fixture_path = './test/fixtures' # set the path of your fixtures
|
99
|
+
|
100
|
+
def run(*args, &block)
|
101
|
+
Sequel::Model.db.transaction(:rollback=>:always){super}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
88
106
|
### With other testing libraries:
|
89
107
|
|
90
108
|
You can just use FixtureDependencies.load to handle the loading of fixtures.
|
@@ -96,6 +114,16 @@ FixtureDependencies:
|
|
96
114
|
FixtureDependencies.fixture_path = '/path/to/fixtures'
|
97
115
|
```
|
98
116
|
|
117
|
+
A few helper methods are also available, just include them in your test superclass:
|
118
|
+
|
119
|
+
```
|
120
|
+
require 'fixture_dependencies/helper_methods'
|
121
|
+
|
122
|
+
class Test < Minitest::Test
|
123
|
+
include FixtureDependencies::HelperMethods
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
99
127
|
## Changes to Rails default fixtures:
|
100
128
|
|
101
129
|
fixture_dependencies is designed to require the least possible changes to
|
@@ -105,11 +133,11 @@ For example, see the following changes:
|
|
105
133
|
```
|
106
134
|
OLD NEW
|
107
135
|
asset1: asset1:
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
136
|
+
id: 1 id: 1
|
137
|
+
employee_id: 2 employee: jeremy
|
138
|
+
product_id: 3 product: nx7010
|
139
|
+
vendor_id: 2 vendor: lxg_computers
|
140
|
+
note: in working order note: in working order
|
113
141
|
```
|
114
142
|
|
115
143
|
As you can see, you just replace the foreign key attribute and value with the
|
@@ -117,8 +145,8 @@ name of the association and the associations name. This assumes you have an
|
|
117
145
|
employee fixture with a name of jeremy, and products fixture with the name of
|
118
146
|
nx7010, and a vendors fixture with the name lxg_computers.
|
119
147
|
|
120
|
-
Fixture files still use the table_name of the model. Note that you
|
121
|
-
|
148
|
+
Fixture files still use the table_name of the model. Note that you should
|
149
|
+
hard code primary key values for each fixture, as shown in the example
|
122
150
|
above.
|
123
151
|
|
124
152
|
## ERB Fixtures
|
@@ -126,8 +154,8 @@ above.
|
|
126
154
|
Fixtures can also use ERB to preprocess the fixture file, useful if you need
|
127
155
|
to do any programming inside the fixture file, such as looping to create
|
128
156
|
multiple records. For the ERB support to be invoked, your fixture file
|
129
|
-
should be named
|
130
|
-
mix ERB fixture files and regular fixture files, but you
|
157
|
+
should be named `#{table_name}.yml.erb` instead of `#{table_name}.yml`. You can
|
158
|
+
mix ERB fixture files and regular fixture files, but you cannot have an
|
131
159
|
ERB fixture file and a regular fixture file for the same table (the regular
|
132
160
|
fixture file will be used in that case).
|
133
161
|
|
@@ -146,7 +174,7 @@ fixture_dependencies changes this to underscored model names. If you are using
|
|
146
174
|
Rails' recommended table practices, this shouldn't make a difference.
|
147
175
|
|
148
176
|
It is recommended that you do not use the fixtures method, and instead load
|
149
|
-
individual fixtures as needed (see below). This makes your tests
|
177
|
+
individual fixtures as needed (see below). This makes your tests more
|
150
178
|
robust, in case you want to add or remove individual fixtures at a later date.
|
151
179
|
|
152
180
|
## Loading individual fixtures with fixtures class method
|
@@ -160,16 +188,15 @@ using the following syntax:
|
|
160
188
|
end
|
161
189
|
```
|
162
190
|
|
163
|
-
This would load just the jeremy fixture and its dependencies.
|
164
|
-
|
191
|
+
This would load just the jeremy fixture and its dependencies. This is
|
192
|
+
better than loading all fixtures for the model. Even better
|
165
193
|
is loading just the fixtures you want inside every test method (see below).
|
166
|
-
This leads to the most robust testing.
|
167
194
|
|
168
195
|
## Loading fixtures inside test methods
|
169
196
|
|
170
|
-
|
171
|
-
|
172
|
-
|
197
|
+
It is better to skip the use of the fixtures method entirely, and load
|
198
|
+
specific fixtures manually in each test method. This reduces coupling
|
199
|
+
and makes tests less brittle. Here's an example:
|
173
200
|
|
174
201
|
```
|
175
202
|
class EmployeeTest < Test::Unit::TestCase
|
@@ -197,6 +224,9 @@ the loosest coupling possible. Here's an example:
|
|
197
224
|
Don't worry about loading the same fixture twice, if a fixture is already
|
198
225
|
loaded, it won't attempt to load it again.
|
199
226
|
|
227
|
+
One downside of this approach is it can be slower that loading all
|
228
|
+
fixtures before the test suite.
|
229
|
+
|
200
230
|
## Loading attributes only
|
201
231
|
|
202
232
|
You can load only the attributes of fixtures, without saving them with
|
@@ -230,7 +260,7 @@ Here's an example of using has_one (logon_information), has_many (assets), and
|
|
230
260
|
has_and_belongs_to_many (groups) associations.
|
231
261
|
|
232
262
|
```
|
233
|
-
|
263
|
+
jeremy:
|
234
264
|
id: 2
|
235
265
|
name: Jeremy Evans
|
236
266
|
logon_information: jeremy
|
@@ -344,8 +374,7 @@ possible.
|
|
344
374
|
## Known issues
|
345
375
|
|
346
376
|
Currently, the plugin only supports YAML fixtures, but other types of fixtures
|
347
|
-
would be fairly easy to add
|
348
|
-
fixture type).
|
377
|
+
would be fairly easy to add.
|
349
378
|
|
350
379
|
The plugin is significantly slower than the default testing method, because it
|
351
380
|
loads all fixtures inside of a transaction (one per test method), where Rails
|
@@ -359,23 +388,37 @@ use load(:model__fixture_name).
|
|
359
388
|
## Namespace Issues
|
360
389
|
|
361
390
|
By default, fixture dependencies is going to load the model with the camelized
|
362
|
-
name in the symbol used. So for
|
363
|
-
the fixture with name baz for the model FooBar
|
364
|
-
such as Foo::Bar
|
391
|
+
name in the symbol used. So for `:foo_bar__baz`, it's going to look for
|
392
|
+
the fixture with name `baz` for the model `FooBar`. If your model is namespaced,
|
393
|
+
such as `Foo::Bar`, this isn't going to work well. In that case, you can
|
365
394
|
override the default mapping:
|
366
395
|
|
367
396
|
```
|
368
397
|
FixtureDependencies.class_map[:bar] = Foo::Bar
|
369
398
|
```
|
370
399
|
|
371
|
-
and then use
|
372
|
-
Foo::Bar
|
400
|
+
and then use `:bar__baz` to load the fixture with name `baz` for the model
|
401
|
+
`Foo::Bar`.
|
402
|
+
|
403
|
+
## Custom Fixture Filenames
|
404
|
+
|
405
|
+
Fixture dependencies will look for a file that corresponds to the table name
|
406
|
+
for the model by default. You can override this by defining a fixtures_filename
|
407
|
+
class method in the model:
|
408
|
+
|
409
|
+
```
|
410
|
+
class Artist < Sequel::Model
|
411
|
+
def self.fixture_filename
|
412
|
+
:artists_custom_fixture_file
|
413
|
+
end
|
414
|
+
end
|
415
|
+
```
|
373
416
|
|
374
417
|
## Troubleshooting
|
375
418
|
|
376
419
|
If you run into problems with loading your fixtures, it can be difficult to see
|
377
|
-
where the problems are. To aid in debugging an error, add the following
|
378
|
-
|
420
|
+
where the problems are. To aid in debugging an error, add the following code
|
421
|
+
after requiring the library:
|
379
422
|
|
380
423
|
```
|
381
424
|
FixtureDependencies.verbose = 3
|
@@ -386,7 +429,7 @@ every test, including the recursive loading of the dependency graph.
|
|
386
429
|
|
387
430
|
## Specs
|
388
431
|
|
389
|
-
The specs for fixture dependencies
|
432
|
+
The specs for fixture dependencies are run with Rake. They require
|
390
433
|
the sequel, activerecord, and sqlite3 gems installed. The default rake task
|
391
434
|
runs the specs. You should run the spec_migrate task first to create the
|
392
435
|
spec database.
|
@@ -400,6 +443,10 @@ fixture_references is a similar plugin. It uses erb inside yaml, and uses the
|
|
400
443
|
foreign key numbers inside of the association names, which leads me to believe
|
401
444
|
it doesn't support has_* associations.
|
402
445
|
|
446
|
+
## Sample Rails App with Fixtures Working
|
447
|
+
|
448
|
+
Check out [this app which features Fixtures and Minitest and steps to enable you to replicate it](https://github.com/BKSpurgeon/testing_in_sequel).
|
449
|
+
|
403
450
|
## License
|
404
451
|
|
405
452
|
fixture_dependencies is released under the MIT License. See the MIT-LICENSE
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../fixture_dependencies'
|
2
|
+
|
3
|
+
class FixtureDependencies
|
4
|
+
module HelperMethods
|
5
|
+
# Load given fixtures using FixtureDependencies
|
6
|
+
def load(*fixture)
|
7
|
+
FixtureDependencies.load(*fixture)
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_attributes(*args)
|
11
|
+
FixtureDependencies.load_attributes(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def build(*args)
|
15
|
+
FixtureDependencies.build(*args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,15 +1,3 @@
|
|
1
|
-
|
1
|
+
require_relative 'helper_methods'
|
2
2
|
|
3
|
-
|
4
|
-
def load(*args)
|
5
|
-
FixtureDependencies.load(*args)
|
6
|
-
end
|
7
|
-
|
8
|
-
def load_attributes(*args)
|
9
|
-
FixtureDependencies.load_attributes(*args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def build(*args)
|
13
|
-
FixtureDependencies.build(*args)
|
14
|
-
end
|
15
|
-
end
|
3
|
+
Minitest::Spec.send(:include, FixtureDependencies::HelperMethods)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative '../helper_methods'
|
2
|
+
|
1
3
|
if defined?(RSpec)
|
2
4
|
example_group = RSpec::Core::ExampleGroup
|
3
5
|
require 'rspec/version'
|
@@ -26,16 +28,4 @@ else
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
example_group.
|
30
|
-
def load(*args)
|
31
|
-
FixtureDependencies.load(*args)
|
32
|
-
end
|
33
|
-
|
34
|
-
def load_attributes(*args)
|
35
|
-
FixtureDependencies.load_attributes(*args)
|
36
|
-
end
|
37
|
-
|
38
|
-
def build(*args)
|
39
|
-
FixtureDependencies.build(*args)
|
40
|
-
end
|
41
|
-
end
|
31
|
+
example_group.send(:include, FixtureDependencies::HelperMethods)
|
@@ -1,22 +1,3 @@
|
|
1
|
-
|
1
|
+
require_relative 'helper_methods'
|
2
2
|
|
3
|
-
|
4
|
-
module Unit
|
5
|
-
class TestCase
|
6
|
-
private
|
7
|
-
|
8
|
-
# Load given fixtures using FixtureDependencies
|
9
|
-
def load(*fixture)
|
10
|
-
FixtureDependencies.load(*fixture)
|
11
|
-
end
|
12
|
-
|
13
|
-
def load_attributes(*args)
|
14
|
-
FixtureDependencies.load_attributes(*args)
|
15
|
-
end
|
16
|
-
|
17
|
-
def build(*args)
|
18
|
-
FixtureDependencies.build(*args)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
3
|
+
Test::Unit::TestCase.send(:include, FixtureDependencies::HelperMethods)
|
data/lib/fixture_dependencies.rb
CHANGED
@@ -62,6 +62,9 @@ class FixtureDependencies
|
|
62
62
|
end
|
63
63
|
end.flatten.compact.map do |record|
|
64
64
|
model_name, name = split_name(record)
|
65
|
+
unless class_map[model_name.to_sym].nil?
|
66
|
+
record = "#{class_map[model_name.to_sym].to_s.underscore}__#{name}"
|
67
|
+
end
|
65
68
|
if name
|
66
69
|
use(record.to_sym, opts)
|
67
70
|
else
|
@@ -77,9 +80,8 @@ class FixtureDependencies
|
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
+
require_relative 'fixture_dependencies/active_record' if defined?(ActiveRecord::Base)
|
84
|
+
require_relative 'fixture_dependencies/sequel' if defined?(Sequel::Model)
|
83
85
|
|
84
86
|
class << FixtureDependencies
|
85
87
|
attr_reader :fixtures, :loaded
|
@@ -106,7 +108,8 @@ class << FixtureDependencies
|
|
106
108
|
def load_yaml(model_name)
|
107
109
|
raise(ArgumentError, "No fixture_path set. Use FixtureDependencies.fixture_path = ...") unless fixture_path
|
108
110
|
|
109
|
-
|
111
|
+
klass = model_class(model_name)
|
112
|
+
filename = klass.send(klass.respond_to?(:fixture_filename) ? :fixture_filename : :table_name)
|
110
113
|
yaml_path = File.join(fixture_path, "#{filename}.yml")
|
111
114
|
|
112
115
|
if File.exist?(yaml_path)
|
@@ -187,32 +190,22 @@ class << FixtureDependencies
|
|
187
190
|
obj = model.sti_load(model.sti_key => attributes[model.sti_key])
|
188
191
|
obj.send(:initialize)
|
189
192
|
model = obj.model
|
190
|
-
elsif model.respond_to?(:sti_key)
|
191
|
-
obj = attributes[model.sti_key].to_s.camelize.constantize.new
|
192
|
-
elsif model.respond_to?(:cti_key) # support for Sequel's pre-4.24.0 hybrid CTI support
|
193
|
-
mv = attributes[model.cti_key]
|
194
|
-
if (mm = model.cti_model_map)
|
195
|
-
model = mm[mv].to_s.constantize
|
196
|
-
elsif !mv.nil?
|
197
|
-
model = mv.constantize
|
198
|
-
end
|
199
|
-
obj = model.new
|
200
193
|
else
|
201
194
|
obj = model.new
|
202
195
|
end
|
203
196
|
puts "#{spaces}#{model} STI plugin detected, initializing instance of #{obj}" if (verbose > 1 && model.respond_to?(:sti_dataset))
|
204
197
|
many_associations = []
|
205
198
|
attributes.each do |attr, value|
|
206
|
-
next if attr.is_a?(Array)
|
207
199
|
if reflection = model_method(:reflection, mtype, model, attr.to_sym)
|
208
200
|
if [:belongs_to, :many_to_one].include?(model_method(:reflection_type, mtype, reflection))
|
209
201
|
|
210
202
|
if polymorphic_association?(value)
|
211
203
|
value, polymorphic_class = polymorphic_association(value)
|
212
|
-
|
204
|
+
dep_name = "#{polymorphic_class.to_s.underscore}__#{value}".to_sym
|
205
|
+
else
|
206
|
+
dep_name = "#{model_method(:reflection_class, mtype, reflection).name.underscore}__#{value}".to_sym
|
213
207
|
end
|
214
208
|
|
215
|
-
dep_name = "#{model_method(:reflection_class, mtype, reflection).name.underscore}__#{value}".to_sym
|
216
209
|
if dep_name == record
|
217
210
|
# Self referential record, use primary key
|
218
211
|
puts "#{spaces}#{record}.#{attr}: belongs_to self-referential" if verbose > 1
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
require_relative 'fixture_dependencies/test_unit/rails'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixture_dependencies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2022-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest-global_expectations
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description:
|
14
28
|
email: code@jeremyevans.net
|
15
29
|
executables: []
|
@@ -17,10 +31,12 @@ extensions: []
|
|
17
31
|
extra_rdoc_files:
|
18
32
|
- MIT-LICENSE
|
19
33
|
files:
|
34
|
+
- CHANGELOG
|
20
35
|
- MIT-LICENSE
|
21
36
|
- README.md
|
22
37
|
- lib/fixture_dependencies.rb
|
23
38
|
- lib/fixture_dependencies/active_record.rb
|
39
|
+
- lib/fixture_dependencies/helper_methods.rb
|
24
40
|
- lib/fixture_dependencies/minitest_spec.rb
|
25
41
|
- lib/fixture_dependencies/minitest_spec/sequel.rb
|
26
42
|
- lib/fixture_dependencies/rspec/sequel.rb
|
@@ -32,7 +48,10 @@ files:
|
|
32
48
|
homepage: https://github.com/jeremyevans/fixture_dependencies
|
33
49
|
licenses:
|
34
50
|
- MIT
|
35
|
-
metadata:
|
51
|
+
metadata:
|
52
|
+
bug_tracker_uri: https://github.com/jeremyevans/fixture_dependencies/issues
|
53
|
+
mailing_list_uri: https://github.com/jeremyevans/fixture_dependencies/discussions
|
54
|
+
source_code_uri: https://github.com/jeremyevans/fixture_dependencies
|
36
55
|
post_install_message:
|
37
56
|
rdoc_options:
|
38
57
|
- "--inline-source"
|
@@ -45,15 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
64
|
requirements:
|
46
65
|
- - ">="
|
47
66
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
67
|
+
version: 1.9.2
|
49
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
69
|
requirements:
|
51
70
|
- - ">="
|
52
71
|
- !ruby/object:Gem::Version
|
53
72
|
version: '0'
|
54
73
|
requirements: []
|
55
|
-
|
56
|
-
rubygems_version: 2.5.1
|
74
|
+
rubygems_version: 3.3.7
|
57
75
|
signing_key:
|
58
76
|
specification_version: 4
|
59
77
|
summary: Sequel/ActiveRecord fixture loader that handles dependency graphs
|