다음 코드 블록을 environments.rb에 추가하면 ActiveRecord :: Base가 모듈을 개발 환경에서 확장하지만 테스트 환경에서는 확장하지 않습니다.레일에서 ActiveRecord :: Base 확장이 테스트 환경에서 작동하지 않습니다.
module ModelExtensions
def human_name_for(attr_hash)
# do something
end
end
로드 ./script/server 및 ./script/console 개발 환경에 잘 보인다 다음과 같이 모듈이 포함
require "active_record_patch"
ActiveRecord::Base.send(:extend, ModelExtensions)
라이브러리 파일입니다. 그러나 테스트 환경에서, 다음과 같은 오류가 발생합니다
솔루션에 대한/home/test/rails_app/vendor/rails/activerecord/lib/active_record/base.rb:1959:in `method_missing':NoMethodError: undefined method `human_name_for' for #<Class:0x4a8d33>