fixturies 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fixturies.rb +24 -3
  3. metadata +2 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 111de78ccf16d0722626b9a84398e602488be1c181c5aa2a8ebe6d8d6c8c2732
4
- data.tar.gz: 28175fa7dd4a3528e3e173037a1ef47cf01f5859f1f6be8d681d739bef324696
3
+ metadata.gz: 279e30d4f553ebdb0d403f274a98f06e54a6c840fa9dc55174bb034dde2ecbba
4
+ data.tar.gz: 49b631dc9a872f6aee4ec661caf3d86eb18d8477ad5d03156064e811d93e9ae9
5
5
  SHA512:
6
- metadata.gz: a52d50c7c2cebe3a78fbdb361c589a5e755f277c2d90d8dd2d6904399b8a47f7887c722a50d2c5601cb4c55b2a50f1b05c8f9a0e017815c18ac9b20689336292
7
- data.tar.gz: e0fd102ca4656cd6ae621b48952fbbce36cd8cc434c05ddcfccd7cc2562b3964054d17b080cfb643dfefea09d5a9922506a75ada7ab9081dc58c7fb968123b28
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
- hash[name] = record.attributes
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.2
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
- rubyforge_project:
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