Skip to content

Commit

Permalink
Merge commit 'rails/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
miloops committed Oct 13, 2009
2 parents 0cf4662 + 9cd50e7 commit 991d1bc
Show file tree
Hide file tree
Showing 62 changed files with 2,595 additions and 4,019 deletions.
2 changes: 1 addition & 1 deletion actionmailer/test/fixtures/helpers/example_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ExampleHelper
def example_format(text)
"<em><strong><small>#{text}</small></strong></em>"
"<em><strong><small>#{h(text)}</small></strong></em>".html_safe!
end
end
2 changes: 2 additions & 0 deletions actionpack/Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
rails_root = Pathname.new(File.dirname(__FILE__)).join("..")

Gem.sources.each { |uri| source uri }

gem "rack", "~> 1.0.0"
gem "rack-test", "~> 0.5.0"
gem "activesupport", "3.0.pre", :vendored_at => rails_root.join("activesupport")
Expand Down
10 changes: 4 additions & 6 deletions actionpack/lib/abstract_controller/callbacks.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
require "active_support/new_callbacks"

module AbstractController
module Callbacks
extend ActiveSupport::Concern

# Uses ActiveSupport::NewCallbacks as the base functionality. For
# Uses ActiveSupport::Callbacks as the base functionality. For
# more details on the whole callback system, read the documentation
# for ActiveSupport::NewCallbacks.
include ActiveSupport::NewCallbacks
# for ActiveSupport::Callbacks.
include ActiveSupport::Callbacks

included do
define_callbacks :process_action, :terminator => "response_body"
Expand All @@ -16,7 +14,7 @@ module Callbacks
# Override AbstractController::Base's process_action to run the
# process_action callbacks around the normal behavior.
def process_action(method_name)
_run_process_action_callbacks(method_name) do
run_callbacks(:process_action, method_name) do
super
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def session_store=(store)
self.session_store = ActiveRecord::SessionStore
else
@@session_store = store.is_a?(Symbol) ?
Session.const_get(store.to_s.camelize) :
ActionDispatch::Session.const_get(store.to_s.camelize) :
store
end
end
Expand Down
7 changes: 6 additions & 1 deletion actionpack/lib/action_dispatch/http/mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ def symbols
%w(<< concat shift unshift push pop []= clear compact! collect!
delete delete_at delete_if flatten! map! insert reject! reverse!
replace slice! sort! uniq!).each do |method|
define_method(method) {|*args| @symbols = nil; super(*args) }
module_eval <<-CODE
def #{method}(*args)
@symbols = nil
super
end
CODE
end
end

Expand Down
8 changes: 4 additions & 4 deletions actionpack/lib/action_dispatch/middleware/callbacks.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ActionDispatch
class Callbacks
include ActiveSupport::NewCallbacks
include ActiveSupport::Callbacks

define_callbacks :call, :terminator => "result == false", :rescuable => true
define_callbacks :prepare, :scope => :name
Expand Down Expand Up @@ -37,12 +37,12 @@ class << self

def initialize(app, prepare_each_request = false)
@app, @prepare_each_request = app, prepare_each_request
_run_prepare_callbacks
run_callbacks(:prepare)
end

def call(env)
_run_call_callbacks do
_run_prepare_callbacks if @prepare_each_request
run_callbacks(:call) do
run_callbacks(:prepare) if @prepare_each_request
@app.call(env)
end
end
Expand Down
18 changes: 9 additions & 9 deletions actionpack/lib/action_view/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ def self.for_controller(controller)
# they are in AC.
if controller.class.respond_to?(:_helper_serial)
klass = @views[controller.class._helper_serial] ||= Class.new(self) do
name = controller.class.name.gsub(/::/, '__')

Subclasses.class_eval do
if method(:const_defined?).arity == 1
remove_const(name) if const_defined?(name) # Ruby 1.8.x
else
remove_const(name) if const_defined?(name, false) # Ruby 1.9.x
end
const_set(name, self)
const_set(:CONTROLLER_CLASS, controller.class)

# Try to make stack traces clearer
def self.name
"ActionView for #{CONTROLLER_CLASS}"
end

def inspect
"#<#{self.class.name}>"
end

if controller.respond_to?(:_helpers)
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_view/helpers/record_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module RecordTagHelper
def div_for(record, *args, &block)
content_tag_for(:div, record, *args, &block)
end

