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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 473a2a53021fcb6a622b9585c95769a343c7a5bbeaba96e25a347f96211ae156
|
4
|
+
data.tar.gz: ec5cbfaa5d092b11c1ba9716b47440795866fee6ae377d968ce1a44bf9a2e93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
8
|
+
return nil unless File.exist?(fixtures_file_path)
|
9
9
|
|
10
|
-
fixtures = YAML.load_file(
|
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
|
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
|
-
|
128
|
+
fixtures_file_path = model_instance.fixtures_file_path
|
129
129
|
|
130
|
-
fixtures = File.exist?(
|
130
|
+
fixtures = File.exist?(fixtures_file_path) ? YAML.load_file(fixtures_file_path) : {}
|
131
131
|
fixtures[new_fixture_name] = yaml_attributes
|
132
132
|
|
133
|
-
|
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
|
data/lib/fixture_farm/version.rb
CHANGED