From 8151ee678bcd2cfab261bdf4703e3611fba41d22 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Sat, 19 May 2012 14:49:13 +0000 Subject: [PATCH] Fix tests and mock Solr when not necessary --- app/controllers/my_profile/cms_controller.rb | 1 + app/controllers/public/profile_search_controller.rb | 3 +-- app/controllers/public/search_controller.rb | 2 +- app/models/article.rb | 5 ++++- app/models/product.rb | 2 +- app/models/profile.rb | 4 +++- app/models/region.rb | 7 +++---- app/views/search/_results_header.rhtml | 8 +++++--- db/schema.rb | 86 +++++++++----------------------------------------------------------------------------- test/functional/cms_controller_test.rb | 4 +++- test/functional/enterprise_registration_controller_test.rb | 7 ++++--- test/functional/profile_editor_controller_test.rb | 1 - test/functional/profile_members_controller_test.rb | 2 +- test/functional/profile_search_controller_test.rb | 3 ++- test/functional/region_validators_controller_test.rb | 1 + test/functional/search_controller_test.rb | 26 +++++++++++++++----------- test/integration/assigning_validator_organizations_to_regions_test.rb | 1 + test/integration/performance_test.rb | 1 + test/test_helper.rb | 12 ++++++++---- test/test_solr_helper.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/acts_as_faceted_test.rb | 14 +++++++------- test/unit/article_test.rb | 43 +++++++++++++++++++------------------------ test/unit/category_test.rb | 8 +++++++- test/unit/enterprise_test.rb | 4 +++- test/unit/environment_test.rb | 7 ++----- test/unit/event_test.rb | 6 ++---- test/unit/product_categorization_test.rb | 8 -------- test/unit/product_test.rb | 35 ++++++++++++++++++++++------------- test/unit/profile_test.rb | 18 ++++++++++++------ test/unit/region_test.rb | 6 ++++-- test/unit/set_profile_region_from_city_state_test.rb | 5 +++++ test/unit/text_article_test.rb | 1 + test/unit/tiny_mce_article_test.rb | 4 ++-- vendor/plugins/delayed_job/lib/delayed/message_sending.rb | 2 +- 34 files changed, 201 insertions(+), 186 deletions(-) create mode 100644 test/test_solr_helper.rb delete mode 100644 test/unit/product_categorization_test.rb diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 1f91881..cf0a19d 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -289,6 +289,7 @@ class CmsController < MyProfileController results = query.blank? ? [] : profile.articles.published.find_by_contents(query)[:results] render :text => article_list_to_json(results), :content_type => 'application/json' end + def media_upload files_uploaded = [] parent = check_parent(params[:parent_id]) diff --git a/app/controllers/public/profile_search_controller.rb b/app/controllers/public/profile_search_controller.rb index e69174d..d6b1209 100644 --- a/app/controllers/public/profile_search_controller.rb +++ b/app/controllers/public/profile_search_controller.rb @@ -11,8 +11,7 @@ class ProfileSearchController < PublicController if params[:where] == 'environment' redirect_to :controller => 'search', :query => @q else - @results = Article.find_by_contents(@q, {:per_page => 10, :page => params[:page]}, - {:filter_queries => ["profile_id:#{profile.id}", 'public:true']})[:results] + @results = profile.articles.published.find_by_contents(@q, {:per_page => 10, :page => params[:page]})[:results] end end end diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 8f30109..68e13a6 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -54,7 +54,7 @@ class SearchController < PublicController sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'} if @geosearch full_text_search ['public:true', "{!geofilt}"], :sql_options => sql_options, :extra_limit => extra_limit, - :alternate_query => "{!boost b=recip(geodist(),#{1/DistBoost},1,1)}", + :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}", :radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng else full_text_search ['public:true'], :sql_options => sql_options, :extra_limit => extra_limit, diff --git a/app/models/article.rb b/app/models/article.rb index 8364cb5..3260c90 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -109,6 +109,8 @@ class Article < ActiveRecord::Base pending_categorizations << c else ArticleCategorization.add_category_to_article(c, self) + self.categories(true) + self.solr_save end self.categories(reload) end @@ -151,7 +153,8 @@ class Article < ActiveRecord::Base } named_scope :public, - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ] + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ], + :include => [:profile] named_scope :more_recent, :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND diff --git a/app/models/product.rb b/app/models/product.rb index af0f9d0..f432931 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -20,7 +20,7 @@ class Product < ActiveRecord::Base validates_numericality_of :price, :allow_nil => true validates_numericality_of :discount, :allow_nil => true - named_scope :more_recent, :order => "updated_at DESC" + named_scope :more_recent, :order => "created_at DESC" after_update :save_image diff --git a/app/models/profile.rb b/app/models/profile.rb index 8a4aef2..3d8bdcd 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -236,6 +236,8 @@ class Profile < ActiveRecord::Base pending_categorizations << c else ProfileCategorization.add_category_to_profile(c, self) + self.categories(true) + self.solr_save end self.categories(reload) end @@ -853,7 +855,7 @@ private :generate_url, :url_options c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0 end def f_categories - category_ids + category_ids - [region_id] end def f_region self.region_id diff --git a/app/models/region.rb b/app/models/region.rb index 8e95afc..cd9a64b 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -7,16 +7,15 @@ class Region < Category # searches for organizations that could become validators for this region. # search is passed as is to find_by_contents on Organization. def search_possible_validators(search) - Organization.find_by_contents(search)[:results].reject {|item| self.validator_ids.include?(item.id) } + Organization.find_by_contents(search)[:results].docs.reject {|item| self.validator_ids.include?(item.id) } end def has_validator? validators.count > 0 end - def self.with_validators - Region.find(:all, :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)', :select => "distinct #{table_name}.*") - end + named_scope :with_validators, :group => 'id', + :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)' end diff --git a/app/views/search/_results_header.rhtml b/app/views/search/_results_header.rhtml index cb2402b..b608f40 100644 --- a/app/views/search/_results_header.rhtml +++ b/app/views/search/_results_header.rhtml @@ -1,9 +1,11 @@
"> <% if !@empty_query %>
- <%= label_total_found(@asset, @results[@asset].total_entries) %> - <% if params[:display] != 'map' %> - <%= _("Showing page %s of %s") % [@results[@asset].current_page, @results[@asset].total_pages] %> + <% if @results[@asset].total_entries > 0 %> + <%= label_total_found(@asset, @results[@asset].total_entries) %> + <% if params[:display] != 'map' %> + <%= _("Showing page %s of %s") % [@results[@asset].current_page, @results[@asset].total_pages] %> + <% end %> <% end %>
diff --git a/db/schema.rb b/db/schema.rb index e7f4701..1d4575f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version => 20120411132751) do end add_index "action_tracker_notifications", ["action_tracker_id"], :name => "index_action_tracker_notifications_on_action_tracker_id" - add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notifications_on_profile_id_and_action_tra", :unique => true + add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notif_on_prof_id_act_tracker_id", :unique => true add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id" create_table "article_versions", :force => true do |t| @@ -159,37 +159,7 @@ ActiveRecord::Schema.define(:version => 20120411132751) do t.integer "position" end - add_index "boxes", ["owner_type", "owner_id"], :name => "index_boxes_on_owner_type_and_owner_id" - - create_table "bsc_plugin_contracts", :force => true do |t| - t.string "client_name" - t.integer "client_type" - t.integer "business_type" - t.string "state" - t.string "city" - t.integer "status", :default => 0 - t.integer "number_of_producers", :default => 0 - t.datetime "supply_start" - t.datetime "supply_end" - t.text "annotations" - t.integer "bsc_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "bsc_plugin_contracts_enterprises", :id => false, :force => true do |t| - t.integer "contract_id" - t.integer "enterprise_id" - end - - create_table "bsc_plugin_sales", :force => true do |t| - t.integer "product_id", :null => false - t.integer "contract_id", :null => false - t.integer "quantity", :null => false - t.decimal "price" - t.datetime "created_at" - t.datetime "updated_at" - end + add_index "boxes", ["owner_id", "owner_type"], :name => "index_boxes_on_owner_type_and_owner_id" create_table "categories", :force => true do |t| t.string "name" @@ -283,7 +253,6 @@ ActiveRecord::Schema.define(:version => 20120411132751) do t.text "terms_of_use_acceptance_text" t.datetime "created_at" t.datetime "updated_at" - t.text "send_email_plugin_allow_to" t.integer "reports_lower_bound", :default => 0, :null => false end @@ -361,28 +330,6 @@ ActiveRecord::Schema.define(:version => 20120411132751) do t.datetime "updated_at" end - create_table "mezuro_plugin_metrics", :force => true do |t| - t.string "name" - t.float "value" - t.integer "metricable_id" - t.string "metricable_type" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "mezuro_plugin_projects", :force => true do |t| - t.string "name" - t.string "identifier" - t.string "personal_webpage" - t.text "description" - t.string "repository_url" - t.string "svn_error" - t.boolean "with_tab" - t.integer "profile_id" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "national_region_types", :force => true do |t| t.string "name" end @@ -450,7 +397,7 @@ ActiveRecord::Schema.define(:version => 20120411132751) do t.string "type" t.string "identifier" t.integer "environment_id" - t.boolean "active", :default => true + t.boolean "active", :default => true t.string "address" t.string "contact_phone" t.integer "home_page_id" @@ -461,23 +408,18 @@ ActiveRecord::Schema.define(:version => 20120411132751) do t.float "lat" t.float "lng" t.integer "geocode_precision" - t.boolean "enabled", :default => true - t.string "nickname", :limit => 16 + t.boolean "enabled", :default => true + t.string "nickname", :limit => 16 t.text "custom_header" t.text "custom_footer" t.string "theme" - t.boolean "public_profile", :default => true + t.boolean "public_profile", :default => true t.date "birth_date" t.integer "preferred_domain_id" t.datetime "updated_at" - t.boolean "visible", :default => true + t.boolean "visible", :default => true t.integer "image_id" - t.integer "bsc_id" - t.string "company_name" - t.boolean "shopping_cart", :default => true - t.boolean "shopping_cart_delivery", :default => false - t.decimal "shopping_cart_delivery_price", :default => 0.0 - t.boolean "validated", :default => true + t.boolean "validated", :default => true t.string "cnpj" t.string "national_region_code" end @@ -527,9 +469,9 @@ ActiveRecord::Schema.define(:version => 20120411132751) do create_table "roles", :force => true do |t| t.string "name" - t.text "permissions" t.string "key" t.boolean "system", :default => false + t.text "permissions" t.integer "environment_id" end @@ -542,15 +484,6 @@ ActiveRecord::Schema.define(:version => 20120411132751) do t.datetime "updated_at" end - create_table "shopping_cart_plugin_purchase_orders", :force => true do |t| - t.integer "customer_id" - t.integer "seller_id" - t.text "data" - t.integer "status" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "taggings", :force => true do |t| t.integer "tag_id" t.integer "taggable_id" @@ -578,7 +511,6 @@ ActiveRecord::Schema.define(:version => 20120411132751) do t.datetime "created_at" t.string "target_type" t.integer "image_id" - t.integer "bsc_id" end create_table "thumbnails", :force => true do |t| diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 0b47b97..dd3fb21 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -9,7 +9,7 @@ class CmsControllerTest < ActionController::TestCase fixtures :environments def setup - ActiveSupport::TestCase::setup + super @controller = CmsController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @@ -283,6 +283,7 @@ class CmsControllerTest < ActionController::TestCase end should 'display destination folder of files when uploading file' do + TestSolr.enable f = Folder.new(:name => 'f'); profile.articles << f; f.save! get :upload_files, :profile => profile.identifier, :parent_id => f.id @@ -1447,6 +1448,7 @@ class CmsControllerTest < ActionController::TestCase end should 'search for content for inclusion in articles' do + TestSolr.enable file = UploadedFile.create!(:profile => @profile, :uploaded_data => fixture_file_upload('files/test.txt', 'text/plain')) get :search, :profile => @profile.identifier, :q => 'test.txt' assert_match /test.txt/, @response.body diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb index ef56bf2..bd9ff4e 100644 --- a/test/functional/enterprise_registration_controller_test.rb +++ b/test/functional/enterprise_registration_controller_test.rb @@ -6,10 +6,11 @@ class EnterpriseRegistrationController; def rescue_action(e) raise e end; end class EnterpriseRegistrationControllerTest < ActionController::TestCase -# all_fixtures:users -all_fixtures + # all_fixtures:users + all_fixtures + def setup - ActiveSupport::TestCase::setup + super @controller = EnterpriseRegistrationController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 5b6024a..dd615ca 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -751,7 +751,6 @@ class ProfileEditorControllerTest < ActionController::TestCase assert_nothing_raised do post :edit, :profile => c.identifier, :profile_data => c.attributes.merge('identifier' => '') end - assert_response :success end should 'show active fields when edit community' do diff --git a/test/functional/profile_members_controller_test.rb b/test/functional/profile_members_controller_test.rb index a209c7f..9fdbb1a 100644 --- a/test/functional/profile_members_controller_test.rb +++ b/test/functional/profile_members_controller_test.rb @@ -6,7 +6,7 @@ class ProfileMembersController; def rescue_action(e) raise e end; end class ProfileMembersControllerTest < ActionController::TestCase def setup - ActiveSupport::TestCase::setup + super @controller = ProfileMembersController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new diff --git a/test/functional/profile_search_controller_test.rb b/test/functional/profile_search_controller_test.rb index 66df80a..fce3b8a 100644 --- a/test/functional/profile_search_controller_test.rb +++ b/test/functional/profile_search_controller_test.rb @@ -6,7 +6,8 @@ class ProfileSearchController; def rescue_action(e) raise e end; end class ProfileSearchControllerTest < ActionController::TestCase def setup - ActiveSupport::TestCase::setup + super + TestSolr.enable @controller = ProfileSearchController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new diff --git a/test/functional/region_validators_controller_test.rb b/test/functional/region_validators_controller_test.rb index 2447fe2..af9b7c9 100644 --- a/test/functional/region_validators_controller_test.rb +++ b/test/functional/region_validators_controller_test.rb @@ -46,6 +46,7 @@ class RegionValidatorsControllerTest < ActionController::TestCase end should 'search possible validators by name' do + TestSolr.enable environment = fast_create(Environment, :name => "my environment") give_permission('ze', 'manage_environment_validators', environment) region = Region.new(:name => 'my region') diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index a68d320..396e386 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -5,8 +5,10 @@ require 'search_controller' class SearchController; def rescue_action(e) raise e end; end class SearchControllerTest < ActionController::TestCase + def setup - ActiveSupport::TestCase::setup + super + TestSolr.enable @controller = SearchController.new @request = ActionController::TestRequest.new @request.stubs(:ssl?).returns(false) @@ -138,18 +140,18 @@ class SearchControllerTest < ActionController::TestCase should 'get facets with people search results' do state = fast_create(State, :name => 'Acre', :acronym => 'AC') city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) - person = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id) - person.region = city + person = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :region_id => city.id) cat1 = fast_create(Category, :name => 'cat1') cat2 = fast_create(Category, :name => 'cat2') - person.add_category cat1, false - person.add_category cat2, true - person.save! + person.add_category cat1 + person.add_category cat2 get 'people', :query => 'Hildebrando' assert !assigns(:results)[:people].facets.blank? assert assigns(:results)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s + + assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'].count == 2 assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'][0][0] == cat1.id.to_s assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'][1][0] == cat2.id.to_s end @@ -499,24 +501,26 @@ class SearchControllerTest < ActionController::TestCase assert_not_equal result1, result2 end - should 'order products by geolocalization in empty search' do + should 'remove far products by geolocalization empty logged search' do user = create_user('a_logged_user') + # trigger geosearch user.person.lat = '1.0' user.person.lng = '1.0' - # trigger geosearch SearchController.any_instance.stubs(:logged_in?).returns(true) SearchController.any_instance.stubs(:current_user).returns(user) cat = fast_create(ProductCategory) - ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0') + ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '1.3', :lng => '1.3') prod1 = Product.create!(:name => 'produto 1', :enterprise_id => ent1.id, :product_category_id => cat.id) ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') prod2 = Product.create!(:name => 'produto 2', :enterprise_id => ent2.id, :product_category_id => cat.id) - ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0') + ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '1.6', :lng => '1.6') prod3 = Product.create!(:name => 'produto 3', :enterprise_id => ent3.id, :product_category_id => cat.id) + ent4 = Enterprise.create!(:name => 'ent4', :identifier => 'ent4', :lat => '10', :lng => '10') + prod4 = Product.create!(:name => 'produto 4', :enterprise_id => ent4.id, :product_category_id => cat.id) get :products - assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs + assert_equivalent [prod1, prod3, prod2], assigns(:results)[:products].docs end should 'display properly in conjuntion with a category' do diff --git a/test/integration/assigning_validator_organizations_to_regions_test.rb b/test/integration/assigning_validator_organizations_to_regions_test.rb index 31a1d4c..06c5e4c 100644 --- a/test/integration/assigning_validator_organizations_to_regions_test.rb +++ b/test/integration/assigning_validator_organizations_to_regions_test.rb @@ -3,6 +3,7 @@ require "#{File.dirname(__FILE__)}/../test_helper" class AssigningValidatorOrganizationsToRegionsTest < ActionController::IntegrationTest should 'be able to properly assign organizations as validators to regions' do + TestSolr.enable env = Environment.default Organization.destroy_all diff --git a/test/integration/performance_test.rb b/test/integration/performance_test.rb index c1f8084..ff70caf 100644 --- a/test/integration/performance_test.rb +++ b/test/integration/performance_test.rb @@ -54,6 +54,7 @@ class PerformanceTest < ActionController::IntegrationTest end should 'not have a linear increase in time to save enterprise due to amount of products' do + $DISABLE_DELAYED_JOB_TEST_ENV_RUN = true enterprise0 = Enterprise.create!(:name => 'Enterprise 0', :identifier => 'enterprise0') enterprise1 = Enterprise.create!(:name => 'Enterprise 1', :identifier => 'enterprise1') enterprise2 = Enterprise.create!(:name => 'Enterprise 2', :identifier => 'enterprise2') diff --git a/test/test_helper.rb b/test/test_helper.rb index ac34778..1ba032d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,6 +17,7 @@ require 'noosfero/test' require File.dirname(__FILE__) + '/factories' require File.dirname(__FILE__) + '/noosfero_doc_test' require File.dirname(__FILE__) + '/action_tracker_test_helper' +require File.expand_path(File.dirname(__FILE__) + "/test_solr_helper.rb") FileUtils.rm_rf(File.join(RAILS_ROOT, 'index', 'test')) @@ -59,11 +60,14 @@ class ActiveSupport::TestCase fixtures :environments, :roles - def self.setup - # clean up index db before each test - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*')) + def setup + TestSolr.disable end - + + def teardown + TestSolr.disable + end + def self.all_fixtures Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.yml')).each do |item| fixtures File.basename(item).sub(/\.yml$/, '').to_s diff --git a/test/test_solr_helper.rb b/test/test_solr_helper.rb new file mode 100644 index 0000000..9e77e27 --- /dev/null +++ b/test/test_solr_helper.rb @@ -0,0 +1,50 @@ +class ActsAsSolr::Post + class << self + alias_method :execute_orig, :execute + end +end +module ActsAsSolr::ParserMethods + alias_method :parse_results_orig, :parse_results +end + +class TestSolr + + def self.enable + ActsAsSolr::Post.class_eval do + def self.execute(*args) + execute_orig *args + end + end + ActsAsSolr::ParserMethods.module_eval do + def parse_results(*args) + parse_results_orig *args + end + end + + # clear index + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*')) + + @solr_disabled = false + end + + def self.disable + return if @solr_disabled + + ActsAsSolr::Post.class_eval do + def self.execute(*args) + true + end + end + ActsAsSolr::ParserMethods.module_eval do + def parse_results(*args) + parse_results_orig nil, args[1] + end + end + + @solr_disabled = true + end + +end + +# disable solr actions by default +TestSolr.disable diff --git a/test/unit/acts_as_faceted_test.rb b/test/unit/acts_as_faceted_test.rb index 71f1ccc..54c848b 100644 --- a/test/unit/acts_as_faceted_test.rb +++ b/test/unit/acts_as_faceted_test.rb @@ -10,8 +10,6 @@ class TestModel < ActiveRecord::Base 'Event' => "Event", 'EnterpriseHomepage' => "Homepage", 'Gallery' => "Gallery", - 'Blog' => "Blog", - 'Forum' => "Forum" } h[klass] end @@ -26,7 +24,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase def setup @facets = { "facet_fields"=> { - "f_type_facet"=>{"TextArticle"=>15, "Blog"=>3, "Folder"=>3, "Forum"=>1, "UploadedFile"=>6, "Gallery"=>1}, + "f_type_facet"=>{"TextArticle"=>15, "Folder"=>3, "UploadedFile"=>6, "Gallery"=>1}, }, "facet_ranges"=>{}, "facet_dates"=>{}, "facet_queries"=>{"f_published_at_d:[* TO NOW-1YEARS/DAY]"=>10, "f_published_at_d:[NOW-1YEARS TO NOW/DAY]"=>19} } @@ -85,7 +83,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase f = facets.select{ |f| f[:id] == 'f_type' }.first r = TestModel.map_facet_results f, @facet_params, @facets, @all_facets, {} - assert_equivalent [["TextArticle", 'Text', 15], ["Blog", "Blog", 3], ["Folder", "Folder", 3], ["Forum", "Forum", 1], ["UploadedFile", "Uploaded File", 6], ["Gallery", "Gallery", 1]], r + assert_equivalent [["TextArticle", 'Text', 15], ["Folder", "Folder", 3], ["UploadedFile", "Uploaded File", 6], ["Gallery", "Gallery", 1]], r f = facets.select{ |f| f[:id] == 'f_published_at' }.first r = TestModel.map_facet_results f, @facet_params, @facets, @all_facets, {} @@ -132,7 +130,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase should 'return facet options hash in acts_as_solr format' do options = TestModel.facets_find_options()[:facets] assert_equal [:f_type], options[:fields] - assert_equal ["f_published_at:[NOW-1YEARS TO NOW/DAY]", "f_published_at:[* TO NOW-1YEARS/DAY]"], options[:query] + assert_equivalent ["f_published_at:[NOW-1YEARS TO NOW/DAY]", "f_published_at:[* TO NOW-1YEARS/DAY]"], options[:query] end should 'return browse options hash in acts_as_solr format' do @@ -148,7 +146,8 @@ class ActsAsFacetedTest < ActiveSupport::TestCase facet = facets.select{ |f| f[:id] == 'f_type' }.first facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {} sorted = TestModel.facet_result_sort(facet, facet_data, :alphabetically) - assert_equal [["Blog", "Blog", 3], ["Folder", "Folder", 3], ["Forum", "Forum", 1], ["Gallery", "Gallery", 1], ["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6]], sorted + assert_equal sorted, + [["Folder", "Folder", 3], ["Gallery", "Gallery", 1], ["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6]] end should 'sort facet results by count' do @@ -156,6 +155,7 @@ class ActsAsFacetedTest < ActiveSupport::TestCase facet = facets.select{ |f| f[:id] == 'f_type' }.first facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {} sorted = TestModel.facet_result_sort(facet, facet_data, :count) - assert_equal [["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6], ["Blog", "Blog", 3], ["Folder", "Folder", 3], ["Forum", "Forum", 1], ["Gallery", "Gallery", 1]], sorted + assert_equal sorted, + [["TextArticle", "Text", 15], ["UploadedFile", "Uploaded File", 6], ["Folder", "Folder", 3], ["Gallery", "Gallery", 1]] end end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 19511ed..e616cab 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -148,8 +148,6 @@ class ArticleTest < ActiveSupport::TestCase should 'search for recent documents' do other_profile = create_user('otherpropfile').person - Article.destroy_all - first = fast_create(TextArticle, :profile_id => profile.id, :name => 'first') second = fast_create(TextArticle, :profile_id => profile.id, :name => 'second') third = fast_create(TextArticle, :profile_id => profile.id, :name => 'third') @@ -365,6 +363,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'index comments title together with article' do + TestSolr.enable owner = create_user('testuser').person art = owner.articles.build(:name => 'ytest'); art.save! c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save! @@ -373,6 +372,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'index comments body together with article' do + TestSolr.enable owner = create_user('testuser').person art = owner.articles.build(:name => 'ytest'); art.save! c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save! @@ -1525,6 +1525,7 @@ class ArticleTest < ActiveSupport::TestCase 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 @@ -1539,6 +1540,7 @@ class ArticleTest < ActiveSupport::TestCase 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 @@ -1690,6 +1692,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'act as searchable' do + TestSolr.enable person = fast_create(Person, :name => "Hiro", :address => 'U-Stor-It @ Inglewood, California', :nickname => 'Protagonist') person2 = fast_create(Person, :name => "Raven") @@ -1726,6 +1729,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'boost name matches' do + TestSolr.enable person = fast_create(Person) in_body = Article.create!(:name => 'something', :profile_id => person.id, :body => 'bananas in the body!') in_name = Article.create!(:name => 'bananas in the name!', :profile_id => person.id) @@ -1733,6 +1737,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'boost if profile is enabled' do + TestSolr.enable person2 = fast_create(Person, :enabled => false) art_profile_disabled = Article.create!(:name => 'profile disabled', :profile_id => person2.id) person1 = fast_create(Person, :enabled => true) @@ -1749,6 +1754,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'show more popular articles' do + Article.destroy_all art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id) art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id) art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id) @@ -1760,30 +1766,19 @@ class ArticleTest < ActiveSupport::TestCase assert_equal [art3, art1, art2], Article.more_popular end - should 'return more commented with pagination' do - art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id) - art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id) - art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id) - - art1.comments_count = 56; art1.save! - art3.comments_count = 92; art3.save! - art2.comments_count = 3; art2.save! - - assert_equal [art3, art1], Article.most_commented(2) - end - should 'show if article is public' do art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id) - art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id) - art2.advertise = false; art2.save! - art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id) - art3.published = false; art3.save! - art4 = Article.create!(:name => 'article 4', :profile_id => fast_create(Person).id) - art4.profile.visible = false; art4.save! - art5 = Article.create!(:name => 'article 5', :profile_id => fast_create(Person).id) - art5.profile.public_profile = false; art5.save! - - assert_equal [art1], Article.public + art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id, :advertise => false) + art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id, :published => false) + art4 = Article.create!(:name => 'article 4', :profile_id => fast_create(Person, :visible => false).id) + art5 = Article.create!(:name => 'article 5', :profile_id => fast_create(Person, :public_profile => false).id) + + articles = Article.public + assert_includes articles, art1 + assert_not_includes articles, art2 + assert_not_includes articles, art3 + assert_not_includes articles, art4 + assert_not_includes articles, art5 end end diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb index dce6eee..f1f58ba 100644 --- a/test/unit/category_test.rb +++ b/test/unit/category_test.rb @@ -514,6 +514,7 @@ class CategoryTest < ActiveSupport::TestCase end should 'act as searchable' do + TestSolr.enable parent = fast_create(Category, :name => 'books') c = Category.create!(:name => "science fiction", :acronym => "sf", :abbreviation => "sci-fi", :environment_id => Environment.default.id, :parent_id => parent.id) @@ -528,6 +529,7 @@ class CategoryTest < ActiveSupport::TestCase end should 'boost name matches' do + TestSolr.enable c_abbr = Category.create!(:name => "something else", :abbreviation => "science", :environment_id => Environment.default.id) c_name = Category.create!(:name => "science fiction", :environment_id => Environment.default.id) assert_equal [c_name, c_abbr], Category.find_by_contents("science")[:results].docs @@ -542,8 +544,12 @@ class CategoryTest < ActiveSupport::TestCase 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) - Category.expects(:solr_batch_add).with(includes(art)) 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/enterprise_test.rb b/test/unit/enterprise_test.rb index 53642a8..7471ead 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -4,7 +4,7 @@ class EnterpriseTest < ActiveSupport::TestCase fixtures :profiles, :environments, :users def setup - ActiveSupport::TestCase::setup + super @product_category = fast_create(ProductCategory, :name => 'Products') end @@ -86,6 +86,7 @@ class EnterpriseTest < ActiveSupport::TestCase 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) @@ -99,6 +100,7 @@ class EnterpriseTest < ActiveSupport::TestCase 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) diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 28c3884..1c8be57 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -3,11 +3,6 @@ require File.dirname(__FILE__) + '/../test_helper' class EnvironmentTest < ActiveSupport::TestCase fixtures :environments - def setup - ActiveSupport::TestCase::setup - Article.rebuild_index - end - def test_exists_default_and_it_is_unique Environment.delete_all vc = Environment.new(:name => 'Test Community') @@ -447,6 +442,7 @@ class EnvironmentTest < ActiveSupport::TestCase end should 'find by contents from articles' do + TestSolr.enable environment = fast_create(Environment) assert_nothing_raised do environment.articles.find_by_contents('')[:results] @@ -550,6 +546,7 @@ class EnvironmentTest < ActiveSupport::TestCase end should 'return more than 10 enterprises by contents' do + TestSolr.enable env = Environment.default Enterprise.destroy_all ('1'..'20').each do |n| diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb index 6edec25..236abf4 100644 --- a/test/unit/event_test.rb +++ b/test/unit/event_test.rb @@ -2,10 +2,6 @@ require File.dirname(__FILE__) + '/../test_helper' class EventTest < ActiveSupport::TestCase - def setup - ActiveSupport::TestCase::setup - end - should 'be an article' do assert_kind_of Article, Event.new end @@ -61,12 +57,14 @@ class EventTest < ActiveSupport::TestCase 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 diff --git a/test/unit/product_categorization_test.rb b/test/unit/product_categorization_test.rb deleted file mode 100644 index 64f6c13..0000000 --- a/test/unit/product_categorization_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class ProductCategorizationTest < ActiveSupport::TestCase - # Replace this with your real tests. - def test_truth - assert true - end -end diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb index a7d30fa..6fd875d 100644 --- a/test/unit/product_test.rb +++ b/test/unit/product_test.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' class ProductTest < ActiveSupport::TestCase def setup - ActiveSupport::TestCase::setup + super @product_category = fast_create(ProductCategory, :name => 'Products') @profile = fast_create(Enterprise) end @@ -105,6 +105,7 @@ class ProductTest < ActiveSupport::TestCase 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') @@ -343,6 +344,7 @@ class ProductTest < ActiveSupport::TestCase 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 @@ -357,6 +359,7 @@ class ProductTest < ActiveSupport::TestCase 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 @@ -583,6 +586,7 @@ class ProductTest < ActiveSupport::TestCase end should 'act as searchable' do + TestSolr.enable s = fast_create(State, :acronym => 'XZ') c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun") @@ -615,6 +619,7 @@ class ProductTest < ActiveSupport::TestCase end should 'boost name matches' do + TestSolr.enable ent = fast_create(Enterprise) cat = fast_create(ProductCategory) in_desc = Product.create!(:name => 'something', :enterprise_id => ent.id, :description => 'bananas in the description!', @@ -632,6 +637,7 @@ class ProductTest < ActiveSupport::TestCase 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, :enterprise_id => @profile.id) product_with_image = Product.create!(:name => 'product with image', :product_category => @product_category, @@ -641,6 +647,7 @@ class ProductTest < ActiveSupport::TestCase end should 'boost search results that include qualifier' do + TestSolr.enable product_without_q = Product.create!(:name => 'product without qualifier', :product_category => @product_category, :enterprise_id => @profile.id) product_with_q = Product.create!(:name => 'product with qualifier', :product_category => @product_category, @@ -652,24 +659,17 @@ class ProductTest < ActiveSupport::TestCase end should 'boost search results with open price' do - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id) - product.price = 100 - product.save! - open_price = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) - open_price.price = 100 - Input.create!(:product_id => open_price.id, :product_category_id => @product_category.id, - :amount_used => 10, :price_per_unit => 10) - open_price.update_price_details [] + TestSolr.enable + product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id, :price => 100) + open_price = Product.new(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id, :price => 100) + open_price.inputs << Input.new(:product => open_price, :product_category_id => @product_category.id, :amount_used => 10, :price_per_unit => 10) open_price.save! - #pp Product::Boosts[2][2].call(product) - #pp Product::Boosts[2][2].call(open_price) - #pp Product.find_by_contents('product')[:results].docs.first.solr_score - #pp Product.find_by_contents('product')[:results].docs.last.solr_score assert_equal [open_price, product], Product.find_by_contents('product')[:results].docs end should 'boost search results with solidarity inputs' do + TestSolr.enable product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id) perc_50 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) Input.create!(:product_id => perc_50.id, :product_category_id => @product_category.id, @@ -692,6 +692,7 @@ class ProductTest < ActiveSupport::TestCase end should 'boost available search results' do + TestSolr.enable product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id) product.available = false product.save! @@ -703,6 +704,7 @@ class ProductTest < ActiveSupport::TestCase end should 'boost search results created updated recently' do + TestSolr.enable product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id) product.update_attribute :created_at, Time.now - 10.day product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) @@ -711,6 +713,7 @@ class ProductTest < ActiveSupport::TestCase end should 'boost search results with description' do + TestSolr.enable product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id, :description => '') product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id, @@ -720,6 +723,7 @@ class ProductTest < ActiveSupport::TestCase end should 'boost if enterprise is enabled' do + TestSolr.enable ent = Enterprise.create!(:name => 'ent', :identifier => 'ent', :enabled => false) product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => ent.id) product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) @@ -728,6 +732,7 @@ class ProductTest < ActiveSupport::TestCase end should 'combine different boost types' do + TestSolr.enable product = Product.create!(:name => 'product', :product_category => @product_category, :enterprise_id => @profile.id) image_only = Product.create!(:name => 'product with image', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, @@ -750,6 +755,10 @@ class ProductTest < ActiveSupport::TestCase prod2 = Product.create!(:name => 'Damaged CD', :enterprise_id => @profile.id, :product_category_id => @product_category.id) prod3 = Product.create!(:name => 'Damaged DVD', :enterprise_id => @profile.id, :product_category_id => @product_category.id) + prod1.update_attribute :created_at, Time.now-2.days + prod2.update_attribute :created_at, Time.now-1.days + prod3.update_attribute :created_at, Time.now + assert_equal [prod3, prod2, prod1], Product.more_recent end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 340f854..03de207 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -4,7 +4,7 @@ class ProfileTest < ActiveSupport::TestCase fixtures :profiles, :environments, :users, :roles, :domains def setup - ActiveSupport::TestCase::setup + super end def test_identifier_validation @@ -102,6 +102,7 @@ class ProfileTest < ActiveSupport::TestCase end def test_find_by_contents + TestSolr.enable p = create(Profile, :name => 'wanted') assert Profile.find_by_contents('wanted')[:results].include?(p) @@ -194,6 +195,7 @@ class ProfileTest < ActiveSupport::TestCase # 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') @@ -441,6 +443,7 @@ class ProfileTest < ActiveSupport::TestCase 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 @@ -521,18 +524,21 @@ class ProfileTest < ActiveSupport::TestCase # content to be added to the index. The block returns "sample indexed text" # see test/mocks/test/testing_extra_data_for_index.rb should 'actually index by results of extra_data_for_index' do + TestSolr.enable profile = TestingExtraDataForIndex.create!(:name => 'testprofile', :identifier => 'testprofile') assert_includes TestingExtraDataForIndex.find_by_contents('sample')[:results], profile 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 @@ -1204,10 +1210,9 @@ class ProfileTest < ActiveSupport::TestCase env = fast_create(Environment) p1 = fast_create(Profile, :identifier => 'mytestprofile', :environment_id => env.id) - p2 = Profile.new(:identifier => 'mytestprofile', :environment => env) - assert !p2.valid? + assert !p2.valid? assert p2.errors.on(:identifier) assert_equal p1.environment, p2.environment end @@ -1683,6 +1688,7 @@ class ProfileTest < ActiveSupport::TestCase 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 @@ -1697,6 +1703,7 @@ class ProfileTest < ActiveSupport::TestCase 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 @@ -1803,15 +1810,13 @@ class ProfileTest < ActiveSupport::TestCase end should 'act as searchable' do + TestSolr.enable st = create(State, :name => 'California', :acronym => 'CA', :environment_id => Environment.default.id) city = create(City, :name => 'Inglewood', :parent_id => st.id, :environment_id => Environment.default.id) p = create(Person, :name => "Hiro", :address => 'U-Stor-It', :nickname => 'Protagonist', :user_id => fast_create(User).id, :region_id => city.id) cat = create(Category, :name => "Science Fiction", :acronym => "sf", :abbreviation => "sci-fi") p.add_category cat - cat.profiles.reload - cat.save! - p.save! # fields assert_includes Profile.find_by_contents('Hiro')[:results].docs, p @@ -1828,6 +1833,7 @@ class ProfileTest < ActiveSupport::TestCase end should 'boost name matches' do + TestSolr.enable in_addr = create(Person, :name => 'something', :address => 'bananas in the address!', :user_id => fast_create(User).id) in_name = create(Person, :name => 'bananas in the name!', :user_id => fast_create(User).id) assert_equal [in_name, in_addr], Person.find_by_contents('bananas')[:results].docs diff --git a/test/unit/region_test.rb b/test/unit/region_test.rb index b2a3f45..c213c4a 100644 --- a/test/unit/region_test.rb +++ b/test/unit/region_test.rb @@ -17,6 +17,7 @@ class RegionTest < ActiveSupport::TestCase end should 'be able to search for possible validators by name' do + TestSolr.enable env = fast_create(Environment) region = fast_create(Region, :environment_id => env.id, :name => 'My Region') org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) @@ -29,10 +30,11 @@ class RegionTest < ActiveSupport::TestCase end should 'return search results without validators that are already associated to the current region' do + TestSolr.enable env = fast_create(Environment) region = fast_create(Region, :environment_id => env.id, :name => 'My Region') - org1 = fast_create(Organization, :name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) - org2 = fast_create(Organization, :name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) + org1 = fast_create(Organization, {:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id}, :search => true) + org2 = fast_create(Organization, {:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id}, :search => true) region.validators << org1 possible = region.search_possible_validators('organization') diff --git a/test/unit/set_profile_region_from_city_state_test.rb b/test/unit/set_profile_region_from_city_state_test.rb index 87f46c0..e3659dd 100644 --- a/test/unit/set_profile_region_from_city_state_test.rb +++ b/test/unit/set_profile_region_from_city_state_test.rb @@ -2,6 +2,11 @@ require File.dirname(__FILE__) + '/../test_helper' class SetProfileRegionFromCityStateTest < ActiveSupport::TestCase + def setup + super + TestSolr.enable + end + should 'set city and state from names' do s = State.create!(:name => 'Sao Paulo', :acronym => 'SP', :environment_id => Environment.default.id) c = City.create!(:name => 'Pindamonhangaba', :parent_id => s.id, :environment_id => Environment.default.id) diff --git a/test/unit/text_article_test.rb b/test/unit/text_article_test.rb index 1a1c532..1665935 100644 --- a/test/unit/text_article_test.rb +++ b/test/unit/text_article_test.rb @@ -15,6 +15,7 @@ class TextArticleTest < ActiveSupport::TestCase 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 diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index 065c8db..23ba890 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -3,8 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' class TinyMceArticleTest < ActiveSupport::TestCase def setup - ActiveSupport::TestCase::setup - Article.rebuild_solr_index + super @profile = create_user('zezinho').person end attr_reader :profile @@ -23,6 +22,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase 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 diff --git a/vendor/plugins/delayed_job/lib/delayed/message_sending.rb b/vendor/plugins/delayed_job/lib/delayed/message_sending.rb index cb26e9d..c9ec6cb 100644 --- a/vendor/plugins/delayed_job/lib/delayed/message_sending.rb +++ b/vendor/plugins/delayed_job/lib/delayed/message_sending.rb @@ -8,7 +8,7 @@ module Delayed end def method_missing(method, *args) - if (Rails.env == "test" or Rails.env == "cucumber") + if (Rails.env == "test" or Rails.env == "cucumber" and !$DISABLE_DELAYED_JOB_TEST_ENV_RUN) @target.send method, *args return end -- libgit2 0.21.2