comment_paragraph_plugin_test.rb
2.27 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
require_relative '../test_helper'
include ActionView::Helpers::FormTagHelper
class CommentParagraphPluginTest < ActiveSupport::TestCase
def setup
@environment = Environment.default
@plugin = CommentParagraphPlugin.new
@user = create_user('testuser').person
end
attr_reader :environment, :plugin, :user
should 'have a name' do
assert_not_equal Noosfero::Plugin.plugin_name, CommentParagraphPlugin::plugin_name
end
should 'describe yourself' do
assert_not_equal Noosfero::Plugin.plugin_description, CommentParagraphPlugin::plugin_description
end
should 'have a js file' do
assert !plugin.js_files.blank?
end
should 'have stylesheet' do
assert plugin.stylesheet?
end
should 'not add comment_paragraph_selected_area if comment_paragraph_selected_area is blank' do
comment = Comment.new
comment.comment_paragraph_selected_area = ""
comment.paragraph_uuid = 2
cpp = CommentParagraphPlugin.new
prok = cpp.comment_form_extra_contents({:comment=>comment, :paragraph_uuid=>4})
assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect)
end
should 'display button to toggle comment paragraph for users which can edit the article' do
profile = fast_create(Profile)
article = fast_create(Article, :profile_id => profile.id)
article.expects(:comment_paragraph_plugin_enabled?).returns(true)
article.expects(:allow_edit?).with(user).returns(true)
content = plugin.article_toolbar_actions(article)
expects(:button).once
instance_eval(&content)
end
should 'not display button to toggle comment paragraph for users which can not edit the article' do
profile = fast_create(Profile)
article = fast_create(Article, :profile_id => profile.id)
article.expects(:comment_paragraph_plugin_enabled?).returns(true)
article.expects(:allow_edit?).with(user).returns(false)
content = plugin.article_toolbar_actions(article)
assert_equal nil, instance_eval(&content)
end
should 'not display button to toggle comment paragraph if plugin is not enabled' do
profile = fast_create(Profile)
article = fast_create(Article, :profile_id => profile.id)
article.expects(:comment_paragraph_plugin_enabled?).returns(false)
assert_equal nil, plugin.article_toolbar_actions(article)
end
end