aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-09-26 12:53:43 -0400
committerGitHub <noreply@github.com>2018-09-26 12:53:43 -0400
commit0a4c2d4738a536ac6e1f4347205c0c62dd3ceb9a (patch)
tree312d6490ae2540a91fd4e0e136261eeffe239f40
parent36440720689c07eb2c45d9d39005814e71e387a4 (diff)
parent68890d39c9e25bccdd83407cfa6a12800093e432 (diff)
downloadrails-0a4c2d4738a536ac6e1f4347205c0c62dd3ceb9a.tar.gz
rails-0a4c2d4738a536ac6e1f4347205c0c62dd3ceb9a.tar.bz2
rails-0a4c2d4738a536ac6e1f4347205c0c62dd3ceb9a.zip
Merge pull request #33983 from gmcgibbon/raise_if_fixture_path_blank
Raise an error when loading all fixtures from nil fixture_path
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/fixtures.rb1
-rw-r--r--activerecord/test/cases/fixtures_test.rb16
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