Commit d0eca4af17dcc83cb0e7e62d584cce27fc0af79e

Authored by Rafael Martins
1 parent f7a3545b

Fixes for ProductTest

* Category full name indexing test
* New search results object
Showing 1 changed file with 10 additions and 6 deletions   Show diff stats
test/unit/product_test.rb
@@ -98,11 +98,15 @@ class ProductTest < ActiveSupport::TestCase @@ -98,11 +98,15 @@ class ProductTest < ActiveSupport::TestCase
98 end 98 end
99 99
100 should 'be indexed by category full name' do 100 should 'be indexed by category full name' do
101 - p = Product.create(:name => 'a test product', :product_category => @product_category, :enterprise_id => @profile.id)  
102 - p.stubs(:category_full_name).returns('interesting category')  
103 - p.save! 101 + parent_cat = fast_create(ProductCategory, :name => 'Parent')
  102 + prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id)
  103 + prod_cat2 = fast_create(ProductCategory, :name => 'Category2')
  104 + p = Product.create(:name => 'a test', :product_category => prod_cat, :enterprise_id => @profile.id)
  105 + p2 = Product.create(:name => 'another test', :product_category => prod_cat2, :enterprise_id => @profile.id)
104 106
105 - assert_includes Product.find_by_contents('interesting')[:results], p 107 + r = Product.find_by_contents('Parent')[:results].docs
  108 + assert_includes r, p
  109 + assert_not_includes r, p2
106 end 110 end
107 111
108 should 'have same lat and lng of its enterprise' do 112 should 'have same lat and lng of its enterprise' do
@@ -327,7 +331,7 @@ class ProductTest < ActiveSupport::TestCase @@ -327,7 +331,7 @@ class ProductTest < ActiveSupport::TestCase
327 should 'index by schema name when database is postgresql' do 331 should 'index by schema name when database is postgresql' do
328 uses_postgresql 'schema_one' 332 uses_postgresql 'schema_one'
329 p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) 333 p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id)
330 - assert_equal Product.find_by_contents('thing')[:results], [p1] 334 + assert_equal [p1], Product.find_by_contents('thing')[:results].docs
331 uses_postgresql 'schema_two' 335 uses_postgresql 'schema_two'
332 p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) 336 p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id)
333 assert_not_includes Product.find_by_contents('thing')[:results], p1 337 assert_not_includes Product.find_by_contents('thing')[:results], p1
@@ -341,7 +345,7 @@ class ProductTest < ActiveSupport::TestCase @@ -341,7 +345,7 @@ class ProductTest < ActiveSupport::TestCase
341 should 'not index by schema name when database is not postgresql' do 345 should 'not index by schema name when database is not postgresql' do
342 uses_sqlite 346 uses_sqlite
343 p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) 347 p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id)
344 - assert_equal Product.find_by_contents('thing')[:results], [p1] 348 + assert_equal [p1], Product.find_by_contents('thing')[:results].docs
345 p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) 349 p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id)
346 assert_includes Product.find_by_contents('thing')[:results], p1 350 assert_includes Product.find_by_contents('thing')[:results], p1
347 assert_includes Product.find_by_contents('thing')[:results], p2 351 assert_includes Product.find_by_contents('thing')[:results], p2