Commit 815d92a561ee42d1c2484eb3365670e4e6952484

Authored by AntonioTerceiro
1 parent e091d1dc

ActionItem466: adapting CategoryFinder test

to the new interface of articles and profiles


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2070 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/article.rb
... ... @@ -12,7 +12,7 @@ class Article < ActiveRecord::Base
12 12  
13 13 has_many :comments, :dependent => :destroy
14 14  
15   - has_many :article_categorizations, :conditions => { :virtual => false }
  15 + has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ]
16 16 has_many :categories, :through => :article_categorizations
17 17  
18 18 def pending_categorizations
... ...
app/models/profile.rb
... ... @@ -100,7 +100,7 @@ class Profile < ActiveRecord::Base
100 100  
101 101 has_many :tasks, :foreign_key => :target_id
102 102  
103   - has_many :profile_categorizations, :conditions => { :virtual => false }
  103 + has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ]
104 104 has_many :categories, :through => :profile_categorizations
105 105  
106 106 def pending_categorizations
... ...
test/functional/search_controller_test.rb
... ... @@ -65,7 +65,7 @@ class SearchControllerTest < Test::Unit::TestCase
65 65  
66 66 # in category
67 67 art1 = person.articles.build(:name => 'an article to be found')
68   - art1.categories << @category
  68 + art1.add_category @category
69 69 art1.save!
70 70  
71 71 # not in category
... ... @@ -83,9 +83,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase
83 83 person = create_user('testuser').person
84 84 person2 = create_user('anotheruser').person
85 85  
86   - art1 = person.articles.create!(:name => 'one article', :categories => [@category])
  86 + art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id])
87 87  
88   - art2 = person2.articles.create!(:name => 'two article', :categories => [@category])
  88 + art2 = person2.articles.create!(:name => 'two article', :category_ids => [@category.id])
89 89  
90 90 get :assets, :asset => 'articles'
91 91  
... ... @@ -98,8 +98,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
98 98 person = create_user('testuser').person
99 99  
100 100 # in category
101   - art1 = person.articles.create!(:name => 'one article', :categories => [@category])
102   - art2 = person.articles.create!(:name => 'other article', :categories => [@category])
  101 + art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id])
  102 + art2 = person.articles.create!(:name => 'other article', :category_ids => [@category.id])
103 103  
104 104 # not in category
105 105 art3 = person.articles.create!(:name => 'another article')
... ... @@ -120,7 +120,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
120 120 should 'find enterprises in a specified category' do
121 121  
122 122 # in category
123   - ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :categories => [@category])
  123 + ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :category_ids => [@category.id])
124 124  
125 125 # not in category
126 126 ent2 = Enterprise.create!(:name => 'testing enterprise 2', :identifier => 'test2')
... ... @@ -143,7 +143,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
143 143 # 'assets' menu inside a category
144 144 should 'list enterprises in a specified category' do
145 145 # in category
146   - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :categories => [@category])
  146 + ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :category_ids => [@category.id])
147 147  
148 148 # not in category
149 149 ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2')
... ... @@ -160,7 +160,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
160 160 end
161 161  
162 162 should 'find people in a specific category' do
163   - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << @category; p1.save!
  163 + p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category @category; p1.save!
164 164 p2 = create_user('people_2').person; p2.name = 'another beautiful person'; p2.save!
165 165 get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'people' ]
166 166 assert_includes assigns(:results)[:people], p1
... ... @@ -184,7 +184,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
184 184 Profile.delete_all
185 185  
186 186 # in category
187   - p1 = create_user('test1').person; p1.categories << @category
  187 + p1 = create_user('test1').person; p1.add_category @category
188 188  
189 189 # not in category
190 190 p2 = create_user('test2').person
... ... @@ -202,7 +202,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
202 202 should 'find communities in a specified category' do
203 203 c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)
204 204 c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default)
205   - c1.categories << @category; c1.save!
  205 + c1.add_category @category; c1.save!
206 206 get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ]
207 207 assert_includes assigns(:results)[:communities], c1
208 208 assert_not_includes assigns(:results)[:communities], c2
... ... @@ -222,14 +222,14 @@ class SearchControllerTest &lt; Test::Unit::TestCase
222 222  
223 223 # in category
224 224 c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)
225   - c1.categories << @category
  225 + c1.add_category @category
226 226  
227 227 # not in category
228 228 c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default)
229 229  
230 230 # in category
231 231 c3 = Community.create!(:name => 'yet another beautiful community', :identifier => 'yet_an_bea_comm', :environment => Environment.default)
232   - c3.categories << @category
  232 + c3.add_category @category
233 233  
234 234 get :assets, :asset => 'communities', :category_path => [ 'my-category' ]
235 235  
... ... @@ -244,7 +244,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
244 244 end
245 245  
246 246 should 'find products in a specific category' do
247   - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << @category
  247 + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category @category
248 248 ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2')
249 249 prod1 = ent1.products.create!(:name => 'a beautiful product')
250 250 prod2 = ent2.products.create!(:name => 'another beautiful product')
... ... @@ -271,7 +271,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
271 271 Profile.delete_all
272 272  
273 273 # in category
274   - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << @category
  274 + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category @category
275 275 prod1 = ent1.products.create!(:name => 'a beautiful product')
276 276  
277 277 # not in category
... ... @@ -714,7 +714,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
714 714  
715 715 # in category
716 716 ev1 = create_event(person, :name => 'an event to be found')
717   - ev1.categories << @category
  717 + ev1.add_category @category
718 718 ev1.save!
719 719  
720 720 # not in category
... ... @@ -732,9 +732,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase
732 732 person = create_user('testuser').person
733 733 person2 = create_user('anotheruser').person
734 734  
735   - ev1 = create_event(person, :name => 'one event', :categories => [@category])
  735 + ev1 = create_event(person, :name => 'one event', :category_ids => [@category.id])
736 736  
737   - ev2 = create_event(person2, :name => 'two event', :categories => [@category])
  737 + ev2 = create_event(person2, :name => 'two event', :category_ids => [@category.id])
738 738  
739 739 get :assets, :asset => 'events'
740 740  
... ... @@ -747,8 +747,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
747 747 person = create_user('testuser').person
748 748  
749 749 # in category
750   - ev1 = create_event(person, :name => 'one event', :categories => [@category])
751   - ev2 = create_event(person, :name => 'other event', :categories => [@category])
  750 + ev1 = create_event(person, :name => 'one event', :category_ids => [@category.id])
  751 + ev2 = create_event(person, :name => 'other event', :category_ids => [@category.id])
752 752  
753 753 # not in category
754 754 ev3 = create_event(person, :name => 'another event')
... ...
test/unit/category_finder_test.rb
... ... @@ -12,7 +12,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
12 12  
13 13 # in category
14 14 art1 = person.articles.build(:name => 'an article to be found')
15   - art1.categories << @category
  15 + art1.add_category(@category)
16 16 art1.save!
17 17  
18 18 # not in category
... ... @@ -29,7 +29,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
29 29  
30 30 # in category
31 31 art1 = person.articles.build(:name => 'an article to be found')
32   - art1.categories << @category
  32 + art1.add_category(@category)
33 33 art1.save!
34 34  
35 35 # not in category
... ... @@ -43,7 +43,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
43 43 should 'search for enterprises in a specific category' do
44 44  
45 45 # in category
46   - ent1 = Enterprise.create!(:name => 'beautiful enterprise 1', :identifier => 'test1', :categories => [@category])
  46 + ent1 = Enterprise.create!(:name => 'beautiful enterprise 1', :identifier => 'test1', :category_ids => [@category.id])
47 47  
48 48 # not in category
49 49 ent2 = Enterprise.create!(:name => 'beautiful enterprise 2', :identifier => 'test2')
... ... @@ -54,7 +54,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
54 54 end
55 55  
56 56 should 'search for people in a specific category' do
57   - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << @category; p1.save!
  57 + p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category(@category); p1.save!
58 58 p2 = create_user('people_2').person; p2.name = 'another beautiful person'; p2.save!
59 59  
60 60 list = @finder.find(:people, 'beautiful')
... ... @@ -65,7 +65,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
65 65 should 'search for communities in a specific category' do
66 66 c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)
67 67 c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default)
68   - c1.categories << @category; c1.save!
  68 + c1.add_category(@category); c1.save!
69 69  
70 70 list = @finder.find(:communities, 'beautiful')
71 71 assert_includes list, c1
... ... @@ -73,7 +73,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
73 73 end
74 74  
75 75 should 'search for products in a specific category' do
76   - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << @category
  76 + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category(@category)
77 77 ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2')
78 78 prod1 = ent1.products.create!(:name => 'a beautiful product')
79 79 prod2 = ent2.products.create!(:name => 'another beautiful product')
... ... @@ -98,7 +98,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
98 98 should 'search in category hierarchy' do
99 99 parent = Category.create!(:name => 'parent category', :environment => Environment.default)
100 100 child = Category.create!(:name => 'child category', :environment => Environment.default, :parent => parent)
101   - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << child; p1.save!
  101 + p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category(child); p1.save!
102 102  
103 103 parent.reload
104 104  
... ... @@ -107,27 +107,27 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
107 107 end
108 108  
109 109 should 'list recent enterprises' do
110   - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :categories => [@category])
  110 + ent = Enterprise.create!(:name => 'teste', :identifier => 'teste', :category_ids => [@category.id])
111 111 assert_includes @finder.recent('enterprises'), ent
112 112 end
113 113  
114 114 should 'not list more enterprises than limit' do
115   - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :categories => [@category])
116   - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :categories => [@category])
  115 + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id])
  116 + ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2', :category_ids => [@category.id])
117 117 recent = @finder.recent('enterprises', 1)
118 118 assert_includes recent, ent2
119 119 assert_not_includes recent, ent1
120 120 end
121 121  
122   - should 'count entrprises' do
  122 + should 'count enterprises' do
123 123 count = @finder.count('enterprises')
124   - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :categories => [@category])
  124 + ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id])
125 125 assert_equal count+1, @finder.count('enterprises')
126 126 end
127 127  
128 128 should 'not list more people than limit' do
129   - p1 = create_user('test1').person; p1.categories << @category
130   - p2 = create_user('test2').person; p2.categories << @category
  129 + p1 = create_user('test1').person; p1.add_category(@category)
  130 + p2 = create_user('test2').person; p2.add_category(@category)
131 131 recent = @finder.recent('people', 1)
132 132 assert_includes recent, p2
133 133 assert_not_includes recent, p1
... ... @@ -135,9 +135,9 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
135 135  
136 136 should 'list recent articles' do
137 137 person = create_user('teste').person
138   - art1 = person.articles.build(:name => 'an article to be found'); art1.categories << @category; art1.save!
  138 + art1 = person.articles.build(:name => 'an article to be found'); art1.add_category(@category); art1.save!
139 139  
140   - art2 = person.articles.build(:name => 'another article to be found'); art2.categories << @category; art2.save!
  140 + art2 = person.articles.build(:name => 'another article to be found'); art2.add_category(@category); art2.save!
141 141  
142 142 result = @finder.recent('articles', 1)
143 143 assert_includes result, art2
... ... @@ -147,8 +147,8 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
147 147 should 'not return the same result twice' do
148 148 parent = Category.create!(:name => 'parent category', :environment => Environment.default)
149 149 child = Category.create!(:name => 'child category', :environment => Environment.default, :parent => parent)
150   - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << child; p1.save!
151   - p1.categories << parent; p1.save!
  150 + p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.add_category(child); p1.save!
  151 + p1.add_category(parent); p1.save!
152 152  
153 153 f = CategoryFinder.new(parent)
154 154 result = f.find(:people, 'beautiful')
... ... @@ -161,7 +161,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
161 161 Article.delete_all
162 162  
163 163 person = create_user('testuser').person
164   - articles = (1..4).map {|n| a = person.articles.build(:name => "art #{n}", :categories => [@category]); a.save!; a }
  164 + articles = (1..4).map {|n| a = person.articles.build(:name => "art #{n}", :category_ids => [@category.id]); a.save!; a }
165 165  
166 166 2.times { articles[0].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! }
167 167 4.times { articles[1].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! }
... ... @@ -171,8 +171,8 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
171 171 end
172 172  
173 173 should 'find people by initial' do
174   - p1 = create_user('aaaa').person; p1.categories << @category
175   - p2 = create_user('bbbb').person; p2.categories << @category
  174 + p1 = create_user('aaaa').person; p1.add_category(@category)
  175 + p2 = create_user('bbbb').person; p2.add_category(@category)
176 176  
177 177 list = CategoryFinder.new(@category).find_by_initial(:people, 'a')
178 178  
... ... @@ -181,8 +181,8 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
181 181 end
182 182  
183 183 should 'find enterprises by initial' do
184   - ent1 = Enterprise.create!(:name => 'aaaa', :identifier => 'aaaa'); ent1.categories << @category
185   - ent2 = Enterprise.create!(:name => 'bbbb', :identifier => 'bbbb'); ent2.categories << @category
  184 + ent1 = Enterprise.create!(:name => 'aaaa', :identifier => 'aaaa'); ent1.add_category(@category)
  185 + ent2 = Enterprise.create!(:name => 'bbbb', :identifier => 'bbbb'); ent2.add_category(@category)
186 186  
187 187 list = CategoryFinder.new(@category).find_by_initial(:enterprises, 'a')
188 188  
... ... @@ -191,8 +191,8 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
191 191 end
192 192  
193 193 should 'find communities by initial' do
194   - comm1 = Community.create!(:name => 'aaaa', :identifier => 'aaaa'); comm1.categories << @category
195   - comm2 = Community.create!(:name => 'bbbb', :identifier => 'bbbb'); comm2.categories << @category
  194 + comm1 = Community.create!(:name => 'aaaa', :identifier => 'aaaa'); comm1.add_category(@category)
  195 + comm2 = Community.create!(:name => 'bbbb', :identifier => 'bbbb'); comm2.add_category(@category)
196 196  
197 197 list = CategoryFinder.new(@category).find_by_initial(:communities, 'a')
198 198  
... ... @@ -202,7 +202,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
202 202  
203 203 should 'find products by initial' do
204 204 ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent')
205   - ent.categories << @category
  205 + ent.add_category(@category)
206 206  
207 207 p1 = ent.products.create!(:name => 'A product')
208 208 p2 = ent.products.create!(:name => 'Better product')
... ... @@ -215,8 +215,8 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
215 215  
216 216 should 'find articles by initial' do
217 217 person = create_user('testuser').person
218   - a1 = person.articles.create!(:name => 'aaaa', :body => '...', :categories => [@category])
219   - a2 = person.articles.create!(:name => 'bbbb', :body => '...', :categories => [@category])
  218 + a1 = person.articles.create!(:name => 'aaaa', :body => '...', :category_ids => [@category.id])
  219 + a2 = person.articles.create!(:name => 'bbbb', :body => '...', :category_ids => [@category.id])
220 220  
221 221 list = CategoryFinder.new(@category).find_by_initial(:articles, 'a')
222 222  
... ... @@ -228,12 +228,12 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
228 228 finder = CategoryFinder.new(@category)
229 229  
230 230 region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0)
231   - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :categories => [@category])
  231 + ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [@category.id])
232 232 p1 = create_user('test2').person
233   - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.categories = [@category]; p1.save!
234   - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :categories => [@category])
  233 + p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(@category); p1.save!
  234 + ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :category_ids => [@category.id])
235 235 p2 = create_user('test4').person
236   - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.categories = [@category]; p2.save!
  236 + p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.add_category(@category); p2.save!
237 237  
238 238 ents = finder.find(:enterprises, 'test', :within => 10, :region => region.id)
239 239 people = finder.find(:people, 'test', :within => 10, :region => region.id)
... ... @@ -248,7 +248,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
248 248 finder = CategoryFinder.new(@category)
249 249 person = create_user('testuser').person
250 250  
251   - e1 = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,1), :categories => [@category])
  251 + e1 = Event.create!(:name => 'e1', :profile => person, :start_date => Date.new(2008,1,1), :category_ids => [@category.id])
252 252  
253 253 # not in category
254 254 e2 = Event.create!(:name => 'e2', :profile => person, :start_date => Date.new(2008,1,15))
... ... @@ -263,12 +263,12 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
263 263 finder = CategoryFinder.new(cat)
264 264  
265 265 region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0)
266   - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :categories => [cat])
  266 + ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0, :category_ids => [cat.id])
267 267 p1 = create_user('test2').person
268   - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.categories = [cat]; p1.save!
269   - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :categories => [cat])
  268 + p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.add_category(cat); p1.save!
  269 + ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0, :category_ids => [cat.id])
270 270 p2 = create_user('test4').person
271   - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.categories = [cat]; p2.save!
  271 + p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.add_category(cat); p2.save!
272 272  
273 273 ents = finder.find(:enterprises, nil, :within => 10, :region => region.id)
274 274 people = finder.find(:people, nil, :within => 10, :region => region.id)
... ... @@ -284,7 +284,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
284 284 finder = CategoryFinder.new(cat)
285 285  
286 286 prod_cat = ProductCategory.create!(:name => 'test product category', :environment => Environment.default)
287   - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :categories => [cat])
  287 + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :category_ids => [cat.id])
288 288 prod1 = ent.products.create!(:name => 'test product 1', :product_category => prod_cat)
289 289 prod2 = ent.products.create!(:name => 'test product 2')
290 290  
... ...
test/unit/category_test.rb
... ... @@ -242,11 +242,11 @@ class CategoryTest &lt; Test::Unit::TestCase
242 242 person = create_user('testuser').person
243 243  
244 244 a1 = person.articles.build(:name => 'art1')
245   - a1.categories << c
  245 + a1.add_category c
246 246 a1.save!
247 247  
248 248 a2 = person.articles.build(:name => 'art2')
249   - a2.categories << c
  249 + a2.add_category c
250 250 a2.save!
251 251  
252 252 assert_equivalent [a1, a2], c.recent_articles
... ... @@ -257,12 +257,12 @@ class CategoryTest &lt; Test::Unit::TestCase
257 257 person = create_user('testuser').person
258 258  
259 259 a1 = person.articles.build(:name => 'art1')
260   - a1.categories << c
  260 + a1.add_category c
261 261 a1.save!
262 262 c1 = a1.comments.build(:title => 'comm1', :body => 'khdkashd ', :author => person); c1.save!
263 263  
264 264 a2 = person.articles.build(:name => 'art2')
265   - a2.categories << c
  265 + a2.add_category c
266 266 a2.save!
267 267 c2 = a2.comments.build(:title => 'comm1', :body => 'khdkashd ', :author => person); c2.save!
268 268  
... ... @@ -273,9 +273,9 @@ class CategoryTest &lt; Test::Unit::TestCase
273 273 c = @env.categories.build(:name => 'my category'); c.save!
274 274 person = create_user('testuser').person
275 275  
276   - a1 = person.articles.build(:name => 'art1', :categories => [c]); a1.save!
277   - a2 = person.articles.build(:name => 'art2', :categories => [c]); a2.save!
278   - a3 = person.articles.build(:name => 'art3', :categories => [c]); a3.save!
  276 + a1 = person.articles.build(:name => 'art1', :category_ids => [c.id]); a1.save!
  277 + a2 = person.articles.build(:name => 'art2', :category_ids => [c.id]); a2.save!
  278 + a3 = person.articles.build(:name => 'art3', :category_ids => [c.id]); a3.save!
279 279  
280 280 a1.comments.build(:title => 'test', :body => 'asdsa', :author => person).save!
281 281 5.times { a2.comments.build(:title => 'test', :body => 'asdsa', :author => person).save! }
... ... @@ -288,9 +288,9 @@ class CategoryTest &lt; Test::Unit::TestCase
288 288 c = @env.categories.build(:name => 'my category'); c.save!
289 289 person = create_user('testuser').person
290 290  
291   - a1 = person.articles.build(:name => 'art1', :categories => [c]); a1.save!
292   - a2 = person.articles.build(:name => 'art2', :categories => [c]); a2.save!
293   - a3 = person.articles.build(:name => 'art3', :categories => [c]); a3.save!
  291 + a1 = person.articles.build(:name => 'art1', :category_ids => [c]); a1.save!
  292 + a2 = person.articles.build(:name => 'art2', :category_ids => [c]); a2.save!
  293 + a3 = person.articles.build(:name => 'art3', :category_ids => [c]); a3.save!
294 294  
295 295 c1 = a1.comments.build(:title => 'test', :body => 'asdsa', :author => person); c1.save!
296 296 c2 = a2.comments.build(:title => 'test', :body => 'asdsa', :author => person); c2.save!
... ... @@ -302,9 +302,9 @@ class CategoryTest &lt; Test::Unit::TestCase
302 302 should 'have enterprises' do
303 303 c = @env.categories.build(:name => 'my category'); c.save!
304 304 ent1 = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one')
305   - ent1.categories << c
  305 + ent1.add_category c
306 306 ent2 = Enterprise.create!(:identifier => 'enterprise_2', :name => 'Enterprise one')
307   - ent2.categories << c
  307 + ent2.add_category c
308 308 assert_includes c.enterprises, ent1
309 309 assert_includes c.enterprises, ent2
310 310 end
... ... @@ -321,18 +321,18 @@ class CategoryTest &lt; Test::Unit::TestCase
321 321 should 'have communities' do
322 322 c = @env.categories.build(:name => 'my category'); c.save!
323 323 c1 = Environment.default.communities.create!(:name => 'testcommunity_1')
324   - c1.categories << c
  324 + c1.add_category c
325 325 c2 = Environment.default.communities.create!(:name => 'testcommunity_2')
326   - c2.categories << c
  326 + c2.add_category c
327 327 assert_equal [c1, c2], c.communities
328 328 end
329 329  
330 330 should 'have products through enteprises' do
331 331 c = @env.categories.build(:name => 'my category'); c.save!
332 332 ent1 = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one')
333   - ent1.categories << c
  333 + ent1.add_category c
334 334 ent2 = Enterprise.create!(:identifier => 'enterprise_2', :name => 'Enterprise one')
335   - ent2.categories << c
  335 + ent2.add_category c
336 336 prod1 = ent1.products.create!(:name => 'test_prod1')
337 337 prod2 = ent2.products.create!(:name => 'test_prod2')
338 338 assert_includes c.products, prod1
... ... @@ -342,9 +342,9 @@ class CategoryTest &lt; Test::Unit::TestCase
342 342 should 'not have person through communities' do
343 343 c = @env.categories.build(:name => 'my category'); c.save!
344 344 com = Community.create!(:identifier => 'community_1', :name => 'Community one')
345   - com.categories << c
  345 + com.add_category c
346 346 person = create_user('test_user').person
347   - person.categories << c
  347 + person.add_category c
348 348 assert_includes c.communities, com
349 349 assert_not_includes c.communities, person
350 350 end
... ... @@ -352,9 +352,9 @@ class CategoryTest &lt; Test::Unit::TestCase
352 352 should 'not have person through enterprises' do
353 353 c = @env.categories.build(:name => 'my category'); c.save!
354 354 ent = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one')
355   - ent.categories << c
  355 + ent.add_category c
356 356 person = create_user('test_user').person
357   - person.categories << c
  357 + person.add_category c
358 358 assert_includes c.enterprises, ent
359 359 assert_not_includes c.enterprises, person
360 360 end
... ... @@ -362,9 +362,9 @@ class CategoryTest &lt; Test::Unit::TestCase
362 362 should 'not have enterprises through people' do
363 363 c = @env.categories.build(:name => 'my category'); c.save!
364 364 person = create_user('test_user').person
365   - person.categories << c
  365 + person.add_category c
366 366 ent = Enterprise.create!(:identifier => 'enterprise_1', :name => 'Enterprise one')
367   - ent.categories << c
  367 + ent.add_category c
368 368 assert_includes c.people, person
369 369 assert_not_includes c.people, ent
370 370 end
... ... @@ -372,11 +372,11 @@ class CategoryTest &lt; Test::Unit::TestCase
372 372 should 'report the total items in this category' do
373 373 @category = Category.create!(:name => 'my category', :environment => @env)
374 374 # in category
375   - person1 = create_user('test1').person; person1.categories << @category; person1.save!
376   - art1 = person1.articles.build(:name => 'an article to be counted'); art1.categories << @category; art1.save!
  375 + person1 = create_user('test1').person; person1.add_category @category; person1.save!
  376 + art1 = person1.articles.build(:name => 'an article to be counted'); art1.add_category @category; art1.save!
377 377 comment1 = art1.comments.build(:title => 'comment to be counted', :body => 'hfyfyh', :author => person1); comment1.save!
378   - ent1 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :categories => [@category])
379   - com1 = Community.create!(:name => 'test3', :identifier => 'test3', :categories => [@category])
  378 + ent1 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :category_ids => [@category.id])
  379 + com1 = Community.create!(:name => 'test3', :identifier => 'test3', :category_ids => [@category.id])
380 380 prod1 = Product.create!(:name => 'test4', :enterprise => ent1)
381 381  
382 382 # not in category
... ... @@ -390,15 +390,6 @@ class CategoryTest &lt; Test::Unit::TestCase
390 390 assert_equal 6, @category.total_items
391 391 end
392 392  
393   - # NOT YET
394   - #should 'list people that are categorized in children categories' do
395   - # c1 = @env.categories.create!(:name => 'top category')
396   - # c2 = @env.categories.create!(:name => 'child category', :parent => c1)
397   - # person = create_user('test_user').person
398   - # person.categories << c2
399   - # assert_includes c1.people, person
400   - #end
401   -
402 393 should 'have image' do
403 394 assert_difference Category, :count do
404 395 c = Category.create!(:name => 'test category1', :environment => Environment.default, :image_builder => {
... ...