article_test.rb
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require File.dirname(__FILE__) + '/../test_helper'
class ArticleTest < Test::Unit::TestCase
def setup
@profile = create_user('testing').person
end
attr_reader :profile
should 'have and require an associated profile' do
a = Article.new
a.valid?
assert a.errors.invalid?(:profile_id)
a.profile = profile
a.valid?
assert !a.errors.invalid?(:profile_id)
end
should 'require values for name, slug and path' do
a = Article.new
a.valid?
assert a.errors.invalid?(:name)
assert a.errors.invalid?(:slug)
assert a.errors.invalid?(:path)
a.name = 'my article'
a.valid?
assert !a.errors.invalid?(:name)
assert !a.errors.invalid?(:name)
assert !a.errors.invalid?(:path)
end
should 'act as versioned' do
a = Article.create!(:name => 'my article', :body => 'my text', :profile_id => profile.id)
assert_equal 1, a.versions(true).size
a.name = 'some other name'
a.save!
assert_equal 2, a.versions(true).size
end
should 'act as taggable' do
a = Article.create!(:name => 'my article', :profile_id => profile.id)
a.tag_list = ['one', 'two']
tags = a.tag_list.names
assert tags.include?('one')
assert tags.include?('two')
end
should 'act as filesystem' do
a = Article.create!(:name => 'my article', :profile_id => profile.id)
b = a.children.build(:name => 'child article', :profile_id => profile.id)
b.save!
assert_equal 'my-article/child-article', b.path
a.name = 'another name'
a.save!
assert_equal 'another-name/child-article', Article.find(b.id).path
end
should 'provide HTML version' do
profile = create_user('testinguser').person
a = Article.create!(:name => 'my article', :profile_id => profile.id)
a.expects(:body).returns('the body of the article')
assert_equal 'the body of the article', a.to_html
end
should 'inform the icon to be used' do
assert_equal 'text-html', Article.new.icon_name
end
should 'provide a (translatable) description' do
result = 'the description'
a = Article.new
a.expects(:_).returns(result)
assert_same result, a.mime_type_description
end
end