Commit 8151ee678bcd2cfab261bdf4703e3611fba41d22

Authored by Braulio Bhavamitra
1 parent ce943de2

Fix tests and mock Solr when not necessary

Mocking Solr disable indexing and search,
so it speeds tests that don't need solr.
Tests that need searches have to call TestSolr.enable
app/controllers/my_profile/cms_controller.rb
... ... @@ -289,6 +289,7 @@ class CmsController < MyProfileController
289 289 results = query.blank? ? [] : profile.articles.published.find_by_contents(query)[:results]
290 290 render :text => article_list_to_json(results), :content_type => 'application/json'
291 291 end
  292 +
292 293 def media_upload
293 294 files_uploaded = []
294 295 parent = check_parent(params[:parent_id])
... ...
app/controllers/public/profile_search_controller.rb
... ... @@ -11,8 +11,7 @@ class ProfileSearchController < PublicController
11 11 if params[:where] == 'environment'
12 12 redirect_to :controller => 'search', :query => @q
13 13 else
14   - @results = Article.find_by_contents(@q, {:per_page => 10, :page => params[:page]},
15   - {:filter_queries => ["profile_id:#{profile.id}", 'public:true']})[:results]
  14 + @results = profile.articles.published.find_by_contents(@q, {:per_page => 10, :page => params[:page]})[:results]
16 15 end
17 16 end
18 17 end
... ...
app/controllers/public/search_controller.rb
... ... @@ -54,7 +54,7 @@ class SearchController < PublicController
54 54 sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'}
55 55 if @geosearch
56 56 full_text_search ['public:true', "{!geofilt}"], :sql_options => sql_options, :extra_limit => extra_limit,
57   - :alternate_query => "{!boost b=recip(geodist(),#{1/DistBoost},1,1)}",
  57 + :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}",
58 58 :radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng
59 59 else
60 60 full_text_search ['public:true'], :sql_options => sql_options, :extra_limit => extra_limit,
... ...
app/models/article.rb
... ... @@ -109,6 +109,8 @@ class Article < ActiveRecord::Base
109 109 pending_categorizations << c
110 110 else
111 111 ArticleCategorization.add_category_to_article(c, self)
  112 + self.categories(true)
  113 + self.solr_save
112 114 end
113 115 self.categories(reload)
114 116 end
... ... @@ -151,7 +153,8 @@ class Article &lt; ActiveRecord::Base
151 153 }
152 154  
153 155 named_scope :public,
154   - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ]
  156 + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ],
  157 + :include => [:profile]
155 158  
156 159 named_scope :more_recent,
157 160 :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND
... ...
app/models/product.rb
... ... @@ -20,7 +20,7 @@ class Product &lt; ActiveRecord::Base
20 20 validates_numericality_of :price, :allow_nil => true
21 21 validates_numericality_of :discount, :allow_nil => true
22 22  
23   - named_scope :more_recent, :order => "updated_at DESC"
  23 + named_scope :more_recent, :order => "created_at DESC"
24 24  
25 25 after_update :save_image
26 26  
... ...
app/models/profile.rb
... ... @@ -236,6 +236,8 @@ class Profile &lt; ActiveRecord::Base
236 236 pending_categorizations << c
237 237 else
238 238 ProfileCategorization.add_category_to_profile(c, self)
  239 + self.categories(true)
  240 + self.solr_save
239 241 end
240 242 self.categories(reload)
241 243 end
... ... @@ -853,7 +855,7 @@ private :generate_url, :url_options
853 855 c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0
854 856 end
855 857 def f_categories
856   - category_ids
  858 + category_ids - [region_id]
857 859 end
858 860 def f_region
859 861 self.region_id
... ...
app/models/region.rb
... ... @@ -7,16 +7,15 @@ class Region &lt; Category
7 7 # searches for organizations that could become validators for this region.
8 8 # <tt>search</tt> is passed as is to find_by_contents on Organization.
9 9 def search_possible_validators(search)
10   - Organization.find_by_contents(search)[:results].reject {|item| self.validator_ids.include?(item.id) }
  10 + Organization.find_by_contents(search)[:results].docs.reject {|item| self.validator_ids.include?(item.id) }
11 11 end
12 12  
13 13 def has_validator?
14 14 validators.count > 0
15 15 end
16 16  
17   - def self.with_validators
18   - Region.find(:all, :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)', :select => "distinct #{table_name}.*")
19   - end
  17 + named_scope :with_validators, :group => 'id',
  18 + :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)'
20 19  
21 20 end
22 21  
... ...
app/views/search/_results_header.rhtml
1 1 <div class="search-results-header <%= "search-no-results" if @results[@asset].nil? or @results[@asset].length == 0 %>">
2 2 <% if !@empty_query %>
3 3 <div class="search-results-header-information">
4   - <%= label_total_found(@asset, @results[@asset].total_entries) %>
5   - <% if params[:display] != 'map' %>
6   - <span class="current-page"><%= _("Showing page %s of %s") % [@results[@asset].current_page, @results[@asset].total_pages] %></span>
  4 + <% if @results[@asset].total_entries > 0 %>
  5 + <%= label_total_found(@asset, @results[@asset].total_entries) %>
  6 + <% if params[:display] != 'map' %>
  7 + <span class="current-page"><%= _("Showing page %s of %s") % [@results[@asset].current_page, @results[@asset].total_pages] %></span>
  8 + <% end %>
7 9 <% end %>
8 10 </div>
9 11  
... ...
db/schema.rb
... ... @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
41 41 end
42 42  
43 43 add_index "action_tracker_notifications", ["action_tracker_id"], :name => "index_action_tracker_notifications_on_action_tracker_id"
44   - add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notifications_on_profile_id_and_action_tra", :unique => true
  44 + add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notif_on_prof_id_act_tracker_id", :unique => true
45 45 add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id"
46 46  
47 47 create_table "article_versions", :force => true do |t|
... ... @@ -159,37 +159,7 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
159 159 t.integer "position"
160 160 end
161 161  
162   - add_index "boxes", ["owner_type", "owner_id"], :name => "index_boxes_on_owner_type_and_owner_id"
163   -
164   - create_table "bsc_plugin_contracts", :force => true do |t|
165   - t.string "client_name"
166   - t.integer "client_type"
167   - t.integer "business_type"
168   - t.string "state"
169   - t.string "city"
170   - t.integer "status", :default => 0
171   - t.integer "number_of_producers", :default => 0
172   - t.datetime "supply_start"
173   - t.datetime "supply_end"
174   - t.text "annotations"
175   - t.integer "bsc_id"
176   - t.datetime "created_at"
177   - t.datetime "updated_at"
178   - end
179   -
180   - create_table "bsc_plugin_contracts_enterprises", :id => false, :force => true do |t|
181   - t.integer "contract_id"
182   - t.integer "enterprise_id"
183   - end
184   -
185   - create_table "bsc_plugin_sales", :force => true do |t|
186   - t.integer "product_id", :null => false
187   - t.integer "contract_id", :null => false
188   - t.integer "quantity", :null => false
189   - t.decimal "price"
190   - t.datetime "created_at"
191   - t.datetime "updated_at"
192   - end
  162 + add_index "boxes", ["owner_id", "owner_type"], :name => "index_boxes_on_owner_type_and_owner_id"
