Ticket #11056: load_errors_should_not_be_silent.diff
| File load_errors_should_not_be_silent.diff, 2.1 kB (added by stuthulhu, 8 months ago) |
|---|
-
test/cases/fixtures_test.rb
old new 590 590 assert_equal parrots(:louis), Parrot.find_by_name("King Louis") 591 591 end 592 592 end 593 594 class FixtureLoadingTest < ActiveRecord::TestCase 595 def test_logs_message_for_failed_dependency_load 596 Test::Unit::TestCase.expects(:require_dependency).with(:does_not_exist).raises(LoadError) 597 ActiveRecord::Base.logger.expects(:warn) 598 Test::Unit::TestCase.try_to_load_dependency(:does_not_exist) 599 end 600 601 def test_does_not_logs_message_for_successful_dependency_load 602 Test::Unit::TestCase.expects(:require_dependency).with(:works_out_fine) 603 ActiveRecord::Base.logger.expects(:warn).never 604 Test::Unit::TestCase.try_to_load_dependency(:works_out_fine) 605 end 606 end -
lib/active_record/fixtures.rb
old new 846 846 setup_fixture_accessors(table_names) 847 847 end 848 848 849 def try_to_load_dependency(file_name) 850 require_dependency file_name 851 rescue LoadError => e 852 # Let's hope the developer has included it himself 853 854 # Let's warn in case this is a subdependency, otherwise 855 # subdependency error messages are totally cryptic 856 ActiveRecord::Base.logger.warn("Unable to load #{file_name}, underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}") 857 end 858 849 859 def require_fixture_classes(table_names = nil) 850 860 (table_names || fixture_table_names).each do |table_name| 851 861 file_name = table_name.to_s 852 862 file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names 853 begin 854 require_dependency file_name 855 rescue LoadError 856 # Let's hope the developer has included it himself 857 end 863 try_to_load_dependency(file_name) 858 864 end 859 865 end 860 866