article_block_test.rb
2.11 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
82
83
84
require File.dirname(__FILE__) + '/../test_helper'
class ArticleBlockTest < Test::Unit::TestCase
should 'describe itself' do
assert_not_equal Block.description, ArticleBlock.description
end
should "take article's content" do
block = ArticleBlock.new
html = mock
article = mock
article.expects(:to_html).returns(html)
block.stubs(:article).returns(article)
assert_same html, block.content
end
should 'refer to an article' do
profile = create_user('testuser').person
article = profile.articles.build(:name => 'test article')
article.save!
block = ArticleBlock.new
block.article = article
block.save!
assert_equal article, Block.find(block.id).article
end
should 'not crash when referenced article is removed' do
person = create_user('testuser').person
a = person.articles.create!(:name => 'test')
block = ArticleBlock.create(:article => a)
person.boxes.first.blocks << block
block.save!
a.destroy
block.reload
assert_nil block.article
end
should 'nullify reference to unexisting article' do
Article.delete_all
block = ArticleBlock.new
block.article_id = 999
block.article
assert_nil block.article_id
end
should "take available articles with a person as the box owner" do
person = create_user('testuser').person
person.articles.delete_all
assert_equal [], person.articles
a = person.articles.create!(:name => 'test')
block = ArticleBlock.create(:article => a)
person.boxes.first.blocks << block
block.save!
block.reload
assert_equal [a],block.available_articles
end
should "take available articles with an environment as the box owner" do
env = Environment.create!(:name => 'test env')
env.articles.destroy_all
assert_equal [], env.articles
community = fast_create(Community)
a = community.articles.create!(:name => 'test')
env.portal_community=community
env.save
block = ArticleBlock.create(:article => a)
env.boxes.first.blocks << block
block.save!
block.reload
assert_equal [a],block.available_articles
end
end