我正在使用 Solidus 和 Ruby on Rails 来创建一个网上商店,并且我有多个用于该网上商店的模块。
因此,我使用以下代码将 me 控制器定义到名为“solidus_jwt_auth”的模块中:
module Spree
module Api
class MeController < Spree::Api::BaseController
def index
...
end
def orders
...
end
def addresses
...
end
end
end
end
我想在另一个名为“solidus_prescriptions”的模块中扩展它,所以我使用以下代码为此创建了一个装饰器me_decorator
:
if defined? Spree::Api::MeController.class
Spree::Api::MeController.class_eval do
def prescriptions
...
end
def create_prescription
...
end
private
def prescription_params
params.require(:prescription).permit(
*Spree::CustomerPrescription.permitted_attributes
)
end
end
end
为此,我在solidus_prescription 模块中编写了单元测试,并在webshop 中编写了集成测试。单元测试工作正常,但集成测试出现以下错误:
错误:MeEndpointsTest#test_me/prescriptions_post_endpoint_throws_an_error_when_wrong_params:AbstractController::ActionNotFound:找不到 Spree::Api::MeController test/integration/me_endpoints_test.rb:68:in 'block in' 的操作'create_prescription'
这意味着他找不到在另一个模块中定义的 MeController。我如何检查 MeController 是否已定义,因为下面的代码对我没有任何帮助:
if defined? Spree::Api::MeController.class
end