myronmarston-factory_data_preloader 0.2.0 → 0.3.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.
- data/VERSION.yml +1 -1
- data/lib/factory_data_preloader.rb +13 -1
- data/lib/factory_data_preloader/factory_data.rb +20 -1
- metadata +1 -1
data/VERSION.yml
CHANGED
@@ -14,4 +14,16 @@ require 'active_record/fixtures'
|
|
14
14
|
require 'factory_data_preloader/core_ext'
|
15
15
|
require 'factory_data_preloader/preloader'
|
16
16
|
require 'factory_data_preloader/factory_data'
|
17
|
-
require 'factory_data_preloader/rails_core_ext'
|
17
|
+
require 'factory_data_preloader/rails_core_ext'
|
18
|
+
|
19
|
+
if defined? Rails.configuration
|
20
|
+
Rails.configuration.after_initialize do
|
21
|
+
FactoryData.definition_file_paths = [
|
22
|
+
File.join(RAILS_ROOT, 'test', 'factory_data'),
|
23
|
+
File.join(RAILS_ROOT, 'spec', 'factory_data')
|
24
|
+
]
|
25
|
+
FactoryData.find_definitions
|
26
|
+
end
|
27
|
+
else
|
28
|
+
FactoryData.find_definitions
|
29
|
+
end
|
@@ -11,7 +11,12 @@ module FactoryDataPreloader
|
|
11
11
|
@@preloaders = []
|
12
12
|
|
13
13
|
class << self
|
14
|
-
|
14
|
+
# An Array of strings specifying locations that should be searched for
|
15
|
+
# factory_data definitions. By default, factory_data_preloader will attempt to require
|
16
|
+
# "factory_data," "test/factory_data," and "spec/factory_data." Only the first
|
17
|
+
# existing file will be loaded.
|
18
|
+
attr_accessor :definition_file_paths
|
19
|
+
|
15
20
|
def preload(model_type, options = {}, &proc)
|
16
21
|
raise PreloaderAlreadyDefinedError.new, "You have already defined the preloader for #{model_type.to_s}" if @@preloaders.map(&:model_type).include?(model_type)
|
17
22
|
|
@@ -61,6 +66,18 @@ module FactoryDataPreloader
|
|
61
66
|
def reset_cache!
|
62
67
|
@@single_test_cache = {}
|
63
68
|
end
|
69
|
+
|
70
|
+
def find_definitions
|
71
|
+
definition_file_paths.each do |path|
|
72
|
+
require("#{path}.rb") if File.exists?("#{path}.rb")
|
73
|
+
|
74
|
+
if File.directory? path
|
75
|
+
Dir[File.join(path, '*.rb')].each do |file|
|
76
|
+
require file
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
64
81
|
|
65
82
|
private
|
66
83
|
|
@@ -81,6 +98,8 @@ module FactoryDataPreloader
|
|
81
98
|
end
|
82
99
|
end
|
83
100
|
end
|
101
|
+
|
102
|
+
self.definition_file_paths = %w(factory_data test/factory_data spec/factory_data)
|
84
103
|
end
|
85
104
|
end
|
86
105
|
|