-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfixation.rb
90 lines (76 loc) · 2.56 KB
/
fixation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'erb'
require 'yaml'
require 'set'
require 'active_support/dependencies'
require 'active_record/errors'
require_relative "fixation/version"
require_relative "fixation/fixture_table"
require_relative "fixation/fixtures"
module Fixation
# The list of paths to look in to find fixture files.
cattr_accessor :paths
self.paths = %w(test/fixtures spec/fixtures)
# The list of extensions to look for in fixture directories.
cattr_accessor :extensions
self.extensions = %w(.yml .yml.erb)
# Set to true to clear any tables found in the database that do *not* have a fixture file.
cattr_accessor :clear_other_tables
# Set to the list of tables you don't want to clear (if clear_other_tables is turned on).
# Defaults to just schema_migrations and ar_internal_metadata.
cattr_accessor :tables_not_to_clear
self.tables_not_to_clear = %w(schema_migrations ar_internal_metadata)
# Set to true to log some debugging information to stdout.
cattr_accessor :trace
def self.build_fixtures
@fixtures = Fixtures.new
@fixtures.compile_fixture_files
end
def self.apply_fixtures
build_fixtures unless @fixtures
@fixtures.apply_fixtures
end
def self.fixture_methods
build_fixtures unless @fixtures
@fixtures.fixture_methods
end
def self.add_fixture(fixture_for, name, attributes)
@fixtures.add_fixture(fixture_for, name, attributes)
end
# Returns a consistent, platform-independent identifier for +label+.
# Integer identifiers are values less than 2^30. UUIDs are RFC 4122 version 5 SHA-1 hashes.
#
# Uses the ActiveRecord fixtures method for compatibility.
if ActiveRecord::FixtureSet.method(:identify).arity == 1
def self.identify(label, _column_type = :integer)
ActiveRecord::FixtureSet.identify(label)
end
else
def self.identify(label, column_type = :integer)
ActiveRecord::FixtureSet.identify(label, column_type)
end
end
def self.running_under_spring?
defined?(Spring::Application)
end
def self.preload_for_spring
build_fixtures
unload_models!
watch_paths
end
def self.watch_paths
paths.each do |path|
Spring.watch(path)
end
end
# reloads Rails (using the code from Spring) in order to unload the model classes that get
# auto-loaded when we read the fixture definitions.
def self.unload_models!
# Rails 5.1 forward-compat. AD::R is deprecated to AS::R in Rails 5.
if defined? ActiveSupport::Reloader
Rails.application.reloader.reload!
else
ActionDispatch::Reloader.cleanup!
ActionDispatch::Reloader.prepare!
end
end
end