Skip to content

Commit

Permalink
Merge branch 'master' into nested_has_many_through
Browse files Browse the repository at this point in the history
Conflicts:
	activerecord/CHANGELOG
  • Loading branch information
jonleighton committed Mar 5, 2011
2 parents b7f1b36 + 74818a3 commit 28ed10d
Show file tree
Hide file tree
Showing 63 changed files with 380 additions and 117 deletions.
7 changes: 4 additions & 3 deletions actionmailer/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Or you can just chain the methods together like:
== Receiving emails

To receive emails, you need to implement a public instance method called <tt>receive</tt> that takes a
tmail object as its single parameter. The Action Mailer framework has a corresponding class method,
email object as its single parameter. The Action Mailer framework has a corresponding class method,
which is also called <tt>receive</tt>, that accepts a raw, unprocessed email as a string, which it then turns
into the tmail object and calls the receive instance method.
into the email object and calls the receive instance method.

Example:

Expand All @@ -104,7 +104,7 @@ trivial case like this:
rails runner 'Mailman.receive(STDIN.read)'

However, invoking Rails in the runner for each mail to be received is very resource intensive. A single
instance of Rails should be run within a daemon if it is going to be utilized to process more than just
instance of Rails should be run within a daemon, if it is going to be utilized to process more than just
a limited number of email.

== Configuration
Expand Down Expand Up @@ -145,3 +145,4 @@ API documentation is at
Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:

* https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets

2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ module ActionMailer #:nodoc:
# * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the
# authentication type here.
# This is a symbol and one of <tt>:plain</tt> (will send the password in the clear), <tt>:login</tt> (will
# send password BASE64 encoded) or <tt>:cram_md5</tt> (combines a Challenge/Response mechanism to exchange
# send password Base64 encoded) or <tt>:cram_md5</tt> (combines a Challenge/Response mechanism to exchange
# information and a cryptographic Message Digest 5 algorithm to hash important information)
# * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server
# and starts to use it.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/caching/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module Caching
# header the Content-Type of the cached response could be wrong because
# no information about the MIME type is stored in the cache key. So, if
# you first ask for MIME type M in the Accept header, a cache entry is
# created, and then perform a second resquest to the same resource asking
# created, and then perform a second request to the same resource asking
# for a different MIME type, you'd get the content cached for M.
#
# The <tt>:format</tt> parameter is taken into account though. The safest
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def cleanup_view_runtime #:nodoc:
yield
end

# Everytime after an action is processed, this method is invoked
# Every time after an action is processed, this method is invoked
# with the payload, so you can add more information.
# :api: plugin
def append_info_to_payload(payload) #:nodoc:
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def namespace(path, options = {})
# Now routes such as +/posts/1+ will no longer be valid, but +/posts/1.1+ will be.
# The +id+ parameter must match the constraint passed in for this example.
#
# You may use this to also resrict other parameters:
# You may use this to also restrict other parameters:
#
# resources :posts do
# constraints(:post_id => /\d+\.\d+) do
Expand All @@ -720,7 +720,7 @@ def namespace(path, options = {})
#
# === Dynamic request matching
#
# Requests to routes can be constrained based on specific critera:
# Requests to routes can be constrained based on specific criteria:
#
# constraints(lambda { |req| req.env["HTTP_USER_AGENT"] =~ /iPhone/ }) do
# resources :iphones
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/date_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def select_datetime
@options[:discard_second] ||= true unless @options[:include_seconds] && !@options[:discard_minute]

# If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are
# valid (otherwise it could be 31 and february wouldn't be a valid date)
# valid (otherwise it could be 31 and February wouldn't be a valid date)
if @datetime && @options[:discard_day] && !@options[:discard_month]
@datetime = @datetime.change(:day => 1)
end
Expand All @@ -644,7 +644,7 @@ def select_date
@options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day)

# If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are
# valid (otherwise it could be 31 and february wouldn't be a valid date)
# valid (otherwise it could be 31 and February wouldn't be a valid date)
if @datetime && @options[:discard_day] && !@options[:discard_month]
@datetime = @datetime.change(:day => 1)
end
Expand Down
24 changes: 22 additions & 2 deletions actionpack/lib/action_view/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ module FormHelper
# ...
# </form>
#
# === Removing hidden model id's
#
# The form_for method automatically includes the model id as a hidden field in the form.
# This is used to maintain the correlation between the form data and it's associated model.
# Some ORM systems do not use id's on nested models so in this case you want to be able
# to disable the hidden id.
#
# In the following example the Post model has many Comments stored within it in a NoSQL database,
# thus there is no primary key for comments.
#
# Example:
#
# <%= form(@post) do |f| %>
# <% f.fields_for(:comments, :include_id => false) do |cf| %>
# ...
# <% end %>
# <% end %>
#
# === Customized form builders
#
# You can also build forms using a customized FormBuilder class. Subclass
Expand Down Expand Up @@ -332,7 +350,7 @@ def form_for(record, options = {}, &proc)

options[:html][:remote] = options.delete(:remote)
options[:html][:authenticity_token] = options.delete(:authenticity_token)

builder = options[:parent_builder] = instantiate_builder(object_name, object, options, &proc)
fields_for = fields_for(object_name, object, options, &proc)
default_options = builder.multipart? ? { :multipart => true } : {}
Expand Down Expand Up @@ -1326,7 +1344,9 @@ def fields_for_with_nested_attributes(association_name, args, block)
def fields_for_nested_model(name, object, options, block)
object = convert_to_model(object)

options[:hidden_field_id] = object.persisted?
parent_include_id = self.options.fetch(:include_id, true)
include_id = options.fetch(:include_id, parent_include_id)
options[:hidden_field_id] = object.persisted? && include_id
@template.fields_for(name, object, options, &block)
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/form_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def html_options_for_form(url_for_options, options, *parameters_for_url)
options.stringify_keys.tap do |html_options|
html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
# The following URL is unescaped, this is just a hash of options, and it is the
# responsability of the caller to escape all the values.
# responsibility of the caller to escape all the values.
html_options["action"] = url_for(url_for_options, *parameters_for_url)
html_options["accept-charset"] = "UTF-8"
html_options["data-remote"] = true if html_options.delete("remote")
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_view/helpers/number_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def number_to_human_size(number, options = {})
# See <tt>number_to_human_size</tt> if you want to print a file size.
#
# You can also define you own unit-quantifier names if you want to use other decimal units
# (eg.: 1500 becomes "1.5 kilometers", 0.150 becomes "150 mililiters", etc). You may define
# (eg.: 1500 becomes "1.5 kilometers", 0.150 becomes "150 milliliters", etc). You may define
# a wide range of unit quantifiers, even fractional ones (centi, deci, mili, etc).
#
# ==== Options
Expand Down Expand Up @@ -425,13 +425,13 @@ def number_to_human_size(number, options = {})
# thousand:
# one: "kilometer"
# other: "kilometers"
# billion: "gazilion-distance"
# billion: "gazillion-distance"
#
# Then you could do:
#
# number_to_human(543934, :units => :distance) # => "544 kilometers"
# number_to_human(54393498, :units => :distance) # => "54400 kilometers"
# number_to_human(54393498000, :units => :distance) # => "54.4 gazilion-distance"
# number_to_human(54393498000, :units => :distance) # => "54.4 gazillion-distance"
# number_to_human(343, :units => :distance, :precision => 1) # => "300 meters"
# number_to_human(1, :units => :distance) # => "1 meter"
# number_to_human(0.34, :units => :distance) # => "34 centimeters"
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/translation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module TranslationHelper
#
# E.g. the value returned for a missing translation key :"blog.post.title" will be
# <span class="translation_missing" title="translation missing: blog.post.title">Title</span>.
# This way your views will display rather reasonableful strings but it will still
# This way your views will display rather reasonable strings but it will still
# be easy to spot missing translations.
#
# Second, it'll scope the key by the current partial if the key starts
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
format:
# Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
separator: "."
# Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
# Delimits thousands (e.g. 1,000,000 is a million) (always in groups of three)
delimiter: ","
# Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
precision: 3
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template/handlers/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ERB
class_attribute :default_format
self.default_format = Mime::HTML

# Default implemenation used.
# Default implementation used.
class_attribute :erb_implementation
self.erb_implementation = Erubis

Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def test_route_with_text_default
assert_equal '/page/foo', url_for(rs, { :controller => 'content', :action => 'show_page', :id => 'foo' })
assert_equal({ :controller => "content", :action => 'show_page', :id => 'foo' }, rs.recognize_path("/page/foo"))

token = "\321\202\320\265\320\272\321\201\321\202" # 'text' in russian
token = "\321\202\320\265\320\272\321\201\321\202" # 'text' in Russian
token.force_encoding(Encoding::BINARY) if token.respond_to?(:force_encoding)
escaped_token = CGI::escape(token)

Expand Down
135 changes: 135 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,61 @@ def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to
assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association_with_disabled_hidden_id
@post.author = Author.new(321)

form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:author, :include_id => false) { |af|
af.text_field(:name)
}
end

expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />'
end

assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association_with_disabled_hidden_id_inherited
@post.author = Author.new(321)

form_for(@post, :include_id => false) do |f|
concat f.text_field(:title)
concat f.fields_for(:author) { |af|
af.text_field(:name)
}
end

expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />'
end

assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association_with_disabled_hidden_id_override
@post.author = Author.new(321)

form_for(@post, :include_id => false) do |f|
concat f.text_field(:title)
concat f.fields_for(:author, :include_id => true) { |af|
af.text_field(:name)
}
end

expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />'
end

assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement
@post.author = Author.new(321)

Expand Down Expand Up @@ -1146,6 +1201,86 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collecti
assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.author = Author.new(321)

form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:author) { |af|
concat af.text_field(:name)
}
@post.comments.each do |comment|
concat f.fields_for(:comments, comment, :include_id => false) { |cf|
concat cf.text_field(:name)
}
end
end

expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />'
end

assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id_inherited
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.author = Author.new(321)

form_for(@post, :include_id => false) do |f|
concat f.text_field(:title)
concat f.fields_for(:author) { |af|
concat af.text_field(:name)
}
@post.comments.each do |comment|
concat f.fields_for(:comments, comment) { |cf|
concat cf.text_field(:name)
}
end
end

expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />'
end

assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id_override
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.author = Author.new(321)

form_for(@post, :include_id => false) do |f|
concat f.text_field(:title)
concat f.fields_for(:author, :include_id => true) { |af|
concat af.text_field(:name)
}
@post.comments.each do |comment|
concat f.fields_for(:comments, comment) { |cf|
concat cf.text_field(:name)
}
end
end

expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />'
end

assert_dom_equal expected, output_buffer
end

def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_using_erb_and_inline_block
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }

Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/template/number_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_number_with_precision_with_strip_insignificant_zeros

def test_number_with_precision_with_significant_true_and_zero_precision
# Zero precision with significant is a mistake (would always return zero),
# so we treat it as if significant was false (increases backwards compatibily for number_to_human_size)
# so we treat it as if significant was false (increases backwards compatibility for number_to_human_size)
assert_equal "124", number_with_precision(123.987, :precision => 0, :significant => true)
assert_equal "12", number_with_precision(12, :precision => 0, :significant => true )
assert_equal "12", number_with_precision("12.3", :precision => 0, :significant => true )
Expand Down
2 changes: 1 addition & 1 deletion activemodel/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ the Rails framework.
Prior to Rails 3.0, if a plugin or gem developer wanted to have an object
interact with Action Pack helpers, it was required to either copy chunks of
code from Rails, or monkey patch entire helpers to make them handle objects
that did not exacly conform to the Active Record interface. This would result
that did not exactly conform to the Active Record interface. This would result
in code duplication and fragile applications that broke on upgrades.

Active Model solves this. You can include functionality from the following
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def teardown

NIL = [nil]
BLANK = ["", " ", " \t \r \n"]
BIGDECIMAL_STRINGS = %w(12345678901234567890.1234567890) # 30 significent digits
BIGDECIMAL_STRINGS = %w(12345678901234567890.1234567890) # 30 significant digits
FLOAT_STRINGS = %w(0.0 +0.0 -0.0 10.0 10.5 -10.5 -0.0001 -090.1 90.1e1 -90.1e5 -90.1e-5 90e-5)
INTEGER_STRINGS = %w(0 +0 -0 10 +10 -10 0090 -090)
FLOATS = [0.0, 10.0, 10.5, -10.5, -0.0001] + FLOAT_STRINGS
Expand Down
3 changes: 3 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

[Jon Leighton]

* The configuration for the current database connection is now accessible via
ActiveRecord::Base.connection_config. [fxn]

* limits and offsets are removed from COUNT queries unless both are supplied.
For example:

Expand Down
Loading

0 comments on commit 28ed10d

Please sign in to comment.