193 163  
194 164 create_table "categories", :force => true do |t|
195 165 t.string "name"
... ... @@ -283,7 +253,6 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
283 253 t.text "terms_of_use_acceptance_text"
284 254 t.datetime "created_at"
285 255 t.datetime "updated_at"
286   - t.text "send_email_plugin_allow_to"
287 256 t.integer "reports_lower_bound", :default => 0, :null => false
288 257 end
289 258  
... ... @@ -361,28 +330,6 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
361 330 t.datetime "updated_at"
362 331 end
363 332  
364   - create_table "mezuro_plugin_metrics", :force => true do |t|
365   - t.string "name"
366   - t.float "value"
367   - t.integer "metricable_id"
368   - t.string "metricable_type"
369   - t.datetime "created_at"
370   - t.datetime "updated_at"
371   - end
372   -
373   - create_table "mezuro_plugin_projects", :force => true do |t|
374   - t.string "name"
375   - t.string "identifier"
376   - t.string "personal_webpage"
377   - t.text "description"
378   - t.string "repository_url"
379   - t.string "svn_error"
380   - t.boolean "with_tab"
381   - t.integer "profile_id"
382   - t.datetime "created_at"
383   - t.datetime "updated_at"
384   - end
385   -
386 333 create_table "national_region_types", :force => true do |t|
387 334 t.string "name"
388 335 end
... ... @@ -450,7 +397,7 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
450 397 t.string "type"
451 398 t.string "identifier"
452 399 t.integer "environment_id"
453   - t.boolean "active", :default => true
  400 + t.boolean "active", :default => true
454 401 t.string "address"
455 402 t.string "contact_phone"
456 403 t.integer "home_page_id"
... ... @@ -461,23 +408,18 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
461 408 t.float "lat"
462 409 t.float "lng"
463 410 t.integer "geocode_precision"
464   - t.boolean "enabled", :default => true
465   - t.string "nickname", :limit => 16
  411 + t.boolean "enabled", :default => true
  412 + t.string "nickname", :limit => 16
466 413 t.text "custom_header"
467 414 t.text "custom_footer"
468 415 t.string "theme"
469   - t.boolean "public_profile", :default => true
  416 + t.boolean "public_profile", :default => true
470 417 t.date "birth_date"
471 418 t.integer "preferred_domain_id"
472 419 t.datetime "updated_at"
473   - t.boolean "visible", :default => true
  420 + t.boolean "visible", :default => true
474 421 t.integer "image_id"
475   - t.integer "bsc_id"
476   - t.string "company_name"
477   - t.boolean "shopping_cart", :default => true
478   - t.boolean "shopping_cart_delivery", :default => false
479   - t.decimal "shopping_cart_delivery_price", :default => 0.0
480   - t.boolean "validated", :default => true
  422 + t.boolean "validated", :default => true
481 423 t.string "cnpj"
482 424 t.string "national_region_code"
483 425 end
... ... @@ -527,9 +469,9 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
527 469  
528 470 create_table "roles", :force => true do |t|
529 471 t.string "name"
530   - t.text "permissions"
531 472 t.string "key"
532 473 t.boolean "system", :default => false
  474 + t.text "permissions"
533 475 t.integer "environment_id"
534 476 end
535 477  
... ... @@ -542,15 +484,6 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
542 484 t.datetime "updated_at"
543 485 end
544 486  
545   - create_table "shopping_cart_plugin_purchase_orders", :force => true do |t|
546   - t.integer "customer_id"
547   - t.integer "seller_id"
548   - t.text "data"
549   - t.integer "status"
550   - t.datetime "created_at"
551   - t.datetime "updated_at"
552   - end
553   -
554 487 create_table "taggings", :force => true do |t|
555 488 t.integer "tag_id"
556 489 t.integer "taggable_id"
... ... @@ -578,7 +511,6 @@ ActiveRecord::Schema.define(:version =&gt; 20120411132751) do
578 511 t.datetime "created_at"
579 512 t.string "target_type"
580 513 t.integer "image_id"
581   - t.integer "bsc_id"
582 514 end
583 515  
584 516 create_table "thumbnails", :force => true do |t|
... ...
test/functional/cms_controller_test.rb
... ... @@ -9,7 +9,7 @@ class CmsControllerTest &lt; ActionController::TestCase
9 9 fixtures :environments
10 10  
11 11 def setup
12   - ActiveSupport::TestCase::setup
  12 + super
13 13 @controller = CmsController.new
14 14 @request = ActionController::TestRequest.new
15 15 @response = ActionController::TestResponse.new
... ... @@ -283,6 +283,7 @@ class CmsControllerTest &lt; ActionController::TestCase
283 283 end
284 284  
285 285 should 'display destination folder of files when uploading file' do
  286 + TestSolr.enable
286 287 f = Folder.new(:name => 'f'); profile.articles << f; f.save!
287 288 get :upload_files, :profile => profile.identifier, :parent_id => f.id
288 289  
... ... @@ -1447,6 +1448,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1447 1448 end
1448 1449  
1449 1450 should 'search for content for inclusion in articles' do
  1451 + TestSolr.enable
1450 1452 file = UploadedFile.create!(:profile => @profile, :uploaded_data => fixture_file_upload('files/test.txt', 'text/plain'))
1451 1453 get :search, :profile => @profile.identifier, :q => 'test.txt'
1452 1454 assert_match /test.txt/, @response.body
... ...
test/functional/enterprise_registration_controller_test.rb
... ... @@ -6,10 +6,11 @@ class EnterpriseRegistrationController; def rescue_action(e) raise e end; end
6 6  
7 7 class EnterpriseRegistrationControllerTest < ActionController::TestCase
8 8  
9   -# all_fixtures:users
10   -all_fixtures
  9 + # all_fixtures:users
  10 + all_fixtures
  11 +
11 12 def setup
12   - ActiveSupport::TestCase::setup
  13 + super
13 14 @controller = EnterpriseRegistrationController.new
14 15 @request = ActionController::TestRequest.new
15 16 @response = ActionController::TestResponse.new
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -751,7 +751,6 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
751 751 assert_nothing_raised do
752 752 post :edit, :profile => c.identifier, :profile_data => c.attributes.merge('identifier' => '')
753 753 end
754   - assert_response :success
755 754 end
756 755  
757 756 should 'show active fields when edit community' do
... ...
test/functional/profile_members_controller_test.rb
... ... @@ -6,7 +6,7 @@ class ProfileMembersController; def rescue_action(e) raise e end; end
6 6  
7 7 class ProfileMembersControllerTest < ActionController::TestCase
8 8 def setup
9   - ActiveSupport::TestCase::setup
  9 + super
10 10 @controller = ProfileMembersController.new
11 11 @request = ActionController::TestRequest.new
12 12 @response = ActionController::TestResponse.new
... ...
test/functional/profile_search_controller_test.rb
... ... @@ -6,7 +6,8 @@ class ProfileSearchController; def rescue_action(e) raise e end; end
6 6  
7 7 class ProfileSearchControllerTest < ActionController::TestCase
8 8 def setup
9   - ActiveSupport::TestCase::setup
  9 + super
  10 + TestSolr.enable
10 11 @controller = ProfileSearchController.new
11 12 @request = ActionController::TestRequest.new
12 13 @response = ActionController::TestResponse.new
... ...
test/functional/region_validators_controller_test.rb
... ... @@ -46,6 +46,7 @@ class RegionValidatorsControllerTest &lt; ActionController::TestCase
46 46 end
47 47  
48 48 should 'search possible validators by name' do
  49 + TestSolr.enable
49 50 environment = fast_create(Environment, :name => "my environment")
50 51 give_permission('ze', 'manage_environment_validators', environment)
51 52 region = Region.new(:name => 'my region')
... ...
test/functional/search_controller_test.rb
... ... @@ -5,8 +5,10 @@ require &#39;search_controller&#39;
5 5 class SearchController; def rescue_action(e) raise e end; end
6 6  
7 7 class SearchControllerTest < ActionController::TestCase
  8 +
8 9 def setup
9   - ActiveSupport::TestCase::setup
  10 + super
  11 + TestSolr.enable
10 12 @controller = SearchController.new
11 13 @request = ActionController::TestRequest.new
12 14 @request.stubs(:ssl?).returns(false)
... ... @@ -138,18 +140,18 @@ class SearchControllerTest &lt; ActionController::TestCase
138 140 should 'get facets with people search results' do
139 141 state = fast_create(State, :name => 'Acre', :acronym => 'AC')
140 142 city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id)
141   - person = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id)
142   - person.region = city
  143 + person = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :region_id => city.id)
143 144 cat1 = fast_create(Category, :name => 'cat1')
144 145 cat2 = fast_create(Category, :name => 'cat2')
145   - person.add_category cat1, false
146   - person.add_category cat2, true
147   - person.save!
  146 + person.add_category cat1
  147 + person.add_category cat2
148 148  
149 149 get 'people', :query => 'Hildebrando'
150 150  
151 151 assert !assigns(:results)[:people].facets.blank?
152 152 assert assigns(:results)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
  153 +
  154 + assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'].count == 2
153 155 assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'][0][0] == cat1.id.to_s
154 156 assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'][1][0] == cat2.id.to_s
155 157 end
... ... @@ -499,24 +501,26 @@ class SearchControllerTest &lt; ActionController::TestCase
499 501 assert_not_equal result1, result2
500 502 end
501 503  
502   - should 'order products by geolocalization in empty search' do
  504 + should 'remove far products by geolocalization empty logged search' do
503 505 user = create_user('a_logged_user')
  506 + # trigger geosearch
504 507 user.person.lat = '1.0'
505 508 user.person.lng = '1.0'
506   - # trigger geosearch
507 509 SearchController.any_instance.stubs(:logged_in?).returns(true)
508 510 SearchController.any_instance.stubs(:current_user).returns(user)
509 511  
510 512 cat = fast_create(ProductCategory)
511   - ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0')
  513 + ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '1.3', :lng => '1.3')
512 514 prod1 = Product.create!(:name => 'produto 1', :enterprise_id => ent1.id, :product_category_id => cat.id)
513 515 ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0')
514 516 prod2 = Product.create!(:name => 'produto 2', :enterprise_id => ent2.id, :product_category_id => cat.id)
515   - ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0')
  517 + ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '1.6', :lng => '1.6')
516 518 prod3 = Product.create!(:name => 'produto 3', :enterprise_id => ent3.id, :product_category_id => cat.id)
  519 + ent4 = Enterprise.create!(:name => 'ent4', :identifier => 'ent4', :lat => '10', :lng => '10')
  520 + prod4 = Product.create!(:name => 'produto 4', :enterprise_id => ent4.id, :product_category_id => cat.id)
517 521  
518 522 get :products
519   - assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs
  523 + assert_equivalent [prod1, prod3, prod2], assigns(:results)[:products].docs
520 524 end
521 525  
522 526 should 'display properly in conjuntion with a category' do
... ...
test/integration/assigning_validator_organizations_to_regions_test.rb
... ... @@ -3,6 +3,7 @@ require &quot;#{File.dirname(__FILE__)}/../test_helper&quot;
3 3 class AssigningValidatorOrganizationsToRegionsTest < ActionController::IntegrationTest
4 4  
5 5 should 'be able to properly assign organizations as validators to regions' do
  6 + TestSolr.enable
6 7 env = Environment.default
7 8  
8 9 Organization.destroy_all
... ...
test/integration/performance_test.rb
... ... @@ -54,6 +54,7 @@ class PerformanceTest &lt; ActionController::IntegrationTest
54 54 end
55 55  
56 56 should 'not have a linear increase in time to save enterprise due to amount of products' do
  57 + $DISABLE_DELAYED_JOB_TEST_ENV_RUN = true
57 58 enterprise0 = Enterprise.create!(:name => 'Enterprise 0', :identifier => 'enterprise0')
58 59 enterprise1 = Enterprise.create!(:name => 'Enterprise 1', :identifier => 'enterprise1')
59 60 enterprise2 = Enterprise.create!(:name => 'Enterprise 2', :identifier => 'enterprise2')
... ...
test/test_helper.rb
... ... @@ -17,6 +17,7 @@ require &#39;noosfero/test&#39;
17 17 require File.dirname(__FILE__) + '/factories'
18 18 require File.dirname(__FILE__) + '/noosfero_doc_test'
19 19 require File.dirname(__FILE__) + '/action_tracker_test_helper'
  20 +require File.expand_path(File.dirname(__FILE__) + "/test_solr_helper.rb")
20 21  
21 22 FileUtils.rm_rf(File.join(RAILS_ROOT, 'index', 'test'))
22 23  
... ... @@ -59,11 +60,14 @@ class ActiveSupport::TestCase
59 60  
60 61 fixtures :environments, :roles
61 62  
62   - def self.setup
63   - # clean up index db before each test
64   - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*'))
  63 + def setup
  64 + TestSolr.disable
65 65 end
66   -
  66 +
  67 + def teardown
  68 + TestSolr.disable
  69 + end
  70 +
67 71 def self.all_fixtures
68 72 Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.yml')).each do |item|
69 73 fixtures File.basename(item).sub(/\.yml$/, '').to_s
... ...
test/test_solr_helper.rb 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +class ActsAsSolr::Post
  2 + class << self
  3 + alias_method :execute_orig, :execute
  4 + end
  5 +end
  6 +module ActsAsSolr::ParserMethods
  7 + alias_method :parse_results_orig, :parse_results
  8 +end
  9 +
  10 +class TestSolr
  11 +
  12 + def self.enable
  13 + ActsAsSolr::Post.class_eval do
  14 + def self.execute(*args)
  15 + execute_orig *args
  16 + end
  17 + end
  18 + ActsAsSolr::ParserMethods.module_eval do
  19 + def parse_results(*args)
  20 + parse_results_orig *args
  21 + end
  22 + end
  23 +
  24 + # clear index
  25 + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*'))
  26 +
  27 + @solr_disabled = false
  28 + end
  29 +
  30 + def self.disable
  31 + return if @solr_disabled
  32 +
  33 + ActsAsSolr::Post.class_eval do
  34 + def self.execute(*args)
  35 + true
  36 + end
  37 + end
  38 + ActsAsSolr::ParserMethods.module_eval do
  39 + def parse_results(*args)
  40 + parse_results_orig nil, args[1]
  41 + end
  42 + end
  43 +
  44 + @solr_disabled = true
  45 + end
  46 +
  47 +end
  48 +
  49 +# disable solr actions by default
  50 +TestSolr.disable
... ...
test/unit/acts_as_faceted_test.rb
... ... @@ -10,8 +10,6 @@ class TestModel &lt; ActiveRecord::Base
10 10 'Event' => "Event",
11 11 'EnterpriseHomepage' => "Homepage",
12 12 'Gallery' => "Gallery",
13   - 'Blog' => "Blog",
14   - 'Forum' => "Forum"
15 13 }
16 14 h[klass]
17 15 end
... ... @@ -26,7 +24,7 @@ class ActsAsFacetedTest &lt; ActiveSupport::TestCase
26 24 def setup
27 25 @facets = {
28 26 "facet_fields"=> {
29   - "f_type_facet"=>{"TextArticle"=>15, "Blog"=>3, "Folder"=>3, "Forum"=>1, "UploadedFile"=>6, "Gallery"=>1},
  27 + "f_type_facet"=>{"TextArticle"=>15, "Folder"=>3, "UploadedFile"=>6, "Gallery"=>1},
30 28 }, "facet_ranges"=>{}, "facet_dates"=>{},
31 29 "facet_queries"=>{"f_published_at_d:[* TO NOW-1YEARS/DAY]"=>10, "f_published_at_d:[NOW-1YEARS TO NOW/DAY]"=>19}
32 30 }
... ... @@ -85,7 +83,7 @@ class ActsAsFacetedTest &lt; ActiveSupport::TestCase
85 83  
86 84 f = facets.select{ |f| f[:id] == 'f_type' }.first
87 85 r = TestModel.map_facet_results f, @facet_params, @facets, @all_facets, {}
88   - assert_equivalent [["TextArticle", 'Text', 15], ["Blog", "Blog", 3], ["Folder", "Folder", 3], ["Forum", "Forum", 1], ["UploadedFile", "Uploaded File", 6], ["Gallery", "Gallery", 1]], r
  86 + assert_equivalent [["TextArticle", 'Text', 15], ["Folder", "Folder", 3], ["UploadedFile", "Uploaded File", 6], ["Gallery", "Gallery", 1]], r
89 87  
90 88 f = facets.select{ |f| f[:id] == 'f_published_at' }.first
91 89 r = TestModel.map_facet_results f, @facet_params, @facets, @all_facets, {}
... ... @@ -132,7 +130,7 @@ class ActsAsFacetedTest &lt; ActiveSupport::TestCase
132 130 should 'return facet options hash in acts_as_solr format' do
133 131 options = TestModel.facets_find_options()[:facets]
134 132 assert_equal [:f_type], options[:fields]
135   - assert_equal ["f_published_at:[NOW-1YEARS TO NOW/DAY]", "f_published_at:[* TO NOW-1YEARS/DAY]"], options[:query]
  133 + assert_equivalent ["f_published_at:[NOW-1YEARS TO NOW/DAY]", "f_published_at:[* TO NOW-1YEARS/DAY]"], options[:query]
