I am trying to validate on the model that my salary
attr, an integer value, fits within a range, despite the value indeed fitting within that range, it fails with salary: ["is not included in the list"]
, any ideas what I'm missing:
model.rb
validates_inclusion_of :salary, :in => [1000..1000000]
passing specs:
it { should validate_presence_of(:salary) }
it { should_not allow_value(100).for(:salary) }
it { should_not allow_value(10000000).for(:salary) }
failing spec:
it { should allow_value(900000).for(:salary) }
900000 is within 1000..1000000 so any ideas why this still fails?
Thanks
You are providing a range as the only valid value for the salary, which is not what you want. Using the following will do:
validates_inclusion_of :salary, :in => 1000..1000000