Sha256: 656c5ded7217a1956d583b6389cfdb3a8a97375195795c599b1ac7d64217689d

Contents?: true

Size: 1.48 KB

Versions: 39

Compression:

Stored size: 1.48 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class ValidateNumericalityOfMatcherTest < ActiveSupport::TestCase # :nodoc:

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

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

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

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

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

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

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

    should "not only allow numeric values for that attribute" do
      assert_rejects validate_numericality_of(:attr), @model
    end
  end

end

Version data entries

39 entries across 39 versions & 11 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.1 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.10 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.11 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.12 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.13 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.14 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.15 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.16 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.17 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.2 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.3 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.4 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.5 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.6 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.7 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
auser-poolparty-1.3.8 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
fairchild-poolparty-1.3.17 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
fairchild-poolparty-1.3.5 vendor/gems/shoulda/test/matchers/active_record/validate_numericality_of_matcher_test.rb
iGEL-shoulda-2.10.2 test/matchers/active_record/validate_numericality_of_matcher_test.rb