Commit 286e4b52a330b57f75a613143f1eff6f060d76e3
1 parent
bc5af220
Exists in
master
and in
29 other branches
rails3: fix person tests
PS: tests failing due to birth_date lib and action_tracker problem
Showing
5 changed files
with
91 additions
and
90 deletions
Show diff stats
app/models/article.rb
app/models/person.rb
| ... | ... | @@ -158,8 +158,9 @@ class Person < Profile |
| 158 | 158 | FIELDS |
| 159 | 159 | end |
| 160 | 160 | |
| 161 | - def validate | |
| 162 | - super | |
| 161 | + validate :presence_of_required_fields | |
| 162 | + | |
| 163 | + def presence_of_required_fields | |
| 163 | 164 | self.required_fields.each do |field| |
| 164 | 165 | if self.send(field).blank? |
| 165 | 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 | 235 | end |
| 236 | 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 | 261 | protected |
| 239 | 262 | |
| 240 | 263 | # This method must be overrided in subclasses, and its implementation must do |
| ... | ... | @@ -266,29 +289,6 @@ class Task < ActiveRecord::Base |
| 266 | 289 | end |
| 267 | 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 | 292 | class << self |
| 293 | 293 | |
| 294 | 294 | # generates a random code string consisting of length characters (or 36 by | ... | ... |
test/unit/person_test.rb
| ... | ... | @@ -5,7 +5,7 @@ class PersonTest < ActiveSupport::TestCase |
| 5 | 5 | fixtures :profiles, :users, :environments |
| 6 | 6 | |
| 7 | 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 | 9 | assert !p.valid? |
| 10 | 10 | p.user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') |
| 11 | 11 | assert !p.valid? |
| ... | ... | @@ -14,22 +14,22 @@ class PersonTest < ActiveSupport::TestCase |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | 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 | 18 | pr.save! |
| 19 | 19 | pe = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person |
| 20 | 20 | pe.save! |
| 21 | - member_role = Role.create(:name => 'somerandomrole') | |
| 21 | + member_role = create(Role, :name => 'somerandomrole') | |
| 22 | 22 | pr.affiliate(pe, member_role) |
| 23 | 23 | |
| 24 | 24 | assert pe.memberships.include?(pr) |
| 25 | 25 | end |
| 26 | 26 | |
| 27 | 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 | 29 | e.save! |
| 30 | 30 | p = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person |
| 31 | 31 | p.save! |
| 32 | - member_role = Role.create(:name => 'somerandomrole') | |
| 32 | + member_role = create(Role, :name => 'somerandomrole') | |
| 33 | 33 | e.affiliate(p, member_role) |
| 34 | 34 | |
| 35 | 35 | assert p.memberships.include?(e) |
| ... | ... | @@ -46,7 +46,7 @@ class PersonTest < ActiveSupport::TestCase |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | 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 | 50 | u.save! |
| 51 | 51 | assert_equal u, Person['john'].user |
| 52 | 52 | end |
| ... | ... | @@ -57,21 +57,21 @@ class PersonTest < ActiveSupport::TestCase |
| 57 | 57 | p1 = u.person |
| 58 | 58 | assert_equal u, p1.user |
| 59 | 59 | |
| 60 | - p2 = Person.new(:environment => Environment.default) | |
| 60 | + p2 = build(Person, :environment => Environment.default) | |
| 61 | 61 | p2.user = u |
| 62 | 62 | assert !p2.valid? |
| 63 | 63 | assert p2.errors[:user_id.to_s].present? |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | 66 | should "have person info fields" do |
| 67 | - p = Person.new(:environment => Environment.default) | |
| 67 | + p = build(Person, :environment => Environment.default) | |
| 68 | 68 | [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country, :zip_code, :image, :district, :address_reference ].each do |i| |
| 69 | 69 | assert_respond_to p, i |
| 70 | 70 | end |
| 71 | 71 | end |
| 72 | 72 | |
| 73 | 73 | should 'not have person_info class' do |
| 74 | - p = Person.new(:environment => Environment.default) | |
| 74 | + p = build(Person, :environment => Environment.default) | |
| 75 | 75 | assert_raise NoMethodError do |
| 76 | 76 | p.person_info |
| 77 | 77 | end |
| ... | ... | @@ -80,9 +80,9 @@ class PersonTest < ActiveSupport::TestCase |
| 80 | 80 | should 'change the roles of the user' do |
| 81 | 81 | p = create_user('jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person |
| 82 | 82 | e = fast_create(Enterprise) |
| 83 | - r1 = Role.create(:name => 'associate') | |
| 83 | + r1 = create(Role, :name => 'associate') | |
| 84 | 84 | assert e.affiliate(p, r1) |
| 85 | - r2 = Role.create(:name => 'partner') | |
| 85 | + r2 = create(Role, :name => 'partner') | |
| 86 | 86 | assert p.define_roles([r2], e) |
| 87 | 87 | p = Person.find(p.id) |
| 88 | 88 | assert p.role_assignments.any? {|ra| ra.role == r2} |
| ... | ... | @@ -91,7 +91,7 @@ class PersonTest < ActiveSupport::TestCase |
| 91 | 91 | |
| 92 | 92 | should 'report that the user has the permission' do |
| 93 | 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 | 95 | e = fast_create(Enterprise) |
| 96 | 96 | assert e.affiliate(p, r) |
| 97 | 97 | p = Person.find(p.id) |
| ... | ... | @@ -106,7 +106,7 @@ class PersonTest < ActiveSupport::TestCase |
| 106 | 106 | end |
| 107 | 107 | |
| 108 | 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 | 110 | assert_nil p.email |
| 111 | 111 | end |
| 112 | 112 | |
| ... | ... | @@ -134,7 +134,7 @@ class PersonTest < ActiveSupport::TestCase |
| 134 | 134 | other.email = 'user@domain.com' |
| 135 | 135 | other.valid? |
| 136 | 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 | 138 | end |
| 139 | 139 | |
| 140 | 140 | should 'be able to use an e-mail already used in other environment' do |
| ... | ... | @@ -148,7 +148,7 @@ class PersonTest < ActiveSupport::TestCase |
| 148 | 148 | end |
| 149 | 149 | |
| 150 | 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 | 152 | env = fast_create(Environment) |
| 153 | 153 | person = create_user('just_another_person').person |
| 154 | 154 | env.affiliate(person, role) |
| ... | ... | @@ -163,7 +163,7 @@ class PersonTest < ActiveSupport::TestCase |
| 163 | 163 | env2 = fast_create(Environment) |
| 164 | 164 | |
| 165 | 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 | 167 | role.update_attributes(:permissions => ['view_environment_admin_panel']) |
| 168 | 168 | |
| 169 | 169 | # user is admin of env1, but not of env2 |
| ... | ... | @@ -176,15 +176,16 @@ class PersonTest < ActiveSupport::TestCase |
| 176 | 176 | end |
| 177 | 177 | |
| 178 | 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 | 185 | end |
| 185 | 186 | |
| 186 | 187 | should 'create a default set of blocks' do |
| 187 | - p = create_user_full('testingblocks').person | |
| 188 | + p = create(User).person | |
| 188 | 189 | |
| 189 | 190 | assert !p.boxes[0].blocks.empty?, 'person must have blocks in area 1' |
| 190 | 191 | assert !p.boxes[1].blocks.empty?, 'person must have blocks in area 2' |
| ... | ... | @@ -192,7 +193,7 @@ class PersonTest < ActiveSupport::TestCase |
| 192 | 193 | end |
| 193 | 194 | |
| 194 | 195 | should 'link to all articles created by default' do |
| 195 | - p = create_user_full('testingblocks').person | |
| 196 | + p = create(User).person | |
| 196 | 197 | blocks = p.blocks.select { |b| b.is_a?(LinkListBlock) } |
| 197 | 198 | p.articles.reject { |a| a.is_a?(RssFeed) }.each do |article| |
| 198 | 199 | path = '/' + p.identifier + '/' + article.path |
| ... | ... | @@ -213,22 +214,21 @@ class PersonTest < ActiveSupport::TestCase |
| 213 | 214 | p1.add_friend(p3) |
| 214 | 215 | |
| 215 | 216 | assert_equal [p2,p3], p1.friends(true) # force reload |
| 216 | - | |
| 217 | 217 | end |
| 218 | 218 | |
| 219 | 219 | should 'suggest default friend groups list' do |
| 220 | - p = Person.new(:environment => Environment.default) | |
| 220 | + p = build(Person, :environment => Environment.default) | |
| 221 | 221 | assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups |
| 222 | 222 | end |
| 223 | 223 | |
| 224 | 224 | should 'suggest current groups as well' do |
| 225 | - p = Person.new(:environment => Environment.default) | |
| 225 | + p = build(Person, :environment => Environment.default) | |
| 226 | 226 | p.expects(:friend_groups).returns(['group1', 'group2']) |
| 227 | 227 | assert_equivalent [ 'friends', 'work', 'school', 'family', 'group1', 'group2' ], p.suggested_friend_groups |
| 228 | 228 | end |
| 229 | 229 | |
| 230 | 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 | 232 | p.expects(:friend_groups).returns([nil]) |
| 233 | 233 | assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups |
| 234 | 234 | end |
| ... | ... | @@ -309,29 +309,29 @@ class PersonTest < ActiveSupport::TestCase |
| 309 | 309 | end |
| 310 | 310 | |
| 311 | 311 | should 'provide desired info fields' do |
| 312 | - p = Person.new(:environment => Environment.default) | |
| 312 | + p = build(Person, :environment => Environment.default) | |
| 313 | 313 | assert p.respond_to?(:photo) |
| 314 | 314 | assert p.respond_to?(:address) |
| 315 | 315 | assert p.respond_to?(:contact_information) |
| 316 | 316 | end |
| 317 | 317 | |
| 318 | 318 | should 'required name' do |
| 319 | - person = Person.new(:environment => Environment.default) | |
| 319 | + person = Person.new | |
| 320 | 320 | assert !person.valid? |
| 321 | - assert person.errors[:name.to_s].present? | |
| 321 | + assert person.errors[:name].present? | |
| 322 | 322 | end |
| 323 | 323 | |
| 324 | 324 | should 'already request friendship' do |
| 325 | 325 | p1 = create_user('testuser1').person |
| 326 | 326 | p2 = create_user('testuser2').person |
| 327 | - AddFriend.create!(:person => p1, :friend => p2) | |
| 327 | + create(AddFriend, :person => p1, :friend => p2) | |
| 328 | 328 | assert p1.already_request_friendship?(p2) |
| 329 | 329 | end |
| 330 | 330 | |
| 331 | 331 | should 'have e-mail addresses' do |
| 332 | 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 | 335 | person.expects(:environment).returns(env) |
| 336 | 336 | |
| 337 | 337 | assert_equal ['testuser@somedomain.com'], person.email_addresses |
| ... | ... | @@ -339,9 +339,9 @@ class PersonTest < ActiveSupport::TestCase |
| 339 | 339 | |
| 340 | 340 | should 'not show www in e-mail addresses when force_www=true' do |
| 341 | 341 | env = fast_create(Environment) |
| 342 | - env.domains << Domain.new(:name => 'somedomain.com') | |
| 342 | + env.domains << build(Domain, :name => 'somedomain.com') | |
| 343 | 343 | env.update_attribute(:force_www, true) |
| 344 | - person = Person.new(:environment => env, :identifier => 'testuser') | |
| 344 | + person = build(Person, :environment => env, :identifier => 'testuser') | |
| 345 | 345 | person.expects(:environment).returns(env) |
| 346 | 346 | |
| 347 | 347 | assert_equal ['testuser@somedomain.com'], person.email_addresses |
| ... | ... | @@ -366,7 +366,7 @@ class PersonTest < ActiveSupport::TestCase |
| 366 | 366 | end |
| 367 | 367 | |
| 368 | 368 | should 'have a default person template' do |
| 369 | - env = Environment.create!(:name => 'test env') | |
| 369 | + env = create(Environment, :name => 'test env') | |
| 370 | 370 | p = create_user('test_user', :environment => env).person |
| 371 | 371 | assert_kind_of Person, p.template |
| 372 | 372 | end |
| ... | ... | @@ -375,7 +375,7 @@ class PersonTest < ActiveSupport::TestCase |
| 375 | 375 | p = create_user('test_profile').person |
| 376 | 376 | |
| 377 | 377 | assert_no_difference Task, :count do |
| 378 | - Task.create(:requestor => p) | |
| 378 | + create(Task, :requestor => p) | |
| 379 | 379 | p.destroy |
| 380 | 380 | end |
| 381 | 381 | end |
| ... | ... | @@ -437,7 +437,7 @@ class PersonTest < ActiveSupport::TestCase |
| 437 | 437 | should 'return active_person_fields' do |
| 438 | 438 | e = Environment.default |
| 439 | 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 | 442 | assert_equal e.active_person_fields, person.active_fields |
| 443 | 443 | end |
| ... | ... | @@ -445,7 +445,7 @@ class PersonTest < ActiveSupport::TestCase |
| 445 | 445 | should 'return email as active_person_fields' do |
| 446 | 446 | e = Environment.default |
| 447 | 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 | 450 | assert_equal ['nickname', 'email'], person.active_fields |
| 451 | 451 | end |
| ... | ... | @@ -453,7 +453,7 @@ class PersonTest < ActiveSupport::TestCase |
| 453 | 453 | should 'return required_person_fields' do |
| 454 | 454 | e = Environment.default |
| 455 | 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 | 458 | assert_equal e.required_person_fields, person.required_fields |
| 459 | 459 | end |
| ... | ... | @@ -461,7 +461,7 @@ class PersonTest < ActiveSupport::TestCase |
| 461 | 461 | should 'require fields if person needs' do |
| 462 | 462 | e = Environment.default |
| 463 | 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 | 465 | assert ! person.valid? |
| 466 | 466 | assert person.errors[:cell_phone.to_s].present? |
| 467 | 467 | |
| ... | ... | @@ -474,7 +474,7 @@ class PersonTest < ActiveSupport::TestCase |
| 474 | 474 | e = Environment.default |
| 475 | 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 | 478 | assert !person.valid? |
| 479 | 479 | assert person.errors[:custom_area_of_study.to_s].present? |
| 480 | 480 | |
| ... | ... | @@ -487,7 +487,7 @@ class PersonTest < ActiveSupport::TestCase |
| 487 | 487 | e = Environment.default |
| 488 | 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 | 491 | person.valid? |
| 492 | 492 | assert ! person.errors[:custom_area_of_study.to_s].present? |
| 493 | 493 | end |
| ... | ... | @@ -496,7 +496,7 @@ class PersonTest < ActiveSupport::TestCase |
| 496 | 496 | e = Environment.default |
| 497 | 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 | 500 | assert !person.valid? |
| 501 | 501 | assert person.errors[:custom_formation.to_s].present? |
| 502 | 502 | |
| ... | ... | @@ -509,7 +509,7 @@ class PersonTest < ActiveSupport::TestCase |
| 509 | 509 | e = Environment.default |
| 510 | 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 | 513 | assert !person.valid? |
| 514 | 514 | assert ! person.errors[:custom_formation.to_s].present? |
| 515 | 515 | end |
| ... | ... | @@ -548,7 +548,7 @@ class PersonTest < ActiveSupport::TestCase |
| 548 | 548 | should 'not ask to join if already asked' do |
| 549 | 549 | p = create_user('test_user').person |
| 550 | 550 | c = fast_create(Community) |
| 551 | - AddMember.create!(:person => p, :organization => c) | |
| 551 | + create(AddMember, :person => p, :organization => c) | |
| 552 | 552 | |
| 553 | 553 | assert !p.ask_to_join?(c) |
| 554 | 554 | end |
| ... | ... | @@ -651,8 +651,8 @@ class PersonTest < ActiveSupport::TestCase |
| 651 | 651 | p1.add_friend(p2) |
| 652 | 652 | p2.add_friend(p1) |
| 653 | 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 | 656 | end |
| 657 | 657 | |
| 658 | 658 | should 'list people that have no friends in more popular list' do |
| ... | ... | @@ -1183,12 +1183,12 @@ class PersonTest < ActiveSupport::TestCase |
| 1183 | 1183 | p2 = create_user('user2').person |
| 1184 | 1184 | profile = fast_create(Profile) |
| 1185 | 1185 | |
| 1186 | - abuse_report1 = AbuseReport.new(:reason => 'some reason') | |
| 1186 | + abuse_report1 = build(AbuseReport, :reason => 'some reason') | |
| 1187 | 1187 | assert_difference AbuseComplaint, :count, 1 do |
| 1188 | 1188 | p1.register_report(abuse_report1, profile) |
| 1189 | 1189 | end |
| 1190 | 1190 | |
| 1191 | - abuse_report2 = AbuseReport.new(:reason => 'some reason') | |
| 1191 | + abuse_report2 = build(AbuseReport, :reason => 'some reason') | |
| 1192 | 1192 | assert_no_difference AbuseComplaint, :count do |
| 1193 | 1193 | p2.register_report(abuse_report2, profile) |
| 1194 | 1194 | end |
| ... | ... | @@ -1206,7 +1206,7 @@ class PersonTest < ActiveSupport::TestCase |
| 1206 | 1206 | profile = fast_create(Profile) |
| 1207 | 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 | 1210 | person.reload |
| 1211 | 1211 | assert person.already_reported?(profile) |
| 1212 | 1212 | end |
| ... | ... | @@ -1226,9 +1226,9 @@ class PersonTest < ActiveSupport::TestCase |
| 1226 | 1226 | person = fast_create(Person) |
| 1227 | 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 | 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 | 1233 | assert_equivalent [scrap,article.activity], person.activities.map { |a| a.klass.constantize.find(a.id) } |
| 1234 | 1234 | end |
| ... | ... | @@ -1237,14 +1237,14 @@ class PersonTest < ActiveSupport::TestCase |
| 1237 | 1237 | person = fast_create(Person) |
| 1238 | 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 | 1244 | another_person_activity = ActionTracker::Record.last |
| 1245 | 1245 | |
| 1246 | 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 | 1248 | person_activity = ActionTracker::Record.last |
| 1249 | 1249 | |
| 1250 | 1250 | assert_equivalent [person_scrap,person_activity], person.activities.map { |a| a.klass.constantize.find(a.id) } |
| ... | ... | @@ -1288,7 +1288,7 @@ class PersonTest < ActiveSupport::TestCase |
| 1288 | 1288 | |
| 1289 | 1289 | should 'define abuser?' do |
| 1290 | 1290 | abuser = create_user('abuser').person |
| 1291 | - AbuseComplaint.create!(:reported => abuser).finish | |
| 1291 | + create(AbuseComplaint, :reported => abuser).finish | |
| 1292 | 1292 | person = create_user('person').person |
| 1293 | 1293 | |
| 1294 | 1294 | assert abuser.abuser? |
| ... | ... | @@ -1297,21 +1297,21 @@ class PersonTest < ActiveSupport::TestCase |
| 1297 | 1297 | |
| 1298 | 1298 | should 'be able to retrieve abusers and non abusers' do |
| 1299 | 1299 | abuser1 = create_user('abuser1').person |
| 1300 | - AbuseComplaint.create!(:reported => abuser1).finish | |
| 1300 | + create(AbuseComplaint, :reported => abuser1).finish | |
| 1301 | 1301 | abuser2 = create_user('abuser2').person |
| 1302 | - AbuseComplaint.create!(:reported => abuser2).finish | |
| 1302 | + create(AbuseComplaint, :reported => abuser2).finish | |
| 1303 | 1303 | person = create_user('person').person |
| 1304 | 1304 | |
| 1305 | 1305 | abusers = Person.abusers |
| 1306 | 1306 | |
| 1307 | - assert_equal ActiveRecord::NamedScope::Scope, abusers.class | |
| 1307 | + assert_equal ActiveRecord::Relation, abusers.class | |
| 1308 | 1308 | assert_includes abusers, abuser1 |
| 1309 | 1309 | assert_includes abusers, abuser2 |
| 1310 | 1310 | assert_not_includes abusers, person |
| 1311 | 1311 | |
| 1312 | 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 | 1315 | assert_not_includes non_abusers, abuser1 |
| 1316 | 1316 | assert_not_includes non_abusers, abuser2 |
| 1317 | 1317 | assert_includes non_abusers, person |
| ... | ... | @@ -1319,9 +1319,9 @@ class PersonTest < ActiveSupport::TestCase |
| 1319 | 1319 | |
| 1320 | 1320 | should 'not return canceled complaints as abusers' do |
| 1321 | 1321 | abuser = create_user('abuser1').person |
| 1322 | - AbuseComplaint.create!(:reported => abuser).finish | |
| 1322 | + create(AbuseComplaint, :reported => abuser).finish | |
| 1323 | 1323 | not_abuser = create_user('abuser2').person |
| 1324 | - AbuseComplaint.create!(:reported => not_abuser).cancel | |
| 1324 | + create(AbuseComplaint, :reported => not_abuser).cancel | |
| 1325 | 1325 | |
| 1326 | 1326 | abusers = Person.abusers |
| 1327 | 1327 | assert_includes abusers, abuser | ... | ... |
vendor/plugins/action_tracker/lib/action_tracker.rb
| ... | ... | @@ -74,7 +74,7 @@ module ActionTracker |
| 74 | 74 | end |
| 75 | 75 | |
| 76 | 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 | 78 | send :include, InstanceMethods |
| 79 | 79 | end |
| 80 | 80 | end | ... | ... |