Sha256: 4f9a631e732a832688ff6feb665b8b7b2bfd82c68295979599cb6ef5ac622391
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
require 'test_helper' class ModelTest < MiniTest::Unit::TestCase class TestModel attr_accessor :body, :subject, :blurb include ActiveModel::Validations validates :body, :subject, not_shouting: {threshold: 0.1} end class TestModelNoThreshold attr_accessor :body, :subject, :blurb include ActiveModel::Validations validates :body, :subject, not_shouting: true end def test_validates_nil m = TestModel.new assert(m.valid?) end def test_validates_shouting m = TestModel.new m.body = "THIS IS SHOUTING AND SHOULD NOT BE OK" m.subject = "THIS IS NOT OK" assert !m.valid? assert m.errors[:body].present? assert m.errors[:subject].present? end def test_validates_with_threshold m = TestModel.new m.subject = "This is actually ok" # < 10% assert m.valid? m = TestModel.new m.subject = "THIs is actually ok" # > 10% assert !m.valid? end def test_without_threshold m = TestModelNoThreshold.new m.body = "ABCabc" # 50% ok assert(m.valid?) m.body = "ABCDabc" # >50% not ok assert(!m.valid?) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_not_shouting-0.0.1 | test/model_test.rb |