次の初期化子があります。
app/config/initializers/store_location.rb
module StoreLocation
def self.skip_store_location
[
Devise::SessionsController,
Devise::RegistrationsController,
Devise::PasswordsController
].each do |controller|
controller.skip_before_filter :store_location
end
end
self.skip_store_location
end
私の ApplicationController の関連部分:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :convert_legacy_cookies
before_filter :store_location
alias_method :devise_current_user, :current_user
def current_user
# do something
end
private
def store_location
# store location
end
さらに、これは config/environments/development.rbにあります
Foo::Application.configure do
# normal rails stuff
config.to_prepare do
StoreLocation.skip_store_location
end
end
RSpec/Rails に self.skip_store_location を実行させると、次のエラーが発生します。
/foo/app/controllers/application_controller.rb:7:in `alias_method': undefined method `current_user' for class `ApplicationController' (NameError)
呼び出しを削除すると、すべてが正常に戻ります (期待どおりにフィルターが実行されることを除く)。どういうわけか依存関係の読み込みを台無しにしていると思いますか?