我正在关注 Railstutorial.org 并在使用 Rspec 时出现 MassAssignment 错误。
10) User when email format is invalid should be invalid
Failure/Error: @user = User.new(name:"Example", email:"example@gmail.com",
ActiveModel::MassAssignmentSecurity::Error:
Can't mass-assign protected attributes: password, password_confirmation
可能是因为我尝试在 RSpec 中分配变量之前:
...
before do
@user = User.new(name:"Example", email:"example@gmail.com",
password: "foobar", password_confirmation: "foobar" )
end
subject { @user }
...
是否可以在开发或测试模式下禁用 MassAssignment 保护?或者当 RSpec 运行时?任何帮助都会很棒!谢谢