我的控制器测试失败如下
ActionController::ParameterMissing:
param is missing or the value is empty: user
Failure/Error:
params.require(:user).permit(
:description,
:url,
:published,
:enabled
)
测试:
it { expect {
post :create, {:user => attributes_for(:user) }
}.to change(User, :count).by(1) }
控制器方法如下
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: t('.notice') }
else
format.html { render :new }
end
end
end
def object_params
Rails.logger.info params
params.require(:user).permit(
:description,
:url,
:published,
:enabled
)
end
日志显示
{"user"=>{"url"=>"http://example.com"}, "controller"=>"users", "action"=>"create"}
清楚地显示了"用户" param 不缺失或为空。
我看不出为什么这个测试失败了?我疯了,还是我错过了一些明显的东西?