fixturies 1.0.2 → 1.1.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/lib/fixturies.rb +24 -3
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 279e30d4f553ebdb0d403f274a98f06e54a6c840fa9dc55174bb034dde2ecbba
|
4
|
+
data.tar.gz: 49b631dc9a872f6aee4ec661caf3d86eb18d8477ad5d03156064e811d93e9ae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9fc1681aed02de05c5bd3d63ff9ed42b361004702009b9b44b2c54454de29331d4902ffc7388b85e9635a329018c95e82be92a25205b16e426b99f7569ec08e
|
7
|
+
data.tar.gz: 48517251205ba71654688ef3c3b92f3ef7910591a204c09abc9d512dfa7e60e57dfa4a9aea6bbd2f827f4dd27b378e956edf756ed85ea047703c20ef8fd7e0b5
|
data/lib/fixturies.rb
CHANGED
@@ -2,7 +2,7 @@ class Fixturies
|
|
2
2
|
|
3
3
|
class << self
|
4
4
|
|
5
|
-
attr_reader :fixtures_directory
|
5
|
+
attr_reader :fixtures_directory, :fixture_class_names
|
6
6
|
|
7
7
|
def build(&proc)
|
8
8
|
meth_name = :"builder_#{rand}"
|
@@ -14,6 +14,11 @@ class Fixturies
|
|
14
14
|
@fixtures_directory = dir
|
15
15
|
end
|
16
16
|
|
17
|
+
def set_fixture_class(class_names = {})
|
18
|
+
@fixture_class_names ||= {}
|
19
|
+
@fixture_class_names = fixture_class_names.merge(class_names.stringify_keys)
|
20
|
+
end
|
21
|
+
|
17
22
|
def create_fixtures
|
18
23
|
self.new.create_fixtures
|
19
24
|
end
|
@@ -108,13 +113,29 @@ class Fixturies
|
|
108
113
|
self.inheritance_column = nil # do not blow up if the type column indicates we should be using single-table inheritance
|
109
114
|
}
|
110
115
|
|
116
|
+
virtual_column_names = klass.columns.filter_map do |column|
|
117
|
+
if column.try(:virtual?)
|
118
|
+
column.name
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
111
122
|
hash = {}
|
112
123
|
klass.all.each_with_index do |record, i|
|
113
124
|
name = record_identifiers[record_key(record)] || "#{table_name.singularize}_#{i}"
|
114
|
-
|
125
|
+
attributes = record.attributes
|
126
|
+
virtual_column_names.each do |column_name|
|
127
|
+
attributes.delete(column_name)
|
128
|
+
end
|
129
|
+
hash[name] = attributes
|
115
130
|
end
|
116
131
|
|
117
132
|
if hash.any?
|
133
|
+
# Rails allows baking the model_class into the YAML file, which
|
134
|
+
# can be useful if the class cannot be inferred from the table_name.
|
135
|
+
# See https://github.com/rails/rails/pull/20574/files
|
136
|
+
klass = self.class.fixture_class_names&.[](table_name)
|
137
|
+
hash['_fixture'] = {'model_class' => klass.to_s} if klass.present?
|
138
|
+
|
118
139
|
File.open(filename, 'w+') do |f|
|
119
140
|
f.write(hash.to_yaml)
|
120
141
|
end
|
@@ -134,4 +155,4 @@ class Fixturies
|
|
134
155
|
|
135
156
|
end
|
136
157
|
|
137
|
-
end
|
158
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixturies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Brustein
|
@@ -36,8 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
|
-
|
40
|
-
rubygems_version: 2.7.6
|
39
|
+
rubygems_version: 3.0.3.1
|
41
40
|
signing_key:
|
42
41
|
specification_version: 4
|
43
42
|
summary: The speed of fixtures meets the maintanability of factories
|