diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-09-25 18:52:45 -0400 |
---|---|---|
committer | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-09-26 10:39:30 -0400 |
commit | 68890d39c9e25bccdd83407cfa6a12800093e432 (patch) | |
tree | 616d721dc00872ac7b3ae6a03591b8ba89610e54 /activerecord | |
parent | 52e11e462f6114a4d12225c639c5f501f0ffec7a (diff) | |
download | rails-68890d39c9e25bccdd83407cfa6a12800093e432.tar.gz rails-68890d39c9e25bccdd83407cfa6a12800093e432.tar.bz2 rails-68890d39c9e25bccdd83407cfa6a12800093e432.zip |
Raise an error when loading all fixtures from nil fixture_path
[Gannon McGibbon + Max Albrecht]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/fixtures_test.rb | 16 |
3 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 0aec999aba..9acc21510a 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -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* diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 6e0f1a0dfb..0d1fdcfb28 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -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 diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 5d5f54ca66..82ca15b415 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -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 |