1 require File.dirname(__FILE__) + '/../test_helper'
3 class SnippetTest < Test::Unit::TestCase
5 test_helper :snippets, :validations
7 # Replace this with your real tests.
9 assert_kind_of Snippet, snippets(:first)
13 @snippet = @model = Snippet.new(VALID_SNIPPET_PARAMS)
16 def test_validates_length_of
20 }.each do |field, max|
21 assert_invalid field, ('%d-character limit' % max), 'x' * (max + 1)
22 assert_valid field, 'x' * max
26 def test_validates_presence_of
27 [:name].each do |field|
28 assert_invalid field, 'required', '', ' ', nil
32 def test_validates_uniqueness_of
33 assert_invalid :name, 'name already in use', 'first', 'another', 'markdown'
34 assert_valid :name, 'just-a-test'
37 def test_validates_format_of_name
38 assert_valid :name, 'abc', 'abcd-efg', 'abcd_efg', 'abc.html', '/', '123'
39 assert_invalid :name, 'cannot contain spaces or tabs'
43 @snippet = snippets(:markdown)
44 assert_kind_of MarkdownFilter, @snippet.filter