Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to validate numericality strictly #613

Closed
betesh opened this issue Nov 11, 2014 · 2 comments
Closed

how to validate numericality strictly #613

betesh opened this issue Nov 11, 2014 · 2 comments

Comments

@betesh
Copy link
Contributor

betesh commented Nov 11, 2014

require "active_model"
require "shoulda-matchers"

class Car
  include ActiveModel::Validations
  attr_accessor :wheels, :windows
  validates_numericality_of :wheels, strict: true
  validates_numericality_of :windows
  def self.instance
    instance = new
    instance.windows = 4
    instance.wheels = 4
    instance
  end
end

describe Car do
  subject { Car.instance }
  it { should validate_numericality_of(:windows) }
  it { should validate_numericality_of(:wheels).strict }
end

Turns out this feature is not supported.

.F

Failures:
  1) Car 
    Failure/Error: it { should validate_numericality_of(:wheels).strict }
    NoMethodError:
      undefined method `strict' for #<Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher:0x00000002e14748>
    # ./car_spec.rb:20:in `block (2 levels) in <top (required)>'

Finished in 0.02826 seconds (files took 0.16763 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./car_spec.rb:20 # Car 
@mcmire
Copy link
Collaborator

mcmire commented Nov 18, 2014

Thank you for pointing this out. I don't know when I can address this but I will keep this here until I do so.

@mcmire
Copy link
Collaborator

mcmire commented Apr 3, 2015

Fixed in 4e4c546. It'll go out in the next release. Cheers!

@mcmire mcmire closed this as completed Apr 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants