actionpack 3.0.0.beta3 → 3.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (83) hide show
  1. data/CHANGELOG +19 -0
  2. data/lib/abstract_controller.rb +1 -1
  3. data/lib/abstract_controller/asset_paths.rb +9 -0
  4. data/lib/abstract_controller/base.rb +5 -13
  5. data/lib/abstract_controller/callbacks.rb +1 -1
  6. data/lib/abstract_controller/helpers.rb +0 -1
  7. data/lib/abstract_controller/layouts.rb +3 -3
  8. data/lib/abstract_controller/logger.rb +1 -1
  9. data/lib/abstract_controller/rendering.rb +1 -0
  10. data/lib/action_controller/base.rb +5 -1
  11. data/lib/action_controller/caching.rb +2 -3
  12. data/lib/action_controller/caching/actions.rb +1 -1
  13. data/lib/action_controller/caching/fragments.rb +1 -1
  14. data/lib/action_controller/caching/pages.rb +8 -8
  15. data/lib/action_controller/caching/sweeping.rb +1 -0
  16. data/lib/action_controller/deprecated/base.rb +10 -36
  17. data/lib/action_controller/metal.rb +45 -3
  18. data/lib/action_controller/metal/compatibility.rb +2 -2
  19. data/lib/action_controller/metal/helpers.rb +3 -3
  20. data/lib/action_controller/metal/http_authentication.rb +158 -0
  21. data/lib/action_controller/metal/instrumentation.rb +5 -5
  22. data/lib/action_controller/metal/rack_delegation.rb +4 -4
  23. data/lib/action_controller/metal/renderers.rb +3 -3
  24. data/lib/action_controller/metal/request_forgery_protection.rb +45 -74
  25. data/lib/action_controller/metal/responder.rb +1 -1
  26. data/lib/action_controller/metal/url_for.rb +8 -0
  27. data/lib/action_controller/railtie.rb +26 -39
  28. data/lib/action_controller/test_case.rb +147 -135
  29. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -0
  30. data/lib/action_dispatch.rb +0 -1
  31. data/lib/action_dispatch/http/parameters.rb +2 -1
  32. data/lib/action_dispatch/http/request.rb +19 -7
  33. data/lib/action_dispatch/http/response.rb +3 -33
  34. data/lib/action_dispatch/middleware/cookies.rb +44 -10
  35. data/lib/action_dispatch/middleware/flash.rb +11 -1
  36. data/lib/action_dispatch/middleware/params_parser.rb +3 -1
  37. data/lib/action_dispatch/middleware/session/abstract_store.rb +47 -83
  38. data/lib/action_dispatch/middleware/session/cookie_store.rb +19 -165
  39. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +2 -2
  40. data/lib/action_dispatch/middleware/show_exceptions.rb +18 -12
  41. data/lib/action_dispatch/middleware/stack.rb +17 -67
  42. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +1 -1
  43. data/lib/action_dispatch/railtie.rb +0 -2
  44. data/lib/action_dispatch/routing/deprecated_mapper.rb +1 -0
  45. data/lib/action_dispatch/routing/mapper.rb +89 -23
  46. data/lib/action_dispatch/routing/route_set.rb +22 -16
  47. data/lib/action_dispatch/routing/url_for.rb +1 -1
  48. data/lib/action_dispatch/testing/assertions/routing.rb +1 -0
  49. data/lib/action_dispatch/testing/assertions/selector.rb +11 -7
  50. data/lib/action_dispatch/testing/test_process.rb +3 -2
  51. data/lib/action_pack/version.rb +1 -1
  52. data/lib/action_view.rb +5 -1
  53. data/lib/action_view/base.rb +10 -4
  54. data/lib/action_view/helpers/active_model_helper.rb +1 -8
  55. data/lib/action_view/helpers/asset_tag_helper.rb +7 -4
  56. data/lib/action_view/helpers/cache_helper.rb +14 -14
  57. data/lib/action_view/helpers/capture_helper.rb +25 -6
  58. data/lib/action_view/helpers/date_helper.rb +33 -44
  59. data/lib/action_view/helpers/form_helper.rb +47 -27
  60. data/lib/action_view/helpers/form_options_helper.rb +26 -3
  61. data/lib/action_view/helpers/form_tag_helper.rb +8 -4
  62. data/lib/action_view/helpers/number_helper.rb +5 -2
  63. data/lib/action_view/helpers/prototype_helper.rb +1 -1
  64. data/lib/action_view/helpers/tag_helper.rb +1 -1
  65. data/lib/action_view/helpers/text_helper.rb +55 -46
  66. data/lib/action_view/helpers/translation_helper.rb +19 -8
  67. data/lib/action_view/helpers/url_helper.rb +2 -4
  68. data/lib/action_view/locale/en.yml +14 -14
  69. data/lib/action_view/lookup_context.rb +52 -22
  70. data/lib/action_view/paths.rb +1 -0
  71. data/lib/action_view/render/layouts.rb +3 -12
  72. data/lib/action_view/render/partials.rb +21 -10
  73. data/lib/action_view/render/rendering.rb +1 -1
  74. data/lib/action_view/template.rb +172 -26
  75. data/lib/action_view/template/error.rb +25 -27
  76. data/lib/action_view/template/handlers.rb +1 -1
  77. data/lib/action_view/template/handlers/erb.rb +92 -45
  78. data/lib/action_view/template/resolver.rb +4 -1
  79. data/lib/action_view/test_case.rb +105 -72
  80. data/lib/action_view/testing/resolvers.rb +43 -0
  81. metadata +62 -20
  82. data/lib/abstract_controller/assigns.rb +0 -21
  83. data/lib/action_dispatch/middleware/cascade.rb +0 -29