136 134 end
137 135  
138 136 should 'return browse options hash in acts_as_solr format' do
... ... @@ -148,7 +146,8 @@ class ActsAsFacetedTest &lt; ActiveSupport::TestCase
148 146 facet = facets.select{ |f| f[:id] == 'f_type' }.first
149 147 facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {}
150 148 sorted = TestModel.facet_result_sort(facet, facet_data, :alphabetically)
151   - assert_equal [["Blog", "Blog", 3], ["Folder", "Folder", 3], ["Forum", "Forum", 1], ["Gallery", "Gallery", 1], ["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6]], sorted
  149 + assert_equal sorted,
  150 + [["Folder", "Folder", 3], ["Gallery", "Gallery", 1], ["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6]]
152 151 end
153 152  
154 153 should 'sort facet results by count' do
... ... @@ -156,6 +155,7 @@ class ActsAsFacetedTest &lt; ActiveSupport::TestCase
156 155 facet = facets.select{ |f| f[:id] == 'f_type' }.first
157 156 facet_data = TestModel.map_facet_results facet, @facet_params, @facets, @all_facets, {}
158 157 sorted = TestModel.facet_result_sort(facet, facet_data, :count)
159   - assert_equal [["TextArticle", 'Text', 15], ["UploadedFile", "Uploaded File", 6], ["Blog", "Blog", 3], ["Folder", "Folder", 3], ["Forum", "Forum", 1], ["Gallery", "Gallery", 1]], sorted
  158 + assert_equal sorted,
  159 + [["TextArticle", "Text", 15], ["UploadedFile", "Uploaded File", 6], ["Folder", "Folder", 3], ["Gallery", "Gallery", 1]]
160 160 end
161 161 end
... ...
test/unit/article_test.rb
... ... @@ -148,8 +148,6 @@ class ArticleTest &lt; ActiveSupport::TestCase
148 148 should 'search for recent documents' do
149 149 other_profile = create_user('otherpropfile').person
150 150  
151   - Article.destroy_all
152   -
153 151 first = fast_create(TextArticle, :profile_id => profile.id, :name => 'first')
154 152 second = fast_create(TextArticle, :profile_id => profile.id, :name => 'second')
155 153 third = fast_create(TextArticle, :profile_id => profile.id, :name => 'third')
... ... @@ -365,6 +363,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
365 363 end
366 364  
367 365 should 'index comments title together with article' do
  366 + TestSolr.enable
368 367 owner = create_user('testuser').person
369 368 art = owner.articles.build(:name => 'ytest'); art.save!
370 369 c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save!
... ... @@ -373,6 +372,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
373 372 end
374 373  
375 374 should 'index comments body together with article' do
  375 + TestSolr.enable
376 376 owner = create_user('testuser').person
377 377 art = owner.articles.build(:name => 'ytest'); art.save!
378 378 c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save!
... ... @@ -1525,6 +1525,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1525 1525 end
1526 1526  
1527 1527 should 'index by schema name when database is postgresql' do
  1528 + TestSolr.enable
1528 1529 uses_postgresql 'schema_one'
1529 1530 art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id)
1530 1531 assert_equal [art1], Article.find_by_contents('thing')[:results].docs
... ... @@ -1539,6 +1540,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1539 1540 end
1540 1541  
1541 1542 should 'not index by schema name when database is not postgresql' do
  1543 + TestSolr.enable
1542 1544 uses_sqlite
1543 1545 art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id)
1544 1546 assert_equal [art1], Article.find_by_contents('thing')[:results].docs
... ... @@ -1690,6 +1692,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1690 1692 end
1691 1693  
1692 1694 should 'act as searchable' do
  1695 + TestSolr.enable
1693 1696 person = fast_create(Person, :name => "Hiro", :address => 'U-Stor-It @ Inglewood, California',
1694 1697 :nickname => 'Protagonist')
1695 1698 person2 = fast_create(Person, :name => "Raven")
... ... @@ -1726,6 +1729,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1726 1729 end
1727 1730  
1728 1731 should 'boost name matches' do
  1732 + TestSolr.enable
1729 1733 person = fast_create(Person)
1730 1734 in_body = Article.create!(:name => 'something', :profile_id => person.id, :body => 'bananas in the body!')
1731 1735 in_name = Article.create!(:name => 'bananas in the name!', :profile_id => person.id)
... ... @@ -1733,6 +1737,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1733 1737 end
1734 1738  
1735 1739 should 'boost if profile is enabled' do
  1740 + TestSolr.enable
1736 1741 person2 = fast_create(Person, :enabled => false)
1737 1742 art_profile_disabled = Article.create!(:name => 'profile disabled', :profile_id => person2.id)
1738 1743 person1 = fast_create(Person, :enabled => true)
... ... @@ -1749,6 +1754,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1749 1754 end
1750 1755  
1751 1756 should 'show more popular articles' do
  1757 + Article.destroy_all
1752 1758 art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id)
1753 1759 art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id)
1754 1760 art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id)
... ... @@ -1760,30 +1766,19 @@ class ArticleTest &lt; ActiveSupport::TestCase
1760 1766 assert_equal [art3, art1, art2], Article.more_popular
1761 1767 end
1762 1768  
1763   - should 'return more commented with pagination' do
1764   - art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id)
1765   - art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id)
1766   - art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id)
1767   -
1768   - art1.comments_count = 56; art1.save!
1769   - art3.comments_count = 92; art3.save!
1770   - art2.comments_count = 3; art2.save!
1771   -
1772   - assert_equal [art3, art1], Article.most_commented(2)
1773   - end
1774   -
1775 1769 should 'show if article is public' do
1776 1770 art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id)
1777   - art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id)
1778   - art2.advertise = false; art2.save!
1779   - art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id)
1780   - art3.published = false; art3.save!
1781   - art4 = Article.create!(:name => 'article 4', :profile_id => fast_create(Person).id)
1782   - art4.profile.visible = false; art4.save!
1783   - art5 = Article.create!(:name => 'article 5', :profile_id => fast_create(Person).id)
1784   - art5.profile.public_profile = false; art5.save!
1785   -
1786   - assert_equal [art1], Article.public
  1771 + art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id, :advertise => false)
  1772 + art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id, :published => false)
  1773 + art4 = Article.create!(:name => 'article 4', :profile_id => fast_create(Person, :visible => false).id)
  1774 + art5 = Article.create!(:name => 'article 5', :profile_id => fast_create(Person, :public_profile => false).id)
  1775 +
  1776 + articles = Article.public
  1777 + assert_includes articles, art1
  1778 + assert_not_includes articles, art2
  1779 + assert_not_includes articles, art3
  1780 + assert_not_includes articles, art4
  1781 + assert_not_includes articles, art5
1787 1782 end
1788 1783  
1789 1784 end
... ...
test/unit/category_test.rb
... ... @@ -514,6 +514,7 @@ class CategoryTest &lt; ActiveSupport::TestCase
514 514 end
515 515  
516 516 should 'act as searchable' do
  517 + TestSolr.enable
517 518 parent = fast_create(Category, :name => 'books')
518 519 c = Category.create!(:name => "science fiction", :acronym => "sf", :abbreviation => "sci-fi",
519 520 :environment_id => Environment.default.id, :parent_id => parent.id)
... ... @@ -528,6 +529,7 @@ class CategoryTest &lt; ActiveSupport::TestCase
528 529 end
529 530  
530 531 should 'boost name matches' do
  532 + TestSolr.enable
531 533 c_abbr = Category.create!(:name => "something else", :abbreviation => "science", :environment_id => Environment.default.id)
532 534 c_name = Category.create!(:name => "science fiction", :environment_id => Environment.default.id)
533 535 assert_equal [c_name, c_abbr], Category.find_by_contents("science")[:results].docs
... ... @@ -542,8 +544,12 @@ class CategoryTest &lt; ActiveSupport::TestCase
542 544 should 'reindex articles after saving' do
543 545 cat = Category.create!(:name => 'category 1', :environment_id => Environment.default.id)
544 546 art = Article.create!(:name => 'something', :profile_id => fast_create(Person).id)
545   - Category.expects(:solr_batch_add).with(includes(art))
546 547 art.add_category cat
  548 + cat.reload
  549 +
  550 + solr_doc = art.to_solr_doc
  551 + Article.any_instance.expects(:to_solr_doc).returns(solr_doc)
