Skip to content

Commit 942fe65

Browse files
author
David Heinemeier Hansson
committed
Merge branch 'master' of github.com:rails/rails
2 parents 0251291 + ffe001f commit 942fe65

File tree

25 files changed

+133
-58
lines changed

25 files changed

+133
-58
lines changed

actionpack/CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
22

3+
* Remove middleware laziness [José Valim]
4+
35
* Make session stores rely on request.cookie_jar and change set_session semantics to return the cookie value instead of a boolean. [José Valim]
46

57
* OAuth 2: HTTP Token Authorization support to complement Basic and Digest Authorization. [Rick Olson]

actionpack/lib/abstract_controller/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'active_support/configurable'
2+
require 'active_support/core_ext/module/anonymous'
23

34
module AbstractController
45
class Error < StandardError; end

actionpack/lib/abstract_controller/rendering.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "abstract_controller/base"
2+
require "action_view"
23

34
module AbstractController
45
class DoubleRenderError < Error

actionpack/lib/action_controller/metal/rack_delegation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module RackDelegation
88
delegate :headers, :status=, :location=, :content_type=,
99
:status, :location, :content_type, :to => "@_response"
1010

11-
def dispatch(action, request)
12-
@_response = ActionDispatch::Response.new
13-
@_response.request = request
14-
super
11+
def dispatch(action, request, response = ActionDispatch::Response.new)
12+
@_response ||= response
13+
@_response.request ||= request
14+
super(action, request)
1515
end
1616

1717
def params

actionpack/lib/action_controller/metal/request_forgery_protection.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module RequestForgeryProtection
4747
extend ActiveSupport::Concern
4848

4949
include AbstractController::Helpers
50+
include AbstractController::Callbacks
5051

5152
included do
5253
# Sets the token parameter name for RequestForgery. Calling +protect_from_forgery+

actionpack/lib/action_view/helpers/text_helper.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ def safe_concat(string)
4343
# ==== Examples
4444
#
4545
# truncate("Once upon a time in a world far far away")
46-
# # => Once upon a time in a worl...
46+
# # => "Once upon a time in a world..."
4747
#
48-
# truncate("Once upon a time in a world far far away", :separator => ' ')
49-
# # => Once upon a time in a world...
48+
# truncate("Once upon a time in a world far far away", :length => 17)
49+
# # => "Once upon a ti..."
5050
#
51-
# truncate("Once upon a time in a world far far away", :length => 14)
52-
# # => Once upon a...
51+
# truncate("Once upon a time in a world far far away", :lenght => 17, :separator => ' ')
52+
# # => "Once upon a..."
5353
#
54-
# truncate("And they found that many people were sleeping better.", :omission => "... (continued)", :length => 25)
55-
# # => And they f... (continued)
54+
# truncate("And they found that many people were sleeping better.", :length => 25, :omission => '... (continued)')
55+
# # => "And they f... (continued)"
5656
#
5757
# You can still use <tt>truncate</tt> with the old API that accepts the
5858
# +length+ as its optional second and the +ellipsis+ as its
5959
# optional third parameter:
6060
# truncate("Once upon a time in a world far far away", 14)
61-
# # => Once upon a...
61+
# # => "Once upon a..."
6262
#
6363
# truncate("And they found that many people were sleeping better.", 25, "... (continued)")
64-
# # => And they f... (continued)
64+
# # => "And they f... (continued)"
6565
def truncate(text, *args)
6666
options = args.extract_options!
6767
unless args.empty?

actionpack/lib/action_view/paths.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def exists?(*args)
3131

3232
def typecast!
3333
each_with_index do |path, i|
34+
path = path.to_s if path.is_a?(Pathname)
3435
next unless path.is_a?(String)
3536
self[i] = FileSystemResolver.new(path)
3637
end

activerecord/lib/active_record/railties/databases.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ namespace :db do
435435
task :create => :environment do
436436
raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
437437
require 'rails/generators'
438+
Rails::Generators.configure!
438439
require 'rails/generators/rails/session_migration/session_migration_generator'
439440
Rails::Generators::SessionMigrationGenerator.start [ ENV["MIGRATION"] || "add_sessions_table" ]
440441
end

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module QueryMethods
99
(ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).each do |query_method|
1010
attr_accessor :"#{query_method}_values"
1111

12-
next if [:where, :having].include?(query_method)
12+
next if [:where, :having, :select].include?(query_method)
1313
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
1414
def #{query_method}(*args, &block)
1515
new_relation = clone
@@ -21,6 +21,19 @@ def #{query_method}(*args, &block)
2121
CEVAL
2222
end
2323

24+
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
25+
def select(*args, &block)
26+
if block_given?
27+
to_a.select(&block)
28+
else
29+
new_relation = clone
30+
value = Array.wrap(args.flatten).reject {|x| x.blank? }
31+
new_relation.select_values += value if value.present?
32+
new_relation
33+
end
34+
end
35+
CEVAL
36+
2437
[:where, :having].each do |query_method|
2538
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
2639
def #{query_method}(*args, &block)

activerecord/test/cases/relations_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def test_finding_with_group
112112
assert_equal 4, developers.map(&:salary).uniq.size
113113
end
114114

115+
def test_select_with_block
116+
even_ids = Developer.scoped.select {|d| d.id % 2 == 0 }.map(&:id)
117+
assert_equal [2, 4, 6, 8, 10], even_ids
118+
end
119+
115120
def test_finding_with_hash_conditions_on_joined_table
116121
firms = DependentFirm.joins(:account).where({:name => 'RailsCore', :accounts => { :credit_limit => 55..60 }}).to_a
117122
assert_equal 1, firms.size

activesupport/lib/active_support/core_ext/string/filters.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,21 @@ def squish!
2020
self
2121
end
2222

23-
# Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>.
24-
# The last characters will be replaced with the <tt>:omission</tt> (defaults to "...")
25-
# for a total length not exceeding <tt>:length</tt>.
23+
# Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>:
2624
#
27-
# Pass a <tt>:separator</tt> to truncate +text+ at a natural break.
25+
# "Once upon a time in a world far far away".truncate(27)
26+
# # => "Once upon a time in a wo..."
2827
#
29-
# ==== Examples
28+
# The last characters will be replaced with the <tt>:omission</tt> string (defaults to "...")
29+
# for a total length not exceeding <tt>:length</tt>:
3030
#
31-
# "Once upon a time in a world far far away".truncate(30)
32-
# # => Once upon a time in a worl...
31+
# "Once upon a time in a world far far away".truncate(27, :separator => ' ')
32+
# # => "Once upon a time in a..."
3333
#
34-
# "Once upon a time in a world far far away".truncate(30, :separator => ' ')
35-
# # => Once upon a time in a world...
36-
#
37-
# "Once upon a time in a world far far away".truncate(14)
38-
# # => Once upon a...
34+
# Pass a <tt>:separator</tt> to truncate +text+ at a natural break:
3935
#
4036
# "And they found that many people were sleeping better.".truncate(25, :omission => "... (continued)")
41-
# # => And they f... (continued)
37+
# # => "And they f... (continued)"
4238
def truncate(length, options = {})
4339
text = self.dup
4440
options[:omission] ||= "..."

railties/CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
22

33
* Version bump
4-
4+
* Removed Rails Metal [YK & JV].
55

66
*Rails 3.0.0 [beta 3] (April 13th, 2010)*
77

railties/guides/source/action_view_overview.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ Creates a scope around a specific model object like form_for, but doesn‘t crea
699699
First name: <%= person_form.text_field :first_name %>
700700
Last name : <%= person_form.text_field :last_name %>
701701

702-
<% fields_for @person.permission do |permission_fields| %>
702+
<%= fields_for @person.permission do |permission_fields| %>
703703
Admin? : <%= permission_fields.check_box :admin %>
704704
<% end %>
705705
<% end %>

railties/guides/source/active_support_core_extensions.textile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,39 @@ There's also the destructive version +String#squish!+.
12541254

12551255
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
12561256

1257+
h4. +truncate+
1258+
1259+
The method +truncate+ returns a copy of its receiver truncated after a given +length+:
1260+
1261+
<ruby>
1262+
"Oh dear! Oh dear! I shall be late!".truncate(20)
1263+
# => "Oh dear! Oh dear!..."
1264+
</ruby>
1265+
1266+
Ellipsis can be customized with the +:omission+ option:
1267+
1268+
<ruby>
1269+
"Oh dear! Oh dear! I shall be late!".truncate(20, :omission => '&hellip;')
1270+
# => "Oh dear! Oh &hellip;"
1271+
</ruby>
1272+
1273+
Note in particular that truncation takes into account the length of the omission string.
1274+
1275+
Pass a +:separator+ to truncate the string at a natural break:
1276+
1277+
<ruby>
1278+
"Oh dear! Oh dear! I shall be late!".truncate(18)
1279+
# => "Oh dear! Oh dea..."
1280+
"Oh dear! Oh dear! I shall be late!".truncate(18, :separator => ' ')
1281+
# => "Oh dear! Oh..."
1282+
</ruby>
1283+
1284+
In the above example "dear" gets cut first, but then +:separator+ prevents it.
1285+
1286+
WARNING: The option +:separator+ can't be a regexp.
1287+
1288+
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
1289+
12571290
h4. Key-based Interpolation
12581291

12591292
In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, both formatted and unformatted:

railties/guides/source/activerecord_validations_callbacks.textile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -879,32 +879,28 @@ Here is a list with all the available Active Record callbacks, listed in the sam
879879
h4. Creating an Object
880880

881881
* +before_validation+
882-
* +before_validation_on_create+
883882
* +after_validation+
884-
* +after_validation_on_create+
885883
* +before_save+
884+
* +after_save+
886885
* +before_create+
887-
* INSERT OPERATION
886+
* +around_create+
888887
* +after_create+
889-
* +after_save+
890888

891889
h4. Updating an Object
892890

893891
* +before_validation+
894-
* +before_validation_on_update+
895892
* +after_validation+
896-
* +after_validation_on_update+
897893
* +before_save+
894+
* +after_save+
898895
* +before_update+
899-
* UPDATE OPERATION
896+
* +around_update+
900897
* +after_update+
901-
* +after_save+
902898

