fixture_farm 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bb437d76da7783d3bcec79d5eb456dfc6279aaf147e4299323c072cb5823ba3
4
- data.tar.gz: 3dbadf4de6166743fb4eeb23c1389479dcdbd6341d0aaed7757478ada4be3042
3
+ metadata.gz: 473a2a53021fcb6a622b9585c95769a343c7a5bbeaba96e25a347f96211ae156
4
+ data.tar.gz: ec5cbfaa5d092b11c1ba9716b47440795866fee6ae377d968ce1a44bf9a2e93c
5
5
  SHA512:
6
- metadata.gz: 31a03a177602b04b48a047ab1cd0d8820784ebc4fc9524e0577eeac5c165579db49891f739ee15e593b57f631388ada0d47d9d1236e31d5a8da2abbdda9797db
7
- data.tar.gz: d385f242b1d5670f0e1ffc70985f40c5297dcd97f5e25c870f205e06f598faaf8c9e6bb0f45bbccb82cf9d4f1e2614558718dc10d618fb6584ecde162226155d
6
+ metadata.gz: d32f502880c8e88e111c640cbdfa8ebfdf7a1369d06eb4421d55e9bfe3b014a91df399605037e77cdc0cbe8720c6a40808551f40c9d918af991d3dfba2ced2c5
7
+ data.tar.gz: e39d80ac110da1f67b1f219fe277bd83a85eb6e6e6dbac0cc4657fd6a22f6103ab469082a641c5caff11ed0b6d33f4a01c9fdcb1718c959422ef83819c1d318b
@@ -5,15 +5,29 @@ module FixtureFarm
5
5
  def fixture_name
6
6
  require 'active_record/fixtures'
7
7
 
8
- return nil unless fixture_file_path
8
+ return nil unless File.exist?(fixtures_file_path)
9
9
 
10
- fixtures = YAML.load_file(fixture_file_path)
10
+ fixtures = YAML.load_file(fixtures_file_path)
11
11
  fixtures.keys.find do |key|
12
12
  ActiveRecord::FixtureSet.identify(key) == id
13
13
  end
14
14
  end
15
15
 
16
- def fixture_file_path
16
+ def fixtures_file_path
17
+ existing_fixtures_file_path || candidate_fixtures_file_path
18
+ end
19
+
20
+ def candidate_fixtures_file_path
21
+ klass = self.class
22
+ loop do
23
+ path = Rails.root.join('test', 'fixtures', "#{klass.to_s.underscore.pluralize}.yml")
24
+ return path if klass >= ActiveRecord::Base || !klass.columns.map(&:name).include?(klass.inheritance_column)
25
+
26
+ klass = klass.superclass
27
+ end
28
+ end
29
+
30
+ def existing_fixtures_file_path
17
31
  klass = self.class
18
32
 
19
33
  while klass < ActiveRecord::Base
@@ -125,12 +125,14 @@ module FixtureFarm
125
125
  end
126
126
  end.to_h
127
127
 
128
- fixture_file_path = model_instance.fixture_file_path || Rails.root.join('test', 'fixtures', "#{model_instance.class.table_name}.yml")
128
+ fixtures_file_path = model_instance.fixtures_file_path
129
129
 
130
- fixtures = File.exist?(fixture_file_path) ? YAML.load_file(fixture_file_path) : {}
130
+ fixtures = File.exist?(fixtures_file_path) ? YAML.load_file(fixtures_file_path) : {}
131
131
  fixtures[new_fixture_name] = yaml_attributes
132
132
 
133
- File.open(fixture_file_path, 'w') do |file|
133
+ FileUtils.mkdir_p(fixtures_file_path.dirname)
134
+
135
+ File.open(fixtures_file_path, 'w') do |file|
134
136
  yaml = YAML.dump(fixtures).gsub(/\n(?=[^\s])/, "\n\n").delete_prefix("---\n\n")
135
137
  file.write(yaml)
136
138
  end
@@ -1,3 +1,3 @@
1
1
  module FixtureFarm
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_farm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - artemave