547 552 cat.save!
548 553 end
  554 +
549 555 end
... ...
test/unit/enterprise_test.rb
... ... @@ -4,7 +4,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
4 4 fixtures :profiles, :environments, :users
5 5  
6 6 def setup
7   - ActiveSupport::TestCase::setup
  7 + super
8 8 @product_category = fast_create(ProductCategory, :name => 'Products')
9 9 end
10 10  
... ... @@ -86,6 +86,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
86 86 end
87 87  
88 88 should 'be found in search for its product categories' do
  89 + TestSolr.enable
89 90 ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1')
90 91 prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id)
91 92 prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat)
... ... @@ -99,6 +100,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
99 100 end
100 101  
101 102 should 'be found in search for its product categories hierarchy' do
  103 + TestSolr.enable
102 104 ent1 = fast_create(Enterprise, :name => 'test1', :identifier => 'test1')
103 105 prod_cat = fast_create(ProductCategory, :name => 'pctest', :environment_id => Environment.default.id)
104 106 prod_child = fast_create(ProductCategory, :name => 'pchild', :environment_id => Environment.default.id, :parent_id => prod_cat.id)
... ...
test/unit/environment_test.rb
... ... @@ -3,11 +3,6 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 3 class EnvironmentTest < ActiveSupport::TestCase
4 4 fixtures :environments
5 5  
6   - def setup
7   - ActiveSupport::TestCase::setup
8   - Article.rebuild_index
9   - end
10   -
11 6 def test_exists_default_and_it_is_unique
12 7 Environment.delete_all
13 8 vc = Environment.new(:name => 'Test Community')
... ... @@ -447,6 +442,7 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
447 442 end
448 443  
449 444 should 'find by contents from articles' do
  445 + TestSolr.enable
450 446 environment = fast_create(Environment)
451 447 assert_nothing_raised do
452 448 environment.articles.find_by_contents('')[:results]
... ... @@ -550,6 +546,7 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
550 546 end
551 547  
552 548 should 'return more than 10 enterprises by contents' do
  549 + TestSolr.enable
553 550 env = Environment.default
554 551 Enterprise.destroy_all
555 552 ('1'..'20').each do |n|
... ...
test/unit/event_test.rb
... ... @@ -2,10 +2,6 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2  
3 3 class EventTest < ActiveSupport::TestCase
4 4  
5   - def setup
6   - ActiveSupport::TestCase::setup
7   - end
8   -
9 5 should 'be an article' do
10 6 assert_kind_of Article, Event.new
11 7 end
... ... @@ -61,12 +57,14 @@ class EventTest &lt; ActiveSupport::TestCase
61 57 end
62 58  
63 59 should 'be indexed by title' do
  60 + TestSolr.enable
64 61 profile = create_user('testuser').person
65 62 e = Event.create!(:name => 'my surprisingly nice event', :start_date => Date.new(2008, 06, 06), :profile => profile)
66 63 assert_includes Event.find_by_contents('surprisingly')[:results], e
67 64 end
68 65  
69 66 should 'be indexed by body' do
  67 + TestSolr.enable
70 68 profile = create_user('testuser').person
71 69 e = Event.create!(:name => 'bli', :start_date => Date.new(2008, 06, 06), :profile => profile, :body => 'my surprisingly long description about my freaking nice event')
72 70 assert_includes Event.find_by_contents('surprisingly')[:results], e
... ...
test/unit/product_categorization_test.rb
... ... @@ -1,8 +0,0 @@
1   -require File.dirname(__FILE__) + '/../test_helper'
2   -
3   -class ProductCategorizationTest < ActiveSupport::TestCase
4   - # Replace this with your real tests.
5   - def test_truth
6   - assert true
7   - end
8   -end
test/unit/product_test.rb
... ... @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 3 class ProductTest < ActiveSupport::TestCase
4 4  
5 5 def setup
6   - ActiveSupport::TestCase::setup
  6 + super
7 7 @product_category = fast_create(ProductCategory, :name => 'Products')
8 8 @profile = fast_create(Enterprise)
9 9 end
... ... @@ -105,6 +105,7 @@ class ProductTest &lt; ActiveSupport::TestCase
105 105 end
106 106  
107 107 should 'be indexed by category full name' do
  108 + TestSolr.enable
108 109 parent_cat = fast_create(ProductCategory, :name => 'Parent')
109 110 prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id)
110 111 prod_cat2 = fast_create(ProductCategory, :name => 'Category2')
... ... @@ -343,6 +344,7 @@ class ProductTest &lt; ActiveSupport::TestCase
343 344 end
344 345  
345 346 should 'index by schema name when database is postgresql' do
  347 + TestSolr.enable
346 348 uses_postgresql 'schema_one'
347 349 p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id)
348 350 assert_equal [p1], Product.find_by_contents('thing')[:results].docs
... ... @@ -357,6 +359,7 @@ class ProductTest &lt; ActiveSupport::TestCase
357 359 end
358 360  
359 361 should 'not index by schema name when database is not postgresql' do
  362 + TestSolr.enable
360 363 uses_sqlite
361 364 p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id)
362 365 assert_equal [p1], Product.find_by_contents('thing')[:results].docs
... ... @@ -583,6 +586,7 @@ class ProductTest &lt; ActiveSupport::TestCase
583 586 end
584 587  
585 588 should 'act as searchable' do
  589 + TestSolr.enable
586 590 s = fast_create(State, :acronym => 'XZ')
587 591 c = fast_create(City, :name => 'Tabajara', :parent_id => s.id)
588 592 ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun")
... ... @@ -615,6 +619,7 @@ class ProductTest &lt; ActiveSupport::TestCase
615 619 end
616 620  
617 621 should 'boost name matches' do
  622 + TestSolr.enable
