Sha256: b874675d0e5a78410e8a403e41dce7c3c756f392d19430f597b7d644395e5678

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'test_helper'

class ModelTest < MiniTest::Unit::TestCase

  class TestModel
    attr_accessor :body, :subject
    include ActiveModel::Validations

    validates :body, :subject, potty_mouth: true
  end

  class CustomList
    attr_accessor :body, :subject
    include ActiveModel::Validations

    validates :body, :subject, potty_mouth: {list: :custom}
  end

  class MissingList
    attr_accessor :body, :subject
    include ActiveModel::Validations

    validates :body, :subject, potty_mouth: {list: :missing}
  end

  PottyMouthValidator.add_word_list(:custom, File.expand_path("../custom_list.txt", __FILE__))

  def test_validates
    m = TestModel.new
    m.subject = "what the fuck?"
    m.body = "what the fuck is this?"
    assert !m.valid?

    assert m.errors[:subject].present?
    assert m.errors[:body].present?
  end

  def test_capitalization
    m = TestModel.new
    m.subject = "Fuck that"
    m.body = "what the fuck is this?"
    assert !m.valid?

    assert m.errors[:subject].present?
    assert m.errors[:body].present?
  end

  def test_custom_list
    m = CustomList.new
    m.subject = "what the fuck?"
    m.body = "foobar blah"
    assert !m.valid?

    assert m.errors[:subject].empty?
    assert m.errors[:body].present?
  end

  def test_missing_list
    m = MissingList.new
    m.subject = "what the fuck?"
    m.body = "foobar blah"
    assert m.valid?

    assert m.errors[:subject].empty?
    assert m.errors[:body].empty?
  end

  def test_stemming
    m = TestModel.new
    m.subject = "what about word stemming?  can I say fucker or fucking or fucked?"
    assert !m.valid?

    assert m.errors[:subject].present?
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_potty_mouth-0.1.0 test/model_test.rb