data/CHANGELOG CHANGED
@@ -1,3 +1,22 @@
1
+ *Rails 3.0.0 [beta 4] (June 8th, 2010)*
2
+
3
+ * Remove middleware laziness [José Valim]
4
+
5
+ * Make session stores rely on request.cookie_jar and change set_session semantics to return the cookie value instead of a boolean. [José Valim]
6
+
7
+ * OAuth 2: HTTP Token Authorization support to complement Basic and Digest Authorization. [Rick Olson]
8
+
9
+ * Fixed inconsistencies in form builder and view helpers #4432 [Neeraj Singh]
10
+
11
+ * Both :xml and :json renderers now forwards the given options to the model, allowing you to invoke them as render :xml => @projects, :include => :tasks [José Valim, Yehuda Katz]
12
+
13
+ * Renamed the field error CSS class from fieldWithErrors to field_with_errors for consistency. [Jeremy Kemper]
14
+
15
+ * Add support for shorthand routes like /projects/status(.:format) #4423 [Diego Carrion]
16
+
17
+ * Changed translate helper so that it doesn’t mark every translation as safe HTML. Only keys with a "_html" suffix and keys named "html" are considered to be safe HTML. All other translations are left untouched. [Craig Davey]
18
+
19
+
1
20
  *Rails 3.0.0 [beta 3] (April 13th, 2010)*
2
21
 
3
22
  * New option :as added to form_for allows to change the object name. The old <% form_for :client, @post %> becomes <% form_for @post, :as => :client %> [spastorino]
@@ -12,7 +12,6 @@ require 'active_support/i18n'
12
12
  module AbstractController
13
13
  extend ActiveSupport::Autoload
14
14
 
15
- autoload :Assigns
16
15
  autoload :Base
17
16
  autoload :Callbacks
18
17
  autoload :Collector
@@ -21,5 +20,6 @@ module AbstractController
21
20
  autoload :Logger
22
21
  autoload :Rendering
23
22
  autoload :Translation
23
+ autoload :AssetPaths
24
24
  autoload :ViewPaths
25
25
  end
