Ticket #9235: vuo_scoping_with_magic_scope.diff
| File vuo_scoping_with_magic_scope.diff, 3.1 kB (added by nik.wakelin, 1 year ago) |
|---|
-
activerecord/test/fixtures/customer.rb
old new 2 2 composed_of :address, :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ], :allow_nil => true 3 3 composed_of :balance, :class_name => "Money", :mapping => %w(balance amount) 4 4 composed_of :gps_location, :allow_nil => true 5 6 has_many :orders, :foreign_key => "shipping_customer_id" 5 7 end 6 8 7 9 class Address -
activerecord/test/fixtures/order.rb
old new 1 1 class Order < ActiveRecord::Base 2 2 belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id' 3 3 belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id' 4 5 validates_uniqueness_of :name 6 7 def self.create_with_magic_scoping(args) 8 Order.create!(args) 9 end 10 4 11 end -
activerecord/test/validations_test.rb
old new 3 3 require 'fixtures/reply' 4 4 require 'fixtures/person' 5 5 require 'fixtures/developer' 6 require 'fixtures/customer' 7 require 'fixtures/order' 6 8 7 9 # The following methods in Topic are used in test_conditional_validation_* 8 10 class Topic … … 368 370 assert t2.valid?, "should validate with nil" 369 371 assert t2.save, "should save with nil" 370 372 end 373 374 def test_validates_uniqueness_breaks_out_of_implicit_scoping 375 376 c1 = Customer.find(1) 377 c2 = Customer.find(2) 378 379 o1 = c1.orders.create_with_magic_scoping(:name => "Should be unique") 380 381 #now create & validate with implicit scoping 382 assert_raises ActiveRecord::RecordInvalid do 383 c2.orders.create_with_magic_scoping(:name => "Should be unique") 384 end 385 end 371 386 372 387 def test_validate_format 373 388 Topic.validates_format_of(:title, :content, :with => /^Validation\smacros \w+!$/, :message => "is bad data") -
activerecord/lib/active_record/validations.rb
old new 640 640 condition_sql << " AND #{record.class.table_name}.#{record.class.primary_key} <> ?" 641 641 condition_params << record.send(:id) 642 642 end 643 if record.class.find(:first, :conditions => [condition_sql, *condition_params]) 644 record.errors.add(attr_name, configuration[:message]) 643 record.class.send(:with_exclusive_scope) do 644 if record.class.find(:first, :conditions => [condition_sql, *condition_params]) 645 record.errors.add(attr_name, configuration[:message]) 646 end 645 647 end 646 648 end 647 649 end