Sha256: d5dac7ba16a6041a1eb59a94a9bbdcea9f9f019ff7807ec50f32d9f3f47006cf

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

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

class ValidateNumericalityOfMatcherTest < Test::Unit::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

10 entries across 10 versions & 5 rubygems

Version Path
Flamefork-shoulda-2.10.1 test/matchers/active_record/validate_numericality_of_matcher_test.rb
Flamefork-shoulda-2.10.2 test/matchers/active_record/validate_numericality_of_matcher_test.rb
francois-shoulda-2.10.1 test/matchers/active_record/validate_numericality_of_matcher_test.rb
technicalpickles-shoulda-2.10.0 test/matchers/active_record/validate_numericality_of_matcher_test.rb
thoughtbot-shoulda-2.10.0 test/matchers/active_record/validate_numericality_of_matcher_test.rb
thoughtbot-shoulda-2.10.1 test/matchers/active_record/validate_numericality_of_matcher_test.rb
thoughtbot-shoulda-2.9.2 test/matchers/active_record/validate_numericality_of_matcher_test.rb
shoulda-2.9.2 test/matchers/active_record/validate_numericality_of_matcher_test.rb
shoulda-2.10.0 test/matchers/active_record/validate_numericality_of_matcher_test.rb
shoulda-2.10.1 test/matchers/active_record/validate_numericality_of_matcher_test.rb