Sha256: cd6fd5779c42a3962a43431f0e36390129b16b08aaf1d23dac15d0437eabcfac

Contents?: true

Size: 1.72 KB

Versions: 22

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do

  context "a numeric attribute" do
    before do
      define_model :example, :attr => :string do
        validates_numericality_of :attr
      end
      @model = Example.new
    end

    it "should only allow numeric values for that attribute" do
      @model.should validate_numericality_of(:attr)
    end

    it "should not override the default message with a blank" do
      @model.should validate_numericality_of(:attr).with_message(nil)
    end
  end

  context "a numeric attribute which must be integer" do
    before do
      define_model :example, :attr => :string do
          validates_numericality_of :attr, { :only_integer => true }
      end
      @model = Example.new
    end

    it "should only allow integer values for that attribute" do
      @model.should validate_numericality_of(:attr).only_integer
    end
  end

  context "a numeric attribute with a custom validation message" do
    before do
      define_model :example, :attr => :string do
        validates_numericality_of :attr, :message => 'custom'
      end
      @model = Example.new
    end

    it "should only allow numeric values for that attribute with that message" do
      @model.should validate_numericality_of(:attr).with_message(/custom/)
    end

    it "should not allow numeric values for that attribute with another message" do
      @model.should_not validate_numericality_of(:attr)
    end
  end

  context "a non-numeric attribute" do
    before do
      @model = define_model(:example, :attr => :string).new
    end

    it "should not only allow numeric values for that attribute" do
      @model.should_not validate_numericality_of(:attr)
    end
  end

end

Version data entries

22 entries across 14 versions & 3 rubygems

Version Path
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.4.1/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.4.1/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.4.1/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
shoulda-matchers-1.4.1 spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
shoulda-matchers-1.4.0 spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.8.1 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.8.0.pre vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
shoulda-matchers-1.3.0 spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.7.1 vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.7.0 vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.7.0.pre2 vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
challah-0.7.0.pre vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb