mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Raise an error when loading all fixtures from nil fixture_path
[Gannon McGibbon + Max Albrecht]
This commit is contained in:
parent
52e11e462f
commit
68890d39c9
3 changed files with 21 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
||||
|
||||
*Gannon McGibbon*, *Max Albrecht*
|
||||
|
||||
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
||||
|
||||
*Gannon McGibbon*
|
||||
|
|
|
@ -892,6 +892,7 @@ module ActiveRecord
|
|||
|
||||
def fixtures(*fixture_set_names)
|
||||
if fixture_set_names.first == :all
|
||||
raise StandardError, "No fixture path found. Please set `#{self}.fixture_path`." if fixture_path.blank?
|
||||
fixture_set_names = Dir["#{fixture_path}/{**,*}/*.{yml}"].uniq
|
||||
fixture_set_names.map! { |f| f[(fixture_path.to_s.size + 1)..-5] }
|
||||
else
|
||||
|
|
|
@ -1344,3 +1344,19 @@ class SameNameDifferentDatabaseFixturesTest < ActiveRecord::TestCase
|
|||
assert_kind_of OtherDog, other_dogs(:lassie)
|
||||
end
|
||||
end
|
||||
|
||||
class NilFixturePathTest < ActiveRecord::TestCase
|
||||
test "raises an error when all fixtures loaded" do
|
||||
error = assert_raises(StandardError) do
|
||||
TestCase = Class.new(ActiveRecord::TestCase)
|
||||
TestCase.class_eval do
|
||||
self.fixture_path = nil
|
||||
fixtures :all
|
||||
end
|
||||
end
|
||||
assert_equal <<~MSG.squish, error.message
|
||||
No fixture path found.
|
||||
Please set `NilFixturePathTest::TestCase.fixture_path`.
|
||||
MSG
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue