Commit 286e4b52a330b57f75a613143f1eff6f060d76e3

Authored by Rodrigo Souto
1 parent bc5af220

rails3: fix person tests

PS: tests failing due to birth_date lib and action_tracker problem
app/models/article.rb
@@ -147,7 +147,7 @@ class Article < ActiveRecord::Base @@ -147,7 +147,7 @@ class Article < ActiveRecord::Base
147 self.profile 147 self.profile
148 end 148 end
149 149
150 - def self.human_attribute_name(attrib) 150 + def self.human_attribute_name(attrib, options = {})
151 case attrib.to_sym 151 case attrib.to_sym
152 when :name 152 when :name
153 _('Title') 153 _('Title')
app/models/person.rb
@@ -158,8 +158,9 @@ class Person < Profile @@ -158,8 +158,9 @@ class Person < Profile
158 FIELDS 158 FIELDS
159 end 159 end
160 160
161 - def validate  
162 - super 161 + validate :presence_of_required_fields
  162 +
  163 + def presence_of_required_fields
163 self.required_fields.each do |field| 164 self.required_fields.each do |field|
164 if self.send(field).blank? 165 if self.send(field).blank?
165 unless (field == 'custom_area_of_study' && self.area_of_study != 'Others') || (field == 'custom_formation' && self.formation != 'Others') 166 unless (field == 'custom_area_of_study' && self.area_of_study != 'Others') || (field == 'custom_formation' && self.formation != 'Others')
app/models/task.rb
@@ -235,6 +235,29 @@ class Task < ActiveRecord::Base @@ -235,6 +235,29 @@ class Task < ActiveRecord::Base
235 end 235 end
236 end 236 end
237 237
  238 + scope :pending, :conditions => { :status => Task::Status::ACTIVE }
  239 + scope :hidden, :conditions => { :status => Task::Status::HIDDEN }
  240 + scope :finished, :conditions => { :status => Task::Status::FINISHED }
  241 + scope :canceled, :conditions => { :status => Task::Status::CANCELLED }
  242 + scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }
  243 + scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] }
  244 + scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} }
  245 + scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} }
  246 +
  247 + scope :to, lambda { |profile|
  248 + environment_condition = nil
  249 + if profile.person?
  250 + envs_ids = Environment.find(:all).select{ |env| profile.is_admin?(env) }.map { |env| "target_id = #{env.id}"}.join(' OR ')
  251 + environment_condition = envs_ids.blank? ? nil : "(target_type = 'Environment' AND (#{envs_ids}))"
  252 + end
  253 + profile_condition = "(target_type = 'Profile' AND target_id = #{profile.id})"
  254 + { :conditions => [environment_condition, profile_condition].compact.join(' OR ') }
  255 + }
  256 +
  257 + def opened?
  258 + status == Task::Status::ACTIVE || status == Task::Status::HIDDEN
  259 + end
  260 +
238 protected 261 protected
239 262
240 # This method must be overrided in subclasses, and its implementation must do 263 # This method must be overrided in subclasses, and its implementation must do
@@ -266,29 +289,6 @@ class Task < ActiveRecord::Base @@ -266,29 +289,6 @@ class Task < ActiveRecord::Base
266 end 289 end
267 end 290 end
268 291
269 - scope :pending, :conditions => { :status => Task::Status::ACTIVE }  
270 - scope :hidden, :conditions => { :status => Task::Status::HIDDEN }  
271 - scope :finished, :conditions => { :status => Task::Status::FINISHED }  
272 - scope :canceled, :conditions => { :status => Task::Status::CANCELLED }  
273 - scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }  
274 - scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] }  
275 - scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} }  
276 - scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} }  
277 -  
278 - scope :to, lambda { |profile|  
279 - environment_condition = nil  
280 - if profile.person?  
281 - envs_ids = Environment.find(:all).select{ |env| profile.is_admin?(env) }.map { |env| "target_id = #{env.id}"}.join(' OR ')  
282 - environment_condition = envs_ids.blank? ? nil : "(target_type = 'Environment' AND (#{envs_ids}))"  
283 - end  
284 - profile_condition = "(target_type = 'Profile' AND target_id = #{profile.id})"  
285 - { :conditions => [environment_condition, profile_condition].compact.join(' OR ') }  
286 - }  
287 -  
288 - def opened?  
289 - status == Task::Status::ACTIVE || status == Task::Status::HIDDEN  
290 - end  
291 -  
292 class << self 292 class << self
293 293
294 # generates a random code string consisting of length characters (or 36 by 294 # generates a random code string consisting of length characters (or 36 by
test/unit/person_test.rb
@@ -5,7 +5,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -5,7 +5,7 @@ class PersonTest &lt; ActiveSupport::TestCase
5 fixtures :profiles, :users, :environments 5 fixtures :profiles, :users, :environments
6 6
7 def test_person_must_come_form_the_cration_of_an_user 7 def test_person_must_come_form_the_cration_of_an_user
8 - p = Person.new(:environment => Environment.default, :name => 'John', :identifier => 'john') 8 + p = build(Person, :environment => Environment.default, :name => 'John', :identifier => 'john')
9 assert !p.valid? 9 assert !p.valid?
10 p.user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') 10 p.user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
11 assert !p.valid? 11 assert !p.valid?
@@ -14,22 +14,22 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -14,22 +14,22 @@ class PersonTest &lt; ActiveSupport::TestCase
14 end 14 end
15 15
16 def test_can_associate_to_a_profile 16 def test_can_associate_to_a_profile
17 - pr = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile') 17 + pr = build(Profile, :identifier => 'mytestprofile', :name => 'My test profile')
18 pr.save! 18 pr.save!
19 pe = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person 19 pe = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person
20 pe.save! 20 pe.save!
21 - member_role = Role.create(:name => 'somerandomrole') 21 + member_role = create(Role, :name => 'somerandomrole')
22 pr.affiliate(pe, member_role) 22 pr.affiliate(pe, member_role)
23 23
24 assert pe.memberships.include?(pr) 24 assert pe.memberships.include?(pr)
25 end 25 end
26 26
27 def test_can_belong_to_an_enterprise 27 def test_can_belong_to_an_enterprise
28 - e = Enterprise.new(:identifier => 'enterprise', :name => 'enterprise') 28 + e = build(Enterprise, :identifier => 'enterprise', :name => 'enterprise')
29 e.save! 29 e.save!
30 p = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person 30 p = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person
31 p.save! 31 p.save!
32 - member_role = Role.create(:name => 'somerandomrole') 32 + member_role = create(Role, :name => 'somerandomrole')
33 e.affiliate(p, member_role) 33 e.affiliate(p, member_role)
34 34
35 assert p.memberships.include?(e) 35 assert p.memberships.include?(e)
@@ -46,7 +46,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -46,7 +46,7 @@ class PersonTest &lt; ActiveSupport::TestCase
46 end 46 end
47 47
48 should 'be associated with a user' do 48 should 'be associated with a user' do
49 - u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') 49 + u = build(User, :login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
50 u.save! 50 u.save!
51 assert_equal u, Person['john'].user 51 assert_equal u, Person['john'].user
52 end 52 end
@@ -57,21 +57,21 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -57,21 +57,21 @@ class PersonTest &lt; ActiveSupport::TestCase
57 p1 = u.person 57 p1 = u.person
58 assert_equal u, p1.user 58 assert_equal u, p1.user
59 59
60 - p2 = Person.new(:environment => Environment.default) 60 + p2 = build(Person, :environment => Environment.default)
61 p2.user = u 61 p2.user = u
62 assert !p2.valid? 62 assert !p2.valid?
63 assert p2.errors[:user_id.to_s].present? 63 assert p2.errors[:user_id.to_s].present?
64 end 64 end
65 65
66 should "have person info fields" do 66 should "have person info fields" do
67 - p = Person.new(:environment => Environment.default) 67 + p = build(Person, :environment => Environment.default)
68 [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country, :zip_code, :image, :district, :address_reference ].each do |i| 68 [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country, :zip_code, :image, :district, :address_reference ].each do |i|
69 assert_respond_to p, i 69 assert_respond_to p, i
70 end 70 end
71 end 71 end
72 72
73 should 'not have person_info class' do 73 should 'not have person_info class' do
74 - p = Person.new(:environment => Environment.default) 74 + p = build(Person, :environment => Environment.default)
75 assert_raise NoMethodError do 75 assert_raise NoMethodError do
76 p.person_info 76 p.person_info
77 end 77 end
@@ -80,9 +80,9 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -80,9 +80,9 @@ class PersonTest &lt; ActiveSupport::TestCase
80 should 'change the roles of the user' do 80 should 'change the roles of the user' do
81 p = create_user('jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person 81 p = create_user('jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
82 e = fast_create(Enterprise) 82 e = fast_create(Enterprise)
83 - r1 = Role.create(:name => 'associate') 83 + r1 = create(Role, :name => 'associate')
84 assert e.affiliate(p, r1) 84 assert e.affiliate(p, r1)
85 - r2 = Role.create(:name => 'partner') 85 + r2 = create(Role, :name => 'partner')
86 assert p.define_roles([r2], e) 86 assert p.define_roles([r2], e)
87 p = Person.find(p.id) 87 p = Person.find(p.id)
88 assert p.role_assignments.any? {|ra| ra.role == r2} 88 assert p.role_assignments.any? {|ra| ra.role == r2}
@@ -91,7 +91,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -91,7 +91,7 @@ class PersonTest &lt; ActiveSupport::TestCase
91 91
92 should 'report that the user has the permission' do 92 should 'report that the user has the permission' do
93 p = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person 93 p = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
94 - r = Role.create(:name => 'associate', :permissions => ['edit_profile']) 94 + r = create(Role, :name => 'associate', :permissions => ['edit_profile'])
95 e = fast_create(Enterprise) 95 e = fast_create(Enterprise)
96 assert e.affiliate(p, r) 96 assert e.affiliate(p, r)
97 p = Person.find(p.id) 97 p = Person.find(p.id)
@@ -106,7 +106,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -106,7 +106,7 @@ class PersonTest &lt; ActiveSupport::TestCase
106 end 106 end
107 107
108 should 'get no email address when there is no associated user' do 108 should 'get no email address when there is no associated user' do
109 - p = Person.new(:environment => Environment.default) 109 + p = build(Person, :environment => Environment.default)
110 assert_nil p.email 110 assert_nil p.email
111 end 111 end
112 112
@@ -134,7 +134,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -134,7 +134,7 @@ class PersonTest &lt; ActiveSupport::TestCase
134 other.email = 'user@domain.com' 134 other.email = 'user@domain.com'
135 other.valid? 135 other.valid?
136 assert other.errors[:email.to_s].present? 136 assert other.errors[:email.to_s].present?
137 - assert_no_match /\{fn\}/, other.errors.on(:email) 137 + assert_no_match /\{fn\}/, other.errors[:email].first
138 end 138 end
139 139
140 should 'be able to use an e-mail already used in other environment' do 140 should 'be able to use an e-mail already used in other environment' do
@@ -148,7 +148,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -148,7 +148,7 @@ class PersonTest &lt; ActiveSupport::TestCase
148 end 148 end
149 149
150 should 'be an admin if have permission of environment administration' do 150 should 'be an admin if have permission of environment administration' do
151 - role = Role.create!(:name => 'just_another_admin_role') 151 + role = create(Role, :name => 'just_another_admin_role')
152 env = fast_create(Environment) 152 env = fast_create(Environment)
153 person = create_user('just_another_person').person 153 person = create_user('just_another_person').person
154 env.affiliate(person, role) 154 env.affiliate(person, role)
@@ -163,7 +163,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -163,7 +163,7 @@ class PersonTest &lt; ActiveSupport::TestCase
163 env2 = fast_create(Environment) 163 env2 = fast_create(Environment)
164 164
165 # role is an admin role 165 # role is an admin role
166 - role = Role.create!(:name => 'just_another_admin_role') 166 + role = create(Role, :name => 'just_another_admin_role')
167 role.update_attributes(:permissions => ['view_environment_admin_panel']) 167 role.update_attributes(:permissions => ['view_environment_admin_panel'])
168 168
169 # user is admin of env1, but not of env2 169 # user is admin of env1, but not of env2
@@ -176,15 +176,16 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -176,15 +176,16 @@ class PersonTest &lt; ActiveSupport::TestCase
176 end 176 end
177 177
178 should 'create a default set of articles' do 178 should 'create a default set of articles' do
179 - Person.any_instance.stubs(:default_set_of_articles).returns([Blog.new(:name => 'blog')])  
180 - person = create_user_full('mytestuser').person 179 + blog = build(Blog)
  180 + Person.any_instance.stubs(:default_set_of_articles).returns([blog])
  181 + person = create(User).person
181 182
182 - assert_kind_of Blog, person.articles.find_by_path('blog')  
183 - assert_kind_of RssFeed, person.articles.find_by_path('blog/feed') 183 + assert_kind_of Blog, person.articles.find_by_path(blog.path)
  184 + assert_kind_of RssFeed, person.articles.find_by_path(blog.feed.path)
184 end 185 end
185 186
186 should 'create a default set of blocks' do 187 should 'create a default set of blocks' do
187 - p = create_user_full('testingblocks').person 188 + p = create(User).person
188 189
189 assert !p.boxes[0].blocks.empty?, 'person must have blocks in area 1' 190 assert !p.boxes[0].blocks.empty?, 'person must have blocks in area 1'
190 assert !p.boxes[1].blocks.empty?, 'person must have blocks in area 2' 191 assert !p.boxes[1].blocks.empty?, 'person must have blocks in area 2'
@@ -192,7 +193,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -192,7 +193,7 @@ class PersonTest &lt; ActiveSupport::TestCase
192 end 193 end
193 194
194 should 'link to all articles created by default' do 195 should 'link to all articles created by default' do
195 - p = create_user_full('testingblocks').person 196 + p = create(User).person
196 blocks = p.blocks.select { |b| b.is_a?(LinkListBlock) } 197 blocks = p.blocks.select { |b| b.is_a?(LinkListBlock) }
197 p.articles.reject { |a| a.is_a?(RssFeed) }.each do |article| 198 p.articles.reject { |a| a.is_a?(RssFeed) }.each do |article|
198 path = '/' + p.identifier + '/' + article.path 199 path = '/' + p.identifier + '/' + article.path
@@ -213,22 +214,21 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -213,22 +214,21 @@ class PersonTest &lt; ActiveSupport::TestCase
213 p1.add_friend(p3) 214 p1.add_friend(p3)
214 215
215 assert_equal [p2,p3], p1.friends(true) # force reload 216 assert_equal [p2,p3], p1.friends(true) # force reload
216 -  
217 end 217 end
218 218
219 should 'suggest default friend groups list' do 219 should 'suggest default friend groups list' do
220 - p = Person.new(:environment => Environment.default) 220 + p = build(Person, :environment => Environment.default)
221 assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups 221 assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups
222 end 222 end
223 223
224 should 'suggest current groups as well' do 224 should 'suggest current groups as well' do
225 - p = Person.new(:environment => Environment.default) 225 + p = build(Person, :environment => Environment.default)
226 p.expects(:friend_groups).returns(['group1', 'group2']) 226 p.expects(:friend_groups).returns(['group1', 'group2'])
227 assert_equivalent [ 'friends', 'work', 'school', 'family', 'group1', 'group2' ], p.suggested_friend_groups 227 assert_equivalent [ 'friends', 'work', 'school', 'family', 'group1', 'group2' ], p.suggested_friend_groups
228 end 228 end
229 229
230 should 'accept nil friend groups when suggesting friend groups' do 230 should 'accept nil friend groups when suggesting friend groups' do
231 - p = Person.new(:environment => Environment.default) 231 + p = build(Person, :environment => Environment.default)
232 p.expects(:friend_groups).returns([nil]) 232 p.expects(:friend_groups).returns([nil])
233 assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups 233 assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups
234 end 234 end
@@ -309,29 +309,29 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -309,29 +309,29 @@ class PersonTest &lt; ActiveSupport::TestCase
309 end 309 end
310 310
311 should 'provide desired info fields' do 311 should 'provide desired info fields' do
312 - p = Person.new(:environment => Environment.default) 312 + p = build(Person, :environment => Environment.default)
313 assert p.respond_to?(:photo) 313 assert p.respond_to?(:photo)
314 assert p.respond_to?(:address) 314 assert p.respond_to?(:address)
315 assert p.respond_to?(:contact_information) 315 assert p.respond_to?(:contact_information)
316 end 316 end
317 317
318 should 'required name' do 318 should 'required name' do
319 - person = Person.new(:environment => Environment.default) 319 + person = Person.new
320 assert !person.valid? 320 assert !person.valid?
321 - assert person.errors[:name.to_s].present? 321 + assert person.errors[:name].present?
322 end 322 end
323 323
324 should 'already request friendship' do 324 should 'already request friendship' do
325 p1 = create_user('testuser1').person 325 p1 = create_user('testuser1').person
326 p2 = create_user('testuser2').person 326 p2 = create_user('testuser2').person
327 - AddFriend.create!(:person => p1, :friend => p2) 327 + create(AddFriend, :person => p1, :friend => p2)
328 assert p1.already_request_friendship?(p2) 328 assert p1.already_request_friendship?(p2)
329 end 329 end
330 330
331 should 'have e-mail addresses' do 331 should 'have e-mail addresses' do
332 env = fast_create(Environment) 332 env = fast_create(Environment)
333 - env.domains << Domain.new(:name => 'somedomain.com')  
334 - person = Person.new(:environment => env, :identifier => 'testuser') 333 + env.domains << build(Domain, :name => 'somedomain.com')
  334 + person = build(Person, :environment => env, :identifier => 'testuser')
335 person.expects(:environment).returns(env) 335 person.expects(:environment).returns(env)
336 336
337 assert_equal ['testuser@somedomain.com'], person.email_addresses 337 assert_equal ['testuser@somedomain.com'], person.email_addresses
@@ -339,9 +339,9 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -339,9 +339,9 @@ class PersonTest &lt; ActiveSupport::TestCase
339 339
340 should 'not show www in e-mail addresses when force_www=true' do 340 should 'not show www in e-mail addresses when force_www=true' do
341 env = fast_create(Environment) 341 env = fast_create(Environment)
342 - env.domains << Domain.new(:name => 'somedomain.com') 342 + env.domains << build(Domain, :name => 'somedomain.com')
343 env.update_attribute(:force_www, true) 343 env.update_attribute(:force_www, true)
344 - person = Person.new(:environment => env, :identifier => 'testuser') 344 + person = build(Person, :environment => env, :identifier => 'testuser')
345 person.expects(:environment).returns(env) 345 person.expects(:environment).returns(env)
346 346
347 assert_equal ['testuser@somedomain.com'], person.email_addresses 347 assert_equal ['testuser@somedomain.com'], person.email_addresses
@@ -366,7 +366,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -366,7 +366,7 @@ class PersonTest &lt; ActiveSupport::TestCase
366 end 366 end
367 367
368 should 'have a default person template' do 368 should 'have a default person template' do
369 - env = Environment.create!(:name => 'test env') 369 + env = create(Environment, :name => 'test env')
370 p = create_user('test_user', :environment => env).person 370 p = create_user('test_user', :environment => env).person
371 assert_kind_of Person, p.template 371 assert_kind_of Person, p.template
372 end 372 end
@@ -375,7 +375,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -375,7 +375,7 @@ class PersonTest &lt; ActiveSupport::TestCase
375 p = create_user('test_profile').person 375 p = create_user('test_profile').person
376 376
377 assert_no_difference Task, :count do 377 assert_no_difference Task, :count do
378 - Task.create(:requestor => p) 378 + create(Task, :requestor => p)
379 p.destroy 379 p.destroy
380 end 380 end
381 end 381 end
@@ -437,7 +437,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -437,7 +437,7 @@ class PersonTest &lt; ActiveSupport::TestCase
437 should 'return active_person_fields' do 437 should 'return active_person_fields' do
438 e = Environment.default 438 e = Environment.default
439 e.expects(:active_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once 439 e.expects(:active_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once
440 - person = Person.new(:environment => e) 440 + person = build(Person, :environment => e)
441 441
442 assert_equal e.active_person_fields, person.active_fields 442 assert_equal e.active_person_fields, person.active_fields
443 end 443 end
@@ -445,7 +445,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -445,7 +445,7 @@ class PersonTest &lt; ActiveSupport::TestCase
445 should 'return email as active_person_fields' do 445 should 'return email as active_person_fields' do
446 e = Environment.default 446 e = Environment.default
447 e.expects(:active_person_fields).returns(['nickname']).at_least_once 447 e.expects(:active_person_fields).returns(['nickname']).at_least_once
448 - person = Person.new(:environment => e) 448 + person = build(Person, :environment => e)
449 449
450 assert_equal ['nickname', 'email'], person.active_fields 450 assert_equal ['nickname', 'email'], person.active_fields
451 end 451 end
@@ -453,7 +453,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -453,7 +453,7 @@ class PersonTest &lt; ActiveSupport::TestCase
453 should 'return required_person_fields' do 453 should 'return required_person_fields' do
454 e = Environment.default 454 e = Environment.default
455 e.expects(:required_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once 455 e.expects(:required_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once
456 - person = Person.new(:environment => e) 456 + person = build(Person, :environment => e)
457 457
458 assert_equal e.required_person_fields, person.required_fields 458 assert_equal e.required_person_fields, person.required_fields
459 end 459 end
@@ -461,7 +461,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -461,7 +461,7 @@ class PersonTest &lt; ActiveSupport::TestCase
461 should 'require fields if person needs' do 461 should 'require fields if person needs' do
462 e = Environment.default 462 e = Environment.default
463 e.expects(:required_person_fields).returns(['cell_phone']).at_least_once 463 e.expects(:required_person_fields).returns(['cell_phone']).at_least_once
464 - person = Person.new(:environment => e) 464 + person = build(Person, :environment => e)
465 assert ! person.valid? 465 assert ! person.valid?
466 assert person.errors[:cell_phone.to_s].present? 466 assert person.errors[:cell_phone.to_s].present?
467 467
@@ -474,7 +474,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -474,7 +474,7 @@ class PersonTest &lt; ActiveSupport::TestCase
474 e = Environment.default 474 e = Environment.default
475 e.expects(:required_person_fields).returns(['area_of_study', 'custom_area_of_study']).at_least_once 475 e.expects(:required_person_fields).returns(['area_of_study', 'custom_area_of_study']).at_least_once
476 476
477 - person = Person.new(:environment => e, :area_of_study => 'Others') 477 + person = build(Person, :environment => e, :area_of_study => 'Others')
478 assert !person.valid? 478 assert !person.valid?
479 assert person.errors[:custom_area_of_study.to_s].present? 479 assert person.errors[:custom_area_of_study.to_s].present?
480 480
@@ -487,7 +487,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -487,7 +487,7 @@ class PersonTest &lt; ActiveSupport::TestCase
487 e = Environment.default 487 e = Environment.default
488 e.expects(:required_person_fields).returns(['area_of_study']).at_least_once 488 e.expects(:required_person_fields).returns(['area_of_study']).at_least_once
489 489
490 - person = Person.new(:environment => e, :area_of_study => 'Agrometeorology') 490 + person = build(Person, :environment => e, :area_of_study => 'Agrometeorology')
491 person.valid? 491 person.valid?
492 assert ! person.errors[:custom_area_of_study.to_s].present? 492 assert ! person.errors[:custom_area_of_study.to_s].present?
493 end 493 end
@@ -496,7 +496,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -496,7 +496,7 @@ class PersonTest &lt; ActiveSupport::TestCase
496 e = Environment.default 496 e = Environment.default
497 e.expects(:required_person_fields).returns(['formation', 'custom_formation']).at_least_once 497 e.expects(:required_person_fields).returns(['formation', 'custom_formation']).at_least_once
498 498
499 - person = Person.new(:environment => e, :formation => 'Others') 499 + person = build(Person, :environment => e, :formation => 'Others')
500 assert !person.valid? 500 assert !person.valid?
501 assert person.errors[:custom_formation.to_s].present? 501 assert person.errors[:custom_formation.to_s].present?
502 502
@@ -509,7 +509,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -509,7 +509,7 @@ class PersonTest &lt; ActiveSupport::TestCase
509 e = Environment.default 509 e = Environment.default
510 e.expects(:required_person_fields).returns(['formation']).at_least_once 510 e.expects(:required_person_fields).returns(['formation']).at_least_once
511 511
512 - person = Person.new(:environment => e, :formation => 'Agrometeorology') 512 + person = build(Person, :environment => e, :formation => 'Agrometeorology')
513 assert !person.valid? 513 assert !person.valid?
514 assert ! person.errors[:custom_formation.to_s].present? 514 assert ! person.errors[:custom_formation.to_s].present?
515 end 515 end
@@ -548,7 +548,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -548,7 +548,7 @@ class PersonTest &lt; ActiveSupport::TestCase
548 should 'not ask to join if already asked' do 548 should 'not ask to join if already asked' do
549 p = create_user('test_user').person 549 p = create_user('test_user').person
550 c = fast_create(Community) 550 c = fast_create(Community)
551 - AddMember.create!(:person => p, :organization => c) 551 + create(AddMember, :person => p, :organization => c)
552 552
553 assert !p.ask_to_join?(c) 553 assert !p.ask_to_join?(c)
554 end 554 end
@@ -651,8 +651,8 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -651,8 +651,8 @@ class PersonTest &lt; ActiveSupport::TestCase
651 p1.add_friend(p2) 651 p1.add_friend(p2)
652 p2.add_friend(p1) 652 p2.add_friend(p1)
653 p2.add_friend(p3) 653 p2.add_friend(p3)
654 - assert_equal p2, Person.more_popular[0]  
655 - assert_equal p1, Person.more_popular[1] 654 + assert_equal p2, Person.more_popular.all[0]
  655 + assert_equal p1, Person.more_popular.all[1]
656 end 656 end
657 657
658 should 'list people that have no friends in more popular list' do 658 should 'list people that have no friends in more popular list' do
@@ -1183,12 +1183,12 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1183,12 +1183,12 @@ class PersonTest &lt; ActiveSupport::TestCase
1183 p2 = create_user('user2').person 1183 p2 = create_user('user2').person
1184 profile = fast_create(Profile) 1184 profile = fast_create(Profile)
1185 1185
1186 - abuse_report1 = AbuseReport.new(:reason => 'some reason') 1186 + abuse_report1 = build(AbuseReport, :reason => 'some reason')
1187 assert_difference AbuseComplaint, :count, 1 do 1187 assert_difference AbuseComplaint, :count, 1 do
1188 p1.register_report(abuse_report1, profile) 1188 p1.register_report(abuse_report1, profile)
1189 end 1189 end
1190 1190
1191 - abuse_report2 = AbuseReport.new(:reason => 'some reason') 1191 + abuse_report2 = build(AbuseReport, :reason => 'some reason')
1192 assert_no_difference AbuseComplaint, :count do 1192 assert_no_difference AbuseComplaint, :count do
1193 p2.register_report(abuse_report2, profile) 1193 p2.register_report(abuse_report2, profile)
1194 end 1194 end
@@ -1206,7 +1206,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1206,7 +1206,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1206 profile = fast_create(Profile) 1206 profile = fast_create(Profile)
1207 assert !person.already_reported?(profile) 1207 assert !person.already_reported?(profile)
1208 1208
1209 - person.register_report(AbuseReport.new(:reason => 'some reason'), profile) 1209 + person.register_report(build(AbuseReport, :reason => 'some reason'), profile)
1210 person.reload 1210 person.reload
1211 assert person.already_reported?(profile) 1211 assert person.already_reported?(profile)
1212 end 1212 end
@@ -1226,9 +1226,9 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1226,9 +1226,9 @@ class PersonTest &lt; ActiveSupport::TestCase
1226 person = fast_create(Person) 1226 person = fast_create(Person)
1227 another_person = fast_create(Person) 1227 another_person = fast_create(Person)
1228 1228
1229 - scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) 1229 + scrap = create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap'))
1230 UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once 1230 UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
1231 - article = TinyMceArticle.create!(:profile => person, :name => 'An article about free software') 1231 + article = create(TinyMceArticle, :profile => person, :name => 'An article about free software')
1232 1232
1233 assert_equivalent [scrap,article.activity], person.activities.map { |a| a.klass.constantize.find(a.id) } 1233 assert_equivalent [scrap,article.activity], person.activities.map { |a| a.klass.constantize.find(a.id) }
1234 end 1234 end
@@ -1237,14 +1237,14 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1237,14 +1237,14 @@ class PersonTest &lt; ActiveSupport::TestCase
1237 person = fast_create(Person) 1237 person = fast_create(Person)
1238 another_person = fast_create(Person) 1238 another_person = fast_create(Person)
1239 1239
1240 - person_scrap = Scrap.create!(defaults_for_scrap(:sender => person, :receiver => person, :content => 'A scrap from person'))  
1241 - another_person_scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => another_person, :content => 'A scrap from another person')) 1240 + person_scrap = create(Scrap, defaults_for_scrap(:sender => person, :receiver => person, :content => 'A scrap from person'))
  1241 + another_person_scrap = create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => another_person, :content => 'A scrap from another person'))
1242 1242
1243 - TinyMceArticle.create!(:profile => another_person, :name => 'An article about free software from another person') 1243 + create(TinyMceArticle, :profile => another_person, :name => 'An article about free software from another person')
1244 another_person_activity = ActionTracker::Record.last 1244 another_person_activity = ActionTracker::Record.last
1245 1245
1246 UserStampSweeper.any_instance.stubs(:current_user).returns(person) 1246 UserStampSweeper.any_instance.stubs(:current_user).returns(person)
1247 - TinyMceArticle.create!(:profile => person, :name => 'An article about free software') 1247 + create(TinyMceArticle, :profile => person, :name => 'An article about free software')
1248 person_activity = ActionTracker::Record.last 1248 person_activity = ActionTracker::Record.last
1249 1249
1250 assert_equivalent [person_scrap,person_activity], person.activities.map { |a| a.klass.constantize.find(a.id) } 1250 assert_equivalent [person_scrap,person_activity], person.activities.map { |a| a.klass.constantize.find(a.id) }
@@ -1288,7 +1288,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1288,7 +1288,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1288 1288
1289 should 'define abuser?' do 1289 should 'define abuser?' do
1290 abuser = create_user('abuser').person 1290 abuser = create_user('abuser').person
1291 - AbuseComplaint.create!(:reported => abuser).finish 1291 + create(AbuseComplaint, :reported => abuser).finish
1292 person = create_user('person').person 1292 person = create_user('person').person
1293 1293
1294 assert abuser.abuser? 1294 assert abuser.abuser?
@@ -1297,21 +1297,21 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1297,21 +1297,21 @@ class PersonTest &lt; ActiveSupport::TestCase
1297 1297
1298 should 'be able to retrieve abusers and non abusers' do 1298 should 'be able to retrieve abusers and non abusers' do
1299 abuser1 = create_user('abuser1').person 1299 abuser1 = create_user('abuser1').person
1300 - AbuseComplaint.create!(:reported => abuser1).finish 1300 + create(AbuseComplaint, :reported => abuser1).finish
1301 abuser2 = create_user('abuser2').person 1301 abuser2 = create_user('abuser2').person
1302 - AbuseComplaint.create!(:reported => abuser2).finish 1302 + create(AbuseComplaint, :reported => abuser2).finish
1303 person = create_user('person').person 1303 person = create_user('person').person
1304 1304
1305 abusers = Person.abusers 1305 abusers = Person.abusers
1306 1306
1307 - assert_equal ActiveRecord::NamedScope::Scope, abusers.class 1307 + assert_equal ActiveRecord::Relation, abusers.class
1308 assert_includes abusers, abuser1 1308 assert_includes abusers, abuser1
1309 assert_includes abusers, abuser2 1309 assert_includes abusers, abuser2
1310 assert_not_includes abusers, person 1310 assert_not_includes abusers, person
1311 1311
1312 non_abusers = Person.non_abusers 1312 non_abusers = Person.non_abusers
1313 1313
1314 - assert_equal ActiveRecord::NamedScope::Scope, non_abusers.class 1314 + assert_equal ActiveRecord::Relation, non_abusers.class
1315 assert_not_includes non_abusers, abuser1 1315 assert_not_includes non_abusers, abuser1
1316 assert_not_includes non_abusers, abuser2 1316 assert_not_includes non_abusers, abuser2
1317 assert_includes non_abusers, person 1317 assert_includes non_abusers, person
@@ -1319,9 +1319,9 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1319,9 +1319,9 @@ class PersonTest &lt; ActiveSupport::TestCase
1319 1319
1320 should 'not return canceled complaints as abusers' do 1320 should 'not return canceled complaints as abusers' do
1321 abuser = create_user('abuser1').person 1321 abuser = create_user('abuser1').person
1322 - AbuseComplaint.create!(:reported => abuser).finish 1322 + create(AbuseComplaint, :reported => abuser).finish
1323 not_abuser = create_user('abuser2').person 1323 not_abuser = create_user('abuser2').person
1324 - AbuseComplaint.create!(:reported => not_abuser).cancel 1324 + create(AbuseComplaint, :reported => not_abuser).cancel
1325 1325
1326 abusers = Person.abusers 1326 abusers = Person.abusers
1327 assert_includes abusers, abuser 1327 assert_includes abusers, abuser
vendor/plugins/action_tracker/lib/action_tracker.rb
@@ -74,7 +74,7 @@ module ActionTracker @@ -74,7 +74,7 @@ module ActionTracker
74 end 74 end
75 75
76 def acts_as_trackable(options = {}) 76 def acts_as_trackable(options = {})
77 - has_many :tracked_actions, { :class_name => "ActionTracker::Record", :order => "updated_at DESC", :foreign_key => :user_id }.merge(options) 77 + has_many :tracked_actions, { :class_name => "ActionTracker::Record", :order => "updated_at DESC", :foreign_key => :user_id, :dependent => :destroy }.merge(options)
78 send :include, InstanceMethods 78 send :include, InstanceMethods
79 end 79 end
80 end 80 end