From 815d92a561ee42d1c2484eb3365670e4e6952484 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Sat, 21 Jun 2008 03:04:35 +0000 Subject: [PATCH] ActionItem466: adapting CategoryFinder test --- app/models/article.rb | 2 +- app/models/profile.rb | 2 +- test/functional/search_controller_test.rb | 38 +++++++++++++++++++------------------- test/unit/category_finder_test.rb | 76 ++++++++++++++++++++++++++++++++++++++-------------------------------------- test/unit/category_test.rb | 61 ++++++++++++++++++++++++++----------------------------------- 5 files changed, 85 insertions(+), 94 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 2e6b199..a7434b3 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -12,7 +12,7 @@ class Article < ActiveRecord::Base has_many :comments, :dependent => :destroy - has_many :article_categorizations, :conditions => { :virtual => false } + has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] has_many :categories, :through => :article_categorizations def pending_categorizations diff --git a/app/models/profile.rb b/app/models/profile.rb index 05edd64..29d6346 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -100,7 +100,7 @@ class Profile < ActiveRecord::Base has_many :tasks, :foreign_key => :target_id - has_many :profile_categorizations, :conditions => { :virtual => false } + has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] has_many :categories, :through => :profile_categorizations def pending_categorizations diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 522cdec..d03099a 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -65,7 +65,7 @@ class SearchControllerTest < Test::Unit::TestCase # in category art1 = person.articles.build(:name => 'an article to be found') - art1.categories << @category + art1.add_category @category art1.save! # not in category @@ -83,9 +83,9 @@ class SearchControllerTest < Test::Unit::TestCase person = create_user('testuser').person person2 = create_user('anotheruser').person - art1 = person.articles.create!(:name => 'one article', :categories => [@category]) + art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id]) - art2 = person2.articles.create!(:name => 'two article', :categories => [@category]) + art2 = person2.articles.create!(:name => 'two article', :category_ids => [@category.id]) get :assets, :asset => 'articles' @@ -98,8 +98,8 @@ class SearchControllerTest < Test::Unit::TestCase person = create_user('testuser').person # in category - art1 = person.articles.create!(:name => 'one article', :categories => [@category]) - art2 = person.articles.create!(:name => 'other article', :categories => [@category]) + art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id]) + art2 = person.articles.create!(:name => 'other article', :category_ids => [@category.id]) # not in category art3 = person.articles.create!(:name => 'another article') @@ -120,7 +120,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'find enterprises in a specified category' do # in category - ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :categories => [@category]) + ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :category_ids => [@category.id]) # not in category ent2 = Enterprise.create!(:name => 'testing enterprise 2', :identifier => 'test2') @@ -143,7 +143,7 @@ class SearchControllerTest < Test::Unit::TestCase # 'assets' menu inside a category should 'list enterprises in a specified category' do # in category - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :categories => [@category]) + ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :category_ids => [@category.id]) # not in category ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2') @@ -160,7 +160,7 @@ class SearchControllerTest < Test::Unit::TestCase end should 'find people in a specific category' do - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << @category; p1.save! + 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! get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'people' ] assert_includes assigns(:results)[:people], p1 @@ -184,7 +184,7 @@ class SearchControllerTest < Test::Unit::TestCase Profile.delete_all # in category - p1 = create_user('test1').person; p1.categories << @category + p1 = create_user('test1').person; p1.add_category @category # not in category p2 = create_user('test2').person @@ -202,7 +202,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'find communities in a specified category' do c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) - c1.categories << @category; c1.save! + c1.add_category @category; c1.save! get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ] assert_includes assigns(:results)[:communities], c1 assert_not_includes assigns(:results)[:communities], c2 @@ -222,14 +222,14 @@ class SearchControllerTest < Test::Unit::TestCase # in category c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) - c1.categories << @category + c1.add_category @category # not in category c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) # in category c3 = Community.create!(:name => 'yet another beautiful community', :identifier => 'yet_an_bea_comm', :environment => Environment.default) - c3.categories << @category + c3.add_category @category get :assets, :asset => 'communities', :category_path => [ 'my-category' ] @@ -244,7 +244,7 @@ class SearchControllerTest < Test::Unit::TestCase end should 'find products in a specific category' do - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << @category + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category @category ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') prod1 = ent1.products.create!(:name => 'a beautiful product') prod2 = ent2.products.create!(:name => 'another beautiful product') @@ -271,7 +271,7 @@ class SearchControllerTest < Test::Unit::TestCase Profile.delete_all # in category - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << @category + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category @category prod1 = ent1.products.create!(:name => 'a beautiful product') # not in category @@ -714,7 +714,7 @@ class SearchControllerTest < Test::Unit::TestCase # in category ev1 = create_event(person, :name => 'an event to be found') - ev1.categories << @category + ev1.add_category @category ev1.save! # not in category @@ -732,9 +732,9 @@ class SearchControllerTest < Test::Unit::TestCase person = create_user('testuser').person person2 = create_user('anotheruser').person - ev1 = create_event(person, :name => 'one event', :categories => [@category]) + ev1 = create_event(person, :name => 'one event', :category_ids => [@category.id]) - ev2 = create_event(person2, :name => 'two event', :categories => [@category]) + ev2 = create_event(person2, :name => 'two event', :category_ids => [@category.id]) get :assets, :asset => 'events' @@ -747,8 +747,8 @@ class SearchControllerTest < Test::Unit::TestCase person = create_user('testuser').person # in category - ev1 = create_event(person, :name => 'one event', :categories => [@category]) - ev2 = create_event(person, :name => 'other event', :categories => [@category]) + ev1 = create_event(person, :name => 'one event', :category_ids => [@category.id]) + ev2 = create_event(person, :name => 'other event', :category_ids => [@category.id]) # not in category ev3 = create_event(person, :name => 'another event') diff --git a/test/unit/category_finder_test.rb b/test/unit/category_finder_test.rb index e48f121..bb7ebd6 100644 --- a/test/unit/category_finder_test.rb +++ b/test/unit/category_finder_test.rb @@ -12,7 +12,7 @@ class CategoryFinderTest < ActiveSupport::TestCase # in category art1 = person.articles.build(:name => 'an article to be found') - art1.categories << @category + art1.add_category(@category) art1.save! # not in category @@ -29,7 +29,7 @@ class CategoryFinderTest < ActiveSupport::TestCase # in category art1 = person.articles.build(:name => 'an article to be found') - art1.categories << @category + art1.add_category(@category) art1.save! # not in category @@ -43,7 +43,7 @@ class CategoryFinderTest < ActiveSupport::TestCase should 'search for enterprises in a specific category' do # in category - ent1 = Enterprise.create!(:name => 'beautiful enterprise 1', :identifier => 'test1', :categories => [@category]) + ent1 = Enterprise.create!(:name => 'beautiful enterprise 1', :identifier => 'test1', :category_ids => [@category.id]) # not in category ent2 = Enterprise.create!(:name => 'beautiful enterprise 2', :identifier => 'test2') @@ -54,7 +54,7 @@ class CategoryFinderTest < ActiveSupport::TestCase end should 'search for people in a specific category' do - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << @category; p1.save! + 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') @@ -65,7 +65,7 @@ class CategoryFinderTest < ActiveSupport::TestCase should 'search for communities in a specific category' do c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) - c1.categories << @category; c1.save! + c1.add_category(@category); c1.save! list = @finder.find(:communities, 'beautiful') assert_includes list, c1 @@ -73,7 +73,7 @@ class CategoryFinderTest < ActiveSupport::TestCase end should 'search for products in a specific category' do - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << @category + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category(@category) ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') prod1 = ent1.products.create!(:name => 'a beautiful product') prod2 = ent2.products.create!(:name => 'another beautiful product') @@ -98,7 +98,7 @@ class CategoryFinderTest < ActiveSupport::TestCase should 'search in category hierarchy' do parent = Category.create!(:name => 'parent category', :environment => Environment.default) child = Category.create!(:name => 'child category', :environment => Environment.default, :parent => parent) - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << child; p1.save! + p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category(child); p1.save! parent.reload @@ -107,27 +107,27 @@ class CategoryFinderTest < ActiveSupport::TestCase end should 'list recent enterprises' do - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :categories => [@category]) + ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :category_ids => [@category.id]) assert_includes @finder.recent('enterprises'), ent end should 'not list more enterprises than limit' do - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :categories => [@category]) - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :categories => [@category]) + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id]) + ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :category_ids => [@category.id]) recent = @finder.recent('enterprises', 1) assert_includes recent, ent2 assert_not_includes recent, ent1 end - should 'count entrprises' do + should 'count enterprises' do count = @finder.count('enterprises') - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :categories => [@category]) + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id]) assert_equal count+1, @finder.count('enterprises') end should 'not list more people than limit' do - p1 = create_user('test1').person; p1.categories << @category - p2 = create_user('test2').person; p2.categories << @category + p1 = create_user('test1').person; p1.add_category(@category) + p2 = create_user('test2').person; p2.add_category(@category) recent = @finder.recent('people', 1) assert_includes recent, p2 assert_not_includes recent, p1 @@ -135,9 +135,9 @@ class CategoryFinderTest < ActiveSupport::TestCase should 'list recent articles' do person = create_user('teste').person - art1 = person.articles.build(:name => 'an article to be found'); art1.categories << @category; art1.save! + art1 = person.articles.build(:name => 'an article to be found'); art1.add_category(@category); art1.save! - art2 = person.articles.build(:name => 'another article to be found'); art2.categories << @category; art2.save! + art2 = person.articles.build(:name => 'another article to be found'); art2.add_category(@category); art2.save! result = @finder.recent('articles', 1) assert_includes result, art2 @@ -147,8 +147,8 @@ class CategoryFinderTest < ActiveSupport::TestCase should 'not return the same result twice' do parent = Category.create!(:name => 'parent category', :environment => Environment.default) child = Category.create!(:name => 'child category', :environment => Environment.default, :parent => parent) - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << child; p1.save! - p1.categories << parent; p1.save! + p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category(child); p1.save! + p1.add_category(parent); p1.save! f = CategoryFinder.new(parent) result = f.find(:people, 'beautiful') @@ -161,7 +161,7 @@ class CategoryFinderTest < ActiveSupport::TestCase Article.delete_all person = create_user('testuser').person - articles = (1..4).map {|n| a = person.articles.build(:name => "art #{n}", :categories => [@category]); a.save!; a } + 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! } @@ -171,8 +171,8 @@ class CategoryFinderTest < ActiveSupport::TestCase end should 'find people by initial' do - p1 = create_user('aaaa').person; p1.categories << @category - p2 = create_user('bbbb').person; p2.categories << @category + p1 = create_user('aaaa').person; p1.add_category(@category) + p2 = create_user('bbbb').person; p2.add_category(@category) list = CategoryFinder.new(@category).find_by_initial(:people, 'a') @@ -181,8 +181,8 @@ class CategoryFinderTest < ActiveSupport::TestCase end should 'find enterprises by initial' do - ent1 = Enterprise.create!(:name => 'aaaa', :identifier => 'aaaa'); ent1.categories << @category - ent2 = Enterprise.create!(:name => 'bbbb', :identifier => 'bbbb'); ent2.categories << @category + ent1 = Enterprise.create!(:name => 'aaaa', :identifier => 'aaaa'); ent1.add_category(@category) + ent2 = Enterprise.create!(:name => 'bbbb', :identifier => 'bbbb'); ent2.add_category(@category) list = CategoryFinder.new(@category).find_by_initial(:enterprises, 'a') @@ -191,8 +191,8 @@ class CategoryFinderTest < ActiveSupport::TestCase end should 'find communities by initial' do - comm1 = Community.create!(:name => 'aaaa', :identifier => 'aaaa'); comm1.categories << @category - comm2 = Community.create!(:name => 'bbbb', :identifier => 'bbbb'); comm2.categories << @category + comm1 = Community.create!(:name => 'aaaa', :identifier => 'aaaa'); comm1.add_category(@category) + comm2 = Community.create!(:name => 'bbbb', :identifier => 'bbbb'); comm2.add_category(@category) list = CategoryFinder.new(@category).find_by_initial(:communities, 'a') @@ -202,7 +202,7 @@ class CategoryFinderTest < ActiveSupport::TestCase should 'find products by initial' do ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent') - ent.categories << @category + ent.add_category(@category) p1 = ent.products.create!(:name => 'A product') p2 = ent.products.create!(:name => 'Better product') @@ -215,8 +215,8 @@ class CategoryFinderTest < ActiveSupport::TestCase should 'find articles by initial' do person = create_user('testuser').person - a1 = person.articles.create!(:name => 'aaaa', :body => '...', :categories => [@category]) - a2 = person.articles.create!(:name => 'bbbb', :body => '...', :categories => [@category]) + a1 = person.articles.create!(:name => 'aaaa', :body => '...', :category_ids => [@category.id]) + a2 = person.articles.create!(:name => 'bbbb', :body => '...', :category_ids => [@category.id]) list = CategoryFinder.new(@category).find_by_initial(:articles, 'a') @@ -228,12 +228,12 @@ class CategoryFinderTest < ActiveSupport::TestCase finder = CategoryFinder.new(@category) region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :categories => [@category]) + 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.categories = [@category]; p1.save! - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :categories => [@category]) + 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.categories = [@category]; p2.save! + 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) @@ -248,7 +248,7 @@ class CategoryFinderTest < ActiveSupport::TestCase finder = CategoryFinder.new(@category) person = create_user('testuser').person - e1 = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,1), :categories => [@category]) + e1 = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,1), :category_ids => [@category.id]) # not in category e2 = Event.create!(:name => 'e2', :profile => person, :start_date => Date.new(2008,1,15)) @@ -263,12 +263,12 @@ class CategoryFinderTest < ActiveSupport::TestCase finder = CategoryFinder.new(cat) region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :categories => [cat]) + 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.categories = [cat]; p1.save! - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :categories => [cat]) + 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.categories = [cat]; p2.save! + 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) @@ -284,7 +284,7 @@ class CategoryFinderTest < ActiveSupport::TestCase finder = CategoryFinder.new(cat) prod_cat = ProductCategory.create!(:name => 'test product category', :environment => Environment.default) - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :categories => [cat]) + 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') diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb index 2ce2754..fcb9495 100644 --- a/test/unit/category_test.rb +++ b/test/unit/category_test.rb @@ -242,11 +242,11 @@ class CategoryTest < Test::Unit::TestCase person = create_user('testuser').person a1 = person.articles.build(:name => 'art1') - a1.categories << c + a1.add_category c a1.save! a2 = person.articles.build(:name => 'art2') - a2.categories << c + a2.add_category c a2.save! assert_equivalent [a1, a2], c.recent_articles @@ -257,12 +257,12 @@ class CategoryTest < Test::Unit::TestCase person = create_user('testuser').person a1 = person.articles.build(:name => 'art1') - a1.categories << c + a1.add_category c a1.save! c1 = a1.comments.build(:title => 'comm1', :body => 'khdkashd ', :author => person); c1.save! a2 = person.articles.build(:name => 'art2') - a2.categories << c + a2.add_category c a2.save! c2 = a2.comments.build(:title => 'comm1', :body => 'khdkashd ', :author => person); c2.save! @@ -273,9 +273,9 @@ class CategoryTest < Test::Unit::TestCase c = @env.categories.build(:name => 'my category'); c.save! person = create_user('testuser').person - a1 = person.articles.build(:name => 'art1', :categories => [c]); a1.save! - a2 = person.articles.build(:name => 'art2', :categories => [c]); a2.save! - a3 = person.articles.build(:name => 'art3', :categories => [c]); a3.save! + a1 = person.articles.build(:name => 'art1', :category_ids => [c.id]); a1.save! + a2 = person.articles.build(:name => 'art2', :category_ids => [c.id]); a2.save! + a3 = person.articles.build(:name => 'art3', :category_ids => [c.id]); a3.save! a1.comments.build(:title => 'test', :body => 'asdsa', :author => person).save! 5.times { a2.comments.build(:title => 'test', :body => 'asdsa', :author => person).save! } @@ -288,9 +288,9 @@ class CategoryTest < Test::Unit::TestCase c = @env.categories.build(:name => 'my category'); c.save! person = create_user('testuser').person - a1 = person.articles.build(:name => 'art1', :categories => [c]); a1.save! - a2 = person.articles.build(:name => 'art2', :categories => [c]); a2.save! - a3 = person.articles.build(:name => 'art3', :categories => [c]); a3.save! + a1 = person.articles.build(:name => 'art1', :category_ids => [c]); a1.save! + a2 = person.articles.build(:name => 'art2', :category_ids => [c]); a2.save! + a3 = person.articles.build(:name => 'art3', :category_ids => [c]); a3.save! c1 = a1.comments.build(:title => 'test', :body => 'asdsa', :author => person); c1.save! c2 = a2.comments.build(:title => 'test', :body => 'asdsa', :author => person); c2.save! @@ -302,9 +302,9 @@ class CategoryTest < Test::Unit::TestCase should 'have enterprises' do c = @env.categories.build(:name => 'my category'); c.save! ent1 = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one') - ent1.categories << c + ent1.add_category c ent2 = Enterprise.create!(:identifier => 'enterprise_2', :name => 'Enterprise one') - ent2.categories << c + ent2.add_category c assert_includes c.enterprises, ent1 assert_includes c.enterprises, ent2 end @@ -321,18 +321,18 @@ class CategoryTest < Test::Unit::TestCase should 'have communities' do c = @env.categories.build(:name => 'my category'); c.save! c1 = Environment.default.communities.create!(:name => 'testcommunity_1') - c1.categories << c + c1.add_category c c2 = Environment.default.communities.create!(:name => 'testcommunity_2') - c2.categories << c + c2.add_category c assert_equal [c1, c2], c.communities end should 'have products through enteprises' do c = @env.categories.build(:name => 'my category'); c.save! ent1 = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one') - ent1.categories << c + ent1.add_category c ent2 = Enterprise.create!(:identifier => 'enterprise_2', :name => 'Enterprise one') - ent2.categories << c + ent2.add_category c prod1 = ent1.products.create!(:name => 'test_prod1') prod2 = ent2.products.create!(:name => 'test_prod2') assert_includes c.products, prod1 @@ -342,9 +342,9 @@ class CategoryTest < Test::Unit::TestCase should 'not have person through communities' do c = @env.categories.build(:name => 'my category'); c.save! com = Community.create!(:identifier => 'community_1', :name => 'Community one') - com.categories << c + com.add_category c person = create_user('test_user').person - person.categories << c + person.add_category c assert_includes c.communities, com assert_not_includes c.communities, person end @@ -352,9 +352,9 @@ class CategoryTest < Test::Unit::TestCase should 'not have person through enterprises' do c = @env.categories.build(:name => 'my category'); c.save! ent = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one') - ent.categories << c + ent.add_category c person = create_user('test_user').person - person.categories << c + person.add_category c assert_includes c.enterprises, ent assert_not_includes c.enterprises, person end @@ -362,9 +362,9 @@ class CategoryTest < Test::Unit::TestCase should 'not have enterprises through people' do c = @env.categories.build(:name => 'my category'); c.save! person = create_user('test_user').person - person.categories << c + person.add_category c ent = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one') - ent.categories << c + ent.add_category c assert_includes c.people, person assert_not_includes c.people, ent end @@ -372,11 +372,11 @@ class CategoryTest < Test::Unit::TestCase should 'report the total items in this category' do @category = Category.create!(:name => 'my category', :environment => @env) # in category - person1 = create_user('test1').person; person1.categories << @category; person1.save! - art1 = person1.articles.build(:name => 'an article to be counted'); art1.categories << @category; art1.save! + person1 = create_user('test1').person; person1.add_category @category; person1.save! + art1 = person1.articles.build(:name => 'an article to be counted'); art1.add_category @category; art1.save! comment1 = art1.comments.build(:title => 'comment to be counted', :body => 'hfyfyh', :author => person1); comment1.save! - ent1 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :categories => [@category]) - com1 = Community.create!(:name => 'test3', :identifier => 'test3', :categories => [@category]) + ent1 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :category_ids => [@category.id]) + com1 = Community.create!(:name => 'test3', :identifier => 'test3', :category_ids => [@category.id]) prod1 = Product.create!(:name => 'test4', :enterprise => ent1) # not in category @@ -390,15 +390,6 @@ class CategoryTest < Test::Unit::TestCase assert_equal 6, @category.total_items end - # NOT YET - #should 'list people that are categorized in children categories' do - # c1 = @env.categories.create!(:name => 'top category') - # c2 = @env.categories.create!(:name => 'child category', :parent => c1) - # person = create_user('test_user').person - # person.categories << c2 - # assert_includes c1.people, person - #end - should 'have image' do assert_difference Category, :count do c = Category.create!(:name => 'test category1', :environment => Environment.default, :image_builder => { -- libgit2 0.21.2