Navigation Menu

Skip to content

Commit

Permalink
Merge commit 'mainstream/master'
Browse files Browse the repository at this point in the history
Conflicts:

	railties/configs/initializers/new_rails_defaults.rb
  • Loading branch information
lifo committed May 25, 2008
2 parents 11ea3e9 + 6277fd9 commit dc6da2e
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 22 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -454,7 +454,7 @@ def set_cycle(name, cycle_object)
( # leading text
<\w+.*?>| # leading HTML tag, or
[^=!:'"/]| # leading punctuation, or
| # nothing
^ # beginning of line
)
(
(?:https?://)| # protocol spec, or
Expand All @@ -468,7 +468,7 @@ def set_cycle(name, cycle_object)
(?:\?[\w\+@%&=.;-]+)? # query string
(?:\#[\w\-]*)? # trailing anchor
)
([[:punct:]]|\s|<|$) # trailing text
([[:punct:]]|<|$|) # trailing text
}x unless const_defined?(:AUTO_LINK_RE)

# Turns all urls into clickable links. If a block is given, each url
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/template/text_helper_test.rb
Expand Up @@ -264,6 +264,7 @@ def test_auto_linking
assert_equal '', auto_link(nil)
assert_equal '', auto_link('')
assert_equal "#{link_result} #{link_result} #{link_result}", auto_link("#{link_raw} #{link_raw} #{link_raw}")
assert_equal '<a href="http://www.rubyonrails.com">Ruby On Rails</a>', auto_link('<a href="http://www.rubyonrails.com">Ruby On Rails</a>')
end

def test_auto_link_at_eol
Expand Down
16 changes: 9 additions & 7 deletions activerecord/lib/active_record/associations.rb 100644 → 100755
Expand Up @@ -678,7 +678,7 @@ module ClassMethods
# * <tt>:limit</tt> - An integer determining the limit on the number of rows that should be returned.
# * <tt>:offset</tt> - An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
# * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if you, for example, want to do a join
# but not include the joined columns.
# but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will rise an error.
# * <tt>:as</tt> - Specifies a polymorphic interface (See <tt>belongs_to</tt>).
# * <tt>:through</tt> - Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt> and <tt>:foreign_key</tt>
# are ignored, as the association uses the source reflection. You can only use a <tt>:through</tt> query through a <tt>belongs_to</tt>
Expand Down Expand Up @@ -758,6 +758,8 @@ def has_many(association_id, options = {}, &extension)
# as the default <tt>:foreign_key</tt>.
# * <tt>:include</tt> - Specify second-order associations that should be eager loaded when this object is loaded.
# * <tt>:as</tt> - Specifies a polymorphic interface (See <tt>belongs_to</tt>).
# * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
# but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
# * <tt>:through</tt>: Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt> and <tt>:foreign_key</tt>
# are ignored, as the association uses the source reflection. You can only use a <tt>:through</tt> query through a
# <tt>has_one</tt> or <tt>belongs_to</tt> association on the join model.
Expand Down Expand Up @@ -832,8 +834,8 @@ def has_one(association_id, options = {})
# if the real class name is Person, you'll have to specify it with this option.
# * <tt>:conditions</tt> - Specify the conditions that the associated object must meet in order to be included as a +WHERE+
# SQL fragment, such as <tt>authorized = 1</tt>.
# * <tt>:order</tt> - Specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment,
# such as <tt>last_name, first_name DESC</tt>.
# * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
# but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
# * <tt>:foreign_key</tt> - Specify the foreign key used for the association. By default this is guessed to be the name
# of the association with an "_id" suffix. So a class that defines a <tt>belongs_to :person</tt> association will use
# "person_id" as the default <tt>:foreign_key</tt>. Similarly, <tt>belongs_to :favorite_person, :class_name => "Person"</tt>
Expand Down Expand Up @@ -1021,7 +1023,7 @@ def belongs_to(association_id, options = {})
# * <tt>:limit</tt> - An integer determining the limit on the number of rows that should be returned.
# * <tt>:offset</tt> - An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
# * <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join
# but not include the joined columns.
# but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
# * <tt>:readonly</tt> - If true, all the associated objects are readonly through the association.
#
# Option examples:
Expand Down Expand Up @@ -1351,22 +1353,22 @@ def create_has_many_reflection(association_id, options, &extension)

def create_has_one_reflection(association_id, options)
options.assert_valid_keys(
:class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly
:class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly
)

create_reflection(:has_one, association_id, options, self)
end

def create_has_one_through_reflection(association_id, options)
options.assert_valid_keys(
:class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :through, :source, :source_type
:class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :through, :source, :source_type
)
create_reflection(:has_one, association_id, options, self)
end

def create_belongs_to_reflection(association_id, options)
options.assert_valid_keys(
:class_name, :foreign_key, :foreign_type, :remote, :conditions, :order, :include, :dependent,
:class_name, :foreign_key, :foreign_type, :remote, :select, :conditions, :include, :dependent,
:counter_cache, :extend, :polymorphic, :readonly
)

Expand Down
Expand Up @@ -166,12 +166,18 @@ def create(attrs = {})
if attrs.is_a?(Array)
attrs.collect { |attr| create(attr) }
else
create_record(attrs) { |record| record.save }
create_record(attrs) do |record|
yield(record) if block_given?
record.save
end
end
end

def create!(attrs = {})
create_record(attrs) { |record| record.save! }
create_record(attrs) do |record|
yield(record) if block_given?
record.save!
end
end

# Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and
Expand Down
5 changes: 3 additions & 2 deletions activerecord/lib/active_record/associations/belongs_to_association.rb 100644 → 100755
Expand Up @@ -42,10 +42,11 @@ def updated?
private
def find_target
@reflection.klass.find(
@owner[@reflection.primary_key_name],
@owner[@reflection.primary_key_name],
:select => @reflection.options[:select],
:conditions => conditions,
:include => @reflection.options[:include],
:readonly => @reflection.options[:readonly]
:readonly => @reflection.options[:readonly]
)
end

Expand Down
5 changes: 3 additions & 2 deletions activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb 100644 → 100755
Expand Up @@ -29,12 +29,13 @@ def find_target

if @reflection.options[:conditions]
association_class.find(
@owner[@reflection.primary_key_name],
@owner[@reflection.primary_key_name],
:select => @reflection.options[:select],
:conditions => conditions,
:include => @reflection.options[:include]
)
else
association_class.find(@owner[@reflection.primary_key_name], :include => @reflection.options[:include])
association_class.find(@owner[@reflection.primary_key_name], :select => @reflection.options[:select], :include => @reflection.options[:include])
end
end

Expand Down
5 changes: 3 additions & 2 deletions activerecord/lib/active_record/associations/has_one_association.rb 100644 → 100755
Expand Up @@ -51,10 +51,11 @@ def replace(obj, dont_save = false)
private
def find_target
@reflection.klass.find(:first,
:conditions => @finder_sql,
:conditions => @finder_sql,
:select => @reflection.options[:select],
:order => @reflection.options[:order],
:include => @reflection.options[:include],
:readonly => @reflection.options[:readonly]
:readonly => @reflection.options[:readonly]
)
end

Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/associations/belongs_to_associations_test.rb 100644 → 100755
Expand Up @@ -92,6 +92,11 @@ def test_with_condition
assert_not_nil Company.find(3).firm_with_condition, "Microsoft should have a firm"
end

def test_with_select
assert_equal Company.find(2).firm_with_select.attributes.size, 1
assert_equal Company.find(2, :include => :firm_with_select ).firm_with_select.attributes.size, 1
end

def test_belongs_to_counter
debate = Topic.create("title" => "debate")
assert_equal 0, debate.send(:read_attribute, "replies_count"), "No replies yet"
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/associations/has_one_associations_test.rb 100644 → 100755
Expand Up @@ -24,6 +24,11 @@ def test_has_one_cache_nils
assert_queries(0) { firms.each(&:account) }
end

def test_with_select
assert_equal Firm.find(1).account_with_select.attributes.size, 2
assert_equal Firm.find(1, :include => :account_with_select).account_with_select.attributes.size, 2
end

def test_can_marshal_has_one_association_with_nil_target
firm = Firm.new
assert_nothing_raised do
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/associations_test.rb
Expand Up @@ -160,6 +160,18 @@ def test_save_on_parent_saves_children
assert_equal 1, developer.reload.audit_logs.size
end

def test_create_via_association_with_block
post = authors(:david).posts.create(:title => "New on Edge") {|p| p.body = "More cool stuff!"}
assert_equal post.title, "New on Edge"
assert_equal post.body, "More cool stuff!"
end

def test_create_with_bang_via_association_with_block
post = authors(:david).posts.create!(:title => "New on Edge") {|p| p.body = "More cool stuff!"}
assert_equal post.title, "New on Edge"
assert_equal post.body, "More cool stuff!"
end

def test_failed_reload_returns_nil
p = setup_dangling_association
assert_nil p.author.reload
Expand Down
5 changes: 3 additions & 2 deletions activerecord/test/cases/reflection_test.rb
Expand Up @@ -159,9 +159,10 @@ def test_association_reflection_in_modules
end

def test_reflection_of_all_associations
assert_equal 19, Firm.reflect_on_all_associations.size
# FIXME these assertions bust a lot
assert_equal 20, Firm.reflect_on_all_associations.size
assert_equal 16, Firm.reflect_on_all_associations(:has_many).size
assert_equal 3, Firm.reflect_on_all_associations(:has_one).size
assert_equal 4, Firm.reflect_on_all_associations(:has_one).size
assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
end

Expand Down
2 changes: 2 additions & 0 deletions activerecord/test/models/company.rb
Expand Up @@ -47,6 +47,7 @@ class Firm < Company
has_many :readonly_clients, :class_name => 'Client', :readonly => true

has_one :account, :foreign_key => "firm_id", :dependent => :destroy
has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
has_one :readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
end

Expand All @@ -64,6 +65,7 @@ class ExclusivelyDependentFirm < Company
class Client < Company
belongs_to :firm, :foreign_key => "client_of"
belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
belongs_to :firm_with_select, :class_name => "Firm", :foreign_key => "firm_id", :select => "id"
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
belongs_to :readonly_firm, :class_name => "Firm", :foreign_key => "firm_id", :readonly => true
Expand Down
3 changes: 0 additions & 3 deletions railties/configs/initializers/new_rails_defaults.rb
@@ -1,9 +1,6 @@
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.

# Only save the attributes that have changed since the record was loaded.
ActiveRecord::Base.partial_updates = true

# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true

Expand Down
3 changes: 3 additions & 0 deletions railties/environments/environment.rb
Expand Up @@ -64,4 +64,7 @@

# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector

# Make ActiveRecord only save the attributes that have changed since the record was loaded.
# config.active_record.partial_updates = true
end

0 comments on commit dc6da2e

Please sign in to comment.