diff --git a/app/models/article.rb b/app/models/article.rb index 033af35..32f72da 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -469,10 +469,6 @@ class Article < ActiveRecord::Base allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile) end - def comments_updated - solr_save - end - def accept_category?(cat) !cat.is_a?(ProductCategory) end diff --git a/app/models/category.rb b/app/models/category.rb index 874f560..8647cfd 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -106,7 +106,6 @@ class Category < ActiveRecord::Base # ordered/query-boosted fields {:name_sortable => :string}, ] - after_save_reindex [:articles, :profiles], :with => :delayed_job handle_asynchronously :solr_save end diff --git a/app/models/certifier.rb b/app/models/certifier.rb index a5e0974..1db7984 100644 --- a/app/models/certifier.rb +++ b/app/models/certifier.rb @@ -24,6 +24,4 @@ class Certifier < ActiveRecord::Base self.name.downcase.transliterate <=> b.name.downcase.transliterate end - after_save_reindex [:products], :with => :delayed_job - end diff --git a/app/models/comment.rb b/app/models/comment.rb index 21d11ac..8e4a68c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -74,12 +74,6 @@ class Comment < ActiveRecord::Base self.find(:all, :order => 'created_at desc, id desc', :limit => limit) end - after_save :notify_article - after_destroy :notify_article - def notify_article - article.comments_updated if article.kind_of?(Article) - end - after_create :new_follower def new_follower if source.kind_of?(Article) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 5001a69..bbcf53c 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -14,7 +14,6 @@ class Enterprise < Organization has_and_belongs_to_many :fans, :class_name => 'Person', :join_table => 'favorite_enteprises_people' - after_save_reindex [:products], :with => :delayed_job extra_data_for_index :product_categories def product_categories products.includes(:product_category).map{|p| p.category_full_name}.compact diff --git a/app/models/product.rb b/app/models/product.rb index 8d910e7..45b214a 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -294,6 +294,5 @@ class Product < ActiveRecord::Base ], :facets => facets_option_for_solr, :boost => proc{ |p| boost = 1; Boosts.each{ |b| boost = boost * (1 - ((1 - b[2].call(p)) * b[1])) }; boost} handle_asynchronously :solr_save - after_save_reindex [:enterprise], :with => :delayed_job end diff --git a/app/models/product_category.rb b/app/models/product_category.rb index 37ef4c5..c3c1553 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -11,6 +11,4 @@ class ProductCategory < Category top_category ? top_category.children : top_level_for(env).select{|c|c.kind_of?(ProductCategory)} end - after_save_reindex [:products], :with => :delayed_job - end diff --git a/app/models/profile.rb b/app/models/profile.rb index 466391d..309dd44 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -963,7 +963,7 @@ private :generate_url, :url_options {:categories => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, ], :facets => facets_option_for_solr, :boost => proc{ |p| 10 if p.enabled } - after_save_reindex [:articles], :with => :delayed_job + handle_asynchronously :solr_save def control_panel_settings_button diff --git a/app/models/qualifier.rb b/app/models/qualifier.rb index 378527b..3852dc7 100644 --- a/app/models/qualifier.rb +++ b/app/models/qualifier.rb @@ -15,6 +15,4 @@ class Qualifier < ActiveRecord::Base self.name.downcase.transliterate <=> b.name.downcase.transliterate end - after_save_reindex [:products], :with => :delayed_job - end diff --git a/plugins/solr/lib/ext/article.rb b/plugins/solr/lib/ext/article.rb new file mode 100644 index 0000000..f6b1856 --- /dev/null +++ b/plugins/solr/lib/ext/article.rb @@ -0,0 +1,7 @@ +require_dependency 'article' + +class Article + def solr_plugin_comments_updated + solr_save + end +end diff --git a/plugins/solr/lib/ext/category.rb b/plugins/solr/lib/ext/category.rb new file mode 100644 index 0000000..d3d29c4 --- /dev/null +++ b/plugins/solr/lib/ext/category.rb @@ -0,0 +1,5 @@ +require_dependency 'category' + +class Category + after_save_reindex [:articles, :profiles], :with => :delayed_job +end diff --git a/plugins/solr/lib/ext/certifier.rb b/plugins/solr/lib/ext/certifier.rb new file mode 100644 index 0000000..b51c2cb --- /dev/null +++ b/plugins/solr/lib/ext/certifier.rb @@ -0,0 +1,6 @@ +require_dependency 'certifier' + +class Certifier + after_save_reindex [:products], :with => :delayed_job +end + diff --git a/plugins/solr/lib/ext/comment.rb b/plugins/solr/lib/ext/comment.rb new file mode 100644 index 0000000..e0a982a --- /dev/null +++ b/plugins/solr/lib/ext/comment.rb @@ -0,0 +1,10 @@ +require_dependency 'comment' + +class Comment + after_save :solr_plugin_notify_article + after_destroy :solr_plugin_notify_article + + def solr_plugin_notify_article + article.solr_plugin_comments_updated if article.kind_of?(Article) + end +end diff --git a/plugins/solr/lib/ext/enterprise.rb b/plugins/solr/lib/ext/enterprise.rb new file mode 100644 index 0000000..4bb35f7 --- /dev/null +++ b/plugins/solr/lib/ext/enterprise.rb @@ -0,0 +1,5 @@ +require_dependency 'enterprise' + +class Enterprise + after_save_reindex [:products], :with => :delayed_job +end diff --git a/plugins/solr/lib/ext/product.rb b/plugins/solr/lib/ext/product.rb new file mode 100644 index 0000000..a3d253a --- /dev/null +++ b/plugins/solr/lib/ext/product.rb @@ -0,0 +1,5 @@ +require_dependency 'product' + +class Product + after_save_reindex [:enterprise], :with => :delayed_job +end diff --git a/plugins/solr/lib/ext/product_category.rb b/plugins/solr/lib/ext/product_category.rb new file mode 100644 index 0000000..19add3f --- /dev/null +++ b/plugins/solr/lib/ext/product_category.rb @@ -0,0 +1,6 @@ +require_dependency 'product_category' + +class ProductCategory + after_save_reindex [:products], :with => :delayed_job +end + diff --git a/plugins/solr/lib/ext/profile.rb b/plugins/solr/lib/ext/profile.rb new file mode 100644 index 0000000..3d83b47 --- /dev/null +++ b/plugins/solr/lib/ext/profile.rb @@ -0,0 +1,5 @@ +require_dependency 'profile' + +class Profile + after_save_reindex [:articles], :with => :delayed_job +end diff --git a/plugins/solr/lib/ext/qualifier.rb b/plugins/solr/lib/ext/qualifier.rb new file mode 100644 index 0000000..ded7da0 --- /dev/null +++ b/plugins/solr/lib/ext/qualifier.rb @@ -0,0 +1,6 @@ +require_dependency 'qualifier' + +class Qualifier + after_save_reindex [:products], :with => :delayed_job +end + diff --git a/plugins/solr/lib/solr_plugin.rb b/plugins/solr/lib/solr_plugin.rb new file mode 100644 index 0000000..c32fc1f --- /dev/null +++ b/plugins/solr/lib/solr_plugin.rb @@ -0,0 +1,13 @@ +class SolrPlugin < Noosfero::Plugin + + def self.plugin_name + "Solr" + end + + def self.plugin_description + _("Uses Solr as search engine.") + end + +end + +Dir[File.join(SolrPlugin.root_path, 'lib', 'ext', '*.rb')].each {|file| require_dependency file } diff --git a/plugins/solr/test/unit/category_test.rb b/plugins/solr/test/unit/category_test.rb new file mode 100644 index 0000000..0d64c32 --- /dev/null +++ b/plugins/solr/test/unit/category_test.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +class CategoryTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + end + + attr_accessor :environment + + should 'reindex articles after saving' do + cat = Category.create!(:name => 'category 1', :environment_id => Environment.default.id) + art = Article.create!(:name => 'something', :profile_id => fast_create(Person).id) + art.add_category cat + cat.reload + + solr_doc = art.to_solr_doc + Article.any_instance.expects(:to_solr_doc).returns(solr_doc) + cat.save! + end +end diff --git a/plugins/solr/test/unit/certifier_test.rb b/plugins/solr/test/unit/certifier_test.rb new file mode 100644 index 0000000..4a3a5fd --- /dev/null +++ b/plugins/solr/test/unit/certifier_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class CertifierTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + end + + attr_accessor :environment + + should 'reindex products after saving' do + product = mock + Certifier.any_instance.stubs(:products).returns([product]) + Certifier.expects(:solr_batch_add).with(includes(product)) + cert = fast_create(Certifier) + cert.save! + end +end + diff --git a/plugins/solr/test/unit/comment_test.rb b/plugins/solr/test/unit/comment_test.rb new file mode 100644 index 0000000..bb4db23 --- /dev/null +++ b/plugins/solr/test/unit/comment_test.rb @@ -0,0 +1,32 @@ +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + end + + attr_accessor :environment + + should 'notify article to reindex after saving' do + owner = create_user('testuser').person + article = owner.articles.create!(:name => 'test', :body => '...') + + article.expects(:solr_plugin_comments_updated) + + c1 = article.comments.new(:title => "A comment", :body => '...', :author => owner) + c1.stubs(:article).returns(article) + c1.save! + end + + should 'notify article to reindex after being removed' do + owner = create_user('testuser').person + article = owner.articles.create!(:name => 'test', :body => '...') + c1 = article.comments.create!(:title => "A comment", :body => '...', :author => owner) + + c1.stubs(:article).returns(article) + article.expects(:solr_plugin_comments_updated) + c1.destroy + end +end + diff --git a/plugins/solr/test/unit/enterprise_test.rb b/plugins/solr/test/unit/enterprise_test.rb new file mode 100644 index 0000000..509cfae --- /dev/null +++ b/plugins/solr/test/unit/enterprise_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class EnterpriseTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + @product_category = fast_create(ProductCategory) + end + + attr_accessor :environment, :product_category + + should 'reindex when products are changed' do + enterprise = fast_create(Enterprise) + product = fast_create(Product, :enterprise_id => enterprise.id, :product_category_id => product_category.id) + Product.expects(:solr_batch_add_association).with(product, :enterprise) + product.update_attribute :name, "novo nome" + end +end diff --git a/plugins/solr/test/unit/product_category_test.rb b/plugins/solr/test/unit/product_category_test.rb new file mode 100644 index 0000000..51a04cc --- /dev/null +++ b/plugins/solr/test/unit/product_category_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class ProductCategoryTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + end + + attr_accessor :environment + + should 'reindex products after save' do + product = mock + ProductCategory.any_instance.stubs(:products).returns([product]) + ProductCategory.expects(:solr_batch_add).with(includes(product)) + pc = fast_create(ProductCategory) + pc.save! + end +end + diff --git a/plugins/solr/test/unit/product_test.rb b/plugins/solr/test/unit/product_test.rb new file mode 100644 index 0000000..7230bb4 --- /dev/null +++ b/plugins/solr/test/unit/product_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + end + + attr_accessor :environment + + should 'reindex enterprise after saving' do + ent = fast_create(Enterprise) + cat = fast_create(ProductCategory) + prod = Product.create!(:name => 'something', :enterprise_id => ent.id, :product_category_id => cat.id) + Product.expects(:solr_batch_add).with([ent]) + prod.save! + end +end + diff --git a/plugins/solr/test/unit/profile_test.rb b/plugins/solr/test/unit/profile_test.rb new file mode 100644 index 0000000..60ad1b3 --- /dev/null +++ b/plugins/solr/test/unit/profile_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + +class ProfileTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + end + + attr_accessor :environment + + should 'reindex articles after saving' do + profile = create(Person, :name => 'something', :user_id => fast_create(User).id) + art = profile.articles.build(:name => 'something') + Profile.expects(:solr_batch_add).with(includes(art)) + profile.save! + end +end diff --git a/plugins/solr/test/unit/qualifier_test.rb b/plugins/solr/test/unit/qualifier_test.rb new file mode 100644 index 0000000..e2653c3 --- /dev/null +++ b/plugins/solr/test/unit/qualifier_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class QualifierTest < ActiveSupport::TestCase + def setup + @environment = Environment.default + @environment.enable_plugin(SolrPlugin) + end + + attr_accessor :environment + + should 'reindex products after saving' do + product = mock + Qualifier.any_instance.stubs(:products).returns([product]) + Qualifier.expects(:solr_batch_add).with(includes(product)) + qual = fast_create(Qualifier) + qual.save! + end +end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 7480304..941e86a 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -357,12 +357,6 @@ class ArticleTest < ActiveSupport::TestCase assert_equal true, a.display_to?(person) end - should 'reindex when comments are changed' do - a = Article.new - a.expects(:solr_save) - a.comments_updated - end - should 'index comments title together with article' do TestSolr.enable owner = create_user('testuser').person diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb index 03b716a..a79c3b9 100644 --- a/test/unit/category_test.rb +++ b/test/unit/category_test.rb @@ -541,15 +541,4 @@ class CategoryTest < ActiveSupport::TestCase c.save! end - should 'reindex articles after saving' do - cat = Category.create!(:name => 'category 1', :environment_id => Environment.default.id) - art = Article.create!(:name => 'something', :profile_id => fast_create(Person).id) - art.add_category cat - cat.reload - - solr_doc = art.to_solr_doc - Article.any_instance.expects(:to_solr_doc).returns(solr_doc) - cat.save! - end - end diff --git a/test/unit/certifier_test.rb b/test/unit/certifier_test.rb index 3b67adf..c99cd4d 100644 --- a/test/unit/certifier_test.rb +++ b/test/unit/certifier_test.rb @@ -58,14 +58,6 @@ class CertifierTest < ActiveSupport::TestCase assert_equal [first, last], Certifier.all.sort end - should 'reindex products after saving' do - product = mock - Certifier.any_instance.stubs(:products).returns([product]) - Certifier.expects(:solr_batch_add).with(includes(product)) - cert = fast_create(Certifier) - cert.save! - end - should 'set qualifier as self-certified when destroyed' do pq = mock Certifier.any_instance.stubs(:product_qualifiers).returns([pq]) diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 077bc54..9615f2a 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -175,27 +175,6 @@ class CommentTest < ActiveSupport::TestCase assert c.errors.invalid?(:email) end - should 'notify article to reindex after saving' do - owner = create_user('testuser').person - article = owner.articles.create!(:name => 'test', :body => '...') - - article.expects(:comments_updated) - - c1 = article.comments.new(:title => "A comment", :body => '...', :author => owner) - c1.stubs(:article).returns(article) - c1.save! - end - - should 'notify article to reindex after being removed' do - owner = create_user('testuser').person - article = owner.articles.create!(:name => 'test', :body => '...') - c1 = article.comments.create!(:title => "A comment", :body => '...', :author => owner) - - c1.stubs(:article).returns(article) - article.expects(:comments_updated) - c1.destroy - end - should 'generate links to comments on images with view set to true' do owner = create_user('testuser').person image = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 365f100..ac39ab2 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -443,13 +443,6 @@ class EnterpriseTest < ActiveSupport::TestCase assert_equal product.inputs, enterprise.inputs end - should 'reindex when products are changed' do - enterprise = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => enterprise.id, :product_category_id => @product_category.id) - Product.expects(:solr_batch_add_association).with(product, :enterprise) - product.update_attribute :name, "novo nome" - end - should "the followed_by? be true only to members" do e = fast_create(Enterprise) e.stubs(:closed?).returns(false) @@ -480,17 +473,6 @@ class EnterpriseTest < ActiveSupport::TestCase assert_respond_to e, :production_costs end - should 'reindex products with full category name after save' do - product = mock - products = mock - product.expects(:category_full_name) - products.stubs(:includes).returns([product]) - Enterprise.any_instance.stubs(:products).returns(products) - Enterprise.expects(:solr_batch_add).with([products]) - ent = fast_create(Enterprise) - ent.save! - end - should 'return scraps as activities' do person = fast_create(Person) enterprise = fast_create(Enterprise) diff --git a/test/unit/product_category_test.rb b/test/unit/product_category_test.rb index 108a364..7c99072 100644 --- a/test/unit/product_category_test.rb +++ b/test/unit/product_category_test.rb @@ -36,12 +36,4 @@ class ProductCategoryTest < ActiveSupport::TestCase assert_equal [c11], ProductCategory.menu_categories(c1, nil) end - should 'reindex products after save' do - product = mock - ProductCategory.any_instance.stubs(:products).returns([product]) - ProductCategory.expects(:solr_batch_add).with(includes(product)) - pc = fast_create(ProductCategory) - pc.save! - end - end diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb index 3d22f0f..93d5de5 100644 --- a/test/unit/product_test.rb +++ b/test/unit/product_test.rb @@ -636,14 +636,6 @@ class ProductTest < ActiveSupport::TestCase assert_equal [in_name, in_desc], Product.find_by_contents('bananas')[:results].docs end - should 'reindex enterprise after saving' do - ent = fast_create(Enterprise) - cat = fast_create(ProductCategory) - prod = Product.create!(:name => 'something', :enterprise_id => ent.id, :product_category_id => cat.id) - Product.expects(:solr_batch_add).with([ent]) - prod.save! - end - should 'boost search results that include an image' do TestSolr.enable product_without_image = Product.create!(:name => 'product without image', :product_category => @product_category, diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index bff378d..890e98d 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1909,13 +1909,6 @@ class ProfileTest < ActiveSupport::TestCase assert_equal [in_name], Person.find_by_contents('bananas')[:results].docs end - should 'reindex articles after saving' do - profile = create(Person, :name => 'something', :user_id => fast_create(User).id) - art = profile.articles.build(:name => 'something') - Profile.expects(:solr_batch_add).with(includes(art)) - profile.save! - end - should 'respond to redirection_after_login' do assert_respond_to Profile.new, :redirection_after_login end diff --git a/test/unit/qualifier_test.rb b/test/unit/qualifier_test.rb index 213c576..ed71d60 100644 --- a/test/unit/qualifier_test.rb +++ b/test/unit/qualifier_test.rb @@ -60,12 +60,4 @@ class QualifierTest < ActiveSupport::TestCase Qualifier.destroy_all assert_equal [], product1.product_qualifiers(true) end - - should 'reindex products after saving' do - product = mock - Qualifier.any_instance.stubs(:products).returns([product]) - Qualifier.expects(:solr_batch_add).with(includes(product)) - qual = fast_create(Qualifier) - qual.save! - end end -- libgit2 0.21.2