为什么这个validates_inclusion_of范围内的整数失败



我正在尝试在模型上验证我的salary attr(整数值(是否适合某个范围,尽管该值确实适合该范围,但它失败了salary: ["is not included in the list"],我缺少的任何想法:

模型.rb

validates_inclusion_of :salary, :in => [1000..1000000]

通过规格:

it { should validate_presence_of(:salary) }
it { should_not allow_value(100).for(:salary) }
it { should_not allow_value(10000000).for(:salary) }

未通过规范:

it { should allow_value(900000).for(:salary) }
900000

在 1000..1000000 以内,所以有什么想法为什么仍然失败吗?

谢谢

您提供的范围作为工资的唯一有效值,这不是您想要的。使用以下内容即可:

validates_inclusion_of :salary, :in => 1000..1000000

最新更新