618 623 ent = fast_create(Enterprise)
619 624 cat = fast_create(ProductCategory)
620 625 in_desc = Product.create!(:name => 'something', :enterprise_id => ent.id, :description => 'bananas in the description!',
... ... @@ -632,6 +637,7 @@ class ProductTest &lt; ActiveSupport::TestCase
632 637 end
633 638  
634 639 should 'boost search results that include an image' do
  640 + TestSolr.enable
635 641 product_without_image = Product.create!(:name => 'product without image', :product_category => @product_category,
636 642 :enterprise_id => @profile.id)
637 643 product_with_image = Product.create!(:name => 'product with image', :product_category => @product_category,
... ... @@ -641,6 +647,7 @@ class ProductTest &lt; ActiveSupport::TestCase
641 647 end
642 648  
643 649 should 'boost search results that include qualifier' do
  650 + TestSolr.enable
644 651 product_without_q = Product.create!(:name => 'product without qualifier', :product_category => @product_category,
645 652 :enterprise_id => @profile.id)
646 653 product_with_q = Product.create!(:name => 'product with qualifier', :product_category => @product_category,
... ... @@ -652,24 +659,17 @@ class ProductTest &lt; ActiveSupport::TestCase
652 659 end
653 660  
654 661 should 'boost search results with open price' do
655   - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id)
656   - product.price = 100
657   - product.save!
658   - open_price = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id)
659   - open_price.price = 100
660   - Input.create!(:product_id => open_price.id, :product_category_id => @product_category.id,
661   - :amount_used => 10, :price_per_unit => 10)
662   - open_price.update_price_details []
  662 + TestSolr.enable
  663 + product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id, :price => 100)
  664 + open_price = Product.new(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id, :price => 100)
  665 + open_price.inputs << Input.new(:product => open_price, :product_category_id => @product_category.id, :amount_used => 10, :price_per_unit => 10)
663 666 open_price.save!
664 667  
665   - #pp Product::Boosts[2][2].call(product)
666   - #pp Product::Boosts[2][2].call(open_price)
667   - #pp Product.find_by_contents('product')[:results].docs.first.solr_score
668   - #pp Product.find_by_contents('product')[:results].docs.last.solr_score
669 668 assert_equal [open_price, product], Product.find_by_contents('product')[:results].docs
670 669 end
671 670  
672 671 should 'boost search results with solidarity inputs' do
  672 + TestSolr.enable
673 673 product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id)
674 674 perc_50 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id)
675 675 Input.create!(:product_id => perc_50.id, :product_category_id => @product_category.id,
... ... @@ -692,6 +692,7 @@ class ProductTest &lt; ActiveSupport::TestCase
692 692 end
693 693  
694 694 should 'boost available search results' do
  695 + TestSolr.enable
695 696 product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id)
696 697 product.available = false
697 698 product.save!
... ... @@ -703,6 +704,7 @@ class ProductTest &lt; ActiveSupport::TestCase
703 704 end
704 705  
705 706 should 'boost search results created updated recently' do
  707 + TestSolr.enable
706 708 product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id)
707 709 product.update_attribute :created_at, Time.now - 10.day
708 710 product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id)
... ... @@ -711,6 +713,7 @@ class ProductTest &lt; ActiveSupport::TestCase
711 713 end
712 714  
713 715 should 'boost search results with description' do
  716 + TestSolr.enable
714 717 product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id,
715 718 :description => '')
716 719 product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id,
... ... @@ -720,6 +723,7 @@ class ProductTest &lt; ActiveSupport::TestCase
720 723 end
721 724  
722 725 should 'boost if enterprise is enabled' do
  726 + TestSolr.enable
723 727 ent = Enterprise.create!(:name => 'ent', :identifier => 'ent', :enabled => false)
724 728 product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => ent.id)
725 729 product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id)
... ... @@ -728,6 +732,7 @@ class ProductTest &lt; ActiveSupport::TestCase
728 732 end
729 733  
730 734 should 'combine different boost types' do
  735 + TestSolr.enable