903899
h4. Destroying an Object
904900

905901
* +before_destroy+
906-
* DELETE OPERATION
907902
* +after_destroy+
903+
* +around_destroy+
908904

909905
WARNING. +after_save+ runs both on create and update, but always _after_ the more specific callbacks +after_create+ and +after_update+, no matter the order in which the macro calls were executed.
910906

railties/guides/source/generators.textile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,10 @@ config.generators do |g|
322322
g.template_engine :erb
323323
g.test_framework :shoulda, :fixture => false
324324
g.stylesheets false
325-
end
326-
</ruby>
327-
328-
And at the end of the same file:
329325

330-
<ruby>
331-
require 'rails/generators'
332-
Rails::Generators.fallbacks[:shoulda] = :test_unit
326+
# Add a fallback!
327+
g.fallbacks[:should] = :test_unit
328+
end
333329
</ruby>
334330

335331
Now, if create a Comment scaffold, you will see that shoulda generators are being invoked, and at the end, they are just falling back to test unit generators:
@@ -361,7 +357,7 @@ $ rails generate scaffold Comment body:text
361357
create test/unit/helpers/comments_helper_test.rb
362358
</shell>
363359

364-
Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of code duplication.
360+
Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of duplication.
365361

366362
h3. Changelog
367363

railties/guides/source/getting_started.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ We also add a <tt>@post.tags.build</tt> at the top of this form, this is to make
13421342
Now create the folder <tt>app/views/tags</tt> and make a file in there called <tt>_form.html.erb</tt> which contains the form for the tag:
13431343

13441344
<erb>
1345-
<% form.fields_for :tags do |tag_form| %>
1345+
<%= form.fields_for :tags do |tag_form| %>
13461346
<div class="field">
13471347
<%= tag_form.label :name, 'Tag:' %>
13481348
<%= tag_form.text_field :name %>

railties/guides/source/nested_model_forms.textile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Now add a nested form for the +address+ association:
143143
<%= form_for @person do |f| %>
144144
<%= f.text_field :name %>
145145

146-
<% f.fields_for :address do |af| %>
146+
<%= f.fields_for :address do |af| %>
147147
<%= f.text_field :street %>
148148
<% end %>
149149
<% end %>
@@ -184,7 +184,7 @@ The form code for an association collection is pretty similar to that of a singl
184184
<%= form_for @person do |f| %>
185185
<%= f.text_field :name %>
186186

187-
<% f.fields_for :projects do |pf| %>
187+
<%= f.fields_for :projects do |pf| %>
188188
<%= f.text_field :name %>
189189
<% end %>
190190
<% end %>

railties/lib/rails/application.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def inherited(base)
6767
raise "You cannot have more than one Rails::Application" if Rails.application
6868
super
6969
Rails.application = base.instance
70+
Rails.application.add_lib_to_load_paths!
7071
ActiveSupport.run_load_hooks(:before_configuration, base.instance)
7172
end
7273

@@ -83,11 +84,21 @@ def method_missing(*args, &block)
8384

8485
delegate :middleware, :to => :config
8586

87+
def add_lib_to_load_paths!
88+
path = config.root.join('lib').to_s
89+
$LOAD_PATH.unshift(path) if File.exists?(path)
90+
end
91+
8692
def require_environment!
8793
environment = paths.config.environment.to_a.first
8894
require environment if environment
8995
end
9096

97+
def eager_load!
98+
railties.all(&:eager_load!)
99+
super
100+
end
101+
91102
def routes
92103
@routes ||= ActionDispatch::Routing::RouteSet.new
93104
end

railties/lib/rails/application/finisher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module Finisher
3838
initializer :eager_load! do
3939
if config.cache_classes && !$rails_rake_task
4040
ActiveSupport.run_load_hooks(:before_eager_load, self)
41-
railties.all(&:eager_load!)
41+
eager_load!
4242
end
4343
end
4444

railties/lib/rails/commands/destroy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rails/generators'
2+
Rails::Generators.configure!
23

34
if [nil, "-h", "--help"].include?(ARGV.first)
45
Rails::Generators.help 'destroy'

railties/lib/rails/commands/generate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rails/generators'
2+
Rails::Generators.configure!
23

34
if [nil, "-h", "--help"].include?(ARGV.first)
45
Rails::Generators.help 'generate'

railties/lib/rails/generators.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def self.configure!(config = Rails.application.config.generators) #:nodoc:
6868
options.deep_merge! config.options
6969
fallbacks.merge! config.fallbacks
7070
templates_path.concat config.templates
71+
templates_path.uniq!
7172
end
7273

7374
def self.templates_path
@@ -328,10 +329,5 @@ def self.namespaces_to_paths(namespaces) #:nodoc:
328329
paths.uniq!
329330
paths
330331
end
331-
332332
end
333-
end
334-
335-
# If the application was already defined, configure generators,
336-
# otherwise you have to configure it by hand.
337-
Rails::Generators.configure! if Rails.respond_to?(:application) && Rails.application
333+
end

0 commit comments

Comments
 (0)