Permalink
Browse files

Added logging for dependency load errors with fixtures (closes #11056)…

… [stuthulhu]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9050 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent d07d6e9 commit fbf41c72a930a1b879452d137ba3d75d5ceaf358 @dhh dhh committed Mar 17, 2008
Showing with 27 additions and 5 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +11 −5 activerecord/lib/active_record/fixtures.rb
  3. +14 −0 activerecord/test/cases/fixtures_test.rb
@@ -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]
@@ -846,15 +846,21 @@ def fixtures(*table_names)
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
@@ -590,3 +590,17 @@ def test_foo
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

0 comments on commit fbf41c7

Please sign in to comment.