1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
David Heinemeier Hansson 2008-03-17 21:48:28 +00:00
parent d07d6e900c
commit fbf41c72a9
3 changed files with 27 additions and 5 deletions

View file

@ -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]

View file

@ -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

View file

@ -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