@@ -0,0 +1,9 @@
1
+ module AbstractController
2
+ module AssetPaths
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ config_accessor :assets_dir, :javascripts_dir, :stylesheets_dir
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,5 @@
1
- require 'active_support/ordered_options'
1
+ require 'active_support/configurable'
2
+ require 'active_support/core_ext/module/anonymous'
2
3
 
3
4
  module AbstractController
4
5
  class Error < StandardError; end
@@ -8,6 +9,8 @@ module AbstractController
8
9
  attr_internal :response_body
9
10
  attr_internal :action_name
10
11
 
12
+ include ActiveSupport::Configurable
13
+
11
14
  class << self
12
15
  attr_reader :abstract
13
16
  alias_method :abstract?, :abstract
@@ -29,14 +32,6 @@ module AbstractController
29
32
  @descendants ||= []
30
33
  end
31
34
 
32
- def config
33
- @config ||= ActiveSupport::InheritableOptions.new(superclass < Base ? superclass.config : {})
34
- end
35
-
36
- def configure
37
- yield config
38
- end
39
-
40
35
  # A list of all internal methods for a controller. This finds the first
41
36
  # abstract superclass of a controller, and gets a list of all public
42
37
  # instance methods on that abstract class. Public instance methods of
@@ -99,10 +94,6 @@ module AbstractController
99
94
 
100
95
  abstract!
101
96
 
102
- def config
103
- @config ||= ActiveSupport::InheritableOptions.new(self.class.config)
104
- end
105
-
106
97
  # Calls the action going through the entire action dispatch stack.
107
98
  #
108
99
  # The actual method that is called is determined by calling
@@ -133,6 +124,7 @@ module AbstractController
133
124
  end
134
125
 
135
126
  private
127
+
136
128
  # Returns true if the name can be considered an action. This can
137
129
  # be overridden in subclasses to modify the semantics of what
138
130
  # can be considered an action.
@@ -20,7 +20,7 @@ module AbstractController
20
20
  end
21
21
 
22
22
  module ClassMethods
23
- # If :only or :accept are used, convert the options into the
23
+ # If :only or :except are used, convert the options into the
24
24
  # primitive form (:per_key) used by ActiveSupport::Callbacks.
25
25
  # The basic idea is that :only => :index gets converted to
26
26
  # :if => proc {|c| c.action_name == "index" }, but that the
@@ -8,7 +8,6 @@ module AbstractController
8
8
 
9
9
  included do
10
10
  class_attribute :_helpers
11
- delegate :_helpers, :to => :'self.class'
12
11
  self._helpers = Module.new
13
12
  end
14
13
 
@@ -245,7 +245,7 @@ module AbstractController
245
245
 
246
246
  case defined?(@_layout) ? @_layout : nil
247
247
  when String
