diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb
index 758987b..5092934 100644
--- a/app/controllers/my_profile/profile_members_controller.rb
+++ b/app/controllers/my_profile/profile_members_controller.rb
@@ -126,11 +126,11 @@ class ProfileMembersController < MyProfileController
if !params[:query] || params[:query].length <= 2
@users_found = []
elsif params[:scope] == 'all_users'
- @users_found = Person.find_by_contents(params[:query] + '*').select {|user| !profile.members.include?(user)}
+ @users_found = Person.find_by_contents(params[:query] + '*')[:results].select {|user| !profile.members.include?(user)}
@button_alt = _('Add member')
@add_action = {:action => 'add_member'}
elsif params[:scope] == 'new_admins'
- @users_found = Person.find_by_contents(params[:query] + '*').select {|user| profile.members.include?(user) && !profile.admins.include?(user)}
+ @users_found = Person.find_by_contents(params[:query] + '*')[:results].select {|user| profile.members.include?(user) && !profile.admins.include?(user)}
@button_alt = _('Add member')
@add_action = {:action => 'add_admin'}
end
diff --git a/app/controllers/public/browse_controller.rb b/app/controllers/public/browse_controller.rb
index 17f85a5..f1e55ef 100644
--- a/app/controllers/public/browse_controller.rb
+++ b/app/controllers/public/browse_controller.rb
@@ -19,7 +19,7 @@ class BrowseController < PublicController
@results = @environment.people.visible.send(@filter)
if !params[:query].blank?
- @results = @results.find_by_contents(params[:query])
+ @results = @results.find_by_contents(params[:query])[:results]
end
@results = @results.compact.paginate(:per_page => per_page, :page => params[:page])
end
@@ -31,7 +31,7 @@ class BrowseController < PublicController
@results = @environment.communities.visible.send(@filter)
if !params[:query].blank?
- @results = @results.find_by_contents(params[:query])
+ @results = @results.find_by_contents(params[:query])[:results]
end
@results = @results.compact.paginate(:per_page => per_page, :page => params[:page])
end
diff --git a/app/models/article.rb b/app/models/article.rb
index 56e39cc..bfcf349 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -388,7 +388,7 @@ class Article < ActiveRecord::Base
end
def comments_updated
- ferret_update
+ solr_save
end
def accept_category?(cat)
diff --git a/app/models/category_finder.rb b/app/models/category_finder.rb
index 1a5b802..1514584 100644
--- a/app/models/category_finder.rb
+++ b/app/models/category_finder.rb
@@ -30,8 +30,8 @@ class CategoryFinder
if query.blank?
asset_class(asset).send(finder_method, :all, options_for_find(asset_class(asset), {:order => "#{asset_table(asset)}.name"}.merge(options), date_range))
else
- ferret_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)}
- asset_class(asset).find_by_contents(query, ferret_options, options_for_find(asset_class(asset), options, date_range))
+ pg_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)}
+ asset_class(asset).find_by_contents(query, pg_options, {}, options_for_find(asset_class(asset), options, date_range))[:results]
end
end
diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb
index aa07583..d9c6394 100644
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -71,7 +71,7 @@ class Enterprise < Organization
end
def product_updated
- ferret_update
+ solr_save
end
after_save do |e|
diff --git a/app/models/environment_finder.rb b/app/models/environment_finder.rb
index 17050fd..2f55485 100644
--- a/app/models/environment_finder.rb
+++ b/app/models/environment_finder.rb
@@ -48,14 +48,14 @@ class EnvironmentFinder
end
end
else
- ferret_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)}
+ pg_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)}
if product_category && asset == :products
# SECURITY no risk of SQL injection, since product_category_ids comes from trusted source
- @environment.send(asset).find_by_contents(query, ferret_options, options.merge({:include => 'product_categorizations', :conditions => 'product_categorizations.category_id = (%s)' % product_category.id }))
+ @environment.send(asset).find_by_contents(query, pg_options, {}, options.merge({:include => 'product_categorizations', :conditions => 'product_categorizations.category_id = (%s)' % product_category.id }))[:results]
elsif product_category && asset == :enterprises
- @environment.send(asset).find_by_contents(query, ferret_options, options.merge(:joins => 'inner join product_categorizations on (product_categorizations.product_id = products.id)', :include => 'products', :conditions => "product_categorizations.category_id = (#{product_category.id})"))
+ @environment.send(asset).find_by_contents(query, pg_options, {}, options.merge(:joins => 'inner join product_categorizations on (product_categorizations.product_id = products.id)', :include => 'products', :conditions => "product_categorizations.category_id = (#{product_category.id})"))[:results]
else
- @environment.send(asset).find_by_contents(query, ferret_options, options)
+ @environment.send(asset).find_by_contents(query, pg_options, {}, options)[:results]
end
end
end
diff --git a/app/models/region.rb b/app/models/region.rb
index f86cb91..8e95afc 100644
--- a/app/models/region.rb
+++ b/app/models/region.rb
@@ -5,10 +5,9 @@ class Region < Category
require_dependency 'enterprise' # enterprises can also be validators
# searches for organizations that could become validators for this region.
- # search is passed as is to ferret's find_by_contents on Organizatio
- # find_by_contents on Organization class.
+ # search is passed as is to find_by_contents on Organization.
def search_possible_validators(search)
- Organization.find_by_contents(search).reject {|item| self.validator_ids.include?(item.id) }
+ Organization.find_by_contents(search)[:results].reject {|item| self.validator_ids.include?(item.id) }
end
def has_validator?
diff --git a/lib/acts_as_searchable.rb b/lib/acts_as_searchable.rb
index 9721368..9b4d42a 100644
--- a/lib/acts_as_searchable.rb
+++ b/lib/acts_as_searchable.rb
@@ -2,56 +2,59 @@ module ActsAsSearchable
module ClassMethods
def acts_as_searchable(options = {})
- if Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?
- options[:additional_fields] ||= {}
- options[:additional_fields] = Hash[*options[:additional_fields].collect{ |v| [v, {}] }.flatten] if options[:additional_fields].is_a?(Array)
- options[:additional_fields].merge!(:schema_name => { :index => :untokenized })
+ if (!options[:fields])
+ options[:additional_fields] |= [{:schema_name => :string}]
+ else
+ options[:fields] << {:schema_name => :string}
end
- acts_as_ferret({ :remote => true }.merge(options))
+ acts_as_solr options
extend FindByContents
send :include, InstanceMethods
end
module InstanceMethods
def schema_name
- ActiveRecord::Base.connection.schema_search_path
+ (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? ActiveRecord::Base.connection.schema_search_path : ''
end
end
module FindByContents
def schema_name
- ActiveRecord::Base.connection.schema_search_path
+ (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? ActiveRecord::Base.connection.schema_search_path : ''
end
- def find_by_contents(query, ferret_options = {}, db_options = {})
- pg_options = {}
- if ferret_options[:page]
- pg_options[:page] = ferret_options.delete(:page)
- end
- if ferret_options[:per_page]
- pg_options[:per_page] = ferret_options.delete(:per_page)
- end
-
- ferret_options[:limit] = :all
-
- ferret_query = (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? "+schema_name:\"#{schema_name}\" AND #{query}" : query
- # FIXME this is a HORRIBLE HACK
- ids = find_ids_with_ferret(ferret_query, ferret_options)[1][0..8000].map{|r|r[:id].to_i}
-
- if ids.empty?
- ids << -1
- end
+ def find_by_contents(query, pg_options = {}, options = {}, db_options = {})
+ pg_options[:page] ||= 1
+ options[:limit] = 1000000;
+ options[:scores] = true;
- if db_options[:conditions]
- db_options[:conditions] = sanitize_sql_for_conditions(db_options[:conditions]) + " and #{table_name}.id in (#{ids.join(', ')})"
+ query = !schema_name.empty? ? "+schema_name:\"#{schema_name}\" AND #{query}" : query
+ solr_result = find_by_solr(query, options)
+ if solr_result.nil?
+ results = facets = []
else
- db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})"
+ facets = options.include?(:facets) ? solr_result.facets : {}
+ if db_options.empty?
+ results = solr_result.results.paginate(pg_options)
+ else
+ ids = solr_result.results.map{|r|r[:id].to_i}
+ if ids.empty?
+ ids << -1
+ end
+
+ if db_options[:conditions]
+ db_options[:conditions] = sanitize_sql_for_conditions(db_options[:conditions]) + " and #{table_name}.id in (#{ids.join(', ')})"
+ else
+ db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})"
+ end
+
+ result = find(:all, db_options)
+ results = result.paginate(pg_options)
+ end
end
- pg_options[:page] ||= 1
- result = find(:all, db_options)
- result.paginate(pg_options)
+ {:results => results, :facets => facets}
end
end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index deefbab..6063c50 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -47,6 +47,10 @@ class Test::Unit::TestCase
include AuthenticatedTestHelper
fixtures :environments, :roles
+
+ def self.setup
+ ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*'))
+ end
def self.all_fixtures
Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.yml')).each do |item|
@@ -190,7 +194,6 @@ class Test::Unit::TestCase
adapter.any_instance.stubs(:adapter_name).returns('PostgreSQL')
adapter.any_instance.stubs(:schema_search_path).returns(schema_name)
Noosfero::MultiTenancy.stubs(:on?).returns(true)
- reload_for_ferret
end
def uses_sqlite
@@ -199,20 +202,6 @@ class Test::Unit::TestCase
Noosfero::MultiTenancy.stubs(:on?).returns(false)
end
- def reload_for_ferret
- ActsAsFerret.send(:remove_const, :DEFAULT_FIELD_OPTIONS)
- load File.join(RAILS_ROOT, 'lib', 'acts_as_searchable.rb')
- load File.join(RAILS_ROOT, 'vendor', 'plugins', 'acts_as_ferret', 'lib', 'acts_as_ferret.rb')
- [Article, Profile, Product].each do |clazz|
- inst_meth = clazz.instance_methods.reject{ |m| m =~ /_to_ferret$/ }
- clazz.stubs(:instance_methods).returns(inst_meth)
- end
- #FIXME Is there a way to avoid this replication from model code?
- Article.acts_as_searchable :additional_fields => [ :comment_data ]
- Profile.acts_as_searchable :additional_fields => [ :extra_data_for_index ]
- Product.acts_as_searchable :fields => [ :name, :description, :category_full_name ]
- end
-
end
module NoosferoTestHelper
diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb
index bb31deb..667269e 100644
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -5,6 +5,7 @@ class ArticleTest < Test::Unit::TestCase
fixtures :environments
def setup
+ Test::Unit::TestCase::setup
@profile = create_user('testing').person
end
attr_reader :profile
@@ -356,7 +357,7 @@ class ArticleTest < Test::Unit::TestCase
should 'reindex when comments are changed' do
a = Article.new
- a.expects(:ferret_update)
+ a.expects(:solr_save)
a.comments_updated
end
@@ -365,7 +366,7 @@ class ArticleTest < Test::Unit::TestCase
art = owner.articles.build(:name => 'ytest'); art.save!
c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save!
- assert_includes Article.find_by_contents('nice'), art
+ assert_includes Article.find_by_contents('nice')[:results], art
end
should 'index comments body together with article' do
@@ -373,7 +374,7 @@ class ArticleTest < Test::Unit::TestCase
art = owner.articles.build(:name => 'ytest'); art.save!
c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save!
- assert_includes Article.find_by_contents('anything'), art
+ assert_includes Article.find_by_contents('anything')[:results], art
end
should 'cache children count' do
@@ -1506,24 +1507,24 @@ class ArticleTest < Test::Unit::TestCase
should 'index by schema name when database is postgresql' do
uses_postgresql 'schema_one'
art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id)
- assert_equal Article.find_by_contents('thing'), [art1]
+ assert_equal Article.find_by_contents('thing')[:results], [art1]
uses_postgresql 'schema_two'
art2 = Article.create!(:name => 'another thing', :profile_id => @profile.id)
- assert_not_includes Article.find_by_contents('thing'), art1
- assert_includes Article.find_by_contents('thing'), art2
+ 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'), art1
- assert_not_includes Article.find_by_contents('thing'), art2
+ 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
uses_sqlite
art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id)
- assert_equal Article.find_by_contents('thing'), [art1]
+ assert_equal Article.find_by_contents('thing')[:results], [art1]
art2 = Article.create!(:name => 'another thing', :profile_id => @profile.id)
- assert_includes Article.find_by_contents('thing'), art1
- assert_includes Article.find_by_contents('thing'), art2
+ 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
diff --git a/test/unit/category_finder_test.rb b/test/unit/category_finder_test.rb
index 3c240b2..1cb2323 100644
--- a/test/unit/category_finder_test.rb
+++ b/test/unit/category_finder_test.rb
@@ -3,11 +3,12 @@ require File.dirname(__FILE__) + '/../test_helper'
class CategoryFinderTest < ActiveSupport::TestCase
def setup
+ Test::Unit::TestCase::setup
@category = Category.create!(:name => 'my category', :environment => Environment.default)
@finder = CategoryFinder.new(@category)
@product_category = fast_create(ProductCategory, :name => 'Products')
- Profile.rebuild_index
+ Profile.rebuild_solr_index
end
should 'search for articles in a specific category' do
diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb
index 762af71..ad30735 100644
--- a/test/unit/enterprise_test.rb
+++ b/test/unit/enterprise_test.rb
@@ -4,6 +4,7 @@ class EnterpriseTest < Test::Unit::TestCase
fixtures :profiles, :environments, :users
def setup
+ Test::Unit::TestCase::setup
@product_category = fast_create(ProductCategory, :name => 'Products')
end
@@ -91,7 +92,7 @@ class EnterpriseTest < Test::Unit::TestCase
ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2')
- result = Enterprise.find_by_contents(prod_cat.name)
+ result = Enterprise.find_by_contents(prod_cat.name)[:results]
assert_includes result, ent1
assert_not_includes result, ent2
@@ -105,7 +106,7 @@ class EnterpriseTest < Test::Unit::TestCase
ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2')
- result = Enterprise.find_by_contents(prod_cat.name)
+ result = Enterprise.find_by_contents(prod_cat.name)[:results]
assert_includes result, ent1
assert_not_includes result, ent2
@@ -406,6 +407,12 @@ class EnterpriseTest < Test::Unit::TestCase
assert_equal product.inputs, enterprise.inputs
end
+
+ should 'reindex when products are changed' do
+ a = Enterprise.new
+ a.expects(:solr_save)
+ a.product_updated
+ end
should "the followed_by? be true only to members" do
e = fast_create(Enterprise)
diff --git a/test/unit/environment_finder_test.rb b/test/unit/environment_finder_test.rb
index d30ed7e..855d0b8 100644
--- a/test/unit/environment_finder_test.rb
+++ b/test/unit/environment_finder_test.rb
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper'
class EnvironmentFinderTest < ActiveSupport::TestCase
def setup
+ Test::Unit::TestCase::setup
@product_category = fast_create(ProductCategory, :name => 'Products')
end
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 3842d28..f19f22e 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../test_helper'
class EnvironmentTest < Test::Unit::TestCase
fixtures :environments
+ def setup
+ Test::Unit::TestCase::setup
+ end
+
def test_exists_default_and_it_is_unique
Environment.delete_all
vc = Environment.new(:name => 'Test Community')
@@ -444,7 +448,7 @@ class EnvironmentTest < Test::Unit::TestCase
should 'find by contents from articles' do
environment = fast_create(Environment)
assert_nothing_raised do
- environment.articles.find_by_contents('')
+ environment.articles.find_by_contents('')[:results]
end
end
@@ -561,7 +565,7 @@ class EnvironmentTest < Test::Unit::TestCase
Enterprise.create!(:name => 'test ' + n, :identifier => 'test_' + n)
end
- assert_equal 20, env.enterprises.find_by_contents('test').total_entries
+ assert_equal 20, env.enterprises.find_by_contents('test')[:results].total_entries
end
should 'set replace_enterprise_template_when_enable on environment' do
diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb
index 7ff9c54..46d8d40 100644
--- a/test/unit/event_test.rb
+++ b/test/unit/event_test.rb
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper'
class EventTest < ActiveSupport::TestCase
+ def setup
+ Test::Unit::TestCase::setup
+ end
+
should 'be an article' do
assert_kind_of Article, Event.new
end
@@ -59,13 +63,13 @@ class EventTest < ActiveSupport::TestCase
should 'be indexed by title' do
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'), e
+ assert_includes Event.find_by_contents('surprisingly')[:results], e
end
should 'be indexed by body' do
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'), e
+ assert_includes Event.find_by_contents('surprisingly')[:results], e
end
should 'use its own icon' do
diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb
index 2562122..bb5b55d 100644
--- a/test/unit/product_test.rb
+++ b/test/unit/product_test.rb
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper'
class ProductTest < Test::Unit::TestCase
def setup
+ Test::Unit::TestCase::setup
@product_category = fast_create(ProductCategory, :name => 'Products')
end
@@ -92,7 +93,7 @@ class ProductTest < Test::Unit::TestCase
p.stubs(:category_full_name).returns('interesting category')
p.save!
- assert_includes Product.find_by_contents('interesting'), p
+ assert_includes Product.find_by_contents('interesting')[:results], p
end
should 'have same lat and lng of its enterprise' do
@@ -355,24 +356,24 @@ class ProductTest < Test::Unit::TestCase
should 'index by schema name when database is postgresql' do
uses_postgresql 'schema_one'
p1 = Product.create!(:name => 'some thing', :product_category => @product_category)
- assert_equal Product.find_by_contents('thing'), [p1]
+ assert_equal Product.find_by_contents('thing')[:results], [p1]
uses_postgresql 'schema_two'
p2 = Product.create!(:name => 'another thing', :product_category => @product_category)
- assert_not_includes Product.find_by_contents('thing'), p1
- assert_includes Product.find_by_contents('thing'), p2
+ 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'), p1
- assert_not_includes Product.find_by_contents('thing'), p2
+ 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
uses_sqlite
p1 = Product.create!(:name => 'some thing', :product_category => @product_category)
- assert_equal Product.find_by_contents('thing'), [p1]
+ assert_equal Product.find_by_contents('thing')[:results], [p1]
p2 = Product.create!(:name => 'another thing', :product_category => @product_category)
- assert_includes Product.find_by_contents('thing'), p1
- assert_includes Product.find_by_contents('thing'), p2
+ assert_includes Product.find_by_contents('thing')[:results], p1
+ assert_includes Product.find_by_contents('thing')[:results], p2
end
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 570bef3..9fa8449 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../test_helper'
class ProfileTest < Test::Unit::TestCase
fixtures :profiles, :environments, :users, :roles, :domains
+ def setup
+ Test::Unit::TestCase::setup
+ end
+
def test_identifier_validation
p = Profile.new
p.valid?
@@ -100,8 +104,8 @@ class ProfileTest < Test::Unit::TestCase
def test_find_by_contents
p = create(Profile, :name => 'wanted')
- assert Profile.find_by_contents('wanted').include?(p)
- assert ! Profile.find_by_contents('not_wanted').include?(p)
+ 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
@@ -192,10 +196,10 @@ class ProfileTest < Test::Unit::TestCase
small = create(Profile, :name => 'A small profile for testing')
big = create(Profile, :name => 'A big profile for testing')
- assert Profile.find_by_contents('small').include?(small)
- assert Profile.find_by_contents('big').include?(big)
+ 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')
+ both = Profile.find_by_contents('profile testing')[:results]
assert both.include?(small)
assert both.include?(big)
end
@@ -517,18 +521,18 @@ class ProfileTest < Test::Unit::TestCase
should 'actually index by results of extra_data_for_index' do
profile = TestingExtraDataForIndex.create!(:name => 'testprofile', :identifier => 'testprofile')
- assert_includes TestingExtraDataForIndex.find_by_contents('sample'), profile
+ assert_includes TestingExtraDataForIndex.find_by_contents('sample')[:results], profile
end
should 'index profile identifier for searching' do
Profile.destroy_all
p = create(Profile, :identifier => 'lalala')
- assert_includes Profile.find_by_contents('lalala'), p
+ assert_includes Profile.find_by_contents('lalala')[:results], p
end
should 'index profile name for searching' do
p = create(Profile, :name => 'Interesting Profile')
- assert_includes Profile.find_by_contents('interesting'), p
+ assert_includes Profile.find_by_contents('interesting')[:results], p
end
should 'enabled by default on creation' do
@@ -1671,24 +1675,24 @@ class ProfileTest < Test::Unit::TestCase
should 'index by schema name when database is postgresql' do
uses_postgresql 'schema_one'
p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing')
- assert_equal Profile.find_by_contents('thing'), [p1]
+ assert_equal Profile.find_by_contents('thing')[:results], [p1]
uses_postgresql 'schema_two'
p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing')
- assert_not_includes Profile.find_by_contents('thing'), p1
- assert_includes Profile.find_by_contents('thing'), p2
+ 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'), p1
- assert_not_includes Profile.find_by_contents('thing'), p2
+ 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
uses_sqlite
p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing')
- assert_equal Profile.find_by_contents('thing'), [p1]
+ assert_equal Profile.find_by_contents('thing')[:results], [p1]
p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing')
- assert_includes Profile.find_by_contents('thing'), p1
- assert_includes Profile.find_by_contents('thing'), p2
+ 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
diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb
index 6a44928..6239aa1 100644
--- a/test/unit/tiny_mce_article_test.rb
+++ b/test/unit/tiny_mce_article_test.rb
@@ -3,7 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper'
class TinyMceArticleTest < Test::Unit::TestCase
def setup
- Article.rebuild_index
+ Test::Unit::TestCase::setup
+ Article.rebuild_solr_index
@profile = create_user('zezinho').person
end
attr_reader :profile
@@ -23,8 +24,8 @@ class TinyMceArticleTest < Test::Unit::TestCase
should 'be found when searching for articles by query' do
tma = TinyMceArticle.create!(:name => 'test tinymce article', :body => '---', :profile => profile)
- assert_includes TinyMceArticle.find_by_contents('article'), tma
- assert_includes Article.find_by_contents('article'), tma
+ 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
diff --git a/vendor/plugins/acts_as_solr/lib/parser_methods.rb b/vendor/plugins/acts_as_solr/lib/parser_methods.rb
index dd0b6ba..bb46e9b 100644
--- a/vendor/plugins/acts_as_solr/lib/parser_methods.rb
+++ b/vendor/plugins/acts_as_solr/lib/parser_methods.rb
@@ -87,7 +87,7 @@ module ActsAsSolr #:nodoc:
def solr_type_condition
subclasses.inject("(#{solr_configuration[:type_field]}:#{self.name}") do |condition, subclass|
- condition << " OR #{solr_configuration[:type_field]}:#{subclass.name}"
+ condition << (subclass.name.empty? ? "" : " OR #{solr_configuration[:type_field]}:#{subclass.name}")
end << ')'
end
@@ -198,4 +198,4 @@ module ActsAsSolr #:nodoc:
end
end
-end
\ No newline at end of file
+end
--
libgit2 0.21.2