fixture_dependencies 1.11.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 +4 -4
- data/CHANGELOG +8 -0
- data/MIT-LICENSE +1 -1
- data/lib/fixture_dependencies/rspec/sequel.rb +8 -2
- data/lib/fixture_dependencies.rb +27 -12
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 524ee808c516b0960cb838c58ad2b7cea8f240b91bd80f6bda6072ccbb363d64
|
|
4
|
+
data.tar.gz: ab570a5ebb17bdbb3d933d81e52758b0164591336f6303b7eb571821c2312181
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93d0d22666a86d8f6a18082ae462a030e7aff7788c8ee066a5fbdbab084008f5ca01b80031f481a73211a0236601b6555fcc6c5bddde4c1271fc79026c624a6d
|
|
7
|
+
data.tar.gz: d01b825c6af877502f424e030c2751c3cf8418bed26034a08fc95ad5bd030a8a8e90b2cf97853dd7495bf084b98a3a3c5759acff5afd8e5317d48618eb13447a
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
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
|
+
|
|
1
9
|
# 1.11.0 (2022-06-30)
|
|
2
10
|
|
|
3
11
|
* Drop Ruby 1.8 support (jeremyevans)
|
data/MIT-LICENSE
CHANGED
|
@@ -2,8 +2,14 @@ require_relative '../helper_methods'
|
|
|
2
2
|
|
|
3
3
|
if defined?(RSpec)
|
|
4
4
|
example_group = RSpec::Core::ExampleGroup
|
|
5
|
-
|
|
6
|
-
|
|
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}
|
data/lib/fixture_dependencies.rb
CHANGED
|
@@ -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,8 +63,9 @@ class FixtureDependencies
|
|
|
62
63
|
end
|
|
63
64
|
end.flatten.compact.map do |record|
|
|
64
65
|
model_name, name = split_name(record)
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
if klass = class_map[model_name.to_sym]
|
|
67
|
+
opts = opts.dup
|
|
68
|
+
opts[:class] = klass
|
|
67
69
|
end
|
|
68
70
|
if name
|
|
69
71
|
use(record.to_sym, opts)
|
|
@@ -85,7 +87,7 @@ require_relative 'fixture_dependencies/sequel' if defined?(Sequel::Model)
|
|
|
85
87
|
|
|
86
88
|
class << FixtureDependencies
|
|
87
89
|
attr_reader :fixtures, :loaded
|
|
88
|
-
attr_accessor :verbose, :fixture_path, :class_map
|
|
90
|
+
attr_accessor :verbose, :fixture_path, :class_map, :use_unsafe_load
|
|
89
91
|
|
|
90
92
|
private
|
|
91
93
|
|
|
@@ -105,21 +107,23 @@ class << FixtureDependencies
|
|
|
105
107
|
|
|
106
108
|
# Adds all fixtures in the yaml fixture file for the model to the fixtures
|
|
107
109
|
# hash (does not add them to the database, see add).
|
|
108
|
-
def load_yaml(model_name)
|
|
110
|
+
def load_yaml(model_name, opts={})
|
|
109
111
|
raise(ArgumentError, "No fixture_path set. Use FixtureDependencies.fixture_path = ...") unless fixture_path
|
|
110
112
|
|
|
111
|
-
klass = model_class(model_name)
|
|
113
|
+
klass = opts[:class] || model_class(model_name)
|
|
112
114
|
filename = klass.send(klass.respond_to?(:fixture_filename) ? :fixture_filename : :table_name)
|
|
113
115
|
yaml_path = File.join(fixture_path, "#{filename}.yml")
|
|
114
116
|
|
|
115
|
-
if File.exist?(yaml_path)
|
|
116
|
-
|
|
117
|
+
yaml_data = if File.exist?(yaml_path)
|
|
118
|
+
File.read(yaml_path)
|
|
117
119
|
elsif File.exist?("#{yaml_path}.erb")
|
|
118
|
-
|
|
120
|
+
ERB.new(File.read("#{yaml_path}.erb")).result
|
|
119
121
|
else
|
|
120
122
|
raise(ArgumentError, "No valid fixture found at #{yaml_path}[.erb]")
|
|
121
123
|
end
|
|
122
124
|
|
|
125
|
+
yaml = parse_yaml_data(yaml_data)
|
|
126
|
+
|
|
123
127
|
yaml.each do |name, attributes|
|
|
124
128
|
symbol_attrs = {}
|
|
125
129
|
attributes.each{|k,v| symbol_attrs[k.to_sym] = v}
|
|
@@ -127,6 +131,12 @@ class << FixtureDependencies
|
|
|
127
131
|
end
|
|
128
132
|
loaded[model_name.to_sym] = true
|
|
129
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
|
|
130
140
|
|
|
131
141
|
# Delegate to the correct method based on mtype
|
|
132
142
|
def model_method(meth, mtype, *args, &block)
|
|
@@ -171,10 +181,10 @@ class << FixtureDependencies
|
|
|
171
181
|
puts "#{spaces}load stack:#{loading.inspect}" if verbose > 1
|
|
172
182
|
loading.push(record)
|
|
173
183
|
model_name, name = split_name(record)
|
|
174
|
-
model = model_class(model_name)
|
|
184
|
+
model = opts[:class] || model_class(model_name)
|
|
175
185
|
unless loaded[model_name.to_sym]
|
|
176
186
|
puts "#{spaces}loading #{model.table_name}.yml" if verbose > 0
|
|
177
|
-
load_yaml(model_name)
|
|
187
|
+
load_yaml(model_name, opts)
|
|
178
188
|
end
|
|
179
189
|
mtype = model_type(model)
|
|
180
190
|
model_method(:raise_model_error, mtype, "Couldn't use fixture #{record.inspect}") unless attributes = fixtures[model_name.to_sym][name.to_sym]
|
|
@@ -203,7 +213,7 @@ class << FixtureDependencies
|
|
|
203
213
|
value, polymorphic_class = polymorphic_association(value)
|
|
204
214
|
dep_name = "#{polymorphic_class.to_s.underscore}__#{value}".to_sym
|
|
205
215
|
else
|
|
206
|
-
dep_name = "#{
|
|
216
|
+
dep_name = "#{dep_class(mtype, reflection)}__#{value}".to_sym
|
|
207
217
|
end
|
|
208
218
|
|
|
209
219
|
if dep_name == record
|
|
@@ -260,7 +270,7 @@ class << FixtureDependencies
|
|
|
260
270
|
# Update the has_many and habtm associations
|
|
261
271
|
many_associations.each do |attr, reflection, values|
|
|
262
272
|
Array(values).each do |value|
|
|
263
|
-
dep_name = "#{
|
|
273
|
+
dep_name = "#{dep_class(mtype, reflection)}__#{value}".to_sym
|
|
264
274
|
rtype = model_method(:reflection_type, mtype, reflection) if verbose > 1
|
|
265
275
|
if dep_name == record
|
|
266
276
|
# Self referential, add association
|
|
@@ -282,6 +292,11 @@ class << FixtureDependencies
|
|
|
282
292
|
obj
|
|
283
293
|
end
|
|
284
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
|
+
|
|
285
300
|
def fixture_pk(model)
|
|
286
301
|
case pk = model.primary_key
|
|
287
302
|
when Symbol, Array
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fixture_dependencies
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
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:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: minitest-global_expectations
|
|
@@ -24,7 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
|
-
description:
|
|
28
26
|
email: code@jeremyevans.net
|
|
29
27
|
executables: []
|
|
30
28
|
extensions: []
|
|
@@ -52,7 +50,6 @@ metadata:
|
|
|
52
50
|
bug_tracker_uri: https://github.com/jeremyevans/fixture_dependencies/issues
|
|
53
51
|
mailing_list_uri: https://github.com/jeremyevans/fixture_dependencies/discussions
|
|
54
52
|
source_code_uri: https://github.com/jeremyevans/fixture_dependencies
|
|
55
|
-
post_install_message:
|
|
56
53
|
rdoc_options:
|
|
57
54
|
- "--inline-source"
|
|
58
55
|
- "--line-numbers"
|
|
@@ -71,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
71
68
|
- !ruby/object:Gem::Version
|
|
72
69
|
version: '0'
|
|
73
70
|
requirements: []
|
|
74
|
-
rubygems_version:
|
|
75
|
-
signing_key:
|
|
71
|
+
rubygems_version: 4.0.10
|
|
76
72
|
specification_version: 4
|
|
77
73
|
summary: Sequel/ActiveRecord fixture loader that handles dependency graphs
|
|
78
74
|
test_files: []
|