From f4be5188784624a959a55bbfabab1f8c15d9f5f0 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 12 Dec 2012 01:21:15 +0000 Subject: [PATCH] [pluginize-solr] Moving find_by_contents tests --- plugins/solr/test/unit/enterprise_test.rb | 29 +++++++++++++++++++++++++++++ plugins/solr/test/unit/product_test.rb | 38 ++++++++++++++++++++++++++++++++++++++ plugins/solr/test/unit/profile_test.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/article_test.rb | 43 ------------------------------------------- test/unit/enterprise_test.rb | 29 ----------------------------- test/unit/environment_test.rb | 19 ------------------- test/unit/event_test.rb | 14 -------------- test/unit/product_test.rb | 38 -------------------------------------- test/unit/profile_test.rb | 67 ------------------------------------------------------------------- test/unit/text_article_test.rb | 7 ------- test/unit/tiny_mce_article_test.rb | 7 ------- 11 files changed, 143 insertions(+), 224 deletions(-) diff --git a/plugins/solr/test/unit/enterprise_test.rb b/plugins/solr/test/unit/enterprise_test.rb index 509cfae..ba5a9d8 100644 --- a/plugins/solr/test/unit/enterprise_test.rb +++ b/plugins/solr/test/unit/enterprise_test.rb @@ -15,4 +15,33 @@ class EnterpriseTest < ActiveSupport::TestCase Product.expects(:solr_batch_add_association).with(product, :enterprise) product.update_attribute :name, "novo nome" end + + should 'be found in search for its product categories' do + TestSolr.enable + ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1') + prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id) + prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) + + ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') + + result = Enterprise.find_by_contents(prod_cat.name)[:results] + + assert_includes result, ent1 + assert_not_includes result, ent2 + end + + should 'be found in search for its product categories hierarchy' do + TestSolr.enable + ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1') + prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id) + prod_child = fast_create(ProductCategory, :name => 'pchild', :environment_id => Environment.default.id, :parent_id => prod_cat.id) + prod = ent1.products.create!(:name => 'teste', :product_category => prod_child) + + ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') + + result = Enterprise.find_by_contents(prod_cat.name)[:results] + + assert_includes result, ent1 + assert_not_includes result, ent2 + end end diff --git a/plugins/solr/test/unit/product_test.rb b/plugins/solr/test/unit/product_test.rb index 297353c..fda059b 100644 --- a/plugins/solr/test/unit/product_test.rb +++ b/plugins/solr/test/unit/product_test.rb @@ -189,5 +189,43 @@ class ProductTest < ActiveSupport::TestCase assert_equal [img_and_qual, image_only, qual_only, product], Product.find_by_contents('product')[:results].docs end + + should 'be indexed by category full name' do + TestSolr.enable + parent_cat = fast_create(ProductCategory, :name => 'Parent') + prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id) + prod_cat2 = fast_create(ProductCategory, :name => 'Category2') + p = Product.create(:name => 'a test', :product_category => prod_cat, :enterprise_id => @profile.id) + p2 = Product.create(:name => 'another test', :product_category => prod_cat2, :enterprise_id => @profile.id) + + r = Product.find_by_contents('Parent')[:results].docs + assert_includes r, p + assert_not_includes r, p2 + end + + should 'index by schema name when database is postgresql' do + TestSolr.enable + uses_postgresql 'schema_one' + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) + assert_equal [p1], Product.find_by_contents('thing')[:results].docs + uses_postgresql 'schema_two' + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) + assert_not_includes Product.find_by_contents('thing')[:results], p1 + assert_includes Product.find_by_contents('thing')[:results], p2 + uses_postgresql 'schema_one' + assert_includes Product.find_by_contents('thing')[:results], p1 + assert_not_includes Product.find_by_contents('thing')[:results], p2 + uses_sqlite + end + + should 'not index by schema name when database is not postgresql' do + TestSolr.enable + uses_sqlite + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) + assert_equal [p1], Product.find_by_contents('thing')[:results].docs + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) + assert_includes Product.find_by_contents('thing')[:results], p1 + assert_includes Product.find_by_contents('thing')[:results], p2 + end end diff --git a/plugins/solr/test/unit/profile_test.rb b/plugins/solr/test/unit/profile_test.rb index a7f9ce6..89e5892 100644 --- a/plugins/solr/test/unit/profile_test.rb +++ b/plugins/solr/test/unit/profile_test.rb @@ -85,4 +85,80 @@ class ProfileTest < ActiveSupport::TestCase assert_includes ExtraDataForIndex.find_by_contents('sample')[:results], profile end + + should 'find_by_contents' do + TestSolr.enable + p = create(Profile, :name => 'wanted') + + assert Profile.find_by_contents('wanted')[:results].include?(p) + assert ! Profile.find_by_contents('not_wanted')[:results].include?(p) + end + + # This problem should be solved; talk to BrĂ¡ulio if it fails + should 'be able to find profiles by their names' do + TestSolr.enable + small = create(Profile, :name => 'A small profile for testing') + big = create(Profile, :name => 'A big profile for testing') + + assert Profile.find_by_contents('small')[:results].include?(small) + assert Profile.find_by_contents('big')[:results].include?(big) + + both = Profile.find_by_contents('profile testing')[:results] + assert both.include?(small) + assert both.include?(big) + end + + should 'search with latitude and longitude' do + TestSolr.enable + e = fast_create(Enterprise, {:lat => 45, :lng => 45}, :search => true) + + assert_includes Enterprise.find_by_contents('', {}, {:radius => 2, :latitude => 45, :longitude => 45})[:results].docs, e + end + + should 'index profile identifier for searching' do + TestSolr.enable + Profile.destroy_all + p = create(Profile, :identifier => 'lalala') + assert_includes Profile.find_by_contents('lalala')[:results], p + end + + should 'index profile name for searching' do + TestSolr.enable + p = create(Profile, :name => 'Interesting Profile') + assert_includes Profile.find_by_contents('interesting')[:results], p + end + + should 'index comments title together with article' do + TestSolr.enable + owner = create_user('testuser').person + art = fast_create(TinyMceArticle, :profile_id => owner.id, :name => 'ytest') + c1 = Comment.create(:title => 'a nice comment', :body => 'anything', :author => owner, :source => art ); c1.save! + + assert_includes Article.find_by_contents('nice')[:results], art + end + + should 'index by schema name when database is postgresql' do + TestSolr.enable + uses_postgresql 'schema_one' + p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') + assert_equal [p1], Profile.find_by_contents('thing')[:results].docs + uses_postgresql 'schema_two' + p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') + assert_not_includes Profile.find_by_contents('thing')[:results], p1 + assert_includes Profile.find_by_contents('thing')[:results], p2 + uses_postgresql 'schema_one' + assert_includes Profile.find_by_contents('thing')[:results], p1 + assert_not_includes Profile.find_by_contents('thing')[:results], p2 + uses_sqlite + end + + should 'not index by schema name when database is not postgresql' do + TestSolr.enable + uses_sqlite + p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') + assert_equal [p1], Profile.find_by_contents('thing')[:results].docs + p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') + assert_includes Profile.find_by_contents('thing')[:results], p1 + assert_includes Profile.find_by_contents('thing')[:results], p2 + end end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index dd764e8..ce960f6 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -357,24 +357,6 @@ class ArticleTest < ActiveSupport::TestCase assert_equal true, a.display_to?(person) end - should 'index comments title together with article' do - TestSolr.enable - owner = create_user('testuser').person - art = fast_create(TinyMceArticle, :profile_id => owner.id, :name => 'ytest') - c1 = Comment.create(:title => 'a nice comment', :body => 'anything', :author => owner, :source => art ); c1.save! - - assert_includes Article.find_by_contents('nice')[:results], art - end - - should 'index comments body together with article' do - TestSolr.enable - owner = create_user('testuser').person - art = fast_create(TinyMceArticle, :profile_id => owner.id, :name => 'ytest') - c1 = Comment.create(:title => 'test comment', :body => 'anything', :author => owner, :source => art); c1.save! - - assert_includes Article.find_by_contents('anything')[:results], art - end - should 'cache children count' do owner = create_user('testuser').person art = owner.articles.build(:name => 'ytest'); art.save! @@ -1434,31 +1416,6 @@ class ArticleTest < ActiveSupport::TestCase assert !child.accept_uploads? end - should 'index by schema name when database is postgresql' do - TestSolr.enable - uses_postgresql 'schema_one' - art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id) - assert_equal [art1], Article.find_by_contents('thing')[:results].docs - uses_postgresql 'schema_two' - art2 = Article.create!(:name => 'another thing', :profile_id => @profile.id) - assert_not_includes Article.find_by_contents('thing')[:results], art1 - assert_includes Article.find_by_contents('thing')[:results], art2 - uses_postgresql 'schema_one' - assert_includes Article.find_by_contents('thing')[:results], art1 - assert_not_includes Article.find_by_contents('thing')[:results], art2 - uses_sqlite - end - - should 'not index by schema name when database is not postgresql' do - TestSolr.enable - uses_sqlite - art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id) - assert_equal [art1], Article.find_by_contents('thing')[:results].docs - art2 = Article.create!(:name => 'another thing', :profile_id => @profile.id) - assert_includes Article.find_by_contents('thing')[:results], art1 - assert_includes Article.find_by_contents('thing')[:results], art2 - end - should 'get images paths in article body' do Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') a = TinyMceArticle.new :profile => @profile diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index ac39ab2..44be51a 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -85,35 +85,6 @@ class EnterpriseTest < ActiveSupport::TestCase assert !e.boxes[2].blocks.empty?, 'person must have blocks in area 3' end - should 'be found in search for its product categories' do - TestSolr.enable - ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1') - prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id) - prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) - - ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') - - result = Enterprise.find_by_contents(prod_cat.name)[:results] - - assert_includes result, ent1 - assert_not_includes result, ent2 - end - - should 'be found in search for its product categories hierarchy' do - TestSolr.enable - ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1') - prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id) - prod_child = fast_create(ProductCategory, :name => 'pchild', :environment_id => Environment.default.id, :parent_id => prod_cat.id) - prod = ent1.products.create!(:name => 'teste', :product_category => prod_child) - - ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') - - result = Enterprise.find_by_contents(prod_cat.name)[:results] - - assert_includes result, ent1 - assert_not_includes result, ent2 - end - should 'allow to add new members if has no members' do enterprise = fast_create(Enterprise) diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index e30c766..1c510f4 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -441,14 +441,6 @@ class EnvironmentTest < ActiveSupport::TestCase assert_equal 'this enterprise was disabled', env.message_for_disabled_enterprise end - should 'find by contents from articles' do - TestSolr.enable - environment = fast_create(Environment) - assert_nothing_raised do - environment.articles.find_by_contents('')[:results] - end - end - should 'provide custom header' do assert_equal 'my header', Environment.new(:custom_header => 'my header').custom_header end @@ -545,17 +537,6 @@ class EnvironmentTest < ActiveSupport::TestCase assert_equal 'default', Environment.new.layout_template end - should 'return more than 10 enterprises by contents' do - TestSolr.enable - env = Environment.default - Enterprise.destroy_all - ('1'..'20').each do |n| - Enterprise.create!(:name => 'test ' + n, :identifier => 'test_' + n) - end - - assert_equal 20, env.enterprises.find_by_contents('test')[:results].total_entries - end - should 'set replace_enterprise_template_when_enable on environment' do e = Environment.new(:name => 'Enterprise test') e.replace_enterprise_template_when_enable = true diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb index d0b2d7c..19cb23b 100644 --- a/test/unit/event_test.rb +++ b/test/unit/event_test.rb @@ -56,20 +56,6 @@ class EventTest < ActiveSupport::TestCase assert_kind_of Date, e.end_date end - should 'be indexed by title' do - TestSolr.enable - profile = create_user('testuser').person - e = Event.create!(:name => 'my surprisingly nice event', :start_date => Date.new(2008, 06, 06), :profile => profile) - assert_includes Event.find_by_contents('surprisingly')[:results], e - end - - should 'be indexed by body' do - TestSolr.enable - profile = create_user('testuser').person - e = Event.create!(:name => 'bli', :start_date => Date.new(2008, 06, 06), :profile => profile, :body => 'my surprisingly long description about my freaking nice event') - assert_includes Event.find_by_contents('surprisingly')[:results], e - end - should 'use its own icon' do assert_equal 'event', Event.icon_name end diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb index f07c5cf..fe42c85 100644 --- a/test/unit/product_test.rb +++ b/test/unit/product_test.rb @@ -104,19 +104,6 @@ class ProductTest < ActiveSupport::TestCase assert_equal nil, p.category_full_name end - should 'be indexed by category full name' do - TestSolr.enable - parent_cat = fast_create(ProductCategory, :name => 'Parent') - prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id) - prod_cat2 = fast_create(ProductCategory, :name => 'Category2') - p = Product.create(:name => 'a test', :product_category => prod_cat, :enterprise_id => @profile.id) - p2 = Product.create(:name => 'another test', :product_category => prod_cat2, :enterprise_id => @profile.id) - - r = Product.find_by_contents('Parent')[:results].docs - assert_includes r, p - assert_not_includes r, p2 - end - should 'have same lat and lng of its enterprise' do ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_enterprise', :lat => 30.0, :lng => 30.0) prod = ent.products.create!(:name => 'test product', :product_category => @product_category) @@ -343,31 +330,6 @@ class ProductTest < ActiveSupport::TestCase assert_kind_of Unit, product.build_unit end - should 'index by schema name when database is postgresql' do - TestSolr.enable - uses_postgresql 'schema_one' - p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) - assert_equal [p1], Product.find_by_contents('thing')[:results].docs - uses_postgresql 'schema_two' - p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) - assert_not_includes Product.find_by_contents('thing')[:results], p1 - assert_includes Product.find_by_contents('thing')[:results], p2 - uses_postgresql 'schema_one' - assert_includes Product.find_by_contents('thing')[:results], p1 - assert_not_includes Product.find_by_contents('thing')[:results], p2 - uses_sqlite - end - - should 'not index by schema name when database is not postgresql' do - TestSolr.enable - uses_sqlite - p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) - assert_equal [p1], Product.find_by_contents('thing')[:results].docs - p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) - assert_includes Product.find_by_contents('thing')[:results], p1 - assert_includes Product.find_by_contents('thing')[:results], p2 - end - should 'respond to price details' do product = Product.new assert_respond_to product, :price_details diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 689eb2b..1d01478 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -97,14 +97,6 @@ class ProfileTest < ActiveSupport::TestCase assert pe.memberships.include?(pr) end - def test_find_by_contents - TestSolr.enable - p = create(Profile, :name => 'wanted') - - assert Profile.find_by_contents('wanted')[:results].include?(p) - assert ! Profile.find_by_contents('not_wanted')[:results].include?(p) - end - should 'remove pages when removing profile' do profile = fast_create(Profile) first = fast_create(Article, :profile_id => profile.id) @@ -189,20 +181,6 @@ class ProfileTest < ActiveSupport::TestCase assert_not_equal list.object_id, other_list.object_id end - # This problem should be solved; talk to BrĂ¡ulio if it fails - should 'be able to find profiles by their names' do - TestSolr.enable - small = create(Profile, :name => 'A small profile for testing') - big = create(Profile, :name => 'A big profile for testing') - - assert Profile.find_by_contents('small')[:results].include?(small) - assert Profile.find_by_contents('big')[:results].include?(big) - - both = Profile.find_by_contents('profile testing')[:results] - assert both.include?(small) - assert both.include?(big) - end - should 'provide a shortcut for picking a profile by its identifier' do profile = fast_create(Profile, :identifier => 'testprofile') assert_equal profile, Profile['testprofile'] @@ -438,13 +416,6 @@ class ProfileTest < ActiveSupport::TestCase assert article.advertise? end - should 'search with latitude and longitude' do - TestSolr.enable - e = fast_create(Enterprise, {:lat => 45, :lng => 45}, :search => true) - - assert_includes Enterprise.find_by_contents('', {}, {:radius => 2, :latitude => 45, :longitude => 45})[:results].docs, e - end - should 'have a public profile by default' do assert_equal true, Profile.new.public_profile end @@ -498,19 +469,6 @@ class ProfileTest < ActiveSupport::TestCase assert p.display_info_to?(admin) end - should 'index profile identifier for searching' do - TestSolr.enable - Profile.destroy_all - p = create(Profile, :identifier => 'lalala') - assert_includes Profile.find_by_contents('lalala')[:results], p - end - - should 'index profile name for searching' do - TestSolr.enable - p = create(Profile, :name => 'Interesting Profile') - assert_includes Profile.find_by_contents('interesting')[:results], p - end - should 'enabled by default on creation' do profile = fast_create(Profile) assert profile.enabled? @@ -1691,31 +1649,6 @@ class ProfileTest < ActiveSupport::TestCase assert_equal 1, community.members_count end - should 'index by schema name when database is postgresql' do - TestSolr.enable - uses_postgresql 'schema_one' - p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') - assert_equal [p1], Profile.find_by_contents('thing')[:results].docs - uses_postgresql 'schema_two' - p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') - assert_not_includes Profile.find_by_contents('thing')[:results], p1 - assert_includes Profile.find_by_contents('thing')[:results], p2 - uses_postgresql 'schema_one' - assert_includes Profile.find_by_contents('thing')[:results], p1 - assert_not_includes Profile.find_by_contents('thing')[:results], p2 - uses_sqlite - end - - should 'not index by schema name when database is not postgresql' do - TestSolr.enable - uses_sqlite - p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') - assert_equal [p1], Profile.find_by_contents('thing')[:results].docs - p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') - assert_includes Profile.find_by_contents('thing')[:results], p1 - assert_includes Profile.find_by_contents('thing')[:results], p2 - end - should 'know if url is the profile homepage' do profile = fast_create(Profile) diff --git a/test/unit/text_article_test.rb b/test/unit/text_article_test.rb index 1665935..dbc73c0 100644 --- a/test/unit/text_article_test.rb +++ b/test/unit/text_article_test.rb @@ -13,13 +13,6 @@ class TextArticleTest < ActiveSupport::TestCase article = fast_create(TextileArticle, :name => 'textile article test', :profile_id => person.id) assert_includes TextArticle.find(:all), article end - - should 'found TextileArticle by TextArticle indexes' do - TestSolr.enable - person = create_user('testuser').person - article = TextileArticle.create!(:name => 'found article test', :profile => person) - assert_equal TextileArticle.find_by_contents('found')[:results].docs, TextArticle.find_by_contents('found')[:results].docs - end should 'remove HTML from name' do person = create_user('testuser').person diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index 5467360..aa2853c 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -21,13 +21,6 @@ class TinyMceArticleTest < ActiveSupport::TestCase assert_kind_of String, TinyMceArticle.short_description end - should 'be found when searching for articles by query' do - TestSolr.enable - tma = TinyMceArticle.create!(:name => 'test tinymce article', :body => '---', :profile => profile) - assert_includes TinyMceArticle.find_by_contents('article')[:results], tma - assert_includes Article.find_by_contents('article')[:results], tma - end - should 'not sanitize target attribute' do article = TinyMceArticle.create!(:name => 'open link in new window', :body => "open link in new window", :profile => profile) assert_tag_in_string article.body, :tag => 'a', :attributes => {:target => '_blank'} -- libgit2 0.21.2