From 860202e8b2e3579402d48d7e56fa738a9529a340 Mon Sep 17 00:00:00 2001 From: thoefer Date: Mon, 1 Aug 2011 11:28:31 +0200 Subject: Fix the issue where default_url_options is being cached on test cases. Closes #1872. Closes #2031. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_controller/metal/testing.rb | 5 +++++ actionpack/lib/action_controller/test_case.rb | 1 + 2 files changed, 6 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/testing.rb b/actionpack/lib/action_controller/metal/testing.rb index f4efeb33ba..d1813ee745 100644 --- a/actionpack/lib/action_controller/metal/testing.rb +++ b/actionpack/lib/action_controller/metal/testing.rb @@ -4,6 +4,11 @@ module ActionController include RackDelegation + def recycle! + @_url_options = nil + end + + # TODO: Clean this up def process_with_new_base_test(request, response) @_request = request diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 45bb641aee..c8cf04bb69 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -450,6 +450,7 @@ module ActionController @controller.params.merge!(parameters) build_request_uri(action, parameters) @controller.class.class_eval { include Testing } + @controller.recycle! @controller.process_with_new_base_test(@request, @response) @assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {} @request.session.delete('flash') if @request.session['flash'].blank? -- cgit v1.2.3 From 8845ae683e2688bc619baade49510c17e978518f Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 7 Aug 2011 12:34:49 -0300 Subject: x_sendfile_header now defaults to nil and production.rb env file doesn't set a particular value for it. This allows servers to set it through X-Sendfile-Type, read https://github.com/rack/rack/blob/master/lib/rack/sendfile.rb for more info. Anyways you can force this value in your production.rb --- actionpack/lib/action_controller/metal/data_streaming.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb index 0785fe9679..5e077dd7bd 100644 --- a/actionpack/lib/action_controller/metal/data_streaming.rb +++ b/actionpack/lib/action_controller/metal/data_streaming.rb @@ -17,7 +17,7 @@ module ActionController #:nodoc: protected # Sends the file. This uses a server-appropriate method (such as X-Sendfile) # via the Rack::Sendfile middleware. The header to use is set via - # config.action_dispatch.x_sendfile_header, and defaults to "X-Sendfile". + # config.action_dispatch.x_sendfile_header. # Your server can also configure this for you by setting the X-Sendfile-Type header. # # Be careful to sanitize the path parameter if it is coming from a web -- cgit v1.2.3 From 5f3265c4714efd697cb71015489a9c59d1129440 Mon Sep 17 00:00:00 2001 From: thoefer Date: Mon, 1 Aug 2011 11:28:31 +0200 Subject: Fix the issue where default_url_options is being cached on test cases. Closes #1872. Closes #2031. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_controller/metal/testing.rb | 5 +++++ actionpack/lib/action_controller/test_case.rb | 1 + 2 files changed, 6 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/testing.rb b/actionpack/lib/action_controller/metal/testing.rb index f4efeb33ba..d1813ee745 100644 --- a/actionpack/lib/action_controller/metal/testing.rb +++ b/actionpack/lib/action_controller/metal/testing.rb @@ -4,6 +4,11 @@ module ActionController include RackDelegation + def recycle! + @_url_options = nil + end + + # TODO: Clean this up def process_with_new_base_test(request, response) @_request = request diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 45bb641aee..c8cf04bb69 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -450,6 +450,7 @@ module ActionController @controller.params.merge!(parameters) build_request_uri(action, parameters) @controller.class.class_eval { include Testing } + @controller.recycle! @controller.process_with_new_base_test(@request, @response) @assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {} @request.session.delete('flash') if @request.session['flash'].blank? -- cgit v1.2.3 From aa0d3cece80f6181bbd664596c46fc0f65b4abbe Mon Sep 17 00:00:00 2001 From: Oge Nnadi Date: Fri, 12 Aug 2011 12:00:32 -0300 Subject: Typo fix --- actionpack/lib/action_controller/caching/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 667ba15cc9..0031d2701f 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -38,7 +38,7 @@ module ActionController #:nodoc: # :action => 'lists' is not the same as # :action => 'list', :format => :xml. # - # You can set modify the default action cache path by passing a + # You can modify the default action cache path by passing a # :cache_path option. This will be passed directly to # ActionCachePath.path_for. This is handy for actions with # multiple possible routes that should be cached differently. If a -- cgit v1.2.3 From 75dd33a0aed96d9f03b79c82f7e5bc5ccf462e8e Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Sun, 14 Aug 2011 18:58:29 +0200 Subject: Methods like status and location are interfering with redirect_to [Closes #2511] --- actionpack/lib/action_controller/metal/instrumentation.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 85d0f5f699..777a0ab343 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -58,8 +58,8 @@ module ActionController def redirect_to(*args) ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload| result = super - payload[:status] = self.status - payload[:location] = self.location + payload[:status] = response.status + payload[:location] = response.location result end end @@ -97,4 +97,4 @@ module ActionController end end end -end \ No newline at end of file +end -- cgit v1.2.3 From 6c5f67cac15c43bafcd917c346cccfcf3fa5fb95 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 00:59:59 +0100 Subject: Don't refer to ActionController::Base in the wrap_parameters initializer - use config object instead. Cuts about 15% off the load time. (#734) --- actionpack/lib/action_controller/metal/params_wrapper.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 2d8afc3a78..dfc4e3d72c 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -121,6 +121,8 @@ module ActionController _set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model) end + alias :wrap_parameters= :wrap_parameters + # Sets the default wrapper key or model which will be used to determine # wrapper key and attribute names. Will be called automatically when the # module is inherited. -- cgit v1.2.3 From 8e236152457ed48bb436e9bffb4c5d6d4b6a26d4 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 19:14:06 +0100 Subject: Use lazy load hooks to set parameter wrapping configuration. This means that it doesn't force Action Controller / Active Record to load, but it doesn't fail if they have already loaded. Thanks @josevalim for the hint. --- actionpack/lib/action_controller/metal/params_wrapper.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index dfc4e3d72c..2d8afc3a78 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -121,8 +121,6 @@ module ActionController _set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model) end - alias :wrap_parameters= :wrap_parameters - # Sets the default wrapper key or model which will be used to determine # wrapper key and attribute names. Will be called automatically when the # module is inherited. -- cgit v1.2.3 From 586a944ddd4d03e66dea1093306147594748037a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 16 Aug 2011 15:17:49 -0700 Subject: Tags with invalid names should also be stripped in order to prevent XSS attacks. Thanks Sascha Depold for the report. --- actionpack/lib/action_controller/vendor/html-scanner/html/node.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index 22b3243104..4e1f016431 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -156,7 +156,7 @@ module HTML #:nodoc: end closing = ( scanner.scan(/\//) ? :close : nil ) - return Text.new(parent, line, pos, content) unless name = scanner.scan(/[\w:-]+/) + return Text.new(parent, line, pos, content) unless name = scanner.scan(/[^\s!>\/]+/) name.downcase! unless closing -- cgit v1.2.3 From 31d38d37d394f6ebbac57ce48f465805edbfec04 Mon Sep 17 00:00:00 2001 From: dharmatech Date: Sat, 20 Aug 2011 00:07:34 -0500 Subject: ActionController::Redirecting : fix docs typo --- actionpack/lib/action_controller/metal/redirecting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index dee7eb1ec8..4f311a1cf5 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -45,7 +45,7 @@ module ActionController # integer, or a symbol representing the downcased, underscored and symbolized description. # Note that the status code must be a 3xx HTTP code, or redirection will not occur. # - # It is also possible to assign a flash message as part of the redirection. There are two special accessors for commonly used the flash names + # It is also possible to assign a flash message as part of the redirection. There are two special accessors for the commonly used flash names # +alert+ and +notice+ as well as a general purpose +flash+ bucket. # # Examples: -- cgit v1.2.3 From dfd03fdbd32d25ef0f70e40ab7cb3794b1ffe0c0 Mon Sep 17 00:00:00 2001 From: dharmatech Date: Sat, 20 Aug 2011 00:17:44 -0500 Subject: actionpack/lib/action_controller/base.rb: docs typo --- actionpack/lib/action_controller/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index ce56d8bc71..da93c988c4 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -63,7 +63,7 @@ module ActionController # # == Sessions # - # Sessions allows you to store objects in between requests. This is useful for objects that are not yet ready to be persisted, + # Sessions allow you to store objects in between requests. This is useful for objects that are not yet ready to be persisted, # such as a Signup object constructed in a multi-paged process, or objects that don't change much and are needed all the time, such # as a User object for a system that requires login. The session should not be used, however, as a cache for objects where it's likely # they could be changed unknowingly. It's usually too much work to keep it all synchronized -- something databases already excel at. -- cgit v1.2.3 From 7da70a431c3c122d3b9425472635bf8368363525 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 20 Aug 2011 23:49:57 +0530 Subject: params wrapper docs correction --- actionpack/lib/action_controller/metal/params_wrapper.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 2d8afc3a78..f24203db3a 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -9,10 +9,9 @@ module ActionController # Wraps parameters hash into nested hash. This will allow client to submit # POST request without having to specify a root element in it. # - # By default this functionality won't be enabled. You can enable - # it globally by setting +ActionController::Base.wrap_parameters+: - # - # ActionController::Base.wrap_parameters = [:json] + # This functionality is enabled in +config/initializers/wrap_parameters.rb+ + # and can be customized. If you are upgrading to Rails 3.1, this file will + # need to be created for the functionality to be enabled. # # You could also turn it on per controller by setting the format array to # non-empty array: -- cgit v1.2.3 From 14cf4b2e353f923155aab1ae0eaafed3c2924b12 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 23 Aug 2011 11:07:37 +0100 Subject: Don't modify params in place - fixes #2624 --- actionpack/lib/action_controller/test_case.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index c8cf04bb69..a38e5a46da 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -401,9 +401,7 @@ module ActionController def paramify_values(hash_or_array_or_value) case hash_or_array_or_value when Hash - hash_or_array_or_value.each do |key, value| - hash_or_array_or_value[key] = paramify_values(value) - end + Hash[hash_or_array_or_value.map{|key, value| [key, paramify_values(value)] }] when Array hash_or_array_or_value.map {|i| paramify_values(i)} when Rack::Test::UploadedFile @@ -416,7 +414,7 @@ module ActionController def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') # Ensure that numbers and symbols passed as params are converted to # proper params, as is the case when engaging rack. - paramify_values(parameters) + parameters = paramify_values(parameters) # Sanity check for required instance variables so we can give an # understandable error message. @@ -450,7 +448,7 @@ module ActionController @controller.params.merge!(parameters) build_request_uri(action, parameters) @controller.class.class_eval { include Testing } - @controller.recycle! + @controller.recycle! @controller.process_with_new_base_test(@request, @response) @assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {} @request.session.delete('flash') if @request.session['flash'].blank? -- cgit v1.2.3 From 68a13eded347248fb9d4c8ef7f0ed2af52bba994 Mon Sep 17 00:00:00 2001 From: David Majda Date: Tue, 23 Aug 2011 14:12:41 +0200 Subject: Make ActionController::TestCase#recycle! set @protocol to nil This ensures that the protocol does not get carried over when there are two or more requests in functional tests. This was a problem when e.g. the first request was HTTP and the second request was HTTPS. Closes #2654. Signed-off-by: Andrew White --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index a38e5a46da..40332da321 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -180,7 +180,7 @@ module ActionController @env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ } @symbolized_path_params = nil @method = @request_method = nil - @fullpath = @ip = @remote_ip = nil + @fullpath = @ip = @remote_ip = @protocol = nil @env['action_dispatch.request.query_parameters'] = {} @set_cookies ||= {} @set_cookies.update(Hash[cookie_jar.instance_variable_get("@set_cookies").map{ |k,o| [k,o[:value]] }]) -- cgit v1.2.3 From 8526f727cfadb49e629e7ac3a0bbcbf9a89ec3cd Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 28 Aug 2011 02:25:54 +0530 Subject: doc fixes --- actionpack/lib/action_controller/metal/params_wrapper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index f24203db3a..6acbb23907 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -6,30 +6,30 @@ require 'active_support/core_ext/module/anonymous' require 'action_dispatch/http/mime_types' module ActionController - # Wraps parameters hash into nested hash. This will allow client to submit - # POST request without having to specify a root element in it. + # Wraps the parameters hash into a nested hash. This will allow clients to submit + # POST requests without having to specify any root elements. # # This functionality is enabled in +config/initializers/wrap_parameters.rb+ - # and can be customized. If you are upgrading to Rails 3.1, this file will + # and can be customized. If you are upgrading to \Rails 3.1, this file will # need to be created for the functionality to be enabled. # # You could also turn it on per controller by setting the format array to - # non-empty array: + # a non-empty array: # # class UsersController < ApplicationController # wrap_parameters :format => [:json, :xml] # end # - # If you enable +ParamsWrapper+ for +:json+ format. Instead of having to + # If you enable +ParamsWrapper+ for +:json+ format, instead of having to # send JSON parameters like this: # # {"user": {"name": "Konata"}} # - # You can now just send a parameters like this: + # You can send parameters like this: # # {"name": "Konata"} # - # And it will be wrapped into a nested hash with the key name matching + # And it will be wrapped into a nested hash with the key name matching the # controller's name. For example, if you're posting to +UsersController+, # your new +params+ hash will look like this: # @@ -81,7 +81,7 @@ module ActionController # # ==== Examples # wrap_parameters :format => :xml - # # enables the parmeter wrapper for XML format + # # enables the parameter wrapper for XML format # # wrap_parameters :person # # wraps parameters into +params[:person]+ hash -- cgit v1.2.3 From bb4dedbc2cc7b96b95bf4519f56ed9624949a7ef Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 27 Aug 2011 15:34:33 -0700 Subject: deletes spurious arrow --- actionpack/lib/action_controller/metal/url_for.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 08132b1900..0b40b1fc4c 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -18,7 +18,7 @@ # @url = root_path # named route from the application. # end # end -# => +# module ActionController module UrlFor extend ActiveSupport::Concern -- cgit v1.2.3 From 19ec3c1ae6d0e0b452a4b2d92b4840abb23f4035 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Sat, 3 Sep 2011 23:13:40 +0400 Subject: fix helpers behavior description --- actionpack/lib/action_controller/metal/helpers.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index 2df0e9422c..bd515bba82 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -7,9 +7,12 @@ module ActionController # by default. # # In addition to using the standard template helpers provided, creating custom helpers to - # extract complicated logic or reusable functionality is strongly encouraged. By default, the controller will - # include a helper whose name matches that of the controller, e.g., MyController will automatically - # include MyHelper. + # extract complicated logic or reusable functionality is strongly encouraged. By default, each controller + # will include all helpers. + # + # In previous versions of \Rails the controller will include a helper whose + # name matches that of the controller, e.g., MyController will automatically + # include MyHelper. To return old behavior set +config.action_controller.include_all_helpers+ to +false+. # # Additional helpers can be specified using the +helper+ class method in ActionController::Base or any # controller which inherits from it. -- cgit v1.2.3 From 9b08afd2f4d501fb1710ba0ed4e19313093605c8 Mon Sep 17 00:00:00 2001 From: Milan Dobrota Date: Sun, 4 Sep 2011 10:44:08 -0500 Subject: if ... nil? is more expensive than unless --- actionpack/lib/action_controller/caching/sweeping.rb | 2 +- actionpack/lib/action_controller/metal/redirecting.rb | 2 +- actionpack/lib/action_controller/test_case.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb index 938a6ae81c..49cf70ec21 100644 --- a/actionpack/lib/action_controller/caching/sweeping.rb +++ b/actionpack/lib/action_controller/caching/sweeping.rb @@ -88,7 +88,7 @@ module ActionController #:nodoc: end def method_missing(method, *arguments, &block) - return if @controller.nil? + return unless @controller @controller.__send__(method, *arguments, &block) end end diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index 4f311a1cf5..f2dfb3833b 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -57,7 +57,7 @@ module ActionController # When using redirect_to :back, if there is no referrer, RedirectBackError will be raised. You may specify some fallback # behavior for this case by rescuing RedirectBackError. def redirect_to(options = {}, response_status = {}) #:doc: - raise ActionControllerError.new("Cannot redirect to nil!") if options.nil? + raise ActionControllerError.new("Cannot redirect to nil!") unless options raise AbstractController::DoubleRenderError if response_body self.status = _extract_redirect_to_status(options, response_status) diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 40332da321..a83fa74795 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -79,10 +79,10 @@ module ActionController "expecting but rendering with ", options, rendered.keys.join(', ')) assert_block(msg) do - if options.nil? - @templates.blank? - else + if options rendered.any? { |t,num| t.match(options) } + else + @templates.blank? end end when Hash -- cgit v1.2.3 From f6ced69a11cdff56c2e87b84e775ef09c6d999d1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 6 Sep 2011 17:25:20 -0700 Subject: Eliminate newlines in basic auth. fixes #2882 --- actionpack/lib/action_controller/metal/http_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 7420a5e7e9..264806cd36 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -145,7 +145,7 @@ module ActionController end def encode_credentials(user_name, password) - "Basic #{ActiveSupport::Base64.encode64("#{user_name}:#{password}")}" + "Basic #{ActiveSupport::Base64.encode64s("#{user_name}:#{password}")}" end def authentication_request(controller, realm) -- cgit v1.2.3 From 9821d982ff3786da8bda4da8e2c9118e5d1cd399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Hock=20Isaza?= Date: Tue, 6 Sep 2011 23:26:56 -0500 Subject: Fixing `record_key_for_dom_id` documentation. The default implementation joins everything with '_' and not with '-' --- actionpack/lib/action_controller/record_identifier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb index c11d676c5e..2036442cfe 100644 --- a/actionpack/lib/action_controller/record_identifier.rb +++ b/actionpack/lib/action_controller/record_identifier.rb @@ -67,7 +67,7 @@ module ActionController # This can be overwritten to customize the default generated string representation if desired. # If you need to read back a key from a dom_id in order to query for the underlying database record, # you should write a helper like 'person_record_from_dom_id' that will extract the key either based - # on the default implementation (which just joins all key attributes with '-') or on your own + # on the default implementation (which just joins all key attributes with '_') or on your own # overwritten version of the method. By default, this implementation passes the key string through a # 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. -- cgit v1.2.3 From 7fb99e5743d88c04357e09960d112376428a6faa Mon Sep 17 00:00:00 2001 From: Mike Dillon Date: Fri, 2 Sep 2011 08:22:29 -0700 Subject: Change log level for CSRF token verification warning --- actionpack/lib/action_controller/metal/request_forgery_protection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index 4d016271ea..bc22e39efb 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -74,7 +74,7 @@ module ActionController #:nodoc: # The actual before_filter that is used. Modify this to change how you handle unverified requests. def verify_authenticity_token unless verified_request? - logger.debug "WARNING: Can't verify CSRF token authenticity" if logger + logger.warn "WARNING: Can't verify CSRF token authenticity" if logger handle_unverified_request end end -- cgit v1.2.3 From e8987c30d0dc3ae5903a6d3a6e293641759b6fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 23 Sep 2011 16:46:33 +0200 Subject: Use safe_constantize where possible. --- actionpack/lib/action_controller/metal/params_wrapper.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 6acbb23907..e0d8e1c992 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -141,19 +141,16 @@ module ActionController # try to find Foo::Bar::User, Foo::User and finally User. def _default_wrap_model #:nodoc: return nil if self.anonymous? - model_name = self.name.sub(/Controller$/, '').singularize begin - model_klass = model_name.constantize - rescue NameError, ArgumentError => e - if e.message =~ /is not missing constant|uninitialized constant #{model_name}/ + if model_klass = model_name.safe_constantize + model_klass + else namespaces = model_name.split("::") namespaces.delete_at(-2) break if namespaces.last == model_name model_name = namespaces.join("::") - else - raise end end until model_klass -- cgit v1.2.3 From 1bd88fdafd9cd0c1c83e8bf41020d0c251cb3108 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 27 Sep 2011 23:39:52 +0400 Subject: add missing require to html sanitizer --- actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb index eaefdc0f15..af06bffa16 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb @@ -1,4 +1,5 @@ require 'set' +require 'cgi' require 'active_support/core_ext/class/attribute' module HTML -- cgit v1.2.3 From 0eb80fabdd46baaf06e27697cfbd2cd8900d7f67 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Mon, 3 Oct 2011 10:01:52 +0400 Subject: use safe_constantize instead constantize in AC::TestCase --- actionpack/lib/action_controller/test_case.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index a83fa74795..343beae1bb 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -352,9 +352,7 @@ module ActionController end def determine_default_controller_class(name) - name.sub(/Test$/, '').constantize - rescue NameError - nil + name.sub(/Test$/, '').safe_constantize end def prepare_controller_class(new_class) -- cgit v1.2.3 From 8e946daf6957b46744a90d25266b0ec5e8537079 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Mon, 3 Oct 2011 10:19:15 +0400 Subject: normalize arg for AC::TestCase tests class method --- actionpack/lib/action_controller/test_case.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index a83fa74795..964ec6d5ae 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -333,9 +333,21 @@ module ActionController module ClassMethods # Sets the controller class name. Useful if the name can't be inferred from test class. - # Expects +controller_class+ as a constant. Example: tests WidgetController. + # Normalizes +controller_class+ before using. Examples: + # + # tests WidgetController + # tests :widget + # tests 'widget' + # def tests(controller_class) - self.controller_class = controller_class + case controller_class + when String, Symbol + self.controller_class = "#{controller_class.to_s.underscore}_controller".camelize.constantize + when Class + self.controller_class = controller_class + else + raise ArgumentError, "controller class must be a String, Symbol, or Class" + end end def controller_class=(new_class) -- cgit v1.2.3 From 22b6e829dc9f07036399e52f0d352e6723c1113b Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Sat, 8 Oct 2011 10:12:58 +0400 Subject: Fix params hash example in AC::Base comment --- actionpack/lib/action_controller/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index da93c988c4..98bfe72fef 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -50,7 +50,7 @@ module ActionController # # All request parameters, whether they come from a GET or POST request, or from the URL, are available through the params method # which returns a hash. For example, an action that was performed through /posts?category=All&limit=5 will include - # { "category" => "All", "limit" => 5 } in params. + # { "category" => "All", "limit" => "5" } in params. # # It's also possible to construct multi-dimensional parameter hashes by specifying keys using brackets, such as: # -- cgit v1.2.3 From a4515b60e316d52a6ac2902886b117588702e20b Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Sat, 8 Oct 2011 11:01:31 +0400 Subject: Remove unnecessary dup in expire_page --- actionpack/lib/action_controller/caching/pages.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index 496390402b..957bb7de6b 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -122,7 +122,7 @@ module ActionController #:nodoc: if options.is_a?(Hash) if options[:action].is_a?(Array) - options[:action].dup.each do |action| + options[:action].each do |action| self.class.expire_page(url_for(options.merge(:only_path => true, :action => action))) end else -- cgit v1.2.3 From d68f27e9b184a8e7e4ce71db11874a6b36ea1edc Mon Sep 17 00:00:00 2001 From: Ben Scheirman Date: Sat, 8 Oct 2011 18:38:02 -0500 Subject: accept optional :host parameter to force_ssl --- actionpack/lib/action_controller/metal/force_ssl.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/force_ssl.rb b/actionpack/lib/action_controller/metal/force_ssl.rb index ed693c5967..0fd42f9d8a 100644 --- a/actionpack/lib/action_controller/metal/force_ssl.rb +++ b/actionpack/lib/action_controller/metal/force_ssl.rb @@ -24,12 +24,15 @@ module ActionController # * only - The callback should be run only for this action # * except - The callback should be run for all actions except this action def force_ssl(options = {}) + host = options.delete(:host) before_filter(options) do if !request.ssl? && !Rails.env.development? - redirect_to :protocol => 'https://', :status => :moved_permanently + redirect_options = {:protocol => 'https://', :status => :moved_permanently} + redirect_options.merge!(:host => host) if host + redirect_to redirect_options end end end end end -end \ No newline at end of file +end -- cgit v1.2.3 From a0a68ecbb22dacf5111198e72e3a803e7c965881 Mon Sep 17 00:00:00 2001 From: Denis Odorcic Date: Mon, 10 Oct 2011 01:42:12 -0400 Subject: JSON responder should return errors with :error root --- actionpack/lib/action_controller/metal/responder.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index 3794e277f6..c7827309dd 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -253,7 +253,7 @@ module ActionController #:nodoc: end def display_errors - controller.render format => resource.errors, :status => :unprocessable_entity + controller.render format => resource_errors, :status => :unprocessable_entity end # Check whether the resource has errors. @@ -286,5 +286,13 @@ module ActionController #:nodoc: def empty_json_resource "{}" end + + def resource_errors + respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors + end + + def json_resource_errors + {:errors => resource.errors} + end end end -- cgit v1.2.3 From 419d4c09dfcc5cbd898ce52d779603c6a29ac3bc Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 11 Oct 2011 12:31:27 +0400 Subject: Add ActionController#head example --- actionpack/lib/action_controller/metal/head.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb index 8abcad55a2..a618533d09 100644 --- a/actionpack/lib/action_controller/metal/head.rb +++ b/actionpack/lib/action_controller/metal/head.rb @@ -9,6 +9,8 @@ module ActionController # # head :created, :location => person_path(@person) # + # head :created, :location => @person + # # It can also be used to return exceptional conditions: # # return head(:method_not_allowed) unless request.post? -- cgit v1.2.3 From 50d262f52ab39680b031e485b89b64875c08358e Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 11 Oct 2011 12:48:03 +0400 Subject: Support symbol and string actions in AC#respond_to options --- actionpack/lib/action_controller/metal/mime_responds.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index f10287afb4..00bd1706e7 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -42,8 +42,8 @@ module ActionController #:nodoc: def respond_to(*mimes) options = mimes.extract_options! - only_actions = Array(options.delete(:only)) - except_actions = Array(options.delete(:except)) + only_actions = Array(options.delete(:only)).map(&:to_s) + except_actions = Array(options.delete(:except)).map(&:to_s) new = mimes_for_respond_to.dup mimes.each do |mime| @@ -245,7 +245,7 @@ module ActionController #:nodoc: # current action. # def collect_mimes_from_class_level #:nodoc: - action = action_name.to_sym + action = action_name.to_s self.class.mimes_for_respond_to.keys.select do |mime| config = self.class.mimes_for_respond_to[mime] -- cgit v1.2.3 From 4a025f0080d05f6c27518a84cde0b93fa3821345 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 12 Oct 2011 15:44:19 +0900 Subject: status is a number in Rails 3 --- actionpack/lib/action_controller/metal/data_streaming.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb index 5e077dd7bd..0670a58d97 100644 --- a/actionpack/lib/action_controller/metal/data_streaming.rb +++ b/actionpack/lib/action_controller/metal/data_streaming.rb @@ -34,7 +34,7 @@ module ActionController #:nodoc: # If no content type is registered for the extension, default type 'application/octet-stream' will be used. # * :disposition - specifies whether the file will be shown inline or downloaded. # Valid values are 'inline' and 'attachment' (default). - # * :status - specifies the status code to send with the response. Defaults to '200 OK'. + # * :status - specifies the status code to send with the response. Defaults to 200. # * :url_based_filename - set to +true+ if you want the browser guess the filename from # the URL, which is necessary for i18n filenames on certain browsers # (setting :filename overrides this option). @@ -92,7 +92,7 @@ module ActionController #:nodoc: # If no content type is registered for the extension, default type 'application/octet-stream' will be used. # * :disposition - specifies whether the file will be shown inline or downloaded. # Valid values are 'inline' and 'attachment' (default). - # * :status - specifies the status code to send with the response. Defaults to '200 OK'. + # * :status - specifies the status code to send with the response. Defaults to 200. # # Generic data download: # -- cgit v1.2.3 From f247c5f81175fc160de6be906ef87316f0528f38 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Sat, 15 Oct 2011 11:34:33 +0400 Subject: Update AC::RecordIdentifier example --- actionpack/lib/action_controller/record_identifier.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb index 2036442cfe..9c38ff44d8 100644 --- a/actionpack/lib/action_controller/record_identifier.rb +++ b/actionpack/lib/action_controller/record_identifier.rb @@ -14,9 +14,9 @@ module ActionController # <% end %> # # # controller - # def destroy + # def update # post = Post.find(params[:id]) - # post.destroy + # post.update_attributes(params[:post]) # # redirect_to(post) # Calls polymorphic_url(post) which in turn calls post_url(post) # end -- cgit v1.2.3 From 8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe Mon Sep 17 00:00:00 2001 From: Jose and Yehuda Date: Mon, 26 Sep 2011 18:48:19 -0400 Subject: Initial commit of serializer support --- actionpack/lib/action_controller/base.rb | 1 + .../lib/action_controller/metal/serialization.rb | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 actionpack/lib/action_controller/metal/serialization.rb (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 98bfe72fef..cfb9cf5e6e 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -190,6 +190,7 @@ module ActionController Redirecting, Rendering, Renderers::All, + Serialization, ConditionalGet, RackDelegation, SessionManagement, diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb new file mode 100644 index 0000000000..9bb665a9ae --- /dev/null +++ b/actionpack/lib/action_controller/metal/serialization.rb @@ -0,0 +1,26 @@ +module ActionController + module Serialization + extend ActiveSupport::Concern + + include ActionController::Renderers + + included do + class_attribute :_serialization_scope + end + + def serialization_scope + send(_serialization_scope) + end + + def _render_option_json(json, options) + json = json.active_model_serializer.new(json, serialization_scope) if json.respond_to?(:active_model_serializer) + super + end + + module ClassMethods + def serialization_scope(scope) + self._serialization_scope = scope + end + end + end +end -- cgit v1.2.3 From a4c04a43cc96d9c94b7a5ecd5c7458fdc2f8617f Mon Sep 17 00:00:00 2001 From: Jose and Yehuda Date: Mon, 26 Sep 2011 18:57:49 -0400 Subject: Refactor to make renderers a Set --- actionpack/lib/action_controller/metal/renderers.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 0ad9dbeda9..6e9ce450ac 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/object/blank' +require 'set' module ActionController # See Renderers.add @@ -12,16 +13,13 @@ module ActionController included do class_attribute :_renderers - self._renderers = {}.freeze + self._renderers = Set.new.freeze end module ClassMethods def use_renderers(*args) - new = _renderers.dup - args.each do |key| - new[key] = RENDERERS[key] - end - self._renderers = new.freeze + renderers = _renderers + args + self._renderers = renderers.freeze end alias use_renderer use_renderers end @@ -31,10 +29,10 @@ module ActionController end def _handle_render_options(options) - _renderers.each do |name, value| - if options.key?(name.to_sym) + _renderers.each do |name| + if options.key?(name) _process_options(options) - return send("_render_option_#{name}", options.delete(name.to_sym), options) + return send("_render_option_#{name}", options.delete(name), options) end end nil @@ -42,7 +40,7 @@ module ActionController # Hash of available renderers, mapping a renderer name to its proc. # Default keys are :json, :js, :xml. - RENDERERS = {} + RENDERERS = Set.new # Adds a new renderer to call within controller actions. # A renderer is invoked by passing its name as an option to @@ -79,7 +77,7 @@ module ActionController # ActionController::MimeResponds#respond_with def self.add(key, &block) define_method("_render_option_#{key}", &block) - RENDERERS[key] = block + RENDERERS << key.to_sym end module All -- cgit v1.2.3 From 8f473dc9aea2099e6e7e47c929c6a9cec02c7902 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Sat, 15 Oct 2011 23:54:26 +0400 Subject: HTMl -> HTML: html scanner comment fix --- actionpack/lib/action_controller/vendor/html-scanner/html/document.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/document.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/document.rb index 7fa3aead82..386820300a 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/document.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/document.rb @@ -4,7 +4,7 @@ require 'html/selector' require 'html/sanitizer' module HTML #:nodoc: - # A top-level HTMl document. You give it a body of text, and it will parse that + # A top-level HTML document. You give it a body of text, and it will parse that # text into a tree of nodes. class Document #:nodoc: -- cgit v1.2.3 From a7641054d80a285c5da85d80b8678d899c27cd1a Mon Sep 17 00:00:00 2001 From: Nick Howard Date: Tue, 25 Oct 2011 10:39:20 -0600 Subject: add namespacing when referring to ActionController::RedirectBackError --- actionpack/lib/action_controller/metal/redirecting.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index f2dfb3833b..0355c9f458 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -54,8 +54,8 @@ module ActionController # redirect_to post_url(@post), :status => 301, :flash => { :updated_post_id => @post.id } # redirect_to { :action=>'atom' }, :alert => "Something serious happened" # - # When using redirect_to :back, if there is no referrer, RedirectBackError will be raised. You may specify some fallback - # behavior for this case by rescuing RedirectBackError. + # When using redirect_to :back, if there is no referrer, ActionController::RedirectBackError will be raised. You may specify some fallback + # behavior for this case by rescuing ActionController::RedirectBackError. def redirect_to(options = {}, response_status = {}) #:doc: raise ActionControllerError.new("Cannot redirect to nil!") unless options raise AbstractController::DoubleRenderError if response_body -- cgit v1.2.3 From 80768b739ed7e2053d85a01dd5fa60bde67aad9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 26 Oct 2011 09:31:56 +0200 Subject: Responders now return 204 No Content for API requests without a response body (as in the new scaffold) --- .../lib/action_controller/metal/responder.rb | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index c7827309dd..b932302a60 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -202,10 +202,8 @@ module ActionController #:nodoc: display resource elsif post? display resource, :status => :created, :location => api_location - elsif has_empty_resource_definition? - display empty_resource, :status => :ok else - head :ok + head :no_content end end @@ -269,24 +267,6 @@ module ActionController #:nodoc: @action ||= ACTIONS_FOR_VERBS[request.request_method_symbol] end - # Check whether resource needs a specific definition of empty resource to be valid - # - def has_empty_resource_definition? - respond_to?("empty_#{format}_resource") - end - - # Delegate to proper empty resource method - # - def empty_resource - send("empty_#{format}_resource") - end - - # Return a valid empty JSON resource - # - def empty_json_resource - "{}" - end - def resource_errors respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors end -- cgit v1.2.3 From 6cbe4223a77d7ea364b4d2dc46cec6a0c58c9537 Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Sat, 30 Jul 2011 00:49:36 -0400 Subject: Ensure that the format isn't applied twice to the cache key, else it becomes impossible to target with expire_action. --- actionpack/lib/action_controller/caching/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 0031d2701f..f6b23e4efc 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -175,7 +175,7 @@ module ActionController #:nodoc: private def normalize!(path) path << 'index' if path[-1] == ?/ - path << ".#{extension}" if extension and !path.ends_with?(extension) + path << ".#{extension}" if extension and !path.split('?').first.try(:ends_with?, ".#{extension}") URI.parser.unescape(path) end end -- cgit v1.2.3 From 62a86748ae8e6a43c20e917a963a614a02098a58 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 31 Oct 2011 15:17:16 -0400 Subject: this should never return nil, so no use for "try" --- actionpack/lib/action_controller/caching/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index f6b23e4efc..f988de39dd 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -175,7 +175,7 @@ module ActionController #:nodoc: private def normalize!(path) path << 'index' if path[-1] == ?/ - path << ".#{extension}" if extension and !path.split('?').first.try(:ends_with?, ".#{extension}") + path << ".#{extension}" if extension and !path.split('?').first.ends_with?(".#{extension}") URI.parser.unescape(path) end end -- cgit v1.2.3 From cc3e738d89cc5a433473559c3f70e98c08f646de Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 7 Nov 2011 16:24:54 +0900 Subject: Fix AC::Metal#response_body= to store same value on Ruby 1.8 and 1.9 This was because String#respond_to?(:each) differs in 1.8 and 1.9 --- actionpack/lib/action_controller/metal.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 0133b2ecbc..125dbf6bb5 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -182,7 +182,13 @@ module ActionController end def response_body=(val) - body = val.nil? ? nil : (val.respond_to?(:each) ? val : [val]) + body = if val.is_a?(String) + [val] + elsif val.nil? || val.respond_to?(:each) + val + else + [val] + end super body end -- cgit v1.2.3 From 6ac56ac93bd9e8a3e003f29eff2816218f0e5db6 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 7 Nov 2011 17:58:03 +0530 Subject: fix incorrect code example --- actionpack/lib/action_controller/metal/mime_responds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 00bd1706e7..ca383be76b 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -182,7 +182,7 @@ module ActionController #:nodoc: # # def index # @people = Person.all - # respond_with(@person) + # respond_with(@people) # end # end # -- cgit v1.2.3 From cf0a96bc6a20d58047934d6d9b78092228cc81d4 Mon Sep 17 00:00:00 2001 From: Ivan Evtukhovich Date: Mon, 7 Nov 2011 18:57:55 +0400 Subject: DrbStore removed from cache backends --- actionpack/lib/action_controller/caching.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 14137f2886..112573a38d 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -24,7 +24,6 @@ module ActionController #:nodoc: # # config.action_controller.cache_store = :memory_store # config.action_controller.cache_store = :file_store, "/path/to/cache/directory" - # config.action_controller.cache_store = :drb_store, "druby://localhost:9192" # config.action_controller.cache_store = :mem_cache_store, "localhost" # config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new("localhost:11211") # config.action_controller.cache_store = MyOwnStore.new("parameter") -- cgit v1.2.3 From a766d834a73efe6a59cbfaf4f25ab73c088465d7 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 11 Nov 2011 19:37:54 +0200 Subject: Fix wording and minor typos in the Responder RDoc --- actionpack/lib/action_controller/metal/responder.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index c7827309dd..2f19c76bff 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -84,8 +84,8 @@ module ActionController #:nodoc: # # === Custom options # - # respond_with also allow you to pass options that are forwarded - # to the underlying render call. Those options are only applied success + # respond_with also allows you to pass options that are forwarded + # to the underlying render call. Those options are only applied for success # scenarios. For instance, you can do the following in the create method above: # # def create @@ -95,7 +95,7 @@ module ActionController #:nodoc: # respond_with(@project, @task, :status => 201) # end # - # This will return status 201 if the task was saved with success. If not, + # This will return status 201 if the task was saved successfully. If not, # it will simply ignore the given options and return status 422 and the # resource errors. To customize the failure scenario, you can pass a # a block to respond_with: @@ -224,7 +224,7 @@ module ActionController #:nodoc: alias :navigation_location :resource_location alias :api_location :resource_location - # If a given response block was given, use it, otherwise call render on + # If a response block was given, use it, otherwise call render on # controller. # def default_render -- cgit v1.2.3 From a9e8cf78fda696738f63e726796f6232c3751603 Mon Sep 17 00:00:00 2001 From: lest Date: Mon, 21 Nov 2011 20:13:54 +0300 Subject: add ActionController::Metal#show_detailed_exceptions? --- actionpack/lib/action_controller/metal.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 125dbf6bb5..d5f150e7c9 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -196,10 +196,15 @@ module ActionController @_request = request @_env = request.env @_env['action_controller.instance'] = self + @_env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions? process(name) to_a end + def show_detailed_exceptions? + defined?(Rails.application) && Rails.application.config.consider_all_requests_local || request.local? + end + def to_a #:nodoc: response ? response.to_a : [status, headers, response_body] end -- cgit v1.2.3 From 5bcd119b8d9bb6d88c949956de1ce13c2673b877 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 22 Nov 2011 13:34:13 +0300 Subject: move show_detailed_exceptions? to Rescue module --- actionpack/lib/action_controller/metal.rb | 5 ----- actionpack/lib/action_controller/metal/rescue.rb | 10 ++++++++++ actionpack/lib/action_controller/railtie.rb | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index d5f150e7c9..125dbf6bb5 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -196,15 +196,10 @@ module ActionController @_request = request @_env = request.env @_env['action_controller.instance'] = self - @_env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions? process(name) to_a end - def show_detailed_exceptions? - defined?(Rails.application) && Rails.application.config.consider_all_requests_local || request.local? - end - def to_a #:nodoc: response ? response.to_a : [status, headers, response_body] end diff --git a/actionpack/lib/action_controller/metal/rescue.rb b/actionpack/lib/action_controller/metal/rescue.rb index eb037aa1b0..736ff5b31c 100644 --- a/actionpack/lib/action_controller/metal/rescue.rb +++ b/actionpack/lib/action_controller/metal/rescue.rb @@ -3,6 +3,11 @@ module ActionController #:nodoc: extend ActiveSupport::Concern include ActiveSupport::Rescuable + included do + config_accessor :consider_all_requests_local + self.consider_all_requests_local = false if consider_all_requests_local.nil? + end + def rescue_with_handler(exception) if (exception.respond_to?(:original_exception) && (orig_exception = exception.original_exception) && @@ -12,10 +17,15 @@ module ActionController #:nodoc: super(exception) end + def show_detailed_exceptions? + consider_all_requests_local || request.local? + end + private def process_action(*args) super rescue Exception => exception + request.env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions? rescue_with_handler(exception) || raise(exception) end end diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index f0c29825ba..de7b837ecc 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -21,6 +21,8 @@ module ActionController paths = app.config.paths options = app.config.action_controller + options.consider_all_requests_local ||= app.config.consider_all_requests_local + options.assets_dir ||= paths["public"].first options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first -- cgit v1.2.3 From fd86a1b6b068df87164d5763bdcd4a323a1e76f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 19:06:45 +0000 Subject: Rely on a public contract between railties instead of accessing railtie methods directly. --- actionpack/lib/action_controller/railties/paths.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/railties/paths.rb b/actionpack/lib/action_controller/railties/paths.rb index 699c44c62c..bbe63149ad 100644 --- a/actionpack/lib/action_controller/railties/paths.rb +++ b/actionpack/lib/action_controller/railties/paths.rb @@ -6,13 +6,14 @@ module ActionController define_method(:inherited) do |klass| super(klass) - if namespace = klass.parents.detect {|m| m.respond_to?(:_railtie) } - paths = namespace._railtie.paths["app/helpers"].existent + if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) } + paths = namespace.railtie_helpers_paths else - paths = app.config.helpers_paths + paths = app.helpers_paths end klass.helpers_path = paths + if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers klass.helper :all end -- cgit v1.2.3 From 7fcc8c0a1f38c77b12cb6ffe81fb2887e6c60b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 23:45:27 +0000 Subject: Rely solely on active_model_serializer and remove the fancy constant lookup. --- actionpack/lib/action_controller/metal/serialization.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb index 9bb665a9ae..9fb49f512e 100644 --- a/actionpack/lib/action_controller/metal/serialization.rb +++ b/actionpack/lib/action_controller/metal/serialization.rb @@ -13,7 +13,9 @@ module ActionController end def _render_option_json(json, options) - json = json.active_model_serializer.new(json, serialization_scope) if json.respond_to?(:active_model_serializer) + if json.respond_to?(:active_model_serializer) && (serializer = json.active_model_serializer) + json = serializer.new(json, serialization_scope) + end super end -- cgit v1.2.3 From 696d01f7f4a8ed787924a41cce6df836cd73c46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 09:49:54 +0000 Subject: Add docs to serializers. Update CHANGELOGs. --- .../lib/action_controller/metal/serialization.rb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb index 9fb49f512e..628d5996d7 100644 --- a/actionpack/lib/action_controller/metal/serialization.rb +++ b/actionpack/lib/action_controller/metal/serialization.rb @@ -1,4 +1,27 @@ module ActionController + # Action Controller Serialization + # + # Overrides render :json to check if the given object implements +active_model_serializer+ + # as a method. If so, use the returned serializer instead of calling +to_json+ in the object. + # + # This module also provides a serialization_scope method that allows you to configure the + # +serialization_scope+ of the serializer. Most apps will likely set the +serialization_scope+ + # to the current user: + # + # class ApplicationController < ActionController::Base + # serialization_scope :current_user + # end + # + # If you need more complex scope rules, you can simply override the serialization_scope: + # + # class ApplicationController < ActionController::Base + # private + # + # def serialization_scope + # current_user + # end + # end + # module Serialization extend ActiveSupport::Concern -- cgit v1.2.3 From 0a4035b12a6c59253cb60f9e3456513c6a6a9d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 19:29:39 +0000 Subject: Revert the serializers API as other alternatives are now also under discussion --- .../lib/action_controller/metal/serialization.rb | 51 ---------------------- 1 file changed, 51 deletions(-) delete mode 100644 actionpack/lib/action_controller/metal/serialization.rb (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb deleted file mode 100644 index 628d5996d7..0000000000 --- a/actionpack/lib/action_controller/metal/serialization.rb +++ /dev/null @@ -1,51 +0,0 @@ -module ActionController - # Action Controller Serialization - # - # Overrides render :json to check if the given object implements +active_model_serializer+ - # as a method. If so, use the returned serializer instead of calling +to_json+ in the object. - # - # This module also provides a serialization_scope method that allows you to configure the - # +serialization_scope+ of the serializer. Most apps will likely set the +serialization_scope+ - # to the current user: - # - # class ApplicationController < ActionController::Base - # serialization_scope :current_user - # end - # - # If you need more complex scope rules, you can simply override the serialization_scope: - # - # class ApplicationController < ActionController::Base - # private - # - # def serialization_scope - # current_user - # end - # end - # - module Serialization - extend ActiveSupport::Concern - - include ActionController::Renderers - - included do - class_attribute :_serialization_scope - end - - def serialization_scope - send(_serialization_scope) - end - - def _render_option_json(json, options) - if json.respond_to?(:active_model_serializer) && (serializer = json.active_model_serializer) - json = serializer.new(json, serialization_scope) - end - super - end - - module ClassMethods - def serialization_scope(scope) - self._serialization_scope = scope - end - end - end -end -- cgit v1.2.3 From b6916e0b925d4c8b4487d574fe07b11440f2ec5e Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 25 Nov 2011 15:06:30 -0800 Subject: removes a Serialization constant left in the previous revert --- actionpack/lib/action_controller/base.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index cfb9cf5e6e..98bfe72fef 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -190,7 +190,6 @@ module ActionController Redirecting, Rendering, Renderers::All, - Serialization, ConditionalGet, RackDelegation, SessionManagement, -- cgit v1.2.3 From 38ab982cfff98570b5f12933cff489364845789c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 30 Nov 2011 09:52:52 +0100 Subject: Log 'Filter chain halted as CALLBACKNAME rendered or redirected' every time a before callback halts. --- actionpack/lib/action_controller/log_subscriber.rb | 4 ++++ actionpack/lib/action_controller/metal/instrumentation.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/log_subscriber.rb b/actionpack/lib/action_controller/log_subscriber.rb index 35e29398e6..8666ecc9c8 100644 --- a/actionpack/lib/action_controller/log_subscriber.rb +++ b/actionpack/lib/action_controller/log_subscriber.rb @@ -29,6 +29,10 @@ module ActionController info(message) end + def halted_callback(event) + info "Filter chain halted as #{event.payload[:filter]} rendered or redirected" + end + def send_file(event) message = "Sent file %s" message << " (%.1fms)" diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 777a0ab343..640ebf5f00 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -64,7 +64,12 @@ module ActionController end end - protected + private + + # A hook invoked everytime a before callback is halted. + def halted_callback_hook(filter) + ActiveSupport::Notifications.instrument("halted_callback.action_controller", :filter => filter) + end # A hook which allows you to clean up any time taken into account in # views wrongly, like database querying time. -- cgit v1.2.3