Commit d0eca4af17dcc83cb0e7e62d584cce27fc0af79e
1 parent
f7a3545b
Exists in
master
and in
22 other branches
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 | 98 | end |
| 99 | 99 | |
| 100 | 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 | 110 | end |
| 107 | 111 | |
| 108 | 112 | should 'have same lat and lng of its enterprise' do |
| ... | ... | @@ -327,7 +331,7 @@ class ProductTest < ActiveSupport::TestCase |
| 327 | 331 | should 'index by schema name when database is postgresql' do |
| 328 | 332 | uses_postgresql 'schema_one' |
| 329 | 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 | 335 | uses_postgresql 'schema_two' |
| 332 | 336 | p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) |
| 333 | 337 | assert_not_includes Product.find_by_contents('thing')[:results], p1 |
| ... | ... | @@ -341,7 +345,7 @@ class ProductTest < ActiveSupport::TestCase |
| 341 | 345 | should 'not index by schema name when database is not postgresql' do |
| 342 | 346 | uses_sqlite |
| 343 | 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 | 349 | p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) |
| 346 | 350 | assert_includes Product.find_by_contents('thing')[:results], p1 |
| 347 | 351 | assert_includes Product.find_by_contents('thing')[:results], p2 | ... | ... |