diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 2ff4f6f..562bee1 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -98,7 +98,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase Environment.any_instance.expects(:default_hostname).returns('example.com') result = "/cat/my-category/my-subcatagory" - expects(:link_to).with('category name', :controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory'], :host => 'example.com').returns(result) + expects(:link_to).with('category name', {:controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory'], :host => 'example.com'}, {}).returns(result) assert_same result, link_to_category(cat) end diff --git a/test/unit/category_finder_test.rb b/test/unit/category_finder_test.rb deleted file mode 100644 index a593a88..0000000 --- a/test/unit/category_finder_test.rb +++ /dev/null @@ -1,526 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class CategoryFinderTest < ActiveSupport::TestCase - - def setup - ActiveSupport::TestCase::setup - @category = Category.create!(:name => 'my category', :environment => Environment.default) - @finder = CategoryFinder.new(@category) - @product_category = fast_create(ProductCategory, :name => 'Products') - - Profile.rebuild_index -# This doesn't exist/never existed; either we remove or implement? -# Comment.skip_captcha! - end - - should 'search for articles in a specific category' do - person = create_user('teste').person - - # in category - art1 = person.articles.build(:name => 'an article to be found') - art1.add_category(@category) - art1.save! - - # not in category - art2 = person.articles.build(:name => 'another article to be found') - art2.save! - - list = @finder.find(:articles, 'found') - assert_includes list, art1 - assert_not_includes list, art2 - end - - should 'search with query for articles in a specific category' do - person = create_user('teste').person - - # in category - art1 = person.articles.build(:name => 'an article to be found') - art1.add_category(@category) - art1.save! - - # not in category - art2 = person.articles.build(:name => 'another article to be found') - art2.save! - - assert_includes @finder.find('articles', 'found'), art1 - assert_not_includes @finder.find('articles','found'), art2 - end - - should 'search for enterprises in a specific category' do - - # in category - ent1 = Enterprise.create!(:name => 'beautiful enterprise 1', :identifier => 'test1', :category_ids => [@category.id]) - - # not in category - ent2 = fast_create(Enterprise, :name => 'beautiful enterprise 2', :identifier => 'test2') - - list = @finder.find(:enterprises, 'beautiful') - assert_includes list, ent1 - assert_not_includes list, ent2 - end - - should 'search for people in a specific category' do - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category(@category); p1.save! - p2 = create_user('people_2').person; p2.name = 'another beautiful person'; p2.save! - - list = @finder.find(:people, 'beautiful') - assert_includes list, p1 - assert_not_includes list, p2 - end - - should 'search for communities in a specific category' do - c1 = fast_create(Community, :name => 'a beautiful community', :identifier => 'bea_comm', :environment_id => Environment.default.id) - c2 = fast_create(Community, :name => 'another beautiful community', :identifier => 'an_bea_comm', :environment_id => Environment.default.id) - c1.add_category(@category); c1.save! - - list = @finder.find(:communities, 'beautiful') - assert_includes list, c1 - assert_not_includes list, c2 - end - - should 'search for products in a specific category' do - ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1'); ent1.add_category(@category) - ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2') - prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) - prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) - - list = @finder.find(:products, 'beautiful') - assert_includes list, prod1 - assert_not_includes list, prod2 - end - - should 'search people in category hierarchy' do - parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id) - child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id) - p1 = create_user('people_1').person - p1.name = 'a beautiful person' - p1.add_category(child) - p1.save! - - parent.reload - - f = CategoryFinder.new(parent) - assert_includes f.find(:people, 'beautiful'), p1 - end - - should 'search article in category hierarchy' do - parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id) - child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id) - - p1 = create_user('people_1').person - - article = p1.articles.create!(:name => 'a beautiful article', :category_ids => [child.id]) - - parent.reload - - f = CategoryFinder.new(parent) - assert_includes f.find(:articles, 'beautiful'), article - end - - should 'list recent enterprises' do - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :category_ids => [@category.id]) - assert_includes @finder.recent('enterprises'), ent - end - - should 'respond to total_entries in the recent enterprises result' do - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :category_ids => [@category.id]) - assert_respond_to @finder.recent('enterprises'), :total_entries - end - - should 'not list more enterprises than limit' do - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id]) - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :category_ids => [@category.id]) - result = @finder.recent('enterprises', 1) - - assert_equal 1, result.size - end - - should 'paginate the list of more enterprises than limit' do - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id]) - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :category_ids => [@category.id]) - - page_1 = @finder.find('enterprises', nil, :per_page => 1, :page => 1) - page_2 = @finder.find('enterprises', nil, :per_page => 1, :page => 2) - - assert_equal 1, page_1.size - assert_equal 1, page_2.size - assert_equivalent [ent1, ent2], page_1 + page_2 - end - - should 'paginate the list of more enterprises than limit with query' do - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :category_ids => [@category.id]) - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2', :category_ids => [@category.id]) - - p1 = @finder.find('enterprises', 'teste', :per_page => 1, :page => 1) - p2 = @finder.find('enterprises', 'teste', :per_page => 1, :page => 2) - - assert_respond_to p1, :total_entries - assert_respond_to p2, :total_entries - assert (p1 == [ent1] && p2 == [ent2]) || (p1 == [ent2] && p2 == [ent1]) # consistent paging - end - - should 'not list more people than limit' do - p1 = create_user('test1').person; p1.add_category(@category) - p2 = create_user('test2').person; p2.add_category(@category) - result = @finder.recent('people', 1) - - assert_equal 1, result.size - end - - should 'list recent articles' do - person = create_user('teste').person - art1 = person.articles.create!(:name => 'an article to be found', :category_ids => [@category.id]) - art2 = person.articles.create!(:name => 'another article to be found', :category_ids => [@category.id]) - - result = @finder.recent('articles', 1) - - assert_equal [art2], result - end - - should 'not return the same result twice' do - parent = fast_create(Category, :name => 'parent category', :environment_id => Environment.default.id) - child = fast_create(Category, :name => 'child category', :environment_id => Environment.default.id, :parent_id => parent.id) - p1 = create_user('people_1').person - p1.name = 'a beautiful person' - p1.category_ids = [child.id, parent.id]; p1.save! - - f = CategoryFinder.new(parent) - result = f.find(:people, 'beautiful') - - assert_equal [p1], result - assert_equal 1, result.size - end - - should 'return most commented articles' do - Article.delete_all - - person = create_user('testuser').person - articles = (1..4).map {|n| a = person.articles.build(:name => "art #{n}", :category_ids => [@category.id]); a.save!; a } - - 2.times { articles[0].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! } - 4.times { articles[1].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! } - - result = @finder.most_commented_articles(2) - # should respect the order (more commented comes first) - assert_equal [articles[1], articles[0]], result - assert_respond_to result, :total_entries - end - - should 'find person and enterprise by radius and region' do - finder = CategoryFinder.new(@category) - - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [@category.id]) - p1 = create_user('test2').person - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(@category); p1.save! - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :category_ids => [@category.id]) - p2 = create_user('test4').person - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.add_category(@category); p2.save! - - ents = finder.find(:enterprises, 'test', :within => 10, :region => region.id) - people = finder.find(:people, 'test', :within => 10, :region => region.id) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - assert_includes people, p1 - assert_not_includes people, p2 - end - - should 'find current events' do - finder = CategoryFinder.new(@category) - person = create_user('testuser').person - - e1 = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,1), :category_ids => [@category.id]) - - # not in category - e2 = fast_create(Event, :name => 'e2', :profile_id => person.id, :start_date => Date.new(2008,1,15)) - - events = finder.current_events(2008, 1) - assert_includes events, e1 - assert_not_includes events, e2 - end - - should 'list upcoming events' do - person = create_user('testuser').person - - Date.expects(:today).returns(Date.new(2008, 1, 15)).at_least_once - - past_event = Event.create!(:name => 'past event', :profile => person, :start_date => Date.new(2008,1,1), :category_ids => [@category.id]) - - # event 2 is created after, but must be listed before (since it happens before) - upcoming_event_2 = Event.create!(:name => 'upcoming event 2', :profile => person, :start_date => Date.new(2008,1,25), :category_ids => [@category.id]) - upcoming_event_1 = Event.create!(:name => 'upcoming event 1', :profile => person, :start_date => Date.new(2008,1,20), :category_ids => [@category.id]) - not_in_category = fast_create(Event, :name => 'e1', :profile_id => person.id, :start_date => Date.new(2008,1,20)) - - assert_equal [upcoming_event_1, upcoming_event_2], @finder.upcoming_events - end - - should 'find person and enterprise in category by radius and region even without query' do - cat = fast_create(Category, :name => 'test category', :environment_id => Environment.default.id) - finder = CategoryFinder.new(cat) - - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [cat.id]) - p1 = create_user('test2').person - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(cat); p1.save! - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :category_ids => [cat.id]) - p2 = create_user('test4').person - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.add_category(cat); p2.save! - - ents = finder.find(:enterprises, nil, :within => 10, :region => region.id) - people = finder.find(:people, nil, :within => 10, :region => region.id) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - assert_includes people, p1 - assert_not_includes people, p2 - end - - should 'find products in category wihin product category' do - cat = fast_create(Category, :name => 'test category', :environment_id => Environment.default.id) - finder = CategoryFinder.new(cat) - - prod_cat = fast_create(ProductCategory, :name => 'test product category', :environment_id => Environment.default.id) - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :category_ids => [cat.id]) - prod1 = ent.products.create!(:name => 'test product 1', :product_category => prod_cat) - prod2 = ent.products.create!(:name => 'test product 2', :product_category => @product_category) - - prods = finder.find(:products, nil, :product_category => prod_cat) - - assert_includes prods, prod1 - assert_not_includes prods, prod2 - end - - should 'find enterprises by its products categories without query' do - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) - - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id]) - ent2.products.create!(:name => 'test product 2', :product_category => pc2) - - ents = @finder.find(:enterprises, nil, :product_category => pc1) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - end - - should 'find enterprises by its products categories with query' do - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) - - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id]) - ent2.products.create!(:name => 'test product 2', :product_category => pc2) - - ents = @finder.find(:enterprises, 'test', :product_category => pc1) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - end - - should 'count product categories results by products' do - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11) - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2) - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc2) # not in the count - p5 = ent.products.create!(:name => 'test product 5', :product_category => pc3) # not in the count - - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) - - counts = @finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id], [p1.id, p2.id, p3.id, p5.id, p6.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 1, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'count product categories results by all products' do - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - ent = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11) - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2) - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc3) # not in the count - - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) - - - counts = @finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 1, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'count product categories results by enterprises' do - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent1.products.create!(:name => 'test product 2', :product_category => pc1) - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id]) - ent2.products.create!(:name => 'test product 2', :product_category => pc11) - ent3 = Enterprise.create!(:name => 'test enterprise 3', :identifier => 'test_ent3', :category_ids => [@category.id]) - ent3.products.create!(:name => 'test product 3', :product_category => pc2) - ent4 = Enterprise.create!(:name => 'test enterprise 4', :identifier => 'test_ent4', :category_ids => [@category.id]) - ent4.products.create!(:name => 'test product 4', :product_category => pc2) - ent5 = Enterprise.create!(:name => 'test enterprise 5', :identifier => 'test_ent5', :category_ids => [@category.id]) - ent5.products.create!(:name => 'test product 5', :product_category => pc2) - ent5.products.create!(:name => 'test product 6', :product_category => pc3) - - ent6 = fast_create(Enterprise, :name => 'test enterprise 6', :identifier => 'test_ent6') - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) - - counts = @finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id], [ent1.id, ent2.id, ent3.id, ent4.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 2, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'count product categories results by all enterprises' do - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'test_ent1', :category_ids => [@category.id]) - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent1.products.create!(:name => 'test product 2', :product_category => pc1) - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'test_ent2', :category_ids => [@category.id]) - ent2.products.create!(:name => 'test product 2', :product_category => pc11) - ent3 = Enterprise.create!(:name => 'test enterprise 3', :identifier => 'test_ent3', :category_ids => [@category.id]) - ent3.products.create!(:name => 'test product 3', :product_category => pc2) - ent4 = Enterprise.create!(:name => 'test enterprise 4', :identifier => 'test_ent4', :category_ids => [@category.id]) - ent4.products.create!(:name => 'test product 4', :product_category => pc2) - ent4.products.create!(:name => 'test product 5', :product_category => pc3) - - ent5 = fast_create(Enterprise, :name => 'test enterprise 5', :identifier => 'test_ent5') - p6 = ent2.products.create!(:name => 'test product 6', :product_category => pc1) - - counts = @finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 2, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'find enterprises in alphabetical order of name' do - ent1 = Enterprise.create!(:name => 'test enterprise B', :identifier => 'test_ent_b', :category_ids => [@category.id]) - ent2 = Enterprise.create!(:name => 'test enterprise A', :identifier => 'test_ent_a', :category_ids => [@category.id]) - ent3 = Enterprise.create!(:name => 'test enterprise C', :identifier => 'test_ent_c', :category_ids => [@category.id]) - - ents = @finder.find(:enterprises, nil) - - assert ents.index(ent2) < ents.index(ent1), "expected #{ents.index(ent2)} be smaller than #{ents.index(ent1)}" - assert ents.index(ent1) < ents.index(ent3), "expected #{ents.index(ent1)} be smaller than #{ents.index(ent3)}" - end - - should 'search for text articles in a specific category' do - person = create_user('teste').person - - # in category - art1 = fast_create(TextileArticle, :name => 'an article to be found', :profile_id => person.id) - art1.add_category(@category) - art1.save! - - # not in category - art2 = fast_create(TextileArticle, :name => 'another article to be found', :profile_id => person.id) - - list = @finder.find(:text_articles, 'found') - assert_includes list, art1 - assert_not_includes list, art2 - end - - should 'find events in a date range' do - person = create_user('testuser').person - - date_range = Date.new(2009, 11, 28)..Date.new(2009, 12, 3) - - event_in_range = Event.create!(:name => 'Event in range', :profile => person, :start_date => Date.new(2009, 11, 27), :end_date => date_range.last, :category_ids => [@category.id]) - event_out_of_range = Event.create!(:name => 'Event out of range', :profile => person, :start_date => Date.new(2009, 12, 4), :category_ids => [@category.id]) - - events_found = @finder.find(:events, '', :date_range => date_range) - - assert_includes events_found, event_in_range - assert_not_includes events_found, event_out_of_range - end - - should 'not paginate events' do - person = create_user('testuser').person - - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - - assert_equal 2, @finder.find(:events, '', :per_page => 1).size - end - - should 'not paginate events within a range' do - person = create_user('testuser').person - - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - - date_range = Date.today..Date.today - assert_equal 2, @finder.find(:events, '', :date_range => date_range, :per_page => 1).size - end - - should 'not paginate current events' do - person = create_user('testuser').person - - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - - assert_equal 2, @finder.current_events(Date.today.year, Date.today.month, :per_page => 1).size - end - - should 'not paginate upcoming events' do - person = create_user('testuser').person - - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - create(:event, :profile_id => person.id, :category_ids => [@category.id]) - - assert_equal 2, @finder.upcoming_events(:per_page => 1).size - end - - should 'not paginate searching for specific event' do - person = create_user('teste').person - - today = Date.today - - event_to_found1 = Event.create!(:name => 'ToFound 1', :profile => person, :category_ids => [@category.id], :start_date => today) - event_to_found2 = Event.create!(:name => 'ToFound 2', :profile => person, :category_ids => [@category.id], :start_date => today) - event_to_not_found1 = Event.create!(:name => 'ToNotFound 1', :profile => person, :category_ids => [@category.id], :start_date => today) - event_to_not_found2 = Event.create!(:name => 'ToNotFound 2', :profile => person, :category_ids => [@category.id], :start_date => today) - - result = @finder.find(:events, 'ToFound', :per_page => 1) - - assert_includes result, event_to_found1 - assert_includes result, event_to_found2 - assert_not_includes result, event_to_not_found1 - assert_not_includes result, event_to_not_found2 - end - -end diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index c496da9..472199f 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -43,7 +43,7 @@ class CommunitiesBlockTest < ActiveSupport::TestCase block = CommunitiesBlock.new block.expects(:owner).returns(env) - expects(:link_to).with('View all', :controller => "browse", :action => 'communities') + expects(:link_to).with('View all', :controller => "search", :action => 'communities') instance_eval(&block.footer) end diff --git a/test/unit/enterprise_homepage_helper_test.rb b/test/unit/enterprise_homepage_helper_test.rb new file mode 100644 index 0000000..8befef1 --- /dev/null +++ b/test/unit/enterprise_homepage_helper_test.rb @@ -0,0 +1,64 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class EnterpriseHomepageHelperTest < ActiveSupport::TestCase + + include EnterpriseHomepageHelper + + def setup + @profile = mock + profile.stubs(:profile_image).returns('profileimage.png') + self.stubs(:url_for).returns('link to profile') + profile.stubs(:name).returns('Name of Profile') + profile.stubs(:url).returns('') + profile.stubs(:products).returns([Product.new(:name => 'product test')]) + profile.stubs(:identifier).returns('name-of-profile') + profile.stubs(:region).returns(Region.new(:name => 'Brazil')) + profile.stubs(:address).returns('Address of Profile') + profile.stubs(:contact_email).returns('Email of Profile') + profile.stubs(:contact_phone).returns('Phone of Profile') + profile.stubs(:contact_person).returns('Profile Owner') + profile.stubs(:location).returns('Profile Location'); + profile.stubs(:economic_activity).returns('Profile Economic Activity'); + end + attr_reader :profile + + should 'display profile info' do + result = display_profile_info(profile) + assert_match /Profile Owner/, result + assert_match /Email of Profile/, result + assert_match /Phone of Profile/, result + assert_match /Profile Location/, result + assert_match /Address of Profile/, result + assert_match /Profile Economic Activity/, result + end + + should 'not display attribute if nil' do + profile.stubs(:contact_person).returns(nil); + result = display_profile_info(profile) + assert_no_match /Profile Owner/, result + end + + should 'not display attribute if blank' do + profile.stubs(:contact_person).returns(''); + result = display_profile_info(profile) + assert_no_match /Profile Owner/, result + end + + should 'display distance' do + profile.stubs(:distance).returns(100.345); + result = display_profile_info(profile) + assert_match /Distance:/, result + assert_match /100.34/, result + end + + should 'not display distance if nil' do + profile.stubs(:distance).returns(nil); + result = display_profile_info(profile) + assert_no_match /Distance:/, result + assert_no_match /100.34/, result + end + + protected + include NoosferoTestHelper + +end diff --git a/test/unit/environment_finder_test.rb b/test/unit/environment_finder_test.rb deleted file mode 100644 index e830f5f..0000000 --- a/test/unit/environment_finder_test.rb +++ /dev/null @@ -1,361 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class EnvironmentFinderTest < ActiveSupport::TestCase - - def setup - ActiveSupport::TestCase::setup - @product_category = fast_create(ProductCategory, :name => 'Products') - end - - should 'find articles' do - person = create_user('teste').person - art = person.articles.build(:name => 'an article to be found'); art.save! - finder = EnvironmentFinder.new(Environment.default) - assert_includes finder.find(:articles, 'found'), art - end - - should 'find people' do - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save! - finder = EnvironmentFinder.new(Environment.default) - assert_includes finder.find(:people, 'beautiful'), p1 - end - - should 'find communities' do - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) - finder = EnvironmentFinder.new(Environment.default) - assert_includes finder.find(:communities, 'beautiful'), c1 - end - - should 'find products' do - finder = EnvironmentFinder.new(Environment.default) - ent = fast_create(Enterprise, :name => 'teste', :identifier => 'teste') - prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) - assert_includes finder.find(:products, 'beautiful'), prod - end - - should 'find enterprises' do - finder = EnvironmentFinder.new(Environment.default) - ent = Enterprise.create!(:name => 'a beautiful enterprise', :identifier => 'teste') - assert_includes finder.find(:enterprises, 'beautiful'), ent - end - - should 'list recent enterprises' do - finder = EnvironmentFinder.new(Environment.default) - ent = fast_create(Enterprise, :name => 'teste', :identifier => 'teste') - assert_includes finder.recent('enterprises'), ent - end - - should 'not list more enterprises than limit' do - finder = EnvironmentFinder.new(Environment.default) - ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1') - ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2') - recent = finder.recent('enterprises', 1) - - assert_equal 1, recent.size - end - - should 'paginate the list of more enterprises than limit' do - finder = EnvironmentFinder.new(Environment.default) - ent1 = fast_create(Enterprise, :name => 'teste1', :identifier => 'teste1') - ent2 = fast_create(Enterprise, :name => 'teste2', :identifier => 'teste2') - - assert_equal 1, finder.find('enterprises', nil, :per_page => 1, :page => 1).size - end - - should 'paginate the list of more enterprises than limit with query' do - finder = EnvironmentFinder.new(Environment.default) - - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1') - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2') - - p1 = finder.find('enterprises', 'teste', :per_page => 1, :page => 1) - p2 = finder.find('enterprises', 'teste', :per_page => 1, :page => 2) - - assert (p1 == [ent1] && p2 == [ent2]) || (p1 == [ent2] && p2 == [ent1]) - end - - should 'find person and enterprise by radius and region' do - finder = EnvironmentFinder.new(Environment.default) - - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) - ent1 = fast_create(Enterprise, {:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0}, :search => true) - p1 = create_user('test2').person - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save! - ent2 = fast_create(Enterprise, {:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0}, :search => true) - p2 = create_user('test4').person - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save! - - ents = finder.find(:enterprises, 'test', :within => 10, :region => region.id) - people = finder.find(:people, 'test', :within => 10, :region => region.id) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - assert_includes people, p1 - assert_not_includes people, p2 - end - - should 'find person and enterprise by radius and region even without query' do - finder = EnvironmentFinder.new(Environment.default) - - region = fast_create(Region, :name => 'r-test', :environment_id => Environment.default.id, :lat => 45.0, :lng => 45.0) - ent1 = fast_create(Enterprise, :name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) - p1 = create_user('test2').person - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save! - ent2 = fast_create(Enterprise, :name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0) - p2 = create_user('test4').person - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save! - - ents = finder.find(:enterprises, nil, :within => 10, :region => region.id) - people = finder.find(:people, nil, :within => 10, :region => region.id) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - assert_includes people, p1 - assert_not_includes people, p2 - end - - should 'find products wihin product category' do - finder = EnvironmentFinder.new(Environment.default) - cat = fast_create(ProductCategory, :name => 'test category', :environment_id => Environment.default.id) - ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent') - prod1 = ent.products.create!(:name => 'test product 1', :product_category => cat) - prod2 = ent.products.create!(:name => 'test product 2', :product_category => @product_category) - - prods = finder.find(:products, nil, :product_category => cat) - - assert_includes prods, prod1 - assert_not_includes prods, prod2 - end - - should 'find products wihin product category with query' do - finder = EnvironmentFinder.new(Environment.default) - cat = fast_create(ProductCategory, :name => 'test category', :environment_id => Environment.default.id) - ent = fast_create(Enterprise, :name => 'test enterprise', :identifier => 'test_ent') - prod1 = ent.products.create!(:name => 'test product a_word 1', :product_category => cat) - prod2 = ent.products.create!(:name => 'test product b_word 1', :product_category => cat) - prod3 = ent.products.create!(:name => 'test product a_word 2', :product_category => @product_category) - prod4 = ent.products.create!(:name => 'test product b_word 2', :product_category => @product_category) - - prods = finder.find(:products, 'a_word', :product_category => cat) - - assert_includes prods, prod1 - assert_not_includes prods, prod2 - assert_not_includes prods, prod3 - assert_not_includes prods, prod4 - end - - should 'find enterprises in alphabetical order of name' do - finder = EnvironmentFinder.new(Environment.default) - - ent1 = fast_create(Enterprise, :name => 'test enterprise B', :identifier => 'test_ent_b') - ent2 = fast_create(Enterprise, :name => 'test enterprise A', :identifier => 'test_ent_a') - ent3 = fast_create(Enterprise, :name => 'test enterprise C', :identifier => 'test_ent_c') - - ents = finder.find(:enterprises, nil) - - assert ents.index(ent2) < ents.index(ent1), "expected #{ents.index(ent2)} be smaller than #{ents.index(ent1)}" - assert ents.index(ent1) < ents.index(ent3), "expected #{ents.index(ent1)} be smaller than #{ents.index(ent3)}" - end - - should 'find enterprises by its products categories' do - finder = EnvironmentFinder.new(Environment.default) - - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) - - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') - ent2.products.create!(:name => 'test product 2', :product_category => pc2) - - ents = finder.find(:enterprises, nil, :product_category => pc1) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - end - - should 'find enterprises by its products categories with query' do - finder = EnvironmentFinder.new(Environment.default) - - pc1 = fast_create(ProductCategory, :name => 'test_cat1', :environment_id => Environment.default.id) - pc2 = fast_create(ProductCategory, :name => 'test_cat2', :environment_id => Environment.default.id) - - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') - ent2.products.create!(:name => 'test product 2', :product_category => pc2) - - ents = finder.find(:enterprises, 'test', :product_category => pc1) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - end - - should 'find enterprises by a product category with name with spaces' do - finder = EnvironmentFinder.new(Environment.default) - - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') - ent2.products.create!(:name => 'test product 2', :product_category => pc2) - - ents = finder.find(:enterprises, 'test', :product_category => pc1) - - assert_includes ents, ent1 - assert_not_includes ents, ent2 - end - - should 'count product categories results by products' do - finder = EnvironmentFinder.new(Environment.default) - - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11= fast_create(ProductCategory, :name => 'test cat11',:environment_id => Environment.default.id, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - - ent = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11) - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2) - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc2) # not in the count - p5 = ent.products.create!(:name => 'test product 5', :product_category => pc3) # not in the count - - counts = finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id], [p1.id, p2.id, p3.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 1, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'count product categories results by all products' do - finder = EnvironmentFinder.new(Environment.default) - - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - - ent = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') - p1 = ent.products.create!(:name => 'test product 1', :product_category => pc1) - p2 = ent.products.create!(:name => 'test product 2', :product_category => pc11) - p3 = ent.products.create!(:name => 'test product 3', :product_category => pc2) - p4 = ent.products.create!(:name => 'test product 4', :product_category => pc3) # not in the count - - counts = finder.product_categories_count(:products, [pc1.id, pc11.id, pc2.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 1, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'count product categories results by enterprises' do - finder = EnvironmentFinder.new(Environment.default) - - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent1.products.create!(:name => 'test product 2', :product_category => pc1) - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') - ent2.products.create!(:name => 'test product 2', :product_category => pc11) - ent3 = fast_create(Enterprise, :name => 'test enterprise 3', :identifier => 'test_ent3') - ent3.products.create!(:name => 'test product 3', :product_category => pc2) - ent4 = fast_create(Enterprise, :name => 'test enterprise 4', :identifier => 'test_ent4') - ent4.products.create!(:name => 'test product 4', :product_category => pc2) - ent5 = fast_create(Enterprise, :name => 'test enterprise 5', :identifier => 'test_ent5') # not in the count - ent5.products.create!(:name => 'test product 5', :product_category => pc2) - ent5.products.create!(:name => 'test product 6', :product_category => pc3) - - counts = finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id], [ent1.id, ent2.id, ent3.id, ent4.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 2, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'count product categories results by all enterprises' do - finder = EnvironmentFinder.new(Environment.default) - - pc1 = fast_create(ProductCategory, :name => 'test cat1', :environment_id => Environment.default.id) - pc11 = fast_create(ProductCategory, :name => 'test cat11', :environment_id => Environment.default.id, :parent_id => pc1.id) - pc2 = fast_create(ProductCategory, :name => 'test cat2', :environment_id => Environment.default.id) - pc3 = fast_create(ProductCategory, :name => 'test cat3', :environment_id => Environment.default.id) - - ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'test_ent1') - ent1.products.create!(:name => 'test product 1', :product_category => pc1) - ent1.products.create!(:name => 'test product 2', :product_category => pc1) - ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'test_ent2') - ent2.products.create!(:name => 'test product 2', :product_category => pc11) - ent3 = fast_create(Enterprise, :name => 'test enterprise 3', :identifier => 'test_ent3') - ent3.products.create!(:name => 'test product 3', :product_category => pc2) - ent4 = fast_create(Enterprise, :name => 'test enterprise 4', :identifier => 'test_ent4') - ent4.products.create!(:name => 'test product 4', :product_category => pc2) - ent4.products.create!(:name => 'test product 5', :product_category => pc3) - - counts = finder.product_categories_count(:enterprises, [pc1.id, pc11.id, pc2.id] ) - - assert_equal 2, counts[pc1.id] - assert_equal 1, counts[pc11.id] - assert_equal 2, counts[pc2.id] - assert_nil counts[pc3.id] - end - - should 'should retrieve more than 10 entries' do - Enterprise.destroy_all - finder = EnvironmentFinder.new(Environment.default) - - ('1'..'20').each do |n| - Enterprise.create!(:name => 'test ' + n, :identifier => 'test_' + n) - end - - assert_equal 20, finder.find(:enterprises, 'test').total_entries - end - - should 'find events in a date range' do - finder = EnvironmentFinder.new(Environment.default) - person = create_user('testuser').person - - date_range = Date.new(2009, 11, 28)..Date.new(2009, 12, 3) - - event_in_range = fast_create(Event, :name => 'Event in range', :profile_id => person.id, :start_date => Date.new(2009, 11, 27), :end_date => date_range.last) - event_out_of_range = fast_create(Event, :name => 'Event out of range', :profile_id => person.id, :start_date => Date.new(2009, 12, 4)) - - events_found = finder.find(:events, '', :date_range => date_range) - - assert_includes events_found, event_in_range - assert_not_includes events_found, event_out_of_range - end - - should 'not paginate events' do - finder = EnvironmentFinder.new(Environment.default) - person = create_user('testuser').person - - fast_create(:event, :profile_id => person.id) - fast_create(:event, :profile_id => person.id) - - assert_equal 2, finder.find(:events, '', :per_page => 1, :page => 1).size - end - - should 'not paginate events within date range' do - finder = EnvironmentFinder.new(Environment.default) - person = create_user('testuser').person - - fast_create(:event, :profile_id => person.id) - fast_create(:event, :profile_id => person.id) - - date_range = Date.today..Date.today - assert_equal 2, finder.find(:events, '', :date_range => date_range, :per_page => 1, :page => 1).size - end - -end diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 1aa39a4..28c3884 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -5,6 +5,7 @@ class EnvironmentTest < ActiveSupport::TestCase def setup ActiveSupport::TestCase::setup + Article.rebuild_index end def test_exists_default_and_it_is_unique diff --git a/test/unit/featured_products_block_test.rb b/test/unit/featured_products_block_test.rb index 0f67c4f..8aef8bf 100644 --- a/test/unit/featured_products_block_test.rb +++ b/test/unit/featured_products_block_test.rb @@ -10,6 +10,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase attr_reader :profile should 'refer to products' do + profile = fast_create(Enterprise) products = [] category = fast_create(ProductCategory) 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } diff --git a/test/unit/manage_products_helper_test.rb b/test/unit/manage_products_helper_test.rb index 93a947b..91fb464 100644 --- a/test/unit/manage_products_helper_test.rb +++ b/test/unit/manage_products_helper_test.rb @@ -191,6 +191,7 @@ class ManageProductsHelperTest < ActiveSupport::TestCase qualifier = fast_create(Qualifier) certifier = fast_create(Certifier) ProductQualifier.create!(:product => product, :qualifier => qualifier, :certifier => certifier) +# The relationship between product, certifiers and qualifiers is extremely complicated certifier.destroy assert_nothing_raised do result = display_qualifiers(product) diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb index dfd3d7b..1684fc8 100644 --- a/test/unit/people_block_test.rb +++ b/test/unit/people_block_test.rb @@ -40,7 +40,7 @@ class PeopleBlockTest < ActiveSupport::TestCase block.stubs(:owner).returns(Environment.default) expects(:_).with('View all').returns('View all people') - expects(:link_to).with('View all people', :controller => 'browse', :action => 'people') + expects(:link_to).with('View all people', :controller => 'search', :action => 'people') instance_eval(&block.footer) end diff --git a/test/unit/product_category_test.rb b/test/unit/product_category_test.rb index eb6de59..2e7f2b1 100644 --- a/test/unit/product_category_test.rb +++ b/test/unit/product_category_test.rb @@ -6,12 +6,13 @@ class ProductCategoryTest < ActiveSupport::TestCase c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default) assert_equivalent [], c0.all_products - p0 = Product.create(:name => 'product1', :product_category => c0) + profile = fast_create(Enterprise) + p0 = Product.create(:name => 'product1', :product_category => c0, :enterprise_id => profile.id) c0.reload assert_equivalent [p0], c0.all_products c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default) - p1 = Product.create(:name => 'product2', :product_category => c1) + p1 = Product.create(:name => 'product2', :product_category => c1, :enterprise_id => profile.id) c0.reload; c1.reload assert_equivalent [p0, p1], c0.all_products assert_equivalent [p1], c1.all_products diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb index 71ce90e..e923ba8 100644 --- a/test/unit/product_test.rb +++ b/test/unit/product_test.rb @@ -5,11 +5,12 @@ class ProductTest < ActiveSupport::TestCase def setup ActiveSupport::TestCase::setup @product_category = fast_create(ProductCategory, :name => 'Products') + @profile = fast_create(Enterprise) end should 'create product' do assert_difference Product, :count do - p = Product.new(:name => 'test product1', :product_category => @product_category) + p = Product.new(:name => 'test product1', :product_category => @product_category, :enterprise_id => @profile.id) assert p.save end end @@ -68,7 +69,7 @@ class ProductTest < ActiveSupport::TestCase assert_difference Product, :count do p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') - }) + }, :enterprise_id => @profile.id) assert_equal p.image(true).filename, 'rails.png' end end @@ -89,7 +90,7 @@ class ProductTest < ActiveSupport::TestCase end should 'be indexed by category full name' do - p = Product.new(:name => 'a test product', :product_category => @product_category) + p = Product.create(:name => 'a test product', :product_category => @product_category, :enterprise_id => @profile.id) p.stubs(:category_full_name).returns('interesting category') p.save! @@ -147,7 +148,7 @@ class ProductTest < ActiveSupport::TestCase assert ProductCategorization.find(:first, :conditions => {:product_id => p, :category_id => cat}) end - + should 'categorize parent cateogries with product categorization' do parent_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id) child_cat = fast_create(ProductCategory, :name => 'test cat', :environment_id => Environment.default.id, :parent_id => parent_cat.id) @@ -362,7 +363,7 @@ class ProductTest < ActiveSupport::TestCase should 'index by schema name when database is postgresql' do uses_postgresql 'schema_one' - p1 = Product.create!(:name => 'some thing', :product_category => @product_category) + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) assert_equal Product.find_by_contents('thing')[:results], [p1] uses_postgresql 'schema_two' p2 = Product.create!(:name => 'another thing', :product_category => @product_category) @@ -376,9 +377,9 @@ class ProductTest < ActiveSupport::TestCase should 'not index by schema name when database is not postgresql' do uses_sqlite - p1 = Product.create!(:name => 'some thing', :product_category => @product_category) + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) assert_equal Product.find_by_contents('thing')[:results], [p1] - p2 = Product.create!(:name => 'another thing', :product_category => @product_category) + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) assert_includes Product.find_by_contents('thing')[:results], p1 assert_includes Product.find_by_contents('thing')[:results], p2 end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index ed3aef0..1b1e4df 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -192,7 +192,8 @@ class ProfileTest < ActiveSupport::TestCase assert_not_equal list.object_id, other_list.object_id end - should 'be able to find profiles by their names with ferret' do +# This problem should be solved; talk to BrĂ¡ulio if it fails + should 'be able to find profiles by their names' do small = create(Profile, :name => 'A small profile for testing') big = create(Profile, :name => 'A big profile for testing') @@ -1669,7 +1670,7 @@ class ProfileTest < ActiveSupport::TestCase should 'index by schema name when database is postgresql' do uses_postgresql 'schema_one' p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') - assert_equal Profile.find_by_contents('thing')[:results], [p1] + assert_equal [p1], Profile.find_by_contents('thing')[:results] uses_postgresql 'schema_two' p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') assert_not_includes Profile.find_by_contents('thing')[:results], p1 diff --git a/test/unit/search_helper_test.rb b/test/unit/search_helper_test.rb deleted file mode 100644 index dc09d7f..0000000 --- a/test/unit/search_helper_test.rb +++ /dev/null @@ -1,69 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class SearchHelperTest < ActiveSupport::TestCase - - include SearchHelper - - def _(any) - any - end - - def setup - @profile = mock - self.stubs(:profile_image).returns('profileimage.png') - self.stubs(:url_for).returns('link to profile') - profile.stubs(:name).returns('Name of Profile') - profile.stubs(:url).returns('') - profile.stubs(:products).returns([Product.new(:name => 'product test')]) - profile.stubs(:identifier).returns('name-of-profile') - profile.stubs(:region).returns(Region.new(:name => 'Brazil')) - end - attr_reader :profile - - should 'display profile info' do - profile.stubs(:address).returns('Address of Profile') - profile.stubs(:contact_email).returns('Email of Profile') - profile.stubs(:contact_phone).returns('Phone of Profile') - - result = self.display_profile_info(profile) - assert_match /profileimage.png/, result - assert_match /link to profile/, result - assert_match /Email of Profile/, result - assert_match /Phone of Profile/, result - assert_match /Address of Profile/, result - end - - should 'not display field if nil in profile info' do - profile.stubs(:address).returns('nil') - profile.stubs(:contact_email).returns('nil') - profile.stubs(:contact_phone).returns('nil') - - result = self.display_profile_info(profile) - assert_match /profileimage.png/, result - assert_match /link to profile/, result - assert_no_match /Email of Profile/, result - assert_no_match /Phone of Profile/, result - assert_no_match /Address of Profile/, result - end - - should 'link to products and services of an profile' do - enterprise = fast_create(Enterprise) - product1 = fast_create(Product, :enterprise_id => enterprise.id) - product2 = fast_create(Product, :enterprise_id => enterprise.id) - result = display_profile_info(enterprise) - assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>#{product1.id}/}, :content => product1.name - assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>#{product2.id}/}, :content => product2.name - end - - should 'link to manage_products controller on display_profile_info' do - enterprise = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => enterprise.id) - result = display_profile_info(enterprise) - assert_tag_in_string result, :tag => 'a', :attributes => {:href => /:controller=>\"manage_products\"/}, :content => product.name - assert_no_tag_in_string result, :tag => 'a', :attributes => {:href => /:id=>\"catalog\"/}, :content => product.name - end - - protected - include NoosferoTestHelper - -end -- libgit2 0.21.2