# content_tag_for creates an HTML element with id and class parameters
# that relate to the specified Active Record object. For example:
#
Expand All @@ -34,7 +34,7 @@ def div_for(record, *args, &block)
# <% content_tag_for(:tr, @person, :foo) do %> ...
#
# produces:
#
#
# <tr id="foo_person_123" class="person">...
#
# content_tag_for also accepts a hash of options, which will be converted to
Expand All @@ -50,7 +50,7 @@ def div_for(record, *args, &block)
def content_tag_for(tag_name, record, *args, &block)
prefix = args.first.is_a?(Hash) ? nil : args.shift
options = args.extract_options!
options.merge!({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
options.merge!({ :class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
content_tag(tag_name, options, &block)
end
end
Expand Down
7 changes: 5 additions & 2 deletions actionpack/lib/action_view/paths.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module ActionView #:nodoc:
class PathSet < Array #:nodoc:
def self.type_cast(obj)
def self.type_cast(obj, cache = nil)
# TODO: Clean this up
if obj.is_a?(String)
cache = !defined?(Rails) || !Rails.respond_to?(:configuration) || Rails.configuration.cache_classes
if cache.nil?
cache = !defined?(Rails) || Rails.application.config.cache_classes
end
FileSystemResolverWithFallback.new(obj, :cache => cache)
else
obj
Expand Down
5 changes: 4 additions & 1 deletion actionpack/lib/action_view/render/partials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ def find_template(path = @path)
end

def _find_template(path)
prefix = @view.controller.controller_path unless path.include?(?/)
if controller = @view.controller
prefix = controller.controller_path unless path.include?(?/)
end

@view.find(path, {:formats => @view.formats}, prefix, true)
end

Expand Down
22 changes: 13 additions & 9 deletions actionpack/lib/action_view/render/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def render(options = {}, locals = {}, &block) #:nodoc:
case options
when Hash
layout = options[:layout]
options[:locals] ||= {}

if block_given?
return concat(_render_partial(options.merge(:partial => layout), &block))
Expand All @@ -25,11 +26,11 @@ def render(options = {}, locals = {}, &block) #:nodoc:

if file = options[:file]
template = find(file, {:formats => formats})
_render_template(template, layout, :locals => options[:locals] || {})
_render_template(template, layout, :locals => options[:locals])
elsif inline = options[:inline]
_render_inline(inline, layout, options)
elsif text = options[:text]
_render_text(text, layout, options)
_render_text(text, layout, options[:locals])
end
when :update
update_page(&block)
Expand Down Expand Up @@ -80,16 +81,19 @@ def _layout_for(name = nil)

def _render_inline(inline, layout, options)
handler = Template.handler_class_for_extension(options[:type] || "erb")
template = Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
locals = options[:locals] || {}
template = Template.new(options[:inline],
"inline #{options[:inline].inspect}", handler, {})

locals = options[:locals]
content = template.render(self, locals)
content = layout.render(self, locals) {|*name| _layout_for(*name) { content } } if layout
content
_render_text(content, layout, locals)
end

def _render_text(text, layout, options)
text = layout.render(self, options[:locals]) { text } if layout
text
def _render_text(content, layout, locals)
content = layout.render(self, locals) do |*name|
_layout_for(*name) { content }
end if layout
content
end

# This is the API to render a ViewContext's template from a controller.
Expand Down
28 changes: 0 additions & 28 deletions actionpack/test/controller/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,6 @@ def test_basic_named_route
x.send(:home_url))
end

def test_basic_named_route_with_relative_url_root
rs.draw do |map|
map.home '', :controller => 'content', :action => 'list'
end
x = setup_for_named_route
ActionController::Base.relative_url_root = "/foo"
assert_equal("http://test.host/foo/",
x.send(:home_url))
assert_equal "/foo/", x.send(:home_path)
ActionController::Base.relative_url_root = nil
end

def test_named_route_with_option
rs.draw do |map|
map.page 'page/:title', :controller => 'content', :action => 'show_page'
Expand Down Expand Up @@ -307,19 +295,6 @@ def test_named_route_with_nested_controller
x.send(:users_url))
end

def test_optimised_named_route_call_never_uses_url_for
rs.draw do |map|
map.users 'admin/user', :controller => '/admin/user', :action => 'index'
map.user 'admin/user/:id', :controller=>'/admin/user', :action=>'show'
end
x = setup_for_named_route
x.expects(:url_for).never
x.send(:users_url)
x.send(:users_path)
x.send(:user_url, 2, :foo=>"bar")
x.send(:user_path, 3, :bar=>"foo")
end

def test_optimised_named_route_with_host
rs.draw do |map|
map.pages 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com'
Expand Down Expand Up @@ -984,9 +959,6 @@ def test_draw_default_route
end

assert_equal 1, set.routes.size
route = set.routes.first

assert route.segments.last.optional?

assert_equal '/users/show/10', set.generate(:controller => 'users', :action => 'show', :id => 10)
assert_equal '/users/index/10', set.generate(:controller => 'users', :id => 10)
Expand Down
2 changes: 2 additions & 0 deletions actionpack/test/lib/controller/fake_controllers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Admin
class << self; alias_method :const_available?, :const_defined?; end
class UserController < ActionController::Base; end
class NewsFeedController < ActionController::Base; end
class StuffController < ActionController::Base; end
end

module Api
Expand All @@ -26,6 +27,7 @@ class HiController < ActionController::Base; end
class ImageController < ActionController::Base; end
class PeopleController < ActionController::Base; end
class SessionsController < ActionController::Base; end
class StuffController < ActionController::Base; end
class SubpathBooksController < ActionController::Base; end
class WeblogController < ActionController::Base; end

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

def test_content_tag_for_prefix
expected = %(<ul class="post" id="archived_post_45"></ul>)
expected = %(<ul class="archived_post" id="archived_post_45"></ul>)
actual = content_tag_for(:ul, @post, :archived) { }
assert_dom_equal expected, actual
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup
end

test "Should not mess with a previously escape test" do
@buffer << CGI.escapeHTML("<script>")
@buffer << ERB::Util.html_escape("<script>")
assert_equal "&lt;script&gt;", @buffer
end

Expand Down
10 changes: 4 additions & 6 deletions activemodel/lib/active_model/validations.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/hash/keys'
require 'active_support/concern'
require 'active_support/callbacks'

module ActiveModel
module Validations
extend ActiveSupport::Concern
include ActiveSupport::NewCallbacks
include ActiveSupport::Callbacks

included do
define_callbacks :validate, :scope => :name
Expand Down Expand Up @@ -99,7 +97,7 @@ def valid?
def invalid?
!valid?
end

protected
# Hook method defining how an attribute value should be retieved. By default this is assumed
# to be an instance named after the attribute. Override this method in subclasses should you
Expand All @@ -110,9 +108,9 @@ def invalid?
# def initialize(data = {})
# @data = data
# end
#
#
# private
#
#
# def read_attribute_for_validation(key)
# @data[key]
# end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def remove_records(*records)

def callback(method, record)
callbacks_for(method).each do |callback|
ActiveSupport::Callbacks::Callback.new(method, callback, record).call(@owner, record)
ActiveSupport::DeprecatedCallbacks::Callback.new(method, callback, record).call(@owner, record)
end
end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module ActiveRecord
# * (6) <tt>after_save</tt>
#
# That's a total of eight callbacks, which gives you immense power to react and prepare for each state in the
# Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar, except that each
# Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar, except that each
# <tt>_on_create</tt> callback is replaced by the corresponding <tt>_on_update</tt> callback.
#
# Examples:
Expand Down Expand Up @@ -210,7 +210,7 @@ module ActiveRecord
# instead of quietly returning +false+.
module Callbacks
extend ActiveSupport::Concern
include ActiveSupport::NewCallbacks
include ActiveSupport::Callbacks

CALLBACKS = [
:after_initialize, :after_find, :before_validation, :after_validation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module ConnectionAdapters # :nodoc:
class AbstractAdapter
include Quoting, DatabaseStatements, SchemaStatements
include QueryCache
include ActiveSupport::Callbacks
include ActiveSupport::DeprecatedCallbacks
define_callbacks :checkout, :checkin

@@row_even = true
Expand Down Expand Up @@ -75,7 +75,7 @@ def supports_count_distinct?
def supports_ddl_transactions?
false
end

# Does this adapter support savepoints? PostgreSQL and MySQL do, SQLite
# does not.
def supports_savepoints?
Expand Down
Loading

0 comments on commit 991d1bc

Please sign in to comment.