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