fixture_dependencies 1.10.0 → 1.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37de648e362288f3498e67fb4fb86cb6879eac0ff71bfabe765503675be589af
4
- data.tar.gz: c30678df08b1afca513cacf4c41a6b34c8273de7e6003d3c7b5d13801a5d165c
3
+ metadata.gz: 524ee808c516b0960cb838c58ad2b7cea8f240b91bd80f6bda6072ccbb363d64
4
+ data.tar.gz: ab570a5ebb17bdbb3d933d81e52758b0164591336f6303b7eb571821c2312181
5
5
  SHA512:
6
- metadata.gz: 3b2bbc63521dee5eb5b704511bd99d509a499518e710c44ab9a39aa32babf121f0d3315d028cddb0f93883489f09d699dd989df77be58c564b2c6fdf066a40f8
7
- data.tar.gz: 82dfeb3a76c037fdbac0fcded19fc84fa98fa779c43fb9f4f56d5854630b91783086a4dcdb40f813c13de378b5acfadfb04c4663690c3eaef9feb0e207a247c8
6
+ metadata.gz: 93d0d22666a86d8f6a18082ae462a030e7aff7788c8ee066a5fbdbab084008f5ca01b80031f481a73211a0236601b6555fcc6c5bddde4c1271fc79026c624a6d
7
+ data.tar.gz: d01b825c6af877502f424e030c2751c3cf8418bed26034a08fc95ad5bd030a8a8e90b2cf97853dd7495bf084b98a3a3c5759acff5afd8e5317d48618eb13447a
data/CHANGELOG ADDED
@@ -0,0 +1,127 @@
1
+ # 1.12.0 (2026-05-25)
2
+
3
+ * Make fixture_dependencies/rspec/sequel work with recent versions of rspec (jeremyevans) (#40)
4
+
5
+ * Make FixtureDependencies.class_map handle model names that are not CamelCase (jeremyevans) (#39)
6
+
7
+ * Add FixtureDependencies.use_unsafe_load to use YAML.unsafe_load to load YAML files (jeremyevans, tomasmiguez) (#37, #38)
8
+
9
+ # 1.11.0 (2022-06-30)
10
+
11
+ * Drop Ruby 1.8 support (jeremyevans)
12
+
13
+ * Do not skip fixtures where attributes are an array instead of a hash (jeremyevans)
14
+
15
+ * Drop support for table inheritance when using Sequel <4.24 (jeremyevans)
16
+
17
+ * Raise ActiveRecord::RecordInvalid when unable to save an ActiveRecord object (AlecksJohannes) (#33)
18
+
19
+ * Handle polymorphic associations in newer versions of ActiveRecord (AlecksJohannes) (#32)
20
+
21
+ * Handle recursive relationships correctly when using the class_map feature (rintaun) (#28)
22
+
23
+ # 1.10.0 (2018-05-18)
24
+
25
+ * Add fixture_dependencies/helper_methods for FixtureDependencies::HelperMethods for the load/load_attributes/build methods (adam12) (#25)
26
+
27
+ # 1.9.0 (2017-04-17)
28
+
29
+ * Support a custom fixture filename per model via fixture_filename model method (roupen) (#24)
30
+
31
+ * Fix polymorphic dependency load for multiple polymorphic fixtures (manuwell) (#18)
32
+
33
+ # 1.8.0 (2016-04-25)
34
+
35
+ * Support fixture_dependencies/minitest_spec and fixture_dependencies/minitest_spec/sequel helper integration (halostatue, badosu) (#17, #16)
36
+
37
+ # 1.7.0 (2016-02-26)
38
+
39
+ * Add load_attributes and build methods for instantating objects without persisting them (badosu) (#15)
40
+
41
+ # 1.6.0 (2015-08-31)
42
+
43
+ * Suport polymorphic associations (rpanachi) (#12)
44
+
45
+ # 1.5.0 (2015-07-28)
46
+
47
+ * Support Sequel <4.24.0 class table inheritance (brianphillips) (#11)
48
+
49
+ # 1.4.0 (2014-09-03)
50
+
51
+ * Add support for class_map for custom class mapping (mpalmer, jeremyevans) (#8)
52
+
53
+ # 1.3.3 (2014-05-27)
54
+
55
+ * Add support for RSpec 2+ to the rspec/sequel integration (jeremyevans)
56
+
57
+ * Remove Merb/Webrat integration (jeremyevans)
58
+
59
+ # 1.3.2 (2013-08-21)
60
+
61
+ * Support for Sequel single table inheritance model_map functionality (brianphillips) (#6)
62
+
63
+ # 1.3.1 (2012-06-04)
64
+
65
+ * Fix issues on Ruby 1.9 due to lack of String#each (jeremyevans)
66
+
67
+ * Require yaml instead of depending on it already being required (jeremyevans)
68
+
69
+ # 1.3.0 (2011-04-13)
70
+
71
+ * Add composite key support when using Sequel (gditrick, jeremyevans) (#4)
72
+
73
+ * Raise errors when unable to save (jeremyevans)
74
+
75
+ # 1.2.6 (2011-01-03)
76
+
77
+ * Add support for Sequel single_table_inheritance plugin (derdewey) (#3)
78
+
79
+ * Add Merb/Webrat integration (derdewey) (#3)
80
+
81
+ # 1.2.5 (2010-10-18)
82
+
83
+ * Work with Sequel 3.10+ one_to_one associations (jeremyevans)
84
+
85
+ # 1.2.4 (2010-10-15)
86
+
87
+ * Support preprocessing fixtures with ERB (patcoll) (#1)
88
+
89
+ # 1.2.3 (2010-06-29)
90
+
91
+ * Fix bogus spec suite failures when using the RSpec/Sequel helper (jeremyevans)
92
+
93
+ # 1.2.2 (2009-10-12)
94
+
95
+ * Fix false positive when detecting association cycles (jeremyevans)
96
+
97
+ # 1.2.1 (2009-05-07)
98
+
99
+ * Work with Sequel 3.0.0 (jeremyevans)
100
+
101
+ # 1.2.0 (2009-02-09)
102
+
103
+ * Support hashes for loading specific fixtures, without double underscore notation (jeremyevans)
104
+
105
+ * Add RSpec/Sequel helper (jeremyevans)
106
+
107
+ # 1.1.2 (2008-11-17)
108
+
109
+ * Better handle fixtures without primary keys by setting saved value in fixture (Matthew Willson)
110
+
111
+ # 1.1.1 (2008-10-14)
112
+
113
+ * Fix bug when adding associated objects using Sequel (jeremyevans)
114
+
115
+ # 1.1.0 (2008-08-25)
116
+
117
+ * Allow use of Sequel in addition to ActiveRecord (jeremyevans)
118
+
119
+ * Allow customizing fixture path (jeremyevans)
120
+
121
+ * Fix singularizing already singular names when dealing with individual fixtures (jeremyevans)
122
+
123
+ * Make most FixtureDependencies class methods private (jeremyevans)
124
+
125
+ # 1.0.0 (2007-12-06)
126
+
127
+ * Initial Release (jeremyevans)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2016 Jeremy Evans
1
+ Copyright (c) 2007-2026 Jeremy Evans and contributors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # fixture_dependencies
2
2
 
3
- fixture_dependencies is an advanced fixture loader, allowing the loading of
4
- models from YAML fixtures, along with their entire dependency graph. It has
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
- - Support both Sequel and ActiveRecord
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 very simple API (FixtureDependencies.load(:model__fixture))
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.
@@ -115,11 +133,11 @@ For example, see the following changes:
115
133
  ```
116
134
  OLD NEW
117
135
  asset1: asset1:
118
- id: 1 id: 1
119
- employee_id: 2 employee: jeremy
120
- product_id: 3 product: nx7010
121
- vendor_id: 2 vendor: lxg_computers
122
- note: in working order note: in working order
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
123
141
  ```
124
142
 
125
143
  As you can see, you just replace the foreign key attribute and value with the
@@ -127,8 +145,8 @@ name of the association and the associations name. This assumes you have an
127
145
  employee fixture with a name of jeremy, and products fixture with the name of
128
146
  nx7010, and a vendors fixture with the name lxg_computers.
129
147
 
130
- Fixture files still use the table_name of the model. Note that you make sure
131
- to hard code primary key values for each fixture, as shown in the example
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
132
150
  above.
133
151
 
134
152
  ## ERB Fixtures
@@ -136,8 +154,8 @@ above.
136
154
  Fixtures can also use ERB to preprocess the fixture file, useful if you need
137
155
  to do any programming inside the fixture file, such as looping to create
138
156
  multiple records. For the ERB support to be invoked, your fixture file
139
- should be named #{table_name}.yml.erb instead of #{table_name}.yml. You can
140
- mix ERB fixture files and regular fixture files, but you can not have an
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
141
159
  ERB fixture file and a regular fixture file for the same table (the regular
142
160
  fixture file will be used in that case).
143
161
 
@@ -156,7 +174,7 @@ fixture_dependencies changes this to underscored model names. If you are using
156
174
  Rails' recommended table practices, this shouldn't make a difference.
157
175
 
158
176
  It is recommended that you do not use the fixtures method, and instead load
159
- individual fixtures as needed (see below). This makes your tests much more
177
+ individual fixtures as needed (see below). This makes your tests more
160
178
  robust, in case you want to add or remove individual fixtures at a later date.
161
179
 
162
180
  ## Loading individual fixtures with fixtures class method
@@ -170,16 +188,15 @@ using the following syntax:
170
188
  end
171
189
  ```
172
190
 
173
- This would load just the jeremy fixture and its dependencies. I find this is
174
- much better than loading all fixtures in most of my test suites. Even better
191
+ This would load just the jeremy fixture and its dependencies. This is
192
+ better than loading all fixtures for the model. Even better
175
193
  is loading just the fixtures you want inside every test method (see below).
176
- This leads to the most robust testing.
177
194
 
178
195
  ## Loading fixtures inside test methods
179
196
 
180
- I find that it is often better to skip the use of the fixtures method entirely,
181
- and load the fixtures I want manually in each test method. This provides for
182
- the loosest coupling possible. Here's an example:
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:
183
200
 
184
201
  ```
185
202
  class EmployeeTest < Test::Unit::TestCase
@@ -207,6 +224,9 @@ the loosest coupling possible. Here's an example:
207
224
  Don't worry about loading the same fixture twice, if a fixture is already
208
225
  loaded, it won't attempt to load it again.
209
226
 
227
+ One downside of this approach is it can be slower that loading all
228
+ fixtures before the test suite.
229
+
210
230
  ## Loading attributes only
211
231
 
212
232
  You can load only the attributes of fixtures, without saving them with
@@ -240,7 +260,7 @@ Here's an example of using has_one (logon_information), has_many (assets), and
240
260
  has_and_belongs_to_many (groups) associations.
241
261
 
242
262
  ```
243
- jeremy:
263
+ jeremy:
244
264
  id: 2
245
265
  name: Jeremy Evans
246
266
  logon_information: jeremy
@@ -354,8 +374,7 @@ possible.
354
374
  ## Known issues
355
375
 
356
376
  Currently, the plugin only supports YAML fixtures, but other types of fixtures
357
- would be fairly easy to add (send me a patch if you add support for another
358
- fixture type).
377
+ would be fairly easy to add.
359
378
 
360
379
  The plugin is significantly slower than the default testing method, because it
361
380
  loads all fixtures inside of a transaction (one per test method), where Rails
@@ -369,17 +388,17 @@ use load(:model__fixture_name).
369
388
  ## Namespace Issues
370
389
 
371
390
  By default, fixture dependencies is going to load the model with the camelized
372
- name in the symbol used. So for :foo_bar__baz, it's going to look for
373
- the fixture with name baz for the model FooBar. If your model is namespaced,
374
- such as Foo::Bar, this isn't going to work well. In that case, you can
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
375
394
  override the default mapping:
376
395
 
377
396
  ```
378
397
  FixtureDependencies.class_map[:bar] = Foo::Bar
379
398
  ```
380
399
 
381
- and then use :bar__baz to load the fixture with name baz for the model
382
- Foo::Bar.
400
+ and then use `:bar__baz` to load the fixture with name `baz` for the model
401
+ `Foo::Bar`.
383
402
 
384
403
  ## Custom Fixture Filenames
385
404
 
@@ -398,8 +417,8 @@ class method in the model:
398
417
  ## Troubleshooting
399
418
 
400
419
  If you run into problems with loading your fixtures, it can be difficult to see
401
- where the problems are. To aid in debugging an error, add the following to
402
- test/test_helper.rb:
420
+ where the problems are. To aid in debugging an error, add the following code
421
+ after requiring the library:
403
422
 
404
423
  ```
405
424
  FixtureDependencies.verbose = 3
@@ -410,7 +429,7 @@ every test, including the recursive loading of the dependency graph.
410
429
 
411
430
  ## Specs
412
431
 
413
- The specs for fixture dependencies and be run with Rake. They require
432
+ The specs for fixture dependencies are run with Rake. They require
414
433
  the sequel, activerecord, and sqlite3 gems installed. The default rake task
415
434
  runs the specs. You should run the spec_migrate task first to create the
416
435
  spec database.
@@ -424,6 +443,10 @@ fixture_references is a similar plugin. It uses erb inside yaml, and uses the
424
443
  foreign key numbers inside of the association names, which leads me to believe
425
444
  it doesn't support has_* associations.
426
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
+
427
450
  ## License
428
451
 
429
452
  fixture_dependencies is released under the MIT License. See the MIT-LICENSE
@@ -18,7 +18,7 @@ class << FixtureDependencies
18
18
  end
19
19
 
20
20
  def model_save_AR(object)
21
- object.save || raise(ActiveRecord::ActiveRecordError)
21
+ object.save || raise(ActiveRecord::RecordInvalid, object)
22
22
  end
23
23
 
24
24
  def raise_model_error_AR(message)
@@ -1,4 +1,4 @@
1
- require 'fixture_dependencies'
1
+ require_relative '../fixture_dependencies'
2
2
 
3
3
  class FixtureDependencies
4
4
  module HelperMethods
@@ -1,4 +1,4 @@
1
- require 'fixture_dependencies/minitest_spec'
1
+ require_relative '../minitest_spec'
2
2
 
3
3
  class Minitest::Spec
4
4
  def run(*args, &block)
@@ -1,5 +1,3 @@
1
- require 'fixture_dependencies/helper_methods'
1
+ require_relative 'helper_methods'
2
2
 
3
- class Minitest::Spec
4
- include FixtureDependencies::HelperMethods
5
- end
3
+ Minitest::Spec.send(:include, FixtureDependencies::HelperMethods)
@@ -1,9 +1,15 @@
1
- require 'fixture_dependencies/helper_methods'
1
+ require_relative '../helper_methods'
2
2
 
3
3
  if defined?(RSpec)
4
4
  example_group = RSpec::Core::ExampleGroup
5
- require 'rspec/version'
6
- if RSpec::Version::STRING >= '2.8.0'
5
+ use_rspec_configure = begin
6
+ require 'rspec/core/version'
7
+ rescue LoadError
8
+ require 'rspec/version'
9
+ RSpec::Version::STRING >= '2.8.0'
10
+ end
11
+
12
+ if use_rspec_configure
7
13
  RSpec.configure do |c|
8
14
  c.around(:each) do |example|
9
15
  Sequel::Model.db.transaction(:rollback=>:always){example.run}
@@ -28,6 +34,4 @@ else
28
34
  end
29
35
  end
30
36
 
31
- example_group.class_eval do
32
- include FixtureDependencies::HelperMethods
33
- end
37
+ example_group.send(:include, FixtureDependencies::HelperMethods)
@@ -1,4 +1,4 @@
1
- require 'fixture_dependencies/test_unit'
1
+ require_relative '../test_unit'
2
2
  FixtureDependencies.fixture_path = Test::Unit::TestCase.fixture_path
3
3
 
4
4
  module Test
@@ -1,4 +1,4 @@
1
- require 'fixture_dependencies/test_unit'
1
+ require_relative '../test_unit'
2
2
 
3
3
  class FixtureDependencies::SequelTestCase < Test::Unit::TestCase
4
4
  # Work around for Rails stupidity
@@ -1,5 +1,3 @@
1
- require 'fixture_dependencies/helper_methods'
1
+ require_relative 'helper_methods'
2
2
 
3
- class Test::Unit::TestCase
4
- include FixtureDependencies::HelperMethods
5
- end
3
+ Test::Unit::TestCase.send(:include, FixtureDependencies::HelperMethods)
@@ -7,6 +7,7 @@ class FixtureDependencies
7
7
  @loaded = {}
8
8
  @class_map = {}
9
9
  @verbose = 0
10
+ @use_unsafe_load = false
10
11
 
11
12
  # Load all record arguments into the database. If a single argument is
12
13
  # given and it corresponds to a single fixture, return the the model
@@ -62,6 +63,10 @@ class FixtureDependencies
62
63
  end
63
64
  end.flatten.compact.map do |record|
64
65
  model_name, name = split_name(record)
66
+ if klass = class_map[model_name.to_sym]
67
+ opts = opts.dup
68
+ opts[:class] = klass
69
+ end
65
70
  if name
66
71
  use(record.to_sym, opts)
67
72
  else
@@ -77,13 +82,12 @@ class FixtureDependencies
77
82
  end
78
83
  end
79
84
 
80
- require 'fixture_dependencies/active_record' if defined?(ActiveRecord::Base)
81
- require 'fixture_dependencies/sequel' if defined?(Sequel::Model)
82
-
85
+ require_relative 'fixture_dependencies/active_record' if defined?(ActiveRecord::Base)
86
+ require_relative 'fixture_dependencies/sequel' if defined?(Sequel::Model)
83
87
 
84
88
  class << FixtureDependencies
85
89
  attr_reader :fixtures, :loaded
86
- attr_accessor :verbose, :fixture_path, :class_map
90
+ attr_accessor :verbose, :fixture_path, :class_map, :use_unsafe_load
87
91
 
88
92
  private
89
93
 
@@ -103,21 +107,23 @@ class << FixtureDependencies
103
107
 
104
108
  # Adds all fixtures in the yaml fixture file for the model to the fixtures
105
109
  # hash (does not add them to the database, see add).
106
- def load_yaml(model_name)
110
+ def load_yaml(model_name, opts={})
107
111
  raise(ArgumentError, "No fixture_path set. Use FixtureDependencies.fixture_path = ...") unless fixture_path
108
112
 
109
- klass = model_class(model_name)
113
+ klass = opts[:class] || model_class(model_name)
110
114
  filename = klass.send(klass.respond_to?(:fixture_filename) ? :fixture_filename : :table_name)
111
115
  yaml_path = File.join(fixture_path, "#{filename}.yml")
112
116
 
113
- if File.exist?(yaml_path)
114
- yaml = YAML.load(File.read(yaml_path))
117
+ yaml_data = if File.exist?(yaml_path)
118
+ File.read(yaml_path)
115
119
  elsif File.exist?("#{yaml_path}.erb")
116
- yaml = YAML.load(ERB.new(File.read("#{yaml_path}.erb")).result)
120
+ ERB.new(File.read("#{yaml_path}.erb")).result
117
121
  else
118
122
  raise(ArgumentError, "No valid fixture found at #{yaml_path}[.erb]")
119
123
  end
120
124
 
125
+ yaml = parse_yaml_data(yaml_data)
126
+
121
127
  yaml.each do |name, attributes|
122
128
  symbol_attrs = {}
123
129
  attributes.each{|k,v| symbol_attrs[k.to_sym] = v}
@@ -125,6 +131,12 @@ class << FixtureDependencies
125
131
  end
126
132
  loaded[model_name.to_sym] = true
127
133
  end
134
+
135
+ # Parse the given data as YAML. If use_unsafe_load has been safe, use
136
+ # YAML.unsafe_load instead of YAML.load for parsing.
137
+ def parse_yaml_data(yaml_data)
138
+ @use_unsafe_load ? YAML.unsafe_load(yaml_data) : YAML.load(yaml_data)
139
+ end
128
140
 
129
141
  # Delegate to the correct method based on mtype
130
142
  def model_method(meth, mtype, *args, &block)
@@ -169,10 +181,10 @@ class << FixtureDependencies
169
181
  puts "#{spaces}load stack:#{loading.inspect}" if verbose > 1
170
182
  loading.push(record)
171
183
  model_name, name = split_name(record)
172
- model = model_class(model_name)
184
+ model = opts[:class] || model_class(model_name)
173
185
  unless loaded[model_name.to_sym]
174
186
  puts "#{spaces}loading #{model.table_name}.yml" if verbose > 0
175
- load_yaml(model_name)
187
+ load_yaml(model_name, opts)
176
188
  end
177
189
  mtype = model_type(model)
178
190
  model_method(:raise_model_error, mtype, "Couldn't use fixture #{record.inspect}") unless attributes = fixtures[model_name.to_sym][name.to_sym]
@@ -188,32 +200,20 @@ class << FixtureDependencies
188
200
  obj = model.sti_load(model.sti_key => attributes[model.sti_key])
189
201
  obj.send(:initialize)
190
202
  model = obj.model
191
- elsif model.respond_to?(:sti_key)
192
- obj = attributes[model.sti_key].to_s.camelize.constantize.new
193
- elsif model.respond_to?(:cti_key) # support for Sequel's pre-4.24.0 hybrid CTI support
194
- mv = attributes[model.cti_key]
195
- if (mm = model.cti_model_map)
196
- model = mm[mv].to_s.constantize
197
- elsif !mv.nil?
198
- model = mv.constantize
199
- end
200
- obj = model.new
201
203
  else
202
204
  obj = model.new
203
205
  end
204
206
  puts "#{spaces}#{model} STI plugin detected, initializing instance of #{obj}" if (verbose > 1 && model.respond_to?(:sti_dataset))
205
207
  many_associations = []
206
208
  attributes.each do |attr, value|
207
- next if attr.is_a?(Array)
208
209
  if reflection = model_method(:reflection, mtype, model, attr.to_sym)
209
210
  if [:belongs_to, :many_to_one].include?(model_method(:reflection_type, mtype, reflection))
210
211
 
211
212
  if polymorphic_association?(value)
212
213
  value, polymorphic_class = polymorphic_association(value)
213
- reflection[:class_name] = polymorphic_class
214
214
  dep_name = "#{polymorphic_class.to_s.underscore}__#{value}".to_sym
215
215
  else
216
- dep_name = "#{model_method(:reflection_class, mtype, reflection).name.underscore}__#{value}".to_sym
216
+ dep_name = "#{dep_class(mtype, reflection)}__#{value}".to_sym
217
217
  end
218
218
 
219
219
  if dep_name == record
@@ -270,7 +270,7 @@ class << FixtureDependencies
270
270
  # Update the has_many and habtm associations
271
271
  many_associations.each do |attr, reflection, values|
272
272
  Array(values).each do |value|
273
- dep_name = "#{model_method(:reflection_class, mtype, reflection).name.underscore}__#{value}".to_sym
273
+ dep_name = "#{dep_class(mtype, reflection)}__#{value}".to_sym
274
274
  rtype = model_method(:reflection_type, mtype, reflection) if verbose > 1
275
275
  if dep_name == record
276
276
  # Self referential, add association
@@ -292,6 +292,11 @@ class << FixtureDependencies
292
292
  obj
293
293
  end
294
294
 
295
+ def dep_class(mtype, reflection)
296
+ reflection_class = model_method(:reflection_class, mtype, reflection)
297
+ class_map.find{|k,v| break k if v == reflection_class} || reflection_class.name.underscore
298
+ end
299
+
295
300
  def fixture_pk(model)
296
301
  case pk = model.primary_key
297
302
  when Symbol, Array
@@ -1 +1 @@
1
- require 'fixture_dependencies/test_unit/rails'
1
+ require_relative 'fixture_dependencies/test_unit/rails'
metadata CHANGED
@@ -1,22 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest-global_expectations
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
14
26
  email: code@jeremyevans.net
15
27
  executables: []
16
28
  extensions: []
17
29
  extra_rdoc_files:
18
30
  - MIT-LICENSE
19
31
  files:
32
+ - CHANGELOG
20
33
  - MIT-LICENSE
21
34
  - README.md
22
35
  - lib/fixture_dependencies.rb
@@ -33,8 +46,10 @@ files:
33
46
  homepage: https://github.com/jeremyevans/fixture_dependencies
34
47
  licenses:
35
48
  - MIT
36
- metadata: {}
37
- post_install_message:
49
+ metadata:
50
+ bug_tracker_uri: https://github.com/jeremyevans/fixture_dependencies/issues
51
+ mailing_list_uri: https://github.com/jeremyevans/fixture_dependencies/discussions
52
+ source_code_uri: https://github.com/jeremyevans/fixture_dependencies
38
53
  rdoc_options:
39
54
  - "--inline-source"
40
55
  - "--line-numbers"
@@ -46,16 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
61
  requirements:
47
62
  - - ">="
48
63
  - !ruby/object:Gem::Version
49
- version: '0'
64
+ version: 1.9.2
50
65
  required_rubygems_version: !ruby/object:Gem::Requirement
51
66
  requirements:
52
67
  - - ">="
53
68
  - !ruby/object:Gem::Version
54
69
  version: '0'
55
70
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.7.6
58
- signing_key:
71
+ rubygems_version: 4.0.10
59
72
  specification_version: 4
60
73
  summary: Sequel/ActiveRecord fixture loader that handles dependency graphs
61
74
  test_files: []