248
- self.class_eval %{def _layout; #{@_layout.inspect} end}
248
+ self.class_eval %{def _layout; #{@_layout.inspect} end}, __FILE__, __LINE__
249
249
  when Symbol
250
250
  self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
251
251
  def _layout
@@ -259,9 +259,9 @@ module AbstractController
259
259
  ruby_eval
260
260
  when Proc
261
261
  define_method :_layout_from_proc, &@_layout
262
- self.class_eval %{def _layout; _layout_from_proc(self) end}
262
+ self.class_eval %{def _layout; _layout_from_proc(self) end}, __FILE__, __LINE__
263
263
  when false
264
- self.class_eval %{def _layout; end}
264
+ self.class_eval %{def _layout; end}, __FILE__, __LINE__
265
265
  when true
266
266
  raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil"
267
267
  when nil
@@ -6,7 +6,7 @@ module AbstractController
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- cattr_accessor :logger
9
+ config_accessor :logger
10
10
  extend ActiveSupport::Benchmarkable
11
11
  end
12
12
  end
@@ -1,4 +1,5 @@
1
1
  require "abstract_controller/base"
2
+ require "action_view"
2
3
 
3
4
  module AbstractController
4
5
  class DoubleRenderError < Error
@@ -13,6 +13,7 @@ module ActionController
13
13
  MODULES = [
14
14
  AbstractController::Layouts,
15
15
  AbstractController::Translation,
16
+ AbstractController::AssetPaths,
16
17
 
17
18
  Helpers,
18
19
  HideActions,
@@ -35,6 +36,7 @@ module ActionController
35
36
  RecordIdentifier,
36
37
  HttpAuthentication::Basic::ControllerMethods,
37
38
  HttpAuthentication::Digest::ControllerMethods,
39
+ HttpAuthentication::Token::ControllerMethods,
38
40
 
39
41
  # Add instrumentations hooks at the bottom, to ensure they instrument
40
42
  # all the methods properly.
@@ -65,8 +67,10 @@ module ActionController
65
67
  @subclasses ||= []
66
68
  end
67
69
 
70
+ config_accessor :asset_host, :asset_path
71
+
68
72
  ActiveSupport.run_load_hooks(:action_controller, self)
69
73
  end
70
74
  end
71
75
 
72
- require "action_controller/deprecated/base"
76
+ require "action_controller/deprecated/base"
@@ -63,11 +63,10 @@ module ActionController #:nodoc:
63
63
  included do
64
64
  extend ConfigMethods
65
65
 
66
- @@perform_caching = true
67
- cattr_accessor :perform_caching
66
+ config_accessor :perform_caching
67
+ self.perform_caching = true if perform_caching.nil?
68
68
  end
69
69
 
70
-
71
70
  def caching_allowed?
72
71
  request.get? && response.status == 200
73
72
  end
@@ -133,7 +133,7 @@ module ActionController #:nodoc:
133
133
  body = controller._save_fragment(cache_path.path, @store_options)
134
134
  end
135
135
 
136
- body = controller.render_to_string(:text => cache, :layout => true) unless @cache_layout
136
+ body = controller.render_to_string(:text => body, :layout => true) unless @cache_layout
137
137
 
138
138
  controller.response_body = body
139
139
  controller.content_type = Mime[cache_path.extension || :html]
@@ -99,7 +99,7 @@ module ActionController #:nodoc:
99
99
  end
100
100
 
101
101
  def instrument_fragment_cache(name, key)
102
- ActiveSupport::Notifications.instrument("action_controller.#{name}", :key => key){ yield }
102
+ ActiveSupport::Notifications.instrument("#{name}.action_controller", :key => key){ yield }
103
103
  end
104
104
  end
105
105
  end
@@ -41,11 +41,11 @@ module ActionController #:nodoc:
41
41
  ##
42
42
  # :singleton-method:
43
43
  # The cache directory should be the document root for the web server and is set using <tt>Base.page_cache_directory = "/document/root"</tt>.
44
- # For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>RAILS_ROOT + "/public"</tt>). Changing
44
+ # For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>Rails.root + "/public"</tt>). Changing
45
45
  # this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your
46
46
  # web server to look in the new location for cached files.
47
- @@page_cache_directory = ''
48
- cattr_accessor :page_cache_directory
47
+ config_accessor :page_cache_directory
48
+ self.page_cache_directory ||= ''
49
49
 
50
50
  ##
51
51
  # :singleton-method:
@@ -53,8 +53,8 @@ module ActionController #:nodoc:
53
53
  # order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is <tt>.html</tt>.
54
54
  # If you want something else, like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension. In cases where a request already has an
55
55
  # extension, such as <tt>.xml</tt> or <tt>.rss</tt>, page caching will not add an extension. This allows it to work well with RESTful apps.
56
- @@page_cache_extension = '.html'
57
- cattr_accessor :page_cache_extension
56
+ config_accessor :page_cache_extension
57
+ self.page_cache_extension ||= '.html'
58
58
  end
59
59
 
60
60
  module ClassMethods
@@ -109,14 +109,14 @@ module ActionController #:nodoc:
109
109
  end
110
110
 
111
111
  def instrument_page_cache(name, path)
112
- ActiveSupport::Notifications.instrument("action_controller.#{name}", :path => path){ yield }
112
+ ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield }
113
113
  end
114
114
  end
115
115
 
116
116
  # Expires the page that was cached with the +options+ as a key. Example:
117
117
  # expire_page :controller => "lists", :action => "show"
118
118
  def expire_page(options = {})
119
- return unless perform_caching
119
+ return unless self.class.perform_caching
120
120
 
121
121
  if options.is_a?(Hash)
122
122
  if options[:action].is_a?(Array)
@@ -135,7 +135,7 @@ module ActionController #:nodoc:
135
135
  # If no options are provided, the requested url is used. Example:
136
136
  # cache_page "I'm the cached content", :controller => "lists", :action => "show"
137
137
  def cache_page(content = nil, options = nil)
138
- return unless perform_caching && caching_allowed
138
+ return unless self.class.perform_caching && caching_allowed
139
139
 
140
140
  path = case options
141
141
  when Hash
@@ -57,6 +57,7 @@ module ActionController #:nodoc:
57
57
  def before(controller)
58
58
  self.controller = controller
59
59
  callback(:before) if controller.perform_caching
60
+ true # before method from sweeper should always return true
60
61
  end
61
62
 
62
63
  def after(controller)
@@ -1,33 +1,16 @@
1
1
  module ActionController
2
2
  class Base
3
- class << self
4
- def deprecated_config_accessor(option, message = nil)
5
- deprecated_config_reader(option, message)
6
- deprecated_config_writer(option, message)
3
+ # Deprecated methods. Wrap them in a module so they can be overwritten by plugins
4
+ # (like the verify method.)
5
+ module DeprecatedBehavior #:nodoc:
6
+ def relative_url_root
7
+ ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root is ineffective. " <<
8
+ "Please stop using it.", caller
7
9
  end
8
10
 
9
- def deprecated_config_reader(option, message = nil)
10
- message ||= "Reading #{option} directly from ActionController::Base is deprecated. " \
11
- "Please read it from config.#{option}"
12
-
13
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
14
- def #{option}
15
- ActiveSupport::Deprecation.warn #{message.inspect}, caller
16
- config.#{option}
17
- end
18
- RUBY
19
- end
20
-
21
- def deprecated_config_writer(option, message = nil)
22
- message ||= "Setting #{option} directly on ActionController::Base is deprecated. " \
23
- "Please set it on config.action_controller.#{option}"
24
-
25
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
26
- def #{option}=(val)
27
- ActiveSupport::Deprecation.warn #{message.inspect}, caller
28
- config.#{option} = val
29
- end
30
- RUBY
11
+ def relative_url_root=
12
+ ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root= is ineffective. " <<
13
+ "Please stop using it.", caller
31
14
  end
32
15
 
33
16
  def consider_all_requests_local
@@ -125,9 +108,7 @@ module ActionController
125
108
  def use_accept_header=(val)
126
109
  use_accept_header
127
110
  end
128
- end
129
111
 
130
- module DeprecatedBehavior
131
112
  # This method has been moved to ActionDispatch::Request.filter_parameters
132
113
  def filter_parameter_logging(*args, &block)
133
114
  ActiveSupport::Deprecation.warn("Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead", caller)
@@ -146,14 +127,7 @@ module ActionController
146
127
 
147
128
  extend DeprecatedBehavior
148
129
 
149
- deprecated_config_writer :session_store
150
- deprecated_config_writer :session_options
151
- deprecated_config_accessor :relative_url_root, "relative_url_root is ineffective. Please stop using it"
152
- deprecated_config_accessor :assets_dir
153
- deprecated_config_accessor :javascripts_dir
154
- deprecated_config_accessor :stylesheets_dir
155
-
156
130
  delegate :consider_all_requests_local, :consider_all_requests_local=,
157
131
  :allow_concurrency, :allow_concurrency=, :to => :"self.class"
158
132
  end
159
- end
133
+ end
@@ -1,6 +1,48 @@
1
1
  require 'active_support/core_ext/class/attribute'
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'action_dispatch/middleware/stack'
2
4
 
3
5
  module ActionController
6
+ # Extend ActionDispatch middleware stack to make it aware of options
7
+ # allowing the following syntax in controllers:
8
+ #
9
+ # class PostsController < ApplicationController
10
+ # use AuthenticationMiddleware, :except => [:index, :show]
11
+ # end
12
+ #
13
+ class MiddlewareStack < ActionDispatch::MiddlewareStack #:nodoc:
14
+ class Middleware < ActionDispatch::MiddlewareStack::Middleware #:nodoc:
15
+ def initialize(klass, *args)
16
+ options = args.extract_options!
17
+ @only = Array(options.delete(:only)).map(&:to_s)
18
+ @except = Array(options.delete(:except)).map(&:to_s)
19
+ args << options unless options.empty?
20
+ super
21
+ end
22
+
23
+ def valid?(action)
24
+ if @only.present?
25
+ @only.include?(action)
26
+ elsif @except.present?
27
+ !@except.include?(action)
28
+ else
29
+ true
30
+ end
31
+ end
32
+ end
33
+
34
+ def build(action, app=nil, &block)
35
+ app ||= block
36
+ action = action.to_s
37
+ raise "MiddlewareStack#build requires an app" unless app
38
+
39
+ reverse.inject(app) do |a, middleware|
40
+ middleware.valid?(action) ?
41
+ middleware.build(a) : a
42
+ end
43
+ end
44
+ end
45
+
4
46
  # ActionController::Metal provides a way to get a valid Rack application from a controller.
5
47
  #
6
48
  # In AbstractController, dispatching is triggered directly by calling #process on a new controller.
@@ -91,10 +133,10 @@ module ActionController
91
133
  end
92
134
 
93
135
  class_attribute :middleware_stack
94
- self.middleware_stack = ActionDispatch::MiddlewareStack.new
136
+ self.middleware_stack = ActionController::MiddlewareStack.new
95
137
 
96
138
  def self.inherited(base)
97
- self.middleware_stack = base.middleware_stack.dup
139
+ base.middleware_stack = self.middleware_stack.dup
98
140
  super
99
141
  end
100
142
 
@@ -120,7 +162,7 @@ module ActionController
120
162
  # ==== Returns
121
163
  # Proc:: A rack application
122
164
  def self.action(name, klass = ActionDispatch::Request)
123
- middleware_stack.build do |env|
165
+ middleware_stack.build(name.to_s) do |env|
124
166
  new.dispatch(name, klass.new(env))
125
167
  end
126
168
  end
@@ -21,8 +21,8 @@ module ActionController
21
21
  delegate :default_charset=, :to => "ActionDispatch::Response"
22
22
  end
23
23
 
24
- # cattr_reader :protected_instance_variables
25
- cattr_accessor :protected_instance_variables
24
+ # TODO: Update protected instance variables list
25
+ config_accessor :protected_instance_variables
26
26
  self.protected_instance_variables = %w(@assigns @performed_redirect @performed_render
27
27
  @variables_added @request_origin @url
28
28
  @parent_controller @action_name
@@ -52,8 +52,8 @@ module ActionController
52
52
  include AbstractController::Helpers
53
53
 
54
54
  included do
55
- class_attribute :helpers_path
56
- self.helpers_path = []
55
+ config_accessor :helpers_path
56
+ self.helpers_path ||= []
57
57
  end
58
58
 
59
59
  module ClassMethods
@@ -104,7 +104,7 @@ module ActionController
104
104
  def all_application_helpers
105
105
  helpers = []
106
106
  helpers_path.each do |path|
107
- extract = /^#{Regexp.quote(path)}\/?(.*)_helper.rb$/
107
+ extract = /^#{Regexp.quote(path.to_s)}\/?(.*)_helper.rb$/
108
108
  helpers += Dir["#{path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') }
109
109
  end
110
110
  helpers.sort!