aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb16
-rwxr-xr-xactiverecord/test/cases/fixtures_test.rb14
3 files changed, 27 insertions, 5 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index a1c9a0f4d7..d2ee1faedd 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added logging for dependency load errors with fixtures #11056 [stuthulhu]
+
* Time zone aware attributes use Time#in_time_zone [Geoff Buesing]
* Fixed that scoped joins would not always be respected #6821 [Theory/Danger]
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index c5b90efb4b..a68086bf66 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -846,15 +846,21 @@ module Test #:nodoc:
setup_fixture_accessors(table_names)
end
+ def try_to_load_dependency(file_name)
+ require_dependency file_name
+ rescue LoadError => e
+ # Let's hope the developer has included it himself
+
+ # Let's warn in case this is a subdependency, otherwise
+ # subdependency error messages are totally cryptic
+ ActiveRecord::Base.logger.warn("Unable to load #{file_name}, underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}")
+ end
+
def require_fixture_classes(table_names = nil)
(table_names || fixture_table_names).each do |table_name|
file_name = table_name.to_s
file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names
- begin
- require_dependency file_name
- rescue LoadError
- # Let's hope the developer has included it himself
- end
+ try_to_load_dependency(file_name)
end
end
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb
index 8dbccbba98..dce04e63be 100755
--- a/activerecord/test/cases/fixtures_test.rb
+++ b/activerecord/test/cases/fixtures_test.rb
@@ -590,3 +590,17 @@ class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase
assert_equal parrots(:louis), Parrot.find_by_name("King Louis")
end
end
+
+class FixtureLoadingTest < ActiveRecord::TestCase
+ def test_logs_message_for_failed_dependency_load
+ Test::Unit::TestCase.expects(:require_dependency).with(:does_not_exist).raises(LoadError)
+ ActiveRecord::Base.logger.expects(:warn)
+ Test::Unit::TestCase.try_to_load_dependency(:does_not_exist)
+ end
+
+ def test_does_not_logs_message_for_successful_dependency_load
+ Test::Unit::TestCase.expects(:require_dependency).with(:works_out_fine)
+ ActiveRecord::Base.logger.expects(:warn).never
+ Test::Unit::TestCase.try_to_load_dependency(:works_out_fine)
+ end
+end