mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge remote branch 'miloops/fixes'
This commit is contained in:
commit
73682d016c
8 changed files with 18 additions and 48 deletions
|
@ -190,7 +190,7 @@ module ActiveRecord
|
|||
# :constructor => Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
|
||||
# :converter => Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
|
||||
#
|
||||
def composed_of(part_id, options = {}, &block)
|
||||
def composed_of(part_id, options = {})
|
||||
options.assert_valid_keys(:class_name, :mapping, :allow_nil, :constructor, :converter)
|
||||
|
||||
name = part_id.id2name
|
||||
|
@ -199,9 +199,7 @@ module ActiveRecord
|
|||
mapping = [ mapping ] unless mapping.first.is_a?(Array)
|
||||
allow_nil = options[:allow_nil] || false
|
||||
constructor = options[:constructor] || :new
|
||||
converter = options[:converter] || block
|
||||
|
||||
ActiveSupport::Deprecation.warn('The conversion block has been deprecated, use the :converter option instead.', caller) if block_given?
|
||||
converter = options[:converter]
|
||||
|
||||
reader_method(name, class_name, mapping, allow_nil, constructor)
|
||||
writer_method(name, class_name, mapping, allow_nil, converter)
|
||||
|
|
|
@ -26,10 +26,10 @@ module ActiveRecord
|
|||
|
||||
delegate :group, :order, :limit, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :to => :scoped
|
||||
|
||||
def select(select = nil, &block)
|
||||
def select(select = nil)
|
||||
if block_given?
|
||||
load_target
|
||||
@target.select(&block)
|
||||
@target.select.each { |e| yield e }
|
||||
else
|
||||
scoped.select(select)
|
||||
end
|
||||
|
@ -123,7 +123,7 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
# Add +records+ to this association. Returns +self+ so method calls may be chained.
|
||||
# Add +records+ to this association. Returns +self+ so method calls may be chained.
|
||||
# Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
|
||||
def <<(*records)
|
||||
result = true
|
||||
|
@ -168,7 +168,7 @@ module ActiveRecord
|
|||
reset_target!
|
||||
reset_named_scopes_cache!
|
||||
end
|
||||
|
||||
|
||||
# Calculate sum using SQL, not Enumerable
|
||||
def sum(*args)
|
||||
if block_given?
|
||||
|
@ -241,7 +241,7 @@ module ActiveRecord
|
|||
|
||||
if @reflection.options[:dependent] && @reflection.options[:dependent] == :destroy
|
||||
destroy_all
|
||||
else
|
||||
else
|
||||
delete_all
|
||||
end
|
||||
|
||||
|
@ -520,8 +520,8 @@ module ActiveRecord
|
|||
def callbacks_for(callback_name)
|
||||
full_callback_name = "#{callback_name}_for_#{@reflection.name}"
|
||||
@owner.class.read_inheritable_attribute(full_callback_name.to_sym) || []
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def ensure_owner_is_not_new
|
||||
if @owner.new_record?
|
||||
raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved"
|
||||
|
|
|
@ -107,7 +107,7 @@ module ActiveRecord
|
|||
# REFERENTIAL INTEGRITY ====================================
|
||||
|
||||
# Override to turn off referential integrity while executing <tt>&block</tt>.
|
||||
def disable_referential_integrity(&block)
|
||||
def disable_referential_integrity
|
||||
yield
|
||||
end
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ module ActiveRecord
|
|||
|
||||
# REFERENTIAL INTEGRITY ====================================
|
||||
|
||||
def disable_referential_integrity(&block) #:nodoc:
|
||||
def disable_referential_integrity #:nodoc:
|
||||
old = select_value("SELECT @@FOREIGN_KEY_CHECKS")
|
||||
|
||||
begin
|
||||
|
|
|
@ -375,7 +375,7 @@ module ActiveRecord
|
|||
return false
|
||||
end
|
||||
|
||||
def disable_referential_integrity(&block) #:nodoc:
|
||||
def disable_referential_integrity #:nodoc:
|
||||
if supports_disable_referential_integrity?() then
|
||||
execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
|
||||
end
|
||||
|
|
|
@ -87,8 +87,8 @@ module ActiveRecord
|
|||
# person.visits += 1
|
||||
# person.save!
|
||||
# end
|
||||
def find(*args, &block)
|
||||
return to_a.find(&block) if block_given?
|
||||
def find(*args)
|
||||
return to_a.find { |*block_args| yield(*block_args) } if block_given?
|
||||
|
||||
options = args.extract_options!
|
||||
|
||||
|
@ -259,8 +259,8 @@ module ActiveRecord
|
|||
record
|
||||
end
|
||||
|
||||
def find_with_ids(*ids, &block)
|
||||
return to_a.find(&block) if block_given?
|
||||
def find_with_ids(*ids)
|
||||
return to_a.find { |*block_args| yield(*block_args) } if block_given?
|
||||
|
||||
expects_array = ids.first.kind_of?(Array)
|
||||
return ids.first if expects_array && ids.first.empty?
|
||||
|
|
|
@ -22,9 +22,9 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
|
||||
def select(*args, &block)
|
||||
def select(*args)
|
||||
if block_given?
|
||||
to_a.select(&block)
|
||||
to_a.select { |*block_args| yield(*block_args) }
|
||||
else
|
||||
new_relation = clone
|
||||
value = Array.wrap(args.flatten).reject {|x| x.blank? }
|
||||
|
|
|
@ -121,34 +121,6 @@ class AggregationsTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class DeprecatedAggregationsTest < ActiveRecord::TestCase
|
||||
class Person < ActiveRecord::Base; end
|
||||
|
||||
def test_conversion_block_is_deprecated
|
||||
assert_deprecated 'conversion block has been deprecated' do
|
||||
Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
|
||||
end
|
||||
end
|
||||
|
||||
def test_conversion_block_used_when_converter_option_is_nil
|
||||
assert_deprecated 'conversion block has been deprecated' do
|
||||
Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
|
||||
end
|
||||
assert_raise(NoMethodError) { Person.new.balance = 5 }
|
||||
end
|
||||
|
||||
def test_converter_option_overrides_conversion_block
|
||||
assert_deprecated 'conversion block has been deprecated' do
|
||||
Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount), :converter => Proc.new { |balance| Money.new(balance) }) { |balance| balance.to_money }
|
||||
end
|
||||
|
||||
person = Person.new
|
||||
assert_nothing_raised { person.balance = 5 }
|
||||
assert_equal 5, person.balance.amount
|
||||
assert_kind_of Money, person.balance
|
||||
end
|
||||
end
|
||||
|
||||
class OverridingAggregationsTest < ActiveRecord::TestCase
|
||||
class Name; end
|
||||
class DifferentName; end
|
||||
|
|
Loading…
Reference in a new issue