Permalink
Browse files

Wrote more tests

  • Loading branch information...
1 parent efb706e commit e7682b0dc4aa90f146522113bf2543ff430944a0 @cyrilpic committed May 28, 2012
@@ -0,0 +1,5 @@
+require 'fixtures/simple_model'
+class AlphaNumModel < SimpleModel
+ attributes :attri
+ validates :attri, alpha_numericality: true
+end
@@ -0,0 +1,5 @@
+require 'fixtures/simple_model'
+class SlugModel < SimpleModel
+ attributes :slug
+ validates :slug, slug: true
+end
@@ -1,4 +0,0 @@
-require 'fixtures/simple_model'
-class StringModel < SimpleModel
- attributes :string
-end
@@ -0,0 +1,7 @@
+require 'fixtures/simple_model'
+class WordCountModel < SimpleModel
+ attributes :minmax
+ validates :minmax, word_count: { maximum: 10, minimum: 5 }
+ attributes :exact
+ validates :exact, word_count: { is: 5 }
+end
@@ -0,0 +1,18 @@
+require 'helper'
+require 'fixtures/alpha_num_model'
+
+class TestAlphaNumericalityValidator < Test::Unit::TestCase
+ include ActiveModel::Lint::Tests
+ def setup
+ @model = AlphaNumModel.new
+ end
+
+ should "only validate alpha numerical values" do
+ model.attri = "Hello world"
+ assert !model.valid?, model.errors[:attri].first
+ model.attri = "hello"
+ assert model.valid?
+ model.attri = "hello45"
+ assert model.valid?
+ end
+end
@@ -1,16 +1,15 @@
require 'helper'
-require 'fixtures/string_model'
+require 'fixtures/slug_model'
class TestSlugValidator < Test::Unit::TestCase
include ActiveModel::Lint::Tests
def setup
- StringModel.validates :string, slug: true
- @model = StringModel.new
+ @model = SlugModel.new
end
should "only accept valid slug" do
- model.string = "This is @ regular sentance !"
+ model.slug = "This is @ regular sentance !"
assert !model.valid?, "Provided a sentance instead of a slug"
- model.string = "This is @ regular sentance !".to_slug
+ model.slug = "This is @ regular sentance !".to_slug
assert model.valid?
end
end
@@ -0,0 +1,39 @@
+require 'helper'
+require 'fixtures/word_count_model'
+
+class TestWordCountValidator < Test::Unit::TestCase
+ include ActiveModel::Lint::Tests
+ def setup
+ @model = WordCountModel.new
+ end
+
+ should "only validate valid input between 5 and 10 words" do
+ text2 = "Hello World"
+ text4 = "Hello World from home."
+ text5 = "Hello World from my home."
+ text11 = "Hello World from my very sweet home in Switzerland, Geneva Lake."
+
+ model.minmax = text5
+ model.exact = text2
+ assert !model.valid?
+
+ model.exact = text11
+ assert !model.valid?
+
+ model.exact = text4
+ assert !model.valid?
+
+ model.exact = text5
+ assert model.valid?
+
+ model.minmax = text2
+ assert !model.valid?
+
+ model.minmax = text4
+ assert !model.valid?
+
+ model.minmax = text11
+ assert !model.valid?
+ end
+
+end

0 comments on commit e7682b0

Please sign in to comment.