Sha256: abc4e7bac0de53178a01b102b2687cbd7601bbd891f16e0ba03620e6ad3a7b63

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'test_helper'

ActiveRecord::Schema.define do
  create_table :messages, :force => true do |t|
    t.string :title
    t.string :description
  end
end

class Message < ActiveRecord::Base
  validates_decency_of :title, :description
end

class TestValidatesDecencyOf < Test::Unit::TestCase
  def setup
    @decent = Message.new :title => 'Hello world', :description => 'I am clean'
    @indecent = Message.new :title => 'Hello f*u*c*k*i*n*g world', :description => 'I am ~-S-h-I-t-T-y-~'
  end

  def test_should_not_die_on_empty_strings
    @decent.description = nil
    assert @decent.valid?
  end
  
  def test_should_allow_decent_strings
    assert @decent.valid?
  end
  
  def test_should_disallow_indecent_strings
    assert_equal false, @indecent.valid?
    if ActiveRecord::VERSION::MAJOR == 2
      assert @indecent.errors.on(:title).present?
      assert @indecent.errors.on(:description).present?
    elsif ActiveRecord::VERSION::MAJOR == 3
      assert @indecent.errors[:title].present?
      assert @indecent.errors[:description].present?
    else
      raise "don't know what to do"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_decency_of-1.5.1 test/test_validates_decency_of.rb