From 835f5d0269a8d3615585119e77f1ba7d601c943b Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Sun, 28 Mar 2010 15:02:17 +0430 Subject: Rails 3 application can run performance tests now. [#4171 state:resolved] --- actionpack/lib/action_dispatch/testing/performance_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/performance_test.rb b/actionpack/lib/action_dispatch/testing/performance_test.rb index 1b9a6c18b7..33a5c68b9d 100644 --- a/actionpack/lib/action_dispatch/testing/performance_test.rb +++ b/actionpack/lib/action_dispatch/testing/performance_test.rb @@ -1,7 +1,7 @@ require 'active_support/testing/performance' require 'active_support/testing/default' -if defined?(ActiveSupport::Testing::Performance) +begin module ActionDispatch # An integration test that runs a code profiler on your test methods. # Profiling output for combinations of each test method, measurement, and @@ -14,4 +14,6 @@ if defined?(ActiveSupport::Testing::Performance) include ActiveSupport::Testing::Default end end +rescue NameError + $stderr.puts "Specify ruby-prof as application's dependency in Gemfile to run benchmarks." end \ No newline at end of file -- cgit v1.2.3 From 105f9b8154bbee88b45e0bb9de949206cbc1ba02 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Mar 2010 13:26:13 +0200 Subject: adds missing requires for Object#duplicable? --- actionpack/lib/action_dispatch/http/filter_parameters.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/filter_parameters.rb b/actionpack/lib/action_dispatch/http/filter_parameters.rb index e42b4d09b0..152aaa2e67 100644 --- a/actionpack/lib/action_dispatch/http/filter_parameters.rb +++ b/actionpack/lib/action_dispatch/http/filter_parameters.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/object/blank' require 'active_support/core_ext/hash/keys' +require 'active_support/core_ext/object/duplicable' module ActionDispatch module Http -- cgit v1.2.3 From 76f024ac8db82490a99c71d0d8951d677e3bc9bc Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Mar 2010 14:15:02 +0200 Subject: adds missing requires for Object#blank? and Object#present? --- actionpack/lib/action_controller/metal/http_authentication.rb | 1 + actionpack/lib/action_controller/metal/renderers.rb | 1 + actionpack/lib/action_controller/railties/log_subscriber.rb | 2 ++ actionpack/lib/action_controller/test_case.rb | 1 + actionpack/lib/action_dispatch/http/cache.rb | 2 ++ actionpack/lib/action_dispatch/http/mime_type.rb | 1 + actionpack/lib/action_dispatch/http/response.rb | 1 + actionpack/lib/action_dispatch/http/upload.rb | 2 ++ actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 1 + actionpack/lib/action_dispatch/middleware/session/cookie_store.rb | 1 + actionpack/lib/action_dispatch/routing/deprecated_mapper.rb | 2 ++ actionpack/lib/action_dispatch/routing/mapper.rb | 1 + actionpack/lib/action_dispatch/testing/test_request.rb | 2 ++ actionpack/lib/action_view/helpers/capture_helper.rb | 2 ++ actionpack/lib/action_view/helpers/form_helper.rb | 1 + actionpack/lib/action_view/helpers/form_options_helper.rb | 1 + actionpack/lib/action_view/helpers/form_tag_helper.rb | 1 + actionpack/lib/action_view/helpers/number_helper.rb | 1 + actionpack/lib/action_view/helpers/prototype_helper.rb | 1 + actionpack/lib/action_view/helpers/tag_helper.rb | 1 + actionpack/lib/action_view/helpers/text_helper.rb | 1 + actionpack/lib/action_view/render/partials.rb | 2 ++ actionpack/lib/action_view/test_case.rb | 1 + 23 files changed, 30 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 6ec788f302..424828f7e8 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -1,4 +1,5 @@ require 'active_support/base64' +require 'active_support/core_ext/object/blank' module ActionController module HttpAuthentication diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index d906e1fb5b..aebd71e867 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/class/attribute' +require 'active_support/core_ext/object/blank' module ActionController def self.add_renderer(key, &block) diff --git a/actionpack/lib/action_controller/railties/log_subscriber.rb b/actionpack/lib/action_controller/railties/log_subscriber.rb index c2299d0b05..00ac3bdf67 100644 --- a/actionpack/lib/action_controller/railties/log_subscriber.rb +++ b/actionpack/lib/action_controller/railties/log_subscriber.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/blank' + module ActionController module Railties class LogSubscriber < Rails::LogSubscriber diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 120f34460e..306db4a431 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -1,4 +1,5 @@ require 'rack/session/abstract/id' +require 'active_support/core_ext/object/blank' module ActionController module TemplateAssertions diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb index d2404e63c5..9b9e81440b 100644 --- a/actionpack/lib/action_dispatch/http/cache.rb +++ b/actionpack/lib/action_dispatch/http/cache.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/blank' + module ActionDispatch module Http module Cache diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 3f1a77295d..d6a805bf3b 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -1,5 +1,6 @@ require 'set' require 'active_support/core_ext/class/attribute_accessors' +require 'active_support/core_ext/object/blank' module Mime class Mimes < Array diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 9cfe5a5ea9..362e5ec970 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -1,5 +1,6 @@ require 'digest/md5' require 'active_support/core_ext/module/delegation' +require 'active_support/core_ext/object/blank' module ActionDispatch # :nodoc: # Represents an HTTP response generated by a controller action. One can use diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index dc6121b911..81d2517304 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/blank' + module ActionDispatch module Http module UploadedFile diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 311880cabc..dddedc832f 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -1,5 +1,6 @@ require 'rack/utils' require 'rack/request' +require 'active_support/core_ext/object/blank' module ActionDispatch module Session diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 22da82479e..3331b7c25e 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/hash/keys' +require 'active_support/core_ext/object/blank' module ActionDispatch module Session diff --git a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb index dd650e83d9..b0545279b1 100644 --- a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb +++ b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/blank' + module ActionDispatch module Routing class RouteSet diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5a3868e1d4..26f0e14e72 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/hash/except' +require 'active_support/core_ext/object/blank' module ActionDispatch module Routing diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index 20288aa7a5..090e03cf44 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/blank' + module ActionDispatch class TestRequest < Request DEFAULT_ENV = Rack::MockRequest.env_for('/') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index f0be814700..20598237e9 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/blank' + module ActionView module Helpers # CaptureHelper exposes methods to let you extract generated markup which diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 2ba5339b7d..7b5b3ae000 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -4,6 +4,7 @@ require 'action_view/helpers/tag_helper' require 'action_view/helpers/form_tag_helper' require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/core_ext/hash/slice' +require 'active_support/core_ext/object/blank' module ActionView module Helpers diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 4c523d4b20..11c6351bd3 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -1,6 +1,7 @@ require 'cgi' require 'erb' require 'action_view/helpers/form_helper' +require 'active_support/core_ext/object/blank' module ActionView module Helpers diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 07694f5ebb..ca100e102e 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -1,6 +1,7 @@ require 'cgi' require 'action_view/helpers/tag_helper' require 'active_support/core_ext/object/returning' +require 'active_support/core_ext/object/blank' module ActionView module Helpers diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 719b64b940..605e5d5873 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/big_decimal/conversions' require 'active_support/core_ext/float/rounding' +require 'active_support/core_ext/object/blank' module ActionView module Helpers #:nodoc: diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index ccdc8181db..ebe0b4e876 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -1,6 +1,7 @@ require 'set' require 'active_support/json' require 'active_support/core_ext/object/returning' +require 'active_support/core_ext/object/blank' module ActionView module Helpers diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index 9b4cacd4d7..c09d01eeee 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/object/blank' require 'set' module ActionView diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 27be1690dd..0e1bc139ff 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/object/blank' require 'action_view/helpers/tag_helper' module ActionView diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 17d16556b9..f04a89c1ac 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/blank' + module ActionView # There's also a convenience method for rendering sub templates within the current controller that depends on a # single object (we call this kind of sub templates for partials). It relies on the fact that partials should diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index b0ababe344..23b0c6e121 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/object/blank' require 'action_controller/test_case' require 'action_view' -- cgit v1.2.3 From e1a70faea675499d717cef7662262ceb03b23975 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 28 Mar 2010 11:10:38 +0100 Subject: Add constraints to resources in new routing DSL Signed-off-by: Rizwan Reza --- actionpack/lib/action_dispatch/routing/mapper.rb | 61 ++++++++++++++++++------ 1 file changed, 47 insertions(+), 14 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 26f0e14e72..2546bdd43e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -259,6 +259,7 @@ module ActionDispatch def scope(*args) options = args.extract_options! + options = options.dup case args.first when String @@ -440,6 +441,32 @@ module ActionDispatch def id_segment ":#{singular}_id" end + + def constraints + options[:constraints] || {} + end + + def id_constraint? + options[:id] && options[:id].is_a?(Regexp) || constraints[:id] && constraints[:id].is_a?(Regexp) + end + + def id_constraint + options[:id] || constraints[:id] + end + + def collection_options + (options || {}).dup.tap do |options| + options.delete(:id) + options[:constraints] = options[:constraints].dup if options[:constraints] + options[:constraints].delete(:id) if options[:constraints].is_a?(Hash) + end + end + + def nested_options + options = { :name_prefix => member_name } + options["#{singular}_id".to_sym] = id_constraint if id_constraint? + options + end end class SingletonResource < Resource #:nodoc: @@ -484,12 +511,14 @@ module ActionDispatch yield if block_given? end - get :show if resource.actions.include?(:show) - post :create if resource.actions.include?(:create) - put :update if resource.actions.include?(:update) - delete :destroy if resource.actions.include?(:destroy) - get :new, :as => resource.name if resource.actions.include?(:new) - get :edit, :as => resource.name if resource.actions.include?(:edit) + scope(resource.options) do + get :show if resource.actions.include?(:show) + post :create if resource.actions.include?(:create) + put :update if resource.actions.include?(:update) + delete :destroy if resource.actions.include?(:destroy) + get :new, :as => resource.name if resource.actions.include?(:new) + get :edit, :as => resource.name if resource.actions.include?(:edit) + end end end @@ -510,17 +539,21 @@ module ActionDispatch yield if block_given? with_scope_level(:collection) do - get :index if resource.actions.include?(:index) - post :create if resource.actions.include?(:create) - get :new, :as => resource.singular if resource.actions.include?(:new) + scope(resource.collection_options) do + get :index if resource.actions.include?(:index) + post :create if resource.actions.include?(:create) + get :new, :as => resource.singular if resource.actions.include?(:new) + end end with_scope_level(:member) do scope(':id') do - get :show if resource.actions.include?(:show) - put :update if resource.actions.include?(:update) - delete :destroy if resource.actions.include?(:destroy) - get :edit, :as => resource.singular if resource.actions.include?(:edit) + scope(resource.options) do + get :show if resource.actions.include?(:show) + put :update if resource.actions.include?(:update) + delete :destroy if resource.actions.include?(:destroy) + get :edit, :as => resource.singular if resource.actions.include?(:edit) + end end end end @@ -559,7 +592,7 @@ module ActionDispatch end with_scope_level(:nested) do - scope(parent_resource.id_segment, :name_prefix => parent_resource.member_name) do + scope(parent_resource.id_segment, parent_resource.nested_options) do yield end end -- cgit v1.2.3 From 77a2a3d9b3aa461437ced326ea4a70112a8c68ed Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 28 Mar 2010 13:40:38 -0700 Subject: Request#content_type exists in Rack::Request, and other parts of Rack::Request expect it to return a String. Split the Rails API so that Request#content_type returns a String, and Request#content_mime_type returns a Mime::Type object. --- actionpack/lib/action_dispatch/http/mime_negotiation.rb | 8 ++++++-- actionpack/lib/action_dispatch/http/request.rb | 6 +++--- actionpack/lib/action_dispatch/middleware/params_parser.rb | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index fec250e928..be89924015 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -5,7 +5,7 @@ module ActionDispatch # # For backward compatibility, the post \format is extracted from the # X-Post-Data-Format HTTP header if present. - def content_type + def content_mime_type @env["action_dispatch.request.content_type"] ||= begin if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/ Mime::Type.lookup($1.strip.downcase) @@ -15,13 +15,17 @@ module ActionDispatch end end + def content_type + content_mime_type && content_mime_type.to_s + end + # Returns the accepted MIME type for the request. def accepts @env["action_dispatch.request.accepts"] ||= begin header = @env['HTTP_ACCEPT'].to_s.strip if header.empty? - [content_type] + [content_mime_type] else Mime::Type.parse(header) end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index ea9f0f99c2..8b8426b5aa 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -96,11 +96,11 @@ module ActionDispatch end def forgery_whitelisted? - method == :get || xhr? || content_type.nil? || !content_type.verify_request? + method == :get || xhr? || content_mime_type.nil? || !content_mime_type.verify_request? end def media_type - content_type.to_s + content_mime_type.to_s end # Returns the content length of the request as an integer. @@ -157,7 +157,7 @@ module ActionDispatch end def form_data? - FORM_DATA_MEDIA_TYPES.include?(content_type.to_s) + FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s) end def body_stream #:nodoc: diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index f4c4324fb0..18a3688bb0 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -25,7 +25,9 @@ module ActionDispatch return false if request.content_length.zero? - mime_type = content_type_from_legacy_post_data_format_header(env) || request.content_type + mime_type = content_type_from_legacy_post_data_format_header(env) || + request.content_mime_type + strategy = @parsers[mime_type] return false unless strategy @@ -53,7 +55,7 @@ module ActionDispatch raise { "body" => request.raw_post, - "content_type" => request.content_type, + "content_type" => request.content_mime_type, "content_length" => request.content_length, "exception" => "#{e.message} (#{e.class})", "backtrace" => e.backtrace } -- cgit v1.2.3 From 878a9e02f662516d0d70c44beb1a3f4297342896 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Sat, 27 Mar 2010 16:16:57 +0100 Subject: html_tag option to wrap error_message_on text [#4283 state:resolved] Signed-off-by: wycats --- .../lib/action_view/helpers/active_model_helper.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index 80b3d3a664..bbfac32322 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -97,10 +97,10 @@ module ActionView end # Returns a string containing the error message attached to the +method+ on the +object+ if one exists. - # This error message is wrapped in a DIV tag, which can be extended to include a :prepend_text - # and/or :append_text (to properly explain the error), and a :css_class to style it - # accordingly. +object+ should either be the name of an instance variable or the actual object. The method can be - # passed in either as a string or a symbol. + # This error message is wrapped in a DIV tag by default or with :html_tag if specified, + # which can be extended to include a :prepend_text and/or :append_text (to properly explain + # the error), and a :css_class to style it accordingly. +object+ should either be the name of an + # instance variable or the actual object. The method can be passed in either as a string or a symbol. # As an example, let's say you have a model @post that has an error message on the +title+ attribute: # # <%= error_message_on "post", "title" %> @@ -112,25 +112,28 @@ module ActionView # <%= error_message_on "post", "title", # :prepend_text => "Title simply ", # :append_text => " (or it won't work).", + # :html_tag => "span", # :css_class => "inputError" %> + # # => Title simply can't be empty (or it won't work). def error_message_on(object, method, *args) options = args.extract_options! unless args.empty? ActiveSupport::Deprecation.warn('error_message_on takes an option hash instead of separate ' + - 'prepend_text, append_text, and css_class arguments', caller) + 'prepend_text, append_text, html_tag, and css_class arguments', caller) options[:prepend_text] = args[0] || '' options[:append_text] = args[1] || '' - options[:css_class] = args[2] || 'formError' + options[:html_tag] = args[2] || 'div' + options[:css_class] = args[3] || 'formError' end - options.reverse_merge!(:prepend_text => '', :append_text => '', :css_class => 'formError') + options.reverse_merge!(:prepend_text => '', :append_text => '', :html_tag => 'div', :css_class => 'formError') object = convert_to_model(object) if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) && (errors = obj.errors[method]).presence - content_tag("div", - "#{options[:prepend_text]}#{ERB::Util.h(errors.first)}#{options[:append_text]}".html_safe, + content_tag(options[:html_tag], + (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]), :class => options[:css_class] ) else -- cgit v1.2.3 From 72074aac334a846fbb53e7cb12c0254c15004c26 Mon Sep 17 00:00:00 2001 From: Jan De Poorter Date: Thu, 25 Feb 2010 16:21:41 +0100 Subject: Add _index to named collection routes for uncountable resources (e.g. Sheep) Signed-off-by: Rizwan Reza --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 2546bdd43e..fa64a2f1d0 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -426,7 +426,11 @@ module ActionDispatch end def collection_name - plural + uncountable? ? "#{plural}_index" : plural + end + + def uncountable? + singular == plural end def name_for_action(action) -- cgit v1.2.3 From cf6734fdf9d72bfc7fe92e36bf603d67ad815e6b Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Mon, 29 Mar 2010 05:45:32 +0430 Subject: Add more tests and docs to uncountable routes. [#3930 state:resolved] --- actionpack/lib/action_dispatch/routing/mapper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index fa64a2f1d0..8a84afd315 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -425,10 +425,11 @@ module ActionDispatch singular end + # Checks for uncountable plurals, and appends "_index" if they're. def collection_name uncountable? ? "#{plural}_index" : plural end - + def uncountable? singular == plural end -- cgit v1.2.3 From 49bc6a249e2a200216f8a96c36093a2c7a471c9b Mon Sep 17 00:00:00 2001 From: Craig R Webster Date: Sun, 21 Mar 2010 19:35:38 +0000 Subject: Allow customisation of asset path generation using a proc. Set config.action_controller.asset_path_template to a proc that takes one argument - the direct, unchanged asset path - and returns a path to that asset using the scheme that your assets require. This is useful if you have a setup which scales by introducing new application servers where the mtime of the asset files may not be the same as those of the asset files on your previous servers, but it does require your web servers to have knowledge of the asset template paths that you rewrite to so it's not suitable for out-of-the-box use. An example of configuring asset path generation and rewriting these paths using Apache is included in actionpack/lib/action_view/helpers/asset_tag_helper.rb. Signed-off-by: wycats --- .../lib/action_view/helpers/asset_tag_helper.rb | 68 +++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 02ad41719b..635c58bc35 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -108,7 +108,7 @@ module ActionView # "http://asset%d.example.com", "https://asset1.example.com" # ) # - # === Using asset timestamps + # === Using asset path templates # # By default, Rails appends asset's timestamps to all asset paths. This allows # you to set a cache-expiration date for the asset far into the future, but @@ -133,6 +133,65 @@ module ActionView # will request the same assets over and over again even thought they didn't # change. You can use something like Live HTTP Headers for Firefox to verify # that the cache is indeed working. + # + # This strategy works well enough for most server setups and requires the + # least configuration, but if you deploy several application servers at + # different times - say to handle a temporary spike in load - then the + # asset time stamps will be out of sync. In a setup like this you may want + # to set the way that asset paths are generated yourself. + # + # Altering the asset paths that Rails generates can be done in two ways. + # The easiest is to define the RAILS_ASSET_ID environment variable. The + # contents of this variable will always be used in preference to + # calculated timestamps. A more complex but flexible way is to set + # ActionController::Base.config.asset_path_template to a proc + # that takes the unmodified asset path and returns the path needed for + # your asset caching to work. Typically you'd do something like this in + # config/environments/production.rb: + # + # # Normally you'd calculate RELEASE_NUMBER at startup. + # RELEASE_NUMBER = 12345 + # config.action_controller.asset_path_template = proc { |asset_path| + # "/release-#{RELEASE_NUMBER}#{asset_path}" + # } + # + # This example would cause the following behaviour on all servers no + # matter when they were deployed: + # + # image_tag("rails.png") + # # => Rails + # stylesheet_link_tag("application") + # # => + # + # Changing the asset_path_template does require that your web servers have + # knowledge of the asset template paths that you rewrite to so it's not + # suitable for out-of-the-box use. To use the example given above you + # could use something like this in your Apache VirtualHost configuration: + # + # + # # Some browsers still send conditional-GET requests if there's a + # # Last-Modified header or an ETag header even if they haven't + # # reached the expiry date sent in the Expires header. + # Header unset Last-Modified + # Header unset ETag + # FileETag None + # + # # Assets requested using a cache-busting filename should be served + # # only once and then cached for a really long time. The HTTP/1.1 + # # spec frowns on hugely-long expiration times though and suggests + # # that assets which never expire be served with an expiration date + # # 1 year from access. + # ExpiresActive On + # ExpiresDefault "access plus 1 year" + # + # + # # We use cached-busting location names with the far-future expires + # # headers to ensure that if a file does change it can force a new + # # request. The actual asset filenames are still the same though so we + # # need to rewrite the location from the cache-busting location to the + # # real asset location so that we can serve it. + # RewriteEngine On + # RewriteRule ^/release-\d+/(images|javascripts|stylesheets)/(.*)$ /$1/$2 [L] module AssetTagHelper JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls', 'rails'].freeze unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES) @@ -646,7 +705,12 @@ module ActionView source += ".#{ext}" if rewrite_extension?(source, dir, ext) source = "/#{dir}/#{source}" unless source[0] == ?/ - source = rewrite_asset_path(source) + asset_path_template = config.asset_path_template + if asset_path_template && asset_path_template.respond_to?(:call) + source = asset_path_template.call(source) + else + source = rewrite_asset_path(source) + end has_request = controller.respond_to?(:request) if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/} -- cgit v1.2.3 From 201e8986b15f4d815355e0ca96e02cf16dba9372 Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 28 Mar 2010 18:45:52 -0700 Subject: Updated asset_template_path to asset_path and have it also support a String [#4247 state:resolved] --- .../lib/action_view/helpers/asset_tag_helper.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 635c58bc35..e4ec17467e 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -108,7 +108,7 @@ module ActionView # "http://asset%d.example.com", "https://asset1.example.com" # ) # - # === Using asset path templates + # === Customizing the asset path # # By default, Rails appends asset's timestamps to all asset paths. This allows # you to set a cache-expiration date for the asset far into the future, but @@ -144,7 +144,7 @@ module ActionView # The easiest is to define the RAILS_ASSET_ID environment variable. The # contents of this variable will always be used in preference to # calculated timestamps. A more complex but flexible way is to set - # ActionController::Base.config.asset_path_template to a proc + # ActionController::Base.config.asset_path to a proc # that takes the unmodified asset path and returns the path needed for # your asset caching to work. Typically you'd do something like this in # config/environments/production.rb: @@ -163,7 +163,7 @@ module ActionView # stylesheet_link_tag("application") # # => # - # Changing the asset_path_template does require that your web servers have + # Changing the asset_path does require that your web servers have # knowledge of the asset template paths that you rewrite to so it's not # suitable for out-of-the-box use. To use the example given above you # could use something like this in your Apache VirtualHost configuration: @@ -705,12 +705,7 @@ module ActionView source += ".#{ext}" if rewrite_extension?(source, dir, ext) source = "/#{dir}/#{source}" unless source[0] == ?/ - asset_path_template = config.asset_path_template - if asset_path_template && asset_path_template.respond_to?(:call) - source = asset_path_template.call(source) - else - source = rewrite_asset_path(source) - end + source = rewrite_asset_path(source, config.asset_path) has_request = controller.respond_to?(:request) if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/} @@ -774,7 +769,13 @@ module ActionView # Break out the asset path rewrite in case plugins wish to put the asset id # someplace other than the query string. - def rewrite_asset_path(source) + def rewrite_asset_path(source, path = nil) + if path && path.respond_to?(:call) + return path.call(source) + elsif path && path.is_a?(String) + return path % [source] + end + asset_id = rails_asset_id(source) if asset_id.blank? source -- cgit v1.2.3 From 56bed512f92050f95701eca4f918086a8f1cda1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 30 Mar 2010 01:04:34 +0200 Subject: Fix dom_id for ActiveRecord [#4296 state:resolved] --- actionpack/lib/action_controller/record_identifier.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb index 3f966b1b64..7fdaffe3eb 100644 --- a/actionpack/lib/action_controller/record_identifier.rb +++ b/actionpack/lib/action_controller/record_identifier.rb @@ -76,8 +76,8 @@ module ActionController # method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to # make sure yourself that your dom ids are valid, in case you overwrite this method. def record_key_for_dom_id(record) - return record.id unless record.respond_to?(:to_model) - key = record.to_model.to_key + record = record.to_model if record.respond_to?(:to_model) + key = record.to_key key ? sanitize_dom_id(key.join('_')) : key end -- cgit v1.2.3 From 4aded43b73ff94dbf06b4a2d2075651ce454e1d5 Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 29 Mar 2010 17:08:08 -0700 Subject: Replace the placeholder base_hook API with on_load. To specify some code that should run during framework load do: ActiveSupport.on_load(:action_controller) do # Code run in the context of AC::Base end --- actionpack/lib/action_controller/base.rb | 3 +-- actionpack/lib/action_controller/railtie.rb | 10 +++++----- actionpack/lib/action_view/base.rb | 2 +- actionpack/lib/action_view/helpers/active_model_helper.rb | 2 +- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- actionpack/lib/action_view/railtie.rb | 4 ++-- 6 files changed, 11 insertions(+), 12 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 5797282b41..46a175d2fa 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -64,8 +64,7 @@ module ActionController filter end - ActionController.run_base_hooks(self) - + ActiveSupport.run_load_hooks(:action_controller, self) end end diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 0ec89928af..29d8523ee1 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -41,7 +41,7 @@ module ActionController log_subscriber :action_controller, ActionController::Railties::LogSubscriber.new initializer "action_controller.logger" do - ActionController.base_hook { self.logger ||= Rails.logger } + ActiveSupport.on_load(:action_controller) { self.logger ||= Rails.logger } end initializer "action_controller.set_configs" do |app| @@ -53,23 +53,23 @@ module ActionController ac.stylesheets_dir = paths.public.stylesheets.to_a.first ac.secret = app.config.cookie_secret - ActionController.base_hook do + ActiveSupport.on_load(:action_controller) do self.config.merge!(ac) end end initializer "action_controller.initialize_framework_caches" do - ActionController.base_hook { self.cache_store ||= RAILS_CACHE } + ActiveSupport.on_load(:action_controller) { self.cache_store ||= RAILS_CACHE } end initializer "action_controller.set_helpers_path" do |app| - ActionController.base_hook do + ActiveSupport.on_load(:action_controller) do self.helpers_path = app.config.paths.app.helpers.to_a end end initializer "action_controller.url_helpers" do |app| - ActionController.base_hook do + ActiveSupport.on_load(:action_controller) do extend ::ActionController::Railties::UrlHelpers.with(app.routes) end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 919b1e3470..a9b0715b2e 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -173,7 +173,7 @@ module ActionView #:nodoc: delegate :logger, :to => 'ActionController::Base', :allow_nil => true end - ActionView.run_base_hooks(self) + ActiveSupport.run_load_hooks(:action_view, self) attr_accessor :base_path, :assigns, :template_extension, :lookup_context attr_internal :captures, :request, :controller, :template, :config diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index bbfac32322..44e193f18e 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -6,7 +6,7 @@ require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/object/blank' module ActionView - ActionView.base_hook do + ActiveSupport.on_load(:action_view) do class ActionView::Base @@field_error_proc = Proc.new{ |html_tag, instance| "
#{html_tag}
".html_safe } cattr_accessor :field_error_proc diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 7b5b3ae000..89560d0b49 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1221,7 +1221,7 @@ module ActionView end end - ActionView.base_hook do + ActiveSupport.on_load(:action_view) do class ActionView::Base cattr_accessor :default_form_builder @@default_form_builder = ::ActionView::Helpers::FormBuilder diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb index 9cf007cd2b..c606a71e18 100644 --- a/actionpack/lib/action_view/railtie.rb +++ b/actionpack/lib/action_view/railtie.rb @@ -10,14 +10,14 @@ module ActionView initializer "action_view.cache_asset_timestamps" do |app| unless app.config.cache_classes - ActionView.base_hook do + ActiveSupport.on_load(:action_view) do ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false end end end initializer "action_view.set_configs" do |app| - ActionView.base_hook do + ActiveSupport.on_load(:action_view) do app.config.action_view.each do |k,v| send "#{k}=", v end -- cgit v1.2.3 From 17f0c1e9e8a5bfa7c4d2e1632c3b8b91f4678f03 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 30 Mar 2010 13:58:18 -0500 Subject: Fix stack overflow bug in integration test router helpers --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 1bb81ede3b..08f3d90e18 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -168,7 +168,7 @@ module ActionDispatch # ROUTES TODO: These assertions should really work in an integration context def method_missing(selector, *args, &block) - if @controller && @router.named_routes.helpers.include?(selector) + if @controller && @router && @router.named_routes.helpers.include?(selector) @controller.send(selector, *args, &block) else super -- cgit v1.2.3 From cdf8c35ffdfb39f4de4b030576b1abb06c482668 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 30 Mar 2010 14:05:42 -0500 Subject: Consistent routing language --- .../lib/action_controller/railties/url_helpers.rb | 6 +++--- actionpack/lib/action_controller/test_case.rb | 10 +++++----- .../action_dispatch/testing/assertions/routing.rb | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/railties/url_helpers.rb b/actionpack/lib/action_controller/railties/url_helpers.rb index 5f95e1c621..9df5665542 100644 --- a/actionpack/lib/action_controller/railties/url_helpers.rb +++ b/actionpack/lib/action_controller/railties/url_helpers.rb @@ -1,14 +1,14 @@ module ActionController module Railties module UrlHelpers - def self.with(router) + def self.with(routes) Module.new do define_method(:inherited) do |klass| super(klass) - klass.send(:include, router.url_helpers) + klass.send(:include, routes.url_helpers) end end end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 306db4a431..2d4cf2fafb 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -118,9 +118,9 @@ module ActionController end end - def assign_parameters(router, controller_path, action, parameters = {}) + def assign_parameters(routes, controller_path, action, parameters = {}) parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action) - extra_keys = router.extra_keys(parameters) + extra_keys = routes.extra_keys(parameters) non_path_parameters = get? ? query_parameters : request_parameters parameters.each do |key, value| if value.is_a? Fixnum @@ -322,7 +322,7 @@ module ActionController def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') # Sanity check for required instance variables so we can give an # understandable error message. - %w(@router @controller @request @response).each do |iv_name| + %w(@routes @controller @request @response).each do |iv_name| if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil? raise "#{iv_name} is nil: make sure you set it in your test's setup method." end @@ -338,7 +338,7 @@ module ActionController @request.env['REQUEST_METHOD'] = http_method parameters ||= {} - @request.assign_parameters(@router, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) + @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) @request.session = ActionController::TestSession.new(session) unless session.nil? @request.session["flash"] = @request.flash.update(flash || {}) @@ -447,7 +447,7 @@ module ActionController :relative_url_root => nil, :_path_segments => @request.symbolized_path_parameters) - url, query_string = @router.url_for(options).split("?", 2) + url, query_string = @routes.url_for(options).split("?", 2) @request.env["SCRIPT_NAME"] = @controller.config.relative_url_root @request.env["PATH_INFO"] = url diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 08f3d90e18..b7e9b0c95a 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -80,7 +80,7 @@ module ActionDispatch expected_path = "/#{expected_path}" unless expected_path[0] == ?/ # Load routes.rb if it hasn't been loaded. - generated_path, extra_keys = @router.generate_extras(options, defaults) + generated_path, extra_keys = @routes.generate_extras(options, defaults) found_extras = options.reject {|k, v| ! extra_keys.include? k} msg = build_message(message, "found extras , not ", found_extras, extras) @@ -125,7 +125,7 @@ module ActionDispatch end # A helper to make it easier to test different route configurations. - # This method temporarily replaces @router + # This method temporarily replaces @routes # with a new RouteSet instance. # # The new instance is yielded to the passed block. Typically the block @@ -142,9 +142,9 @@ module ActionDispatch # end # def with_routing - old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new + old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new old_controller, @controller = @controller, @controller.clone if @controller - _router = @router + _routes = @routes # Unfortunately, there is currently an abstraction leak between AC::Base # and AV::Base which requires having the URL helpers in both AC and AV. @@ -153,14 +153,14 @@ module ActionDispatch # # TODO: Make this unnecessary if @controller - @controller.singleton_class.send(:include, _router.url_helpers) + @controller.singleton_class.send(:include, _routes.url_helpers) @controller.view_context_class = Class.new(@controller.view_context_class) do - include _router.url_helpers + include _routes.url_helpers end end - yield @router + yield @routes ensure - @router = old_routes + @routes = old_routes if @controller @controller = old_controller end @@ -168,7 +168,7 @@ module ActionDispatch # ROUTES TODO: These assertions should really work in an integration context def method_missing(selector, *args, &block) - if @controller && @router && @router.named_routes.helpers.include?(selector) + if @controller && @routes && @routes.named_routes.helpers.include?(selector) @controller.send(selector, *args, &block) else super @@ -185,7 +185,7 @@ module ActionDispatch request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method request.path = path - params = @router.recognize_path(path, { :method => request.method }) + params = @routes.recognize_path(path, { :method => request.method }) request.path_parameters = params.with_indifferent_access request -- cgit v1.2.3 From 62151dd272fa59f19d8e0df7e21600b06d865539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 31 Mar 2010 12:59:10 +0200 Subject: Deprecate cookie_verifier_secret in favor of config.cookie_secret allowing signed cookies to work again. --- actionpack/lib/action_controller/deprecated/base.rb | 12 ++++++++++++ actionpack/lib/action_controller/metal/cookies.rb | 1 - actionpack/lib/action_dispatch/middleware/cookies.rb | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/deprecated/base.rb b/actionpack/lib/action_controller/deprecated/base.rb index bbde570ca9..2fd60aacc7 100644 --- a/actionpack/lib/action_controller/deprecated/base.rb +++ b/actionpack/lib/action_controller/deprecated/base.rb @@ -66,6 +66,18 @@ module ActionController Rails.application.config.action_dispatch.ip_spoofing_check end + def cookie_verifier_secret=(value) + ActiveSupport::Deprecation.warn "ActionController::Base.cookie_verifier_secret= is deprecated. " << + "Please configure it on your application with config.cookie_secret=", caller + ActionController::Base.config.secret = value + end + + def cookie_verifier_secret + ActiveSupport::Deprecation.warn "ActionController::Base.cookie_verifier_secret is deprecated. " << + "Please use ActionController::Base.config.secret instead.", caller + ActionController::Base.config.secret + end + def trusted_proxies=(value) ActiveSupport::Deprecation.warn "ActionController::Base.trusted_proxies= is deprecated. " << "Please configure it on your application with config.action_dispatch.trusted_proxies=", caller diff --git a/actionpack/lib/action_controller/metal/cookies.rb b/actionpack/lib/action_controller/metal/cookies.rb index 7aa687b52c..75e5d40a63 100644 --- a/actionpack/lib/action_controller/metal/cookies.rb +++ b/actionpack/lib/action_controller/metal/cookies.rb @@ -6,7 +6,6 @@ module ActionController #:nodoc: included do helper_method :cookies - cattr_accessor :cookie_verifier_secret end private diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index ab7130ab08..cb0d12cab1 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -168,12 +168,12 @@ module ActionDispatch class SignedCookieJar < CookieJar #:nodoc: def initialize(parent_jar) - unless ActionController::Base.cookie_verifier_secret - raise "You must set ActionController::Base.cookie_verifier_secret to use signed cookies" + unless ActionController::Base.config.secret + raise "You must set ActionController::Base.config.secret" end @parent_jar = parent_jar - @verifier = ActiveSupport::MessageVerifier.new(ActionController::Base.cookie_verifier_secret) + @verifier = ActiveSupport::MessageVerifier.new(ActionController::Base.config.secret) end def [](name) -- cgit v1.2.3 From 05337f61f93d4b28fea2cb269483aff0fa4f2545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 31 Mar 2010 16:00:10 +0200 Subject: yield always return an array, so we don't need to use .key? --- actionpack/lib/action_view/template/resolver.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index 8e8afaa43f..a223b3a55f 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -35,12 +35,7 @@ module ActionView def cached(key, prefix, name, partial) return yield unless key && caching? - scope = @cached[key][prefix][name] - if scope.key?(partial) - scope[partial] - else - scope[partial] = yield - end + @cached[key][prefix][name][partial] ||= yield end end -- cgit v1.2.3