Commit a52480d8ab0fa89f4680db5f13ae149c94e641f7

Authored by Rodrigo Souto
1 parent 92c207ee

[macro-support-review] Adding index on article name

@@ -131,6 +131,7 @@ ActiveRecord::Schema.define(:version => 20130606110602) do @@ -131,6 +131,7 @@ ActiveRecord::Schema.define(:version => 20130606110602) do
131 t.integer "license_id" 131 t.integer "license_id"
132 end 132 end
133 133
  134 + add_index "articles", ["name"], :name => "index_articles_on_name"
134 add_index "articles", ["parent_id"], :name => "index_articles_on_parent_id" 135 add_index "articles", ["parent_id"], :name => "index_articles_on_parent_id"
135 add_index "articles", ["profile_id"], :name => "index_articles_on_profile_id" 136 add_index "articles", ["profile_id"], :name => "index_articles_on_profile_id"
136 add_index "articles", ["slug"], :name => "index_articles_on_slug" 137 add_index "articles", ["slug"], :name => "index_articles_on_slug"
lib/noosfero/plugin.rb
@@ -377,7 +377,7 @@ class Noosfero::Plugin @@ -377,7 +377,7 @@ class Noosfero::Plugin
377 def profile_info_extra_contents 377 def profile_info_extra_contents
378 nil 378 nil
379 end 379 end
380 - 380 +
381 # -> Removes the invite friend button from the friends controller 381 # -> Removes the invite friend button from the friends controller
382 # returns = boolean 382 # returns = boolean
383 def remove_invite_friends_button 383 def remove_invite_friends_button
@@ -439,7 +439,7 @@ class Noosfero::Plugin @@ -439,7 +439,7 @@ class Noosfero::Plugin
439 def login_extra_contents 439 def login_extra_contents
440 nil 440 nil
441 end 441 end
442 - 442 +
443 # -> Adds adicional content to comment form 443 # -> Adds adicional content to comment form
444 # returns = lambda block that creates html code 444 # returns = lambda block that creates html code
445 def comment_form_extra_contents(args) 445 def comment_form_extra_contents(args)
plugins/comment_group/controllers/profile/comment_group_plugin_profile_controller.rb
@@ -4,7 +4,7 @@ class CommentGroupPluginProfileController < ProfileController @@ -4,7 +4,7 @@ class CommentGroupPluginProfileController < ProfileController
4 def view_comments 4 def view_comments
5 article_id = params[:article_id] 5 article_id = params[:article_id]
6 group_id = params[:group_id] 6 group_id = params[:group_id]
7 - 7 +
8 article = profile.articles.find(article_id) 8 article = profile.articles.find(article_id)
9 comments = article.group_comments.without_spam.in_group(group_id) 9 comments = article.group_comments.without_spam.in_group(group_id)
10 render :update do |page| 10 render :update do |page|
plugins/comment_group/controllers/public/comment_group_plugin_public_controller.rb
@@ -2,7 +2,7 @@ class CommentGroupPluginPublicController < PublicController @@ -2,7 +2,7 @@ class CommentGroupPluginPublicController < PublicController
2 append_view_path File.join(File.dirname(__FILE__) + '/../views') 2 append_view_path File.join(File.dirname(__FILE__) + '/../views')
3 3
4 def comment_group 4 def comment_group
5 - render :json => { :group_id => Comment.find(params[:id]).group_id } 5 + render :json => { :group_id => Comment.find(params[:id]).group_id }
6 end 6 end
7 7
8 end 8 end
plugins/comment_group/lib/comment_group_plugin/ext/article.rb
@@ -2,13 +2,13 @@ require_dependency 'article' @@ -2,13 +2,13 @@ require_dependency 'article'
2 2
3 class Article 3 class Article
4 4
5 - #FIXME make this test 5 + #FIXME make this test
6 has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL'] 6 has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL']
7 7
8 - #FIXME make this test 8 + #FIXME make this test
9 validate :not_empty_group_comments_removed 9 validate :not_empty_group_comments_removed
10 10
11 - #FIXME make this test 11 + #FIXME make this test
12 def not_empty_group_comments_removed 12 def not_empty_group_comments_removed
13 if body 13 if body
14 groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq 14 groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq
plugins/comment_group/public/comment_group.js
@@ -16,7 +16,7 @@ function makeCommentable() { @@ -16,7 +16,7 @@ function makeCommentable() {
16 //text = start.parent().children(); 16 //text = start.parent().children();
17 text = jQuery('#article_body_ifr').contents().find('*'); 17 text = jQuery('#article_body_ifr').contents().find('*');
18 selection = text.slice(text.index(start), text.index(end)+1); 18 selection = text.slice(text.index(start), text.index(end)+1);
19 - 19 +
20 hasTag = false; 20 hasTag = false;
21 selection.each(function(key, value) { 21 selection.each(function(key, value) {
22 commentTag = jQuery(value).closest('.article_comments'); 22 commentTag = jQuery(value).closest('.article_comments');
plugins/comment_group/public/comment_group_macro.js
@@ -4,7 +4,7 @@ jQuery(document).ready(function($) { @@ -4,7 +4,7 @@ jQuery(document).ready(function($) {
4 if(anchor.length==0) return; 4 if(anchor.length==0) return;
5 5
6 var val = anchor.split('-'); //anchor format = #comment-\d+ 6 var val = anchor.split('-'); //anchor format = #comment-\d+
7 - if(val.length!=2 || val[0]!='#comment') return; 7 + if(val.length!=2 || val[0]!='#comment') return;
8 if($('div[data-macro=comment_group_plugin/allow_comment]').length==0) return; //comment_group_plugin/allow_comment div must exists 8 if($('div[data-macro=comment_group_plugin/allow_comment]').length==0) return; //comment_group_plugin/allow_comment div must exists
9 var comment_id = val[1]; 9 var comment_id = val[1];
10 if(!/^\d+$/.test(comment_id)) return; //test for integer 10 if(!/^\d+$/.test(comment_id)) return; //test for integer
@@ -18,12 +18,12 @@ jQuery(document).ready(function($) { @@ -18,12 +18,12 @@ jQuery(document).ready(function($) {
18 $.scrollTo(button); 18 $.scrollTo(button);
19 } 19 }
20 }); 20 });
21 -}); 21 +});
22 22
23 function toggleGroup(group) { 23 function toggleGroup(group) {
24 var div = jQuery('div.comments_list_toggle_group_'+group); 24 var div = jQuery('div.comments_list_toggle_group_'+group);
25 var visible = div.is(':visible'); 25 var visible = div.is(':visible');
26 - if(!visible) 26 + if(!visible)
27 jQuery('div.comment-group-loading-'+group).addClass('comment-button-loading'); 27 jQuery('div.comment-group-loading-'+group).addClass('comment-button-loading');
28 28
29 div.toggle('fast'); 29 div.toggle('fast');
plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb
@@ -25,7 +25,7 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase @@ -25,7 +25,7 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase
25 assert_match /comments_list_group_0/, @response.body 25 assert_match /comments_list_group_0/, @response.body
26 assert_match /\"comment-count-0\", \"1\"/, @response.body 26 assert_match /\"comment-count-0\", \"1\"/, @response.body
27 end 27 end
28 - 28 +
29 should 'do not show global comments' do 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) 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) 31 comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
@@ -34,5 +34,5 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase @@ -34,5 +34,5 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase
34 assert_match /comments_list_group_0/, @response.body 34 assert_match /comments_list_group_0/, @response.body
35 assert_match /\"comment-count-0\", \"1\"/, @response.body 35 assert_match /\"comment-count-0\", \"1\"/, @response.body
36 end 36 end
37 - 37 +
38 end 38 end
plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb
@@ -20,14 +20,14 @@ class CommentGroupPluginPublicControllerTest < ActionController::TestCase @@ -20,14 +20,14 @@ class CommentGroupPluginPublicControllerTest < ActionController::TestCase
20 20
21 should 'be able to return group_id for a comment' do 21 should 'be able to return group_id for a comment' do
22 comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) 22 comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
23 - xhr :get, :comment_group, :id => comment.id 23 + xhr :get, :comment_group, :id => comment.id
24 assert_match /\{\"group_id\":0\}/, @response.body 24 assert_match /\{\"group_id\":0\}/, @response.body
25 end 25 end
26 - 26 +
27 should 'return group_id=null for a global comment' do 27 should 'return group_id=null for a global comment' do
28 comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) 28 comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' )
29 - xhr :get, :comment_group, :id => comment.id 29 + xhr :get, :comment_group, :id => comment.id
30 assert_match /\{\"group_id\":null\}/, @response.body 30 assert_match /\{\"group_id\":null\}/, @response.body
31 end 31 end
32 - 32 +
33 end 33 end
plugins/comment_group/test/unit/comment_group_plugin_test.rb
@@ -7,7 +7,7 @@ class CommentGroupPluginTest < ActiveSupport::TestCase @@ -7,7 +7,7 @@ class CommentGroupPluginTest < ActiveSupport::TestCase
7 def setup 7 def setup
8 @environment = Environment.default 8 @environment = Environment.default
9 end 9 end
10 - 10 +
11 attr_reader :environment 11 attr_reader :environment
12 12
13 should 'load_comments returns all the comments wihout group of an article passed as parameter' do 13 should 'load_comments returns all the comments wihout group of an article passed as parameter' do
@@ -20,7 +20,7 @@ class CommentGroupPluginTest < ActiveSupport::TestCase @@ -20,7 +20,7 @@ class CommentGroupPluginTest < ActiveSupport::TestCase
20 assert_equal [], [c2, c3] - plugin.load_comments(article) 20 assert_equal [], [c2, c3] - plugin.load_comments(article)
21 assert_equal [], plugin.load_comments(article) - [c2, c3] 21 assert_equal [], plugin.load_comments(article) - [c2, c3]
22 end 22 end
23 - 23 +
24 should 'load_comments not returns spam comments' do 24 should 'load_comments not returns spam comments' do
25 article = fast_create(Article) 25 article = fast_create(Article)
26 c1 = fast_create(Comment, :source_id => article.id, :group_id => 1) 26 c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)
@@ -31,7 +31,7 @@ class CommentGroupPluginTest < ActiveSupport::TestCase @@ -31,7 +31,7 @@ class CommentGroupPluginTest < ActiveSupport::TestCase
31 assert_equal [], [c2] - plugin.load_comments(article) 31 assert_equal [], [c2] - plugin.load_comments(article)
32 assert_equal [], plugin.load_comments(article) - [c2] 32 assert_equal [], plugin.load_comments(article) - [c2]
33 end 33 end
34 - 34 +
35 should 'load_comments returns only root comments of article' do 35 should 'load_comments returns only root comments of article' do
36 article = fast_create(Article) 36 article = fast_create(Article)
37 c1 = fast_create(Comment, :source_id => article.id, :group_id => 1) 37 c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)
@@ -42,5 +42,5 @@ class CommentGroupPluginTest < ActiveSupport::TestCase @@ -42,5 +42,5 @@ class CommentGroupPluginTest < ActiveSupport::TestCase
42 assert_equal [], [c2] - plugin.load_comments(article) 42 assert_equal [], [c2] - plugin.load_comments(article)
43 assert_equal [], plugin.load_comments(article) - [c2] 43 assert_equal [], plugin.load_comments(article) - [c2]
44 end 44 end
45 - 45 +
46 end 46 end
test/unit/application_helper_test.rb
@@ -694,7 +694,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase @@ -694,7 +694,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase
694 <div data-macro='unexistent' class='failed-macro unexistent'>Unsupported macro unexistent!</div> 694 <div data-macro='unexistent' class='failed-macro unexistent'>Unsupported macro unexistent!</div>
695 ").search('div') 695 ").search('div')
696 696
697 - # comparing div attributes between parsed and expected html 697 + # comparing div attributes between parsed and expected html
698 parsed_divs.each_with_index do |div, i| 698 parsed_divs.each_with_index do |div, i|
699 assert_equal expected_divs[i].attributes.to_hash, div.attributes.to_hash 699 assert_equal expected_divs[i].attributes.to_hash, div.attributes.to_hash
700 assert_equal expected_divs[i].inner_text, div.inner_text 700 assert_equal expected_divs[i].inner_text, div.inner_text
test/unit/comment_test.rb
@@ -711,7 +711,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -711,7 +711,7 @@ class CommentTest &lt; ActiveSupport::TestCase
711 c2 = create_comment 711 c2 = create_comment
712 comments.push(c2) 712 comments.push(c2)
713 create_comment(:reply_of_id => c2.id) 713 create_comment(:reply_of_id => c2.id)
714 - 714 +
715 assert_equal 6, Comment.count_thread(comments) 715 assert_equal 6, Comment.count_thread(comments)
716 end 716 end
717 717
test/unit/macros_helper_test.rb
@@ -104,7 +104,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase @@ -104,7 +104,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase
104 104
105 assert_equal "<script src=\"#{Plugin1.public_path('macro.js')}\" type=\"text/javascript\"></script>", include_macro_js_files 105 assert_equal "<script src=\"#{Plugin1.public_path('macro.js')}\" type=\"text/javascript\"></script>", include_macro_js_files
106 end 106 end
107 - 107 +
108 should 'get macro css files' do 108 should 'get macro css files' do
109 class Plugin1::Macro < Noosfero::Plugin::Macro 109 class Plugin1::Macro < Noosfero::Plugin::Macro
110 def self.configuration 110 def self.configuration
@@ -118,7 +118,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase @@ -118,7 +118,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase
118 118
119 assert_equal Plugin1.public_path('macro.css'), macro_css_files 119 assert_equal Plugin1.public_path('macro.css'), macro_css_files
120 end 120 end
121 - 121 +
122 should 'get macro specific generator' do 122 should 'get macro specific generator' do
123 class Plugin1::Macro < Noosfero::Plugin::Macro 123 class Plugin1::Macro < Noosfero::Plugin::Macro
124 def self.configuration 124 def self.configuration