Commit 474d51ba70da4cb2c5619ba8e94dd94a9b69ce0b
Exists in
staging
and in
42 other branches
Merge branches 'ActionItem2748' and 'ActionItem2748_merge' into ActionItem2748_merge
Showing
11 changed files
with
161 additions
and
19 deletions
Show diff stats
plugins/comment_group/controllers/profile/comment_group_plugin_profile_controller.rb
plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb
plugins/comment_group/lib/ext/article.rb
... | ... | @@ -2,13 +2,10 @@ require_dependency 'article' |
2 | 2 | |
3 | 3 | class Article |
4 | 4 | |
5 | - #FIXME make this test | |
6 | 5 | has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL'] |
7 | 6 | |
8 | - #FIXME make this test | |
9 | 7 | validate :not_empty_group_comments_removed |
10 | 8 | |
11 | - #FIXME make this test | |
12 | 9 | def not_empty_group_comments_removed |
13 | 10 | if body |
14 | 11 | groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq | ... | ... |
plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | 2 | require File.dirname(__FILE__) + '/../../controllers/profile/comment_group_plugin_profile_controller' |
3 | 3 | |
4 | 4 | # Re-raise errors caught by the controller. |
... | ... | @@ -21,25 +21,25 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase |
21 | 21 | should 'be able to show group comments' do |
22 | 22 | comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) |
23 | 23 | xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 |
24 | - assert_template 'comment/_comment.rhtml' | |
24 | + assert_template 'comment_group_plugin_profile/view_comments.rjs' | |
25 | 25 | assert_match /comments_list_group_0/, @response.body |
26 | 26 | assert_match /\"comment-count-0\", \"1\"/, @response.body |
27 | 27 | end |
28 | 28 | |
29 | 29 | should 'do not show global comments' do |
30 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil) | |
31 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
30 | + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil) | |
31 | + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
32 | 32 | xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 |
33 | - assert_template 'comment/_comment.rhtml' | |
33 | + assert_template 'comment_group_plugin_profile/view_comments.rjs' | |
34 | 34 | assert_match /comments_list_group_0/, @response.body |
35 | 35 | assert_match /\"comment-count-0\", \"1\"/, @response.body |
36 | 36 | end |
37 | 37 | |
38 | 38 | should 'show first page comments only' do |
39 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 1', :group_id => 0) | |
40 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 2', :group_id => 0) | |
41 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 3', :group_id => 0) | |
42 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :group_id => 0) | |
39 | + comment1 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'secondpage', :group_id => 0) | |
40 | + comment2 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 1', :group_id => 0) | |
41 | + comment3 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 2', :group_id => 0) | |
42 | + comment4 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 3', :group_id => 0) | |
43 | 43 | xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 |
44 | 44 | assert_match /firstpage 1/, @response.body |
45 | 45 | assert_match /firstpage 2/, @response.body | ... | ... |
plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb
plugins/comment_group/test/functional/content_viewer_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,28 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ContentViewerController | |
4 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
5 | + def rescue_action(e) | |
6 | + raise e | |
7 | + end | |
8 | +end | |
9 | + | |
10 | +class ContentViewerControllerTest < ActionController::TestCase | |
11 | + | |
12 | + def setup | |
13 | + @profile = fast_create(Community) | |
14 | + @page = fast_create(Article, :profile_id => @profile.id, :body => "<div class=\"macro\" data-macro-group_id=\"1\" data-macro='comment_group_plugin/allow_comment' ></div>") | |
15 | + @environment = Environment.default | |
16 | + @environment.enable_plugin(CommentGroupPlugin) | |
17 | + end | |
18 | + | |
19 | + attr_reader :page | |
20 | + | |
21 | + should 'parse article body and render comment group view' do | |
22 | + comment1 = fast_create(Comment, :group_id => 1, :source_id => page.id) | |
23 | + get :view_page, @page.url | |
24 | + assert_tag 'div', :attributes => {:class => 'comment_group_1'} | |
25 | + assert_tag 'div', :attributes => {:id => 'comments_group_count_1'} | |
26 | + end | |
27 | + | |
28 | +end | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class AllowCommentTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @macro = CommentGroupPlugin::AllowComment.new | |
7 | + end | |
8 | + | |
9 | + attr_reader :macro | |
10 | + | |
11 | + should 'have a configuration' do | |
12 | + assert CommentGroupPlugin::AllowComment.configuration | |
13 | + end | |
14 | + | |
15 | + should 'parse contents to include comment group view' do | |
16 | + profile = fast_create(Community) | |
17 | + article = fast_create(Article, :profile_id => profile.id) | |
18 | + comment = fast_create(Comment, :group_id => 1, :source_id => article.id) | |
19 | + inner_html = 'inner' | |
20 | + content = macro.parse({:group_id => comment.group_id}, inner_html, article) | |
21 | + | |
22 | + expects(:render).with({:partial => 'plugins/comment_group/views/comment_group.rhtml', :locals => {:group_id => comment.group_id, :article_id => article.id, :inner_html => inner_html, :count => 1, :profile_identifier => profile.identifier} }) | |
23 | + instance_eval(&content) | |
24 | + end | |
25 | + | |
26 | +end | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ArticleTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + profile = fast_create(Community) | |
7 | + @article = fast_create(Article, :profile_id => profile.id) | |
8 | + end | |
9 | + | |
10 | + attr_reader :article | |
11 | + | |
12 | + should 'return group comments from article' do | |
13 | + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) | |
14 | + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id) | |
15 | + assert_equal [comment1], article.group_comments | |
16 | + end | |
17 | + | |
18 | + should 'do not allow a exclusion of a group comment macro if this group has comments' do | |
19 | + article.update_attribute(:body, "<div class=\"macro\" data-macro-group_id=2></div>") | |
20 | + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) | |
21 | + assert !article.save | |
22 | + assert_equal 'Not empty group comment cannot be removed', article.errors[:base] | |
23 | + end | |
24 | + | |
25 | + should 'allow save if comment group macro is not removed for group with comments' do | |
26 | + article.update_attribute(:body, "<div class=\"macro\" data-macro-group_id=1></div>") | |
27 | + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) | |
28 | + assert article.save | |
29 | + end | |
30 | + | |
31 | +end | ... | ... |
plugins/comment_group/test/unit/comment_group_plugin_test.rb
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | 2 | |
3 | 3 | class CommentGroupPluginTest < ActiveSupport::TestCase |
4 | 4 | |
5 | - include Noosfero::Plugin::HotSpot | |
6 | - | |
7 | 5 | def setup |
8 | 6 | @environment = Environment.default |
7 | + @plugin = CommentGroupPlugin.new | |
8 | + end | |
9 | + | |
10 | + attr_reader :environment, :plugin | |
11 | + | |
12 | + should 'have a name' do | |
13 | + assert_not_equal Noosfero::Plugin.plugin_name, CommentGroupPlugin::plugin_name | |
14 | + end | |
15 | + | |
16 | + should 'describe yourself' do | |
17 | + assert_not_equal Noosfero::Plugin.plugin_description, CommentGroupPlugin::plugin_description | |
18 | + end | |
19 | + | |
20 | + should 'have a js file' do | |
21 | + assert !plugin.js_files.blank? | |
9 | 22 | end |
10 | 23 | |
11 | - attr_reader :environment | |
24 | + should 'have stylesheet' do | |
25 | + assert plugin.stylesheet? | |
26 | + end | |
27 | + | |
28 | + should 'have extra contents for comment form' do | |
29 | + comment = fast_create(Comment, :group_id => 1) | |
30 | + content = plugin.comment_form_extra_contents({:comment => comment}) | |
31 | + expects(:hidden_field_tag).with('comment[group_id]', comment.group_id).once | |
32 | + instance_eval(&content) | |
33 | + end | |
34 | + | |
35 | + should 'do not have extra contents for comments without group' do | |
36 | + comment = fast_create(Comment, :group_id => nil) | |
37 | + content = plugin.comment_form_extra_contents({:comment => comment}) | |
38 | + assert_equal nil, instance_eval(&content) | |
39 | + end | |
40 | + | |
41 | + should 'call without_group for scope passed as parameter to unavailable_comments' do | |
42 | + article = fast_create(Article) | |
43 | + article.expects(:without_group).once | |
44 | + plugin.unavailable_comments(article) | |
45 | + end | |
12 | 46 | |
13 | 47 | #FIXME Obsolete test |
14 | 48 | # | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class CommentTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + profile = fast_create(Community) | |
7 | + @article = fast_create(Article, :profile_id => profile.id) | |
8 | + end | |
9 | + | |
10 | + attr_reader :article | |
11 | + | |
12 | + should 'return comments that belongs to a specified group' do | |
13 | + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) | |
14 | + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id) | |
15 | + comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id) | |
16 | + assert_equal [comment1], article.comments.in_group(1) | |
17 | + end | |
18 | + | |
19 | + should 'return comments that do not belongs to any group' do | |
20 | + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) | |
21 | + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id) | |
22 | + comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id) | |
23 | + assert_equal [comment2], article.comments.without_group | |
24 | + end | |
25 | + | |
26 | +end | ... | ... |