recent_content_block_test.rb
2.3 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
require File.dirname(__FILE__) + '/../test_helper'
class RecentContentBlockTest < ActiveSupport::TestCase
INVALID_KIND_OF_ARTICLE = [EnterpriseHomepage, RssFeed, UploadedFile, Gallery, Folder, Blog, Forum]
VALID_KIND_OF_ARTICLE = [RawHTMLArticle, TextArticle, TextileArticle, TinyMceArticle]
should 'describe itself' do
assert_not_equal Block.description, RecentContentBlock.description
end
should 'is editable' do
block = RecentContentBlock.new
assert block.editable?
end
should 'blog_picture be false by default' do
block = RecentContentBlock.new
assert !block.show_blog_picture
end
should 'blog_picture is being stored and restored from database as true' do
block = RecentContentBlock.new
block.show_blog_picture = true
block.save
block.reload
assert block.show_blog_picture
end
should 'blog_picture is being stored and restored from database as false' do
block = RecentContentBlock.new
block.show_blog_picture = false
block.save
block.reload
assert !block.show_blog_picture
end
should 'root be nil for new blocks' do
block = RecentContentBlock.new
assert block.root.nil?
end
should 'root be a Blog when it is configured for' do
profile = create_user('testuser').person
root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
block = RecentContentBlock.new
block.stubs(:holder).returns(profile)
block.selected_folder = root.id
assert block.root.id == root.id
end
should 'return last articles inside a folder' do
profile = create_user('testuser').person
Article.delete_all
root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
a1 = fast_create(TextileArticle, :name => 'article #1', :profile_id => profile.id, :parent_id => root.id, :created_at => Time.now - 2.days)
a2 = fast_create(TextileArticle, :name => 'article #2', :profile_id => profile.id, :parent_id => root.id, :created_at => Time.now - 1.days)
a3 = fast_create(TextileArticle, :name => 'article #3', :profile_id => profile.id, :parent_id => root.id, :created_at => Time.now)
block = RecentContentBlock.new
block.stubs(:holder).returns(profile)
assert block.articles_of_folder(root,2) == [a3, a2]
assert block.articles_of_folder(root,3) == [a3, a2, a1]
end
end