731 736 product = Product.create!(:name => 'product', :product_category => @product_category, :enterprise_id => @profile.id)
732 737 image_only = Product.create!(:name => 'product with image', :product_category => @product_category,
733 738 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')},
... ... @@ -750,6 +755,10 @@ class ProductTest &lt; ActiveSupport::TestCase
750 755 prod2 = Product.create!(:name => 'Damaged CD', :enterprise_id => @profile.id, :product_category_id => @product_category.id)
751 756 prod3 = Product.create!(:name => 'Damaged DVD', :enterprise_id => @profile.id, :product_category_id => @product_category.id)
752 757  
  758 + prod1.update_attribute :created_at, Time.now-2.days
  759 + prod2.update_attribute :created_at, Time.now-1.days
  760 + prod3.update_attribute :created_at, Time.now
  761 +
753 762 assert_equal [prod3, prod2, prod1], Product.more_recent
754 763 end
755 764  
... ...
test/unit/profile_test.rb
... ... @@ -4,7 +4,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
4 4 fixtures :profiles, :environments, :users, :roles, :domains
5 5  
6 6 def setup
7   - ActiveSupport::TestCase::setup
  7 + super
8 8 end
9 9  
10 10 def test_identifier_validation
... ... @@ -102,6 +102,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
102 102 end
103 103  
104 104 def test_find_by_contents
  105 + TestSolr.enable
105 106 p = create(Profile, :name => 'wanted')
106 107  
107 108 assert Profile.find_by_contents('wanted')[:results].include?(p)
... ... @@ -194,6 +195,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
194 195  
195 196 # This problem should be solved; talk to Bráulio if it fails
196 197 should 'be able to find profiles by their names' do
  198 + TestSolr.enable
197 199 small = create(Profile, :name => 'A small profile for testing')
198 200 big = create(Profile, :name => 'A big profile for testing')
199 201  
... ... @@ -441,6 +443,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
441 443 end
442 444  
443 445 should 'search with latitude and longitude' do
  446 + TestSolr.enable
444 447 e = fast_create(Enterprise, {:lat => 45, :lng => 45}, :search => true)
445 448  
446 449 assert_includes Enterprise.find_by_contents('', {}, {:radius => 2, :latitude => 45, :longitude => 45})[:results].docs, e
... ... @@ -521,18 +524,21 @@ class ProfileTest &lt; ActiveSupport::TestCase
521 524 # content to be added to the index. The block returns "sample indexed text"
522 525 # see test/mocks/test/testing_extra_data_for_index.rb
523 526 should 'actually index by results of extra_data_for_index' do
  527 + TestSolr.enable
524 528 profile = TestingExtraDataForIndex.create!(:name => 'testprofile', :identifier => 'testprofile')
525 529  
526 530 assert_includes TestingExtraDataForIndex.find_by_contents('sample')[:results], profile
527 531 end
528 532  
529 533 should 'index profile identifier for searching' do
  534 + TestSolr.enable
530 535 Profile.destroy_all
531 536 p = create(Profile, :identifier => 'lalala')
532 537 assert_includes Profile.find_by_contents('lalala')[:results], p
533 538 end
534 539  
535 540 should 'index profile name for searching' do
  541 + TestSolr.enable
536 542 p = create(Profile, :name => 'Interesting Profile')
537 543 assert_includes Profile.find_by_contents('interesting')[:results], p
538 544 end
... ... @@ -1204,10 +1210,9 @@ class ProfileTest &lt; ActiveSupport::TestCase
1204 1210 env = fast_create(Environment)
1205 1211  
1206 1212 p1 = fast_create(Profile, :identifier => 'mytestprofile', :environment_id => env.id)
1207   -
1208 1213 p2 = Profile.new(:identifier => 'mytestprofile', :environment => env)
1209   - assert !p2.valid?
1210 1214  
  1215 + assert !p2.valid?
1211 1216 assert p2.errors.on(:identifier)
1212 1217 assert_equal p1.environment, p2.environment
1213 1218 end
... ... @@ -1683,6 +1688,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1683 1688 end
1684 1689  
1685 1690 should 'index by schema name when database is postgresql' do
  1691 + TestSolr.enable
1686 1692 uses_postgresql 'schema_one'
1687 1693 p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing')
1688 1694 assert_equal [p1], Profile.find_by_contents('thing')[:results].docs
... ... @@ -1697,6 +1703,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1697 1703 end
1698 1704  
1699 1705 should 'not index by schema name when database is not postgresql' do
  1706 + TestSolr.enable
1700 1707 uses_sqlite
1701 1708 p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing')
1702 1709 assert_equal [p1], Profile.find_by_contents('thing')[:results].docs
... ... @@ -1803,15 +1810,13 @@ class ProfileTest &lt; ActiveSupport::TestCase
1803 1810 end
1804 1811  
1805 1812 should 'act as searchable' do
  1813 + TestSolr.enable
1806 1814 st = create(State, :name => 'California', :acronym => 'CA', :environment_id => Environment.default.id)
1807 1815 city = create(City, :name => 'Inglewood', :parent_id => st.id, :environment_id => Environment.default.id)
1808 1816 p = create(Person, :name => "Hiro", :address => 'U-Stor-It', :nickname => 'Protagonist',
1809 1817 :user_id => fast_create(User).id, :region_id => city.id)
1810 1818 cat = create(Category, :name => "Science Fiction", :acronym => "sf", :abbreviation => "sci-fi")
1811 1819 p.add_category cat
1812   - cat.profiles.reload
1813   - cat.save!
1814   - p.save!
1815 1820  
1816 1821 # fields
1817 1822 assert_includes Profile.find_by_contents('Hiro')[:results].docs, p
... ... @@ -1828,6 +1833,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1828 1833 end
1829 1834  
1830 1835 should 'boost name matches' do
  1836 + TestSolr.enable
1831 1837 in_addr = create(Person, :name => 'something', :address => 'bananas in the address!', :user_id => fast_create(User).id)
1832 1838 in_name = create(Person, :name => 'bananas in the name!', :user_id => fast_create(User).id)
1833 1839 assert_equal [in_name, in_addr], Person.find_by_contents('bananas')[:results].docs
... ...
test/unit/region_test.rb
... ... @@ -17,6 +17,7 @@ class RegionTest &lt; ActiveSupport::TestCase
17 17 end
18 18  
19 19 should 'be able to search for possible validators by name' do
  20 + TestSolr.enable
20 21 env = fast_create(Environment)
21 22 region = fast_create(Region, :environment_id => env.id, :name => 'My Region')
22 23 org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id)
... ... @@ -29,10 +30,11 @@ class RegionTest &lt; ActiveSupport::TestCase
29 30 end
30 31  
31 32 should 'return search results without validators that are already associated to the current region' do
  33 + TestSolr.enable
32 34 env = fast_create(Environment)
33 35 region = fast_create(Region, :environment_id => env.id, :name => 'My Region')
34   - org1 = fast_create(Organization, :name => 'Organization 1', :identifier => 'org1', :environment_id => env.id)
35   - org2 = fast_create(Organization, :name => 'Organization 2', :identifier => 'org2', :environment_id => env.id)
  36 + org1 = fast_create(Organization, {:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id}, :search => true)
  37 + org2 = fast_create(Organization, {:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id}, :search => true)
36 38 region.validators << org1
37 39  
38 40 possible = region.search_possible_validators('organization')
... ...
test/unit/set_profile_region_from_city_state_test.rb
... ... @@ -2,6 +2,11 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2  
3 3 class SetProfileRegionFromCityStateTest < ActiveSupport::TestCase
4 4  
  5 + def setup
  6 + super
  7 + TestSolr.enable
  8 + end
  9 +
5 10 should 'set city and state from names' do
6 11 s = State.create!(:name => 'Sao Paulo', :acronym => 'SP', :environment_id => Environment.default.id)
7 12 c = City.create!(:name => 'Pindamonhangaba', :parent_id => s.id, :environment_id => Environment.default.id)
... ...
test/unit/text_article_test.rb
... ... @@ -15,6 +15,7 @@ class TextArticleTest &lt; ActiveSupport::TestCase
15 15 end
16 16  
17 17 should 'found TextileArticle by TextArticle indexes' do
  18 + TestSolr.enable
18 19 person = create_user('testuser').person
19 20 article = TextileArticle.create!(:name => 'found article test', :profile => person)
20 21 assert_equal TextileArticle.find_by_contents('found')[:results].docs, TextArticle.find_by_contents('found')[:results].docs
... ...
test/unit/tiny_mce_article_test.rb
... ... @@ -3,8 +3,7 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 3 class TinyMceArticleTest < ActiveSupport::TestCase
4 4  
5 5 def setup
6   - ActiveSupport::TestCase::setup
7   - Article.rebuild_solr_index
  6 + super
8 7 @profile = create_user('zezinho').person
9 8 end
10 9 attr_reader :profile
... ... @@ -23,6 +22,7 @@ class TinyMceArticleTest &lt; ActiveSupport::TestCase
23 22 end
24 23  
25 24 should 'be found when searching for articles by query' do
  25 + TestSolr.enable
26 26 tma = TinyMceArticle.create!(:name => 'test tinymce article', :body => '---', :profile => profile)
27 27 assert_includes TinyMceArticle.find_by_contents('article')[:results], tma
28 28 assert_includes Article.find_by_contents('article')[:results], tma
... ...
vendor/plugins/delayed_job/lib/delayed/message_sending.rb
... ... @@ -8,7 +8,7 @@ module Delayed
8 8 end
9 9  
10 10 def method_missing(method, *args)
11   - if (Rails.env == "test" or Rails.env == "cucumber")
  11 + if (Rails.env == "test" or Rails.env == "cucumber" and !$DISABLE_DELAYED_JOB_TEST_ENV_RUN)
12 12 @target.send method, *args
13 13 return
14 14 end
... ...