From 5b92dcb6757e90da316bd0c7a8472b9fa737f268 Mon Sep 17 00:00:00 2001 From: lifo Date: Fri, 17 Apr 2009 14:28:46 +0100 Subject: Merge docrails --- actionpack/lib/action_controller/caching.rb | 2 +- actionpack/lib/action_controller/caching/actions.rb | 2 +- actionpack/lib/action_view/helpers/date_helper.rb | 6 +++--- actionpack/lib/action_view/helpers/form_tag_helper.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 80d13e25f1..ffd8081edc 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -13,7 +13,7 @@ module ActionController #:nodoc: # # == Caching stores # - # All the caching stores from ActiveSupport::Cache is available to be used as backends for Action Controller caching. This setting only + # All the caching stores from ActiveSupport::Cache are available to be used as backends for Action Controller caching. This setting only # affects action and fragment caching as page caching is always written to disk. # # Configuration examples (MemoryStore is the default): diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 87b5029e57..b99feddf77 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -134,7 +134,7 @@ module ActionController #:nodoc: end end - # When true, infer_extension will look up the cache path extension from the request's path & format. + # If +infer_extension+ is true, the cache path extension is looked up from the request's path & format. # This is desirable when reading and writing the cache, but not when expiring the cache - # expire_action should expire the same files regardless of the request format. def initialize(controller, options = {}, infer_extension = true) diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index c74909a360..72fe9a3232 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -106,8 +106,8 @@ module ActionView alias_method :distance_of_time_in_words_to_now, :time_ago_in_words # Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based - # attribute (identified by +method+) on an object assigned to the template (identified by +object+). You can - # the output in the +options+ hash. + # attribute (identified by +method+) on an object assigned to the template (identified by +object+). + # # # ==== Options # * :use_month_numbers - Set to true if you want to use month numbers rather than month names (e.g. @@ -232,7 +232,7 @@ module ActionView # Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a # specified datetime-based attribute (identified by +method+) on an object assigned to the template (identified - # by +object+). Examples: + # by +object+). # # If anything is passed in the html_options hash it will be applied to every select tag in the set. # diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 6d39a53adc..daf38fe3da 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -406,7 +406,7 @@ module ActionView # legend will become the fieldset's title (optional as per W3C). # options accept the same values as tag. # - # === Examples + # ==== Examples # <% field_set_tag do %> #

<%= text_field_tag 'name' %>

# <% end %> -- cgit v1.2.3 From df42d26f990cd013c8d80505a9a92537fbcaa4bf Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 17 Apr 2009 18:34:49 -0500 Subject: Rename render_to_string to render_to_body since it may return any Rack-compatible body, not just strings --- actionpack/lib/action_controller/abstract/renderer.rb | 6 +++--- actionpack/lib/action_controller/new_base/base.rb | 2 +- actionpack/lib/action_controller/new_base/layouts.rb | 4 ++-- actionpack/lib/action_controller/new_base/renderer.rb | 8 ++++---- actionpack/test/abstract_controller/abstract_controller_test.rb | 4 ++-- actionpack/test/abstract_controller/layouts_test.rb | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index 68c3b07b84..eb248652a8 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -17,7 +17,7 @@ module AbstractController end def render(options = {}) - self.response_body = render_to_string(options) + self.response_body = render_to_body(options) end # Raw rendering of a template. @@ -26,7 +26,7 @@ module AbstractController # @option _layout The relative path to the layout template to use # # :api: plugin - def render_to_string(options = {}) + def render_to_body(options = {}) name = options[:_template_name] || action_name template = options[:_template] || view_paths.find_by_parts(name.to_s, formats, options[:_prefix]) @@ -55,4 +55,4 @@ module AbstractController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 0400ddbf7a..1d2cd8428c 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -58,4 +58,4 @@ module ActionController response.to_a end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb index 149847c968..a8e0809ac6 100644 --- a/actionpack/lib/action_controller/new_base/layouts.rb +++ b/actionpack/lib/action_controller/new_base/layouts.rb @@ -9,7 +9,7 @@ module ActionController end end - def render_to_string(options) + def render_to_body(options) # render :text => ..., :layout => ... # or # render :anything_else @@ -34,4 +34,4 @@ module ActionController end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index 044c15f409..ed34c46aed 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -8,7 +8,7 @@ module ActionController end def render(action, options = {}) - # TODO: Move this into #render_to_string + # TODO: Move this into #render_to_body if action.is_a?(Hash) options, action = action, nil else @@ -17,10 +17,10 @@ module ActionController _process_options(options) - self.response_body = render_to_string(options) + self.response_body = render_to_body(options) end - def render_to_string(options) + def render_to_body(options) unless options.is_a?(Hash) options = {:action => options} end @@ -59,4 +59,4 @@ module ActionController end end end -end \ No newline at end of file +end diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 6d33888821..8763ded57e 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -134,7 +134,7 @@ module AbstractController self.class.layout(formats) end - def render_to_string(options = {}) + def render_to_body(options = {}) options[:_layout] = options[:layout] || _layout super end @@ -223,4 +223,4 @@ module AbstractController end end -end \ No newline at end of file +end diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb index 5dd68ec28e..3d4570bfef 100644 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ b/actionpack/test/abstract_controller/layouts_test.rb @@ -23,7 +23,7 @@ module AbstractControllerTests def controller_path() self.class.controller_path end - def render_to_string(options) + def render_to_body(options) options[:_layout] = _default_layout super end @@ -229,4 +229,4 @@ module AbstractControllerTests end end end -end \ No newline at end of file +end -- cgit v1.2.3 From 1414e2afbba0ab116632ecabf8ed92ddf09dcba4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 17 Apr 2009 18:36:28 -0500 Subject: Don't set Content-Length in Base#response_body= since body may be any Rack-compatible body. Leave it up to the content length middleware. --- actionpack/lib/action_controller/new_base/base.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 1d2cd8428c..08e7a1a0e7 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -42,7 +42,6 @@ module ActionController # :api: plugin def response_body=(body) - @_response["Content-Length"] = body.length @_response.body = body end -- cgit v1.2.3 From 8423bb6a684fd68461faab87149a5bdfea61f43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 17 Apr 2009 19:35:03 -0500 Subject: Improve rewindable input test coverage so tests fail when you remove the middleware Signed-off-by: Joshua Peek --- actionpack/test/dispatch/request/multipart_params_parsing_test.rb | 3 +-- actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 2f409f020d..33c909aad9 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -206,8 +206,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest end def call(env) - req = Rack::Request.new(env) - req.params # Parse params + env['rack.input'].read @app.call(env) end end diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 51a660f614..44d13797f0 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -150,8 +150,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest end def call(env) - req = Rack::Request.new(env) - req.params # Parse params + env['rack.input'].read @app.call(env) end end -- cgit v1.2.3 From a22a778f860032b9d6bf3a8b19d0b22fc174550c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 17 Apr 2009 21:33:09 -0500 Subject: render_for_text pushes a body part instead of replacing the whole body --- actionpack/lib/action_controller/base/responder.rb | 21 +++++++++++---------- actionpack/lib/action_controller/testing/process.rb | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/base/responder.rb b/actionpack/lib/action_controller/base/responder.rb index 989f82444b..1aee980da6 100644 --- a/actionpack/lib/action_controller/base/responder.rb +++ b/actionpack/lib/action_controller/base/responder.rb @@ -5,18 +5,19 @@ module ActionController end private - def render_for_text(text = nil, append_response = false) #:nodoc: + def render_for_text(text) #:nodoc: @performed_render = true - if append_response - response.body ||= '' - response.body << text.to_s - else - response.body = case text - when Proc then text - when nil then " " # Safari doesn't pass the headers of the return if the response is zero length - else text.to_s + case text + when Proc + response.body = text + when nil + # Safari 2 doesn't pass response headers if the response is zero-length + if response.body_parts.empty? + response.body_parts << ' ' end + else + response.body_parts << text end end @@ -39,4 +40,4 @@ module ActionController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index 86e193efa9..7e2857614c 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -287,6 +287,7 @@ module ActionController #:nodoc: include TestResponseBehavior def recycle! + body_parts.clear headers.delete('ETag') headers.delete('Last-Modified') end -- cgit v1.2.3 From 7ce0778a1516110cf8015e59e2e8fac15032379c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 17 Apr 2009 21:53:44 -0500 Subject: Always buffer rack.input if it is not rewindable Signed-off-by: Joshua Peek --- .../action_dispatch/middleware/rewindable_input.rb | 25 +++++++--------------- actionpack/test/controller/dispatcher_test.rb | 2 +- .../request/multipart_params_parsing_test.rb | 1 + .../request/url_encoded_params_parsing_test.rb | 1 + 4 files changed, 11 insertions(+), 18 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/rewindable_input.rb b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb index 725414efc4..c818f28cce 100644 --- a/actionpack/lib/action_dispatch/middleware/rewindable_input.rb +++ b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb @@ -1,27 +1,18 @@ module ActionDispatch class RewindableInput - class RewindableIO < ActiveSupport::BasicObject - def initialize(io) - @io = io - @rewindable = io.is_a?(::StringIO) - end - - def method_missing(method, *args, &block) - unless @rewindable - @io = ::StringIO.new(@io.read) - @rewindable = true - end - - @io.__send__(method, *args, &block) - end - end - def initialize(app) @app = app end def call(env) - env['rack.input'] = RewindableIO.new(env['rack.input']) + begin + env['rack.input'].rewind + rescue NoMethodError, Errno::ESPIPE + # Handles exceptions raised by input streams that cannot be rewound + # such as when using plain CGI under Apache + env['rack.input'] = StringIO.new(env['rack.input'].read) + end + @app.call(env) end end diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 721bcf6136..569d698a03 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -94,7 +94,7 @@ class DispatcherTest < Test::Unit::TestCase def dispatch(cache_classes = true) ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response']) Dispatcher.define_dispatcher_callbacks(cache_classes) - Dispatcher.new.call({}) + Dispatcher.new.call({'rack.input' => StringIO.new('')}) end def assert_subclasses(howmany, klass, message = klass.subclasses.inspect) diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 33c909aad9..88b81dc493 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -207,6 +207,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest def call(env) env['rack.input'].read + env['rack.input'].rewind @app.call(env) end end diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 44d13797f0..8de4a83d76 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -151,6 +151,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest def call(env) env['rack.input'].read + env['rack.input'].rewind @app.call(env) end end -- cgit v1.2.3 From 398b07e655b6f643f31fb47b3cf7bc2dba009dc7 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Tue, 21 Apr 2009 14:32:52 +0100 Subject: Remove excess mocking from polymorphic_url tests [#2330 state:resolved] Signed-off-by: Pratik Naik --- .../test/activerecord/polymorphic_routes_test.rb | 394 +++++++++++++++++++++ .../test/controller/polymorphic_routes_test.rb | 293 --------------- 2 files changed, 394 insertions(+), 293 deletions(-) create mode 100644 actionpack/test/activerecord/polymorphic_routes_test.rb delete mode 100644 actionpack/test/controller/polymorphic_routes_test.rb (limited to 'actionpack') diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb new file mode 100644 index 0000000000..35139fbb7f --- /dev/null +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -0,0 +1,394 @@ +require 'active_record_unit' + +class Task < ActiveRecord::Base + set_table_name 'projects' +end + +class Step < ActiveRecord::Base + set_table_name 'projects' +end + +class Bid < ActiveRecord::Base + set_table_name 'projects' +end + +class Tax < ActiveRecord::Base + set_table_name 'projects' +end + +class Fax < ActiveRecord::Base + set_table_name 'projects' +end + +class Series < ActiveRecord::Base + set_table_name 'projects' +end + +class PolymorphicRoutesTest < ActionController::TestCase + include ActionController::UrlWriter + self.default_url_options[:host] = 'example.com' + + def setup + @project = Project.new + @task = Task.new + @step = Step.new + @bid = Bid.new + @tax = Tax.new + @fax = Fax.new + @series = Series.new + end + + def test_with_record + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(@project) + end + end + + def test_with_new_record + with_test_routes do + assert_equal "http://example.com/projects", polymorphic_url(@project) + end + end + + def test_with_record_and_action + with_test_routes do + assert_equal "http://example.com/projects/new", polymorphic_url(@project, :action => 'new') + end + end + + def test_url_helper_prefixed_with_new + with_test_routes do + assert_equal "http://example.com/projects/new", new_polymorphic_url(@project) + end + end + + def test_url_helper_prefixed_with_edit + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}/edit", edit_polymorphic_url(@project) + end + end + + def test_url_helper_prefixed_with_edit_with_url_options + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}/edit?param1=10", edit_polymorphic_url(@project, :param1 => '10') + end + end + + def test_url_helper_with_url_options + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}?param1=10", polymorphic_url(@project, :param1 => '10') + end + end + + def test_formatted_url_helper_is_deprecated + with_test_routes do + assert_deprecated do + formatted_polymorphic_url([@project, :pdf]) + end + end + end + + def test_format_option + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(@project, :format => :pdf) + end + end + + def test_format_option_with_url_options + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}.pdf?param1=10", polymorphic_url(@project, :format => :pdf, :param1 => '10') + end + end + + def test_id_and_format_option + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(:id => @project, :format => :pdf) + end + end + + def test_with_nested + with_test_routes do + @project.save + @task.save + assert_equal "http://example.com/projects/#{@project.id}/tasks/#{@task.id}", polymorphic_url([@project, @task]) + end + end + + def test_with_nested_unsaved + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}/tasks", polymorphic_url([@project, @task]) + end + end + + def test_new_with_array_and_namespace + with_admin_test_routes do + assert_equal "http://example.com/admin/projects/new", polymorphic_url([:admin, @project], :action => 'new') + end + end + + def test_unsaved_with_array_and_namespace + with_admin_test_routes do + assert_equal "http://example.com/admin/projects", polymorphic_url([:admin, @project]) + end + end + + def test_nested_unsaved_with_array_and_namespace + with_admin_test_routes do + @project.save + assert_equal "http://example.com/admin/projects/#{@project.id}/tasks", polymorphic_url([:admin, @project, @task]) + end + end + + def test_nested_with_array_and_namespace + with_admin_test_routes do + @project.save + @task.save + assert_equal "http://example.com/admin/projects/#{@project.id}/tasks/#{@task.id}", polymorphic_url([:admin, @project, @task]) + end + end + + def test_ordering_of_nesting_and_namespace + with_admin_and_site_test_routes do + @project.save + @task.save + @step.save + assert_equal "http://example.com/admin/projects/#{@project.id}/site/tasks/#{@task.id}/steps/#{@step.id}", polymorphic_url([:admin, @project, :site, @task, @step]) + end + end + + def test_nesting_with_array_ending_in_singleton_resource + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, :bid]) + end + end + + def test_nesting_with_array_containing_singleton_resource + with_test_routes do + @project.save + @task.save + assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}", polymorphic_url([@project, :bid, @task]) + end + end + + def test_nesting_with_array_containing_singleton_resource_and_format + with_test_routes do + @project.save + @task.save + assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}.pdf", polymorphic_url([@project, :bid, @task], :format => :pdf) + end + end + + def test_nesting_with_array_containing_namespace_and_singleton_resource + with_admin_test_routes do + @project.save + @task.save + assert_equal "http://example.com/admin/projects/#{@project.id}/bid/tasks/#{@task.id}", polymorphic_url([:admin, @project, :bid, @task]) + end + end + + def test_nesting_with_array_containing_nil + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, nil, :bid]) + end + end + + def test_with_array_containing_single_object + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url([nil, @project]) + end + end + + def test_with_array_containing_single_name + with_test_routes do + @project.save + assert_equal "http://example.com/projects", polymorphic_url([:projects]) + end + end + + def test_with_hash + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(:id => @project) + end + end + + def test_polymorphic_path_accepts_options + with_test_routes do + assert_equal "/projects/new", polymorphic_path(@project, :action => 'new') + end + end + + def test_polymorphic_path_does_not_modify_arguments + with_admin_test_routes do + @project.save + @task.save + object_array = [:admin, @project, @task] + assert_no_difference 'object_array.size' do + polymorphic_url(object_array) + end + end + end + + # Tests for names where .plural.singular doesn't round-trip + def test_with_irregular_plural_record + with_test_routes do + @tax.save + assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url(@tax) + end + end + + def test_with_irregular_plural_new_record + with_test_routes do + assert_equal "http://example.com/taxes", polymorphic_url(@tax) + end + end + + def test_with_irregular_plural_record_and_action + with_test_routes do + assert_equal "http://example.com/taxes/new", polymorphic_url(@tax, :action => 'new') + end + end + + def test_irregular_plural_url_helper_prefixed_with_new + with_test_routes do + assert_equal "http://example.com/taxes/new", new_polymorphic_url(@tax) + end + end + + def test_irregular_plural_url_helper_prefixed_with_edit + with_test_routes do + @tax.save + assert_equal "http://example.com/taxes/#{@tax.id}/edit", edit_polymorphic_url(@tax) + end + end + + def test_with_nested_irregular_plurals + with_test_routes do + @tax.save + @fax.save + assert_equal "http://example.com/taxes/#{@tax.id}/faxes/#{@fax.id}", polymorphic_url([@tax, @fax]) + end + end + + def test_with_nested_unsaved_irregular_plurals + with_test_routes do + @tax.save + assert_equal "http://example.com/taxes/#{@tax.id}/faxes", polymorphic_url([@tax, @fax]) + end + end + + def test_new_with_irregular_plural_array_and_namespace + with_admin_test_routes do + assert_equal "http://example.com/admin/taxes/new", polymorphic_url([:admin, @tax], :action => 'new') + end + end + + def test_unsaved_with_irregular_plural_array_and_namespace + with_admin_test_routes do + assert_equal "http://example.com/admin/taxes", polymorphic_url([:admin, @tax]) + end + end + + def test_nesting_with_irregular_plurals_and_array_ending_in_singleton_resource + with_test_routes do + @tax.save + assert_equal "http://example.com/taxes/#{@tax.id}/bid", polymorphic_url([@tax, :bid]) + end + end + + def test_with_array_containing_single_irregular_plural_object + with_test_routes do + @tax.save + assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url([nil, @tax]) + end + end + + def test_with_array_containing_single_name_irregular_plural + with_test_routes do + @tax.save + assert_equal "http://example.com/taxes", polymorphic_url([:taxes]) + end + end + + # Tests for uncountable names + def test_uncountable_resource + with_test_routes do + @series.save + assert_equal "http://example.com/series/#{@series.id}", polymorphic_url(@series) + end + end + + def with_test_routes(options = {}) + with_routing do |set| + set.draw do |map| + map.resources :projects do |projects| + projects.resources :tasks + projects.resource :bid do |bid| + bid.resources :tasks + end + end + map.resources :taxes do |taxes| + taxes.resources :faxes + taxes.resource :bid + end + map.resources :series + end + + ActionController::Routing::Routes.install_helpers(self.class) + yield + end + end + + def with_admin_test_routes(options = {}) + with_routing do |set| + set.draw do |map| + map.namespace :admin do |admin| + admin.resources :projects do |projects| + projects.resources :tasks + projects.resource :bid do |bid| + bid.resources :tasks + end + end + admin.resources :taxes do |taxes| + taxes.resources :faxes + end + admin.resources :series + end + end + + ActionController::Routing::Routes.install_helpers(self.class) + yield + end + end + + def with_admin_and_site_test_routes(options = {}) + with_routing do |set| + set.draw do |map| + map.namespace :admin do |admin| + admin.resources :projects do |projects| + projects.namespace :site do |site| + site.resources :tasks do |tasks| + tasks.resources :steps + end + end + end + end + end + + ActionController::Routing::Routes.install_helpers(self.class) + yield + end + end + +end \ No newline at end of file diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb deleted file mode 100644 index 146d703619..0000000000 --- a/actionpack/test/controller/polymorphic_routes_test.rb +++ /dev/null @@ -1,293 +0,0 @@ -require 'abstract_unit' - -class Article - attr_reader :id - def save; @id = 1 end - def new_record?; @id.nil? end - def name - model = self.class.name.downcase - @id.nil? ? "new #{model}" : "#{model} ##{@id}" - end -end - -class Response < Article - def post_id; 1 end -end - -class Tag < Article - def response_id; 1 end -end - -class Tax - attr_reader :id - def save; @id = 1 end - def new_record?; @id.nil? end - def name - model = self.class.name.downcase - @id.nil? ? "new #{model}" : "#{model} ##{@id}" - end -end - -class Fax < Tax - def store_id; 1 end -end - -# TODO: test nested models -class Response::Nested < Response; end - -class PolymorphicRoutesTest < ActiveSupport::TestCase - include ActionController::PolymorphicRoutes - - def setup - @article = Article.new - @response = Response.new - @tax = Tax.new - @fax = Fax.new - end - - def test_with_record - @article.save - expects(:article_url).with(@article) - polymorphic_url(@article) - end - - def test_with_new_record - expects(:articles_url).with() - @article.expects(:new_record?).returns(true) - polymorphic_url(@article) - end - - def test_with_record_and_action - expects(:new_article_url).with() - @article.expects(:new_record?).never - polymorphic_url(@article, :action => 'new') - end - - def test_url_helper_prefixed_with_new - expects(:new_article_url).with() - new_polymorphic_url(@article) - end - - def test_url_helper_prefixed_with_edit - @article.save - expects(:edit_article_url).with(@article) - edit_polymorphic_url(@article) - end - - def test_url_helper_prefixed_with_edit_with_url_options - @article.save - expects(:edit_article_url).with(@article, :param1 => '10') - edit_polymorphic_url(@article, :param1 => '10') - end - - def test_url_helper_with_url_options - @article.save - expects(:article_url).with(@article, :param1 => '10') - polymorphic_url(@article, :param1 => '10') - end - - def test_formatted_url_helper_is_deprecated - expects(:articles_url).with(:format => :pdf) - assert_deprecated do - formatted_polymorphic_url([@article, :pdf]) - end - end - - def test_format_option - @article.save - expects(:article_url).with(@article, :format => :pdf) - polymorphic_url(@article, :format => :pdf) - end - - def test_format_option_with_url_options - @article.save - expects(:article_url).with(@article, :format => :pdf, :param1 => '10') - polymorphic_url(@article, :format => :pdf, :param1 => '10') - end - - def test_id_and_format_option - @article.save - expects(:article_url).with(:id => @article, :format => :pdf) - polymorphic_url(:id => @article, :format => :pdf) - end - - def test_with_nested - @response.save - expects(:article_response_url).with(@article, @response) - polymorphic_url([@article, @response]) - end - - def test_with_nested_unsaved - expects(:article_responses_url).with(@article) - polymorphic_url([@article, @response]) - end - - def test_new_with_array_and_namespace - expects(:new_admin_article_url).with() - polymorphic_url([:admin, @article], :action => 'new') - end - - def test_unsaved_with_array_and_namespace - expects(:admin_articles_url).with() - polymorphic_url([:admin, @article]) - end - - def test_nested_unsaved_with_array_and_namespace - @article.save - expects(:admin_article_url).with(@article) - polymorphic_url([:admin, @article]) - expects(:admin_article_responses_url).with(@article) - polymorphic_url([:admin, @article, @response]) - end - - def test_nested_with_array_and_namespace - @response.save - expects(:admin_article_response_url).with(@article, @response) - polymorphic_url([:admin, @article, @response]) - - # a ridiculously long named route tests correct ordering of namespaces and nesting: - @tag = Tag.new - @tag.save - expects(:site_admin_article_response_tag_url).with(@article, @response, @tag) - polymorphic_url([:site, :admin, @article, @response, @tag]) - end - - def test_nesting_with_array_ending_in_singleton_resource - expects(:article_response_url).with(@article) - polymorphic_url([@article, :response]) - end - - def test_nesting_with_array_containing_singleton_resource - @tag = Tag.new - @tag.save - expects(:article_response_tag_url).with(@article, @tag) - polymorphic_url([@article, :response, @tag]) - end - - def test_nesting_with_array_containing_namespace_and_singleton_resource - @tag = Tag.new - @tag.save - expects(:admin_article_response_tag_url).with(@article, @tag) - polymorphic_url([:admin, @article, :response, @tag]) - end - - def test_nesting_with_array_containing_singleton_resource_and_format - @tag = Tag.new - @tag.save - expects(:article_response_tag_url).with(@article, @tag, :format => :pdf) - polymorphic_url([@article, :response, @tag], :format => :pdf) - end - - def test_nesting_with_array_containing_singleton_resource_and_format_option - @tag = Tag.new - @tag.save - expects(:article_response_tag_url).with(@article, @tag, :format => :pdf) - polymorphic_url([@article, :response, @tag], :format => :pdf) - end - - def test_nesting_with_array_containing_nil - expects(:article_response_url).with(@article) - polymorphic_url([@article, nil, :response]) - end - - def test_with_array_containing_single_object - @article.save - expects(:article_url).with(@article) - polymorphic_url([nil, @article]) - end - - def test_with_array_containing_single_name - @article.save - expects(:articles_url) - polymorphic_url([:articles]) - end - - # TODO: Needs to be updated to correctly know about whether the object is in a hash or not - def xtest_with_hash - expects(:article_url).with(@article) - @article.save - polymorphic_url(:id => @article) - end - - def test_polymorphic_path_accepts_options - expects(:new_article_path).with() - polymorphic_path(@article, :action => :new) - end - - def test_polymorphic_path_does_not_modify_arguments - expects(:admin_article_responses_url).with(@article) - path = [:admin, @article, @response] - assert_no_difference 'path.size' do - polymorphic_url(path) - end - end - - # Tests for names where .plural.singular doesn't round-trip - def test_with_irregular_plural_record - @tax.save - expects(:taxis_url).with(@tax) - polymorphic_url(@tax) - end - - def test_with_irregular_plural_new_record - expects(:taxes_url).with() - @tax.expects(:new_record?).returns(true) - polymorphic_url(@tax) - end - - def test_with_irregular_plural_record_and_action - expects(:new_taxis_url).with() - @tax.expects(:new_record?).never - polymorphic_url(@tax, :action => 'new') - end - - def test_irregular_plural_url_helper_prefixed_with_new - expects(:new_taxis_url).with() - new_polymorphic_url(@tax) - end - - def test_irregular_plural_url_helper_prefixed_with_edit - @tax.save - expects(:edit_taxis_url).with(@tax) - edit_polymorphic_url(@tax) - end - - def test_with_nested_irregular_plurals - @fax.save - expects(:taxis_faxis_url).with(@tax, @fax) - polymorphic_url([@tax, @fax]) - end - - def test_with_nested_unsaved_irregular_plurals - expects(:taxis_faxes_url).with(@tax) - polymorphic_url([@tax, @fax]) - end - - def test_new_with_irregular_plural_array_and_namespace - expects(:new_admin_taxis_url).with() - polymorphic_url([:admin, @tax], :action => 'new') - end - - def test_unsaved_with_irregular_plural_array_and_namespace - expects(:admin_taxes_url).with() - polymorphic_url([:admin, @tax]) - end - - def test_nesting_with_irregular_plurals_and_array_ending_in_singleton_resource - expects(:taxis_faxis_url).with(@tax) - polymorphic_url([@tax, :faxis]) - end - - def test_with_array_containing_single_irregular_plural_object - @tax.save - expects(:taxis_url).with(@tax) - polymorphic_url([nil, @tax]) - end - - def test_with_array_containing_single_name_irregular_plural - @tax.save - expects(:taxes_url) - polymorphic_url([:taxes]) - end - -end -- cgit v1.2.3 From f49e3441280380ec810d54bd5a77a7e699415efb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 21 Apr 2009 16:02:30 -0700 Subject: Reinstate Base#render_to_string. Introduce AbstractController#render_to_string which stringifies render_to_body. --- actionpack/lib/action_controller/abstract/renderer.rb | 12 +++++++++++- actionpack/lib/action_controller/base/render.rb | 14 +++++++++----- .../abstract_controller/abstract_controller_test.rb | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index eb248652a8..2a68f048bd 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -20,7 +20,7 @@ module AbstractController self.response_body = render_to_body(options) end - # Raw rendering of a template. + # Raw rendering of a template to a Rack-compatible body. # ==== # @option _prefix The template's path prefix # @option _layout The relative path to the layout template to use @@ -33,6 +33,16 @@ module AbstractController _render_template(template, options) end + # Raw rendering of a template to a string. + # ==== + # @option _prefix The template's path prefix + # @option _layout The relative path to the layout template to use + # + # :api: plugin + def render_to_string(options = {}) + Rack::Utils.body_to_s(render_to_body(options)).to_ary.join + end + def _render_template(template, options) _action_view._render_template_with_layout(template) end diff --git a/actionpack/lib/action_controller/base/render.rb b/actionpack/lib/action_controller/base/render.rb index 0d24f18633..604dd31930 100644 --- a/actionpack/lib/action_controller/base/render.rb +++ b/actionpack/lib/action_controller/base/render.rb @@ -306,9 +306,9 @@ module ActionController (name.is_a?(String) ? name.sub(/^#{controller_path}\//, '') : name).to_s end - # Renders according to the same rules as render, but returns the result in a string instead - # of sending it as the response body to the browser. - def render_to_string(options = nil, &block) #:doc: + # Same rules as render, but returns a Rack-compatible body + # instead of sending the response. + def render_to_body(options = nil, &block) #:doc: render(options, &block) response.body ensure @@ -316,7 +316,11 @@ module ActionController erase_render_results reset_variables_added_to_assigns end - + + def render_to_string(options = {}) + Rack::Utils.body_to_s(render_to_body(options)).to_ary.join + end + # Clears the rendered results, allowing for another render to be performed. def erase_render_results #:nodoc: response.body = [] @@ -387,4 +391,4 @@ module ActionController render_for_parts(parts, layout, options) end end -end \ No newline at end of file +end diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 8763ded57e..918062c7db 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -56,6 +56,14 @@ module AbstractController def naked_render render end + + def rendering_to_body + render_to_body "naked_render.erb" + end + + def rendering_to_string + render_to_string "naked_render.erb" + end end class TestRenderer < ActiveSupport::TestCase @@ -73,6 +81,16 @@ module AbstractController result = Me2.process(:naked_render) assert_equal "Hello from naked_render.erb", result.response_obj[:body] end + + test "rendering to a rack body" do + result = Me2.process(:rendering_to_body) + assert_equal "Hello from naked_render.erb", result.response_obj[:body] + end + + test "rendering to a string" do + result = Me2.process(:rendering_to_string) + assert_equal "Hello from naked_render.erb", result.response_obj[:body] + end end # Test rendering with prefixes -- cgit v1.2.3 From fc5c1b0e901a735a68dd822608eec2f99b6c7b74 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 19 Apr 2009 17:51:23 -0500 Subject: Session tests belong under dispatch folder --- .../test/controller/session/cookie_store_test.rb | 250 --------------------- .../controller/session/mem_cache_store_test.rb | 127 ----------- .../test/controller/session/test_session_test.rb | 58 ----- .../test/dispatch/session/cookie_store_test.rb | 250 +++++++++++++++++++++ .../test/dispatch/session/mem_cache_store_test.rb | 127 +++++++++++ .../test/dispatch/session/test_session_test.rb | 58 +++++ 6 files changed, 435 insertions(+), 435 deletions(-) delete mode 100644 actionpack/test/controller/session/cookie_store_test.rb delete mode 100644 actionpack/test/controller/session/mem_cache_store_test.rb delete mode 100644 actionpack/test/controller/session/test_session_test.rb create mode 100644 actionpack/test/dispatch/session/cookie_store_test.rb create mode 100644 actionpack/test/dispatch/session/mem_cache_store_test.rb create mode 100644 actionpack/test/dispatch/session/test_session_test.rb (limited to 'actionpack') diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb deleted file mode 100644 index b9bf8cf411..0000000000 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ /dev/null @@ -1,250 +0,0 @@ -require 'abstract_unit' -require 'stringio' - -class CookieStoreTest < ActionController::IntegrationTest - SessionKey = '_myapp_session' - SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' - - DispatcherApp = ActionController::Dispatcher.new - CookieStoreApp = ActionDispatch::Session::CookieStore.new(DispatcherApp, - :key => SessionKey, :secret => SessionSecret) - - Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') - - SignedBar = "BAh7BjoIZm9vIghiYXI%3D--fef868465920f415f2c0652d6910d3af288a0367" - - class TestController < ActionController::Base - def no_session_access - head :ok - end - - def persistent_session_id - render :text => session[:session_id] - end - - def set_session_value - session[:foo] = "bar" - render :text => Rack::Utils.escape(Verifier.generate(session.to_hash)) - end - - def get_session_value - render :text => "foo: #{session[:foo].inspect}" - end - - def get_session_id - render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}" - end - - def call_reset_session - reset_session - head :ok - end - - def raise_data_overflow - session[:foo] = 'bye!' * 1024 - head :ok - end - - def rescue_action(e) raise end - end - - def setup - @integration_session = open_session(CookieStoreApp) - end - - def test_raises_argument_error_if_missing_session_key - assert_raise(ArgumentError, nil.inspect) { - ActionDispatch::Session::CookieStore.new(nil, - :key => nil, :secret => SessionSecret) - } - - assert_raise(ArgumentError, ''.inspect) { - ActionDispatch::Session::CookieStore.new(nil, - :key => '', :secret => SessionSecret) - } - end - - def test_raises_argument_error_if_missing_secret - assert_raise(ArgumentError, nil.inspect) { - ActionDispatch::Session::CookieStore.new(nil, - :key => SessionKey, :secret => nil) - } - - assert_raise(ArgumentError, ''.inspect) { - ActionDispatch::Session::CookieStore.new(nil, - :key => SessionKey, :secret => '') - } - end - - def test_raises_argument_error_if_secret_is_probably_insecure - assert_raise(ArgumentError, "password".inspect) { - ActionDispatch::Session::CookieStore.new(nil, - :key => SessionKey, :secret => "password") - } - - assert_raise(ArgumentError, "secret".inspect) { - ActionDispatch::Session::CookieStore.new(nil, - :key => SessionKey, :secret => "secret") - } - - assert_raise(ArgumentError, "12345678901234567890123456789".inspect) { - ActionDispatch::Session::CookieStore.new(nil, - :key => SessionKey, :secret => "12345678901234567890123456789") - } - end - - def test_setting_session_value - with_test_route_set do - get '/set_session_value' - assert_response :success - assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", - headers['Set-Cookie'] - end - end - - def test_getting_session_value - with_test_route_set do - cookies[SessionKey] = SignedBar - get '/get_session_value' - assert_response :success - assert_equal 'foo: "bar"', response.body - end - end - - def test_getting_session_id - with_test_route_set do - cookies[SessionKey] = SignedBar - get '/persistent_session_id' - assert_response :success - assert_equal response.body.size, 32 - session_id = response.body - - get '/get_session_id' - assert_response :success - assert_equal "foo: \"bar\"; id: #{session_id}", response.body - end - end - - def test_disregards_tampered_sessions - with_test_route_set do - cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--123456780" - get '/get_session_value' - assert_response :success - assert_equal 'foo: nil', response.body - end - end - - def test_close_raises_when_data_overflows - with_test_route_set do - assert_raise(ActionDispatch::Session::CookieStore::CookieOverflow) { - get '/raise_data_overflow' - } - end - end - - def test_doesnt_write_session_cookie_if_session_is_not_accessed - with_test_route_set do - get '/no_session_access' - assert_response :success - assert_equal "", headers['Set-Cookie'] - end - end - - def test_doesnt_write_session_cookie_if_session_is_unchanged - with_test_route_set do - cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--" + - "fef868465920f415f2c0652d6910d3af288a0367" - get '/no_session_access' - assert_response :success - assert_equal "", headers['Set-Cookie'] - end - end - - def test_setting_session_value_after_session_reset - with_test_route_set do - get '/set_session_value' - assert_response :success - session_payload = response.body - assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", - headers['Set-Cookie'] - - get '/call_reset_session' - assert_response :success - assert_not_equal [], headers['Set-Cookie'] - assert_not_equal session_payload, cookies[SessionKey] - - get '/get_session_value' - assert_response :success - assert_equal 'foo: nil', response.body - end - end - - def test_persistent_session_id - with_test_route_set do - cookies[SessionKey] = SignedBar - get '/persistent_session_id' - assert_response :success - assert_equal response.body.size, 32 - session_id = response.body - get '/persistent_session_id' - assert_equal session_id, response.body - reset! - get '/persistent_session_id' - assert_not_equal session_id, response.body - end - end - - def test_session_store_with_expire_after - app = ActionDispatch::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours) - @integration_session = open_session(app) - - with_test_route_set do - # First request accesses the session - time = Time.local(2008, 4, 24) - Time.stubs(:now).returns(time) - expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT") - - cookies[SessionKey] = SignedBar - - get '/set_session_value' - assert_response :success - - cookie_body = response.body - assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly", - headers['Set-Cookie'] - - # Second request does not access the session - time = Time.local(2008, 4, 25) - Time.stubs(:now).returns(time) - expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT") - - get '/no_session_access' - assert_response :success - - # Mystery bug that came up in 2.3 as well. What is this trying to test?! - # assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly", - # headers['Set-Cookie'] - end - end - - private - def with_test_route_set - with_routing do |set| - set.draw do |map| - map.with_options :controller => "cookie_store_test/test" do |c| - c.connect "/:action" - end - end - yield - end - end - - def unmarshal_session(cookie_string) - session = Rack::Utils.parse_query(cookie_string, ';,').inject({}) {|h,(k,v)| - h[k] = Array === v ? v.first : v - h - }[SessionKey] - verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') - verifier.verify(session) - end -end diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb deleted file mode 100644 index 7561c93e4a..0000000000 --- a/actionpack/test/controller/session/mem_cache_store_test.rb +++ /dev/null @@ -1,127 +0,0 @@ -require 'abstract_unit' - -# You need to start a memcached server inorder to run these tests -class MemCacheStoreTest < ActionController::IntegrationTest - class TestController < ActionController::Base - def no_session_access - head :ok - end - - def set_session_value - session[:foo] = "bar" - head :ok - end - - def get_session_value - render :text => "foo: #{session[:foo].inspect}" - end - - def get_session_id - session[:foo] - render :text => "#{request.session_options[:id]}" - end - - def call_reset_session - session[:bar] - reset_session - session[:bar] = "baz" - head :ok - end - - def rescue_action(e) raise end - end - - begin - DispatcherApp = ActionController::Dispatcher.new - MemCacheStoreApp = ActionDispatch::Session::MemCacheStore.new( - DispatcherApp, :key => '_session_id') - - - def setup - @integration_session = open_session(MemCacheStoreApp) - end - - def test_setting_and_getting_session_value - with_test_route_set do - get '/set_session_value' - assert_response :success - assert cookies['_session_id'] - - get '/get_session_value' - assert_response :success - assert_equal 'foo: "bar"', response.body - end - end - - def test_getting_nil_session_value - with_test_route_set do - get '/get_session_value' - assert_response :success - assert_equal 'foo: nil', response.body - end - end - - def test_setting_session_value_after_session_reset - with_test_route_set do - get '/set_session_value' - assert_response :success - assert cookies['_session_id'] - session_id = cookies['_session_id'] - - get '/call_reset_session' - assert_response :success - assert_not_equal [], headers['Set-Cookie'] - - get '/get_session_value' - assert_response :success - assert_equal 'foo: nil', response.body - - get '/get_session_id' - assert_response :success - assert_not_equal session_id, response.body - end - end - - def test_getting_session_id - with_test_route_set do - get '/set_session_value' - assert_response :success - assert cookies['_session_id'] - session_id = cookies['_session_id'] - - get '/get_session_id' - assert_response :success - assert_equal session_id, response.body - end - end - - def test_prevents_session_fixation - with_test_route_set do - get '/get_session_value' - assert_response :success - assert_equal 'foo: nil', response.body - session_id = cookies['_session_id'] - - reset! - - get '/set_session_value', :_session_id => session_id - assert_response :success - assert_equal nil, cookies['_session_id'] - end - end - rescue LoadError, RuntimeError - $stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again." - end - - private - def with_test_route_set - with_routing do |set| - set.draw do |map| - map.with_options :controller => "mem_cache_store_test/test" do |c| - c.connect "/:action" - end - end - yield - end - end -end diff --git a/actionpack/test/controller/session/test_session_test.rb b/actionpack/test/controller/session/test_session_test.rb deleted file mode 100644 index de6539e1cc..0000000000 --- a/actionpack/test/controller/session/test_session_test.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'abstract_unit' -require 'stringio' - -class ActionController::TestSessionTest < ActiveSupport::TestCase - - def test_calling_delete_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session - assert_deprecated(/use clear instead/){ ActionController::TestSession.new.delete } - end - - def test_calling_update_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session - assert_deprecated(/use replace instead/){ ActionController::TestSession.new.update } - end - - def test_calling_close_raises_deprecation_warning - assert_deprecated(/sessions should no longer be closed/){ ActionController::TestSession.new.close } - end - - def test_defaults - session = ActionController::TestSession.new - assert_equal({}, session.data) - assert_equal('', session.session_id) - end - - def test_ctor_allows_setting - session = ActionController::TestSession.new({:one => 'one', :two => 'two'}) - assert_equal('one', session[:one]) - assert_equal('two', session[:two]) - end - - def test_setting_session_item_sets_item - session = ActionController::TestSession.new - session[:key] = 'value' - assert_equal('value', session[:key]) - end - - def test_calling_delete_removes_item - session = ActionController::TestSession.new - session[:key] = 'value' - assert_equal('value', session[:key]) - session.delete(:key) - assert_nil(session[:key]) - end - - def test_calling_update_with_params_passes_to_attributes - session = ActionController::TestSession.new() - session.update('key' => 'value') - assert_equal('value', session[:key]) - end - - def test_clear_emptys_session - params = {:one => 'one', :two => 'two'} - session = ActionController::TestSession.new({:one => 'one', :two => 'two'}) - session.clear - assert_nil(session[:one]) - assert_nil(session[:two]) - end - -end \ No newline at end of file diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb new file mode 100644 index 0000000000..b9bf8cf411 --- /dev/null +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -0,0 +1,250 @@ +require 'abstract_unit' +require 'stringio' + +class CookieStoreTest < ActionController::IntegrationTest + SessionKey = '_myapp_session' + SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' + + DispatcherApp = ActionController::Dispatcher.new + CookieStoreApp = ActionDispatch::Session::CookieStore.new(DispatcherApp, + :key => SessionKey, :secret => SessionSecret) + + Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') + + SignedBar = "BAh7BjoIZm9vIghiYXI%3D--fef868465920f415f2c0652d6910d3af288a0367" + + class TestController < ActionController::Base + def no_session_access + head :ok + end + + def persistent_session_id + render :text => session[:session_id] + end + + def set_session_value + session[:foo] = "bar" + render :text => Rack::Utils.escape(Verifier.generate(session.to_hash)) + end + + def get_session_value + render :text => "foo: #{session[:foo].inspect}" + end + + def get_session_id + render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}" + end + + def call_reset_session + reset_session + head :ok + end + + def raise_data_overflow + session[:foo] = 'bye!' * 1024 + head :ok + end + + def rescue_action(e) raise end + end + + def setup + @integration_session = open_session(CookieStoreApp) + end + + def test_raises_argument_error_if_missing_session_key + assert_raise(ArgumentError, nil.inspect) { + ActionDispatch::Session::CookieStore.new(nil, + :key => nil, :secret => SessionSecret) + } + + assert_raise(ArgumentError, ''.inspect) { + ActionDispatch::Session::CookieStore.new(nil, + :key => '', :secret => SessionSecret) + } + end + + def test_raises_argument_error_if_missing_secret + assert_raise(ArgumentError, nil.inspect) { + ActionDispatch::Session::CookieStore.new(nil, + :key => SessionKey, :secret => nil) + } + + assert_raise(ArgumentError, ''.inspect) { + ActionDispatch::Session::CookieStore.new(nil, + :key => SessionKey, :secret => '') + } + end + + def test_raises_argument_error_if_secret_is_probably_insecure + assert_raise(ArgumentError, "password".inspect) { + ActionDispatch::Session::CookieStore.new(nil, + :key => SessionKey, :secret => "password") + } + + assert_raise(ArgumentError, "secret".inspect) { + ActionDispatch::Session::CookieStore.new(nil, + :key => SessionKey, :secret => "secret") + } + + assert_raise(ArgumentError, "12345678901234567890123456789".inspect) { + ActionDispatch::Session::CookieStore.new(nil, + :key => SessionKey, :secret => "12345678901234567890123456789") + } + end + + def test_setting_session_value + with_test_route_set do + get '/set_session_value' + assert_response :success + assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", + headers['Set-Cookie'] + end + end + + def test_getting_session_value + with_test_route_set do + cookies[SessionKey] = SignedBar + get '/get_session_value' + assert_response :success + assert_equal 'foo: "bar"', response.body + end + end + + def test_getting_session_id + with_test_route_set do + cookies[SessionKey] = SignedBar + get '/persistent_session_id' + assert_response :success + assert_equal response.body.size, 32 + session_id = response.body + + get '/get_session_id' + assert_response :success + assert_equal "foo: \"bar\"; id: #{session_id}", response.body + end + end + + def test_disregards_tampered_sessions + with_test_route_set do + cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--123456780" + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + end + end + + def test_close_raises_when_data_overflows + with_test_route_set do + assert_raise(ActionDispatch::Session::CookieStore::CookieOverflow) { + get '/raise_data_overflow' + } + end + end + + def test_doesnt_write_session_cookie_if_session_is_not_accessed + with_test_route_set do + get '/no_session_access' + assert_response :success + assert_equal "", headers['Set-Cookie'] + end + end + + def test_doesnt_write_session_cookie_if_session_is_unchanged + with_test_route_set do + cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--" + + "fef868465920f415f2c0652d6910d3af288a0367" + get '/no_session_access' + assert_response :success + assert_equal "", headers['Set-Cookie'] + end + end + + def test_setting_session_value_after_session_reset + with_test_route_set do + get '/set_session_value' + assert_response :success + session_payload = response.body + assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", + headers['Set-Cookie'] + + get '/call_reset_session' + assert_response :success + assert_not_equal [], headers['Set-Cookie'] + assert_not_equal session_payload, cookies[SessionKey] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + end + end + + def test_persistent_session_id + with_test_route_set do + cookies[SessionKey] = SignedBar + get '/persistent_session_id' + assert_response :success + assert_equal response.body.size, 32 + session_id = response.body + get '/persistent_session_id' + assert_equal session_id, response.body + reset! + get '/persistent_session_id' + assert_not_equal session_id, response.body + end + end + + def test_session_store_with_expire_after + app = ActionDispatch::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours) + @integration_session = open_session(app) + + with_test_route_set do + # First request accesses the session + time = Time.local(2008, 4, 24) + Time.stubs(:now).returns(time) + expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT") + + cookies[SessionKey] = SignedBar + + get '/set_session_value' + assert_response :success + + cookie_body = response.body + assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly", + headers['Set-Cookie'] + + # Second request does not access the session + time = Time.local(2008, 4, 25) + Time.stubs(:now).returns(time) + expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT") + + get '/no_session_access' + assert_response :success + + # Mystery bug that came up in 2.3 as well. What is this trying to test?! + # assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly", + # headers['Set-Cookie'] + end + end + + private + def with_test_route_set + with_routing do |set| + set.draw do |map| + map.with_options :controller => "cookie_store_test/test" do |c| + c.connect "/:action" + end + end + yield + end + end + + def unmarshal_session(cookie_string) + session = Rack::Utils.parse_query(cookie_string, ';,').inject({}) {|h,(k,v)| + h[k] = Array === v ? v.first : v + h + }[SessionKey] + verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') + verifier.verify(session) + end +end diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb new file mode 100644 index 0000000000..7561c93e4a --- /dev/null +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -0,0 +1,127 @@ +require 'abstract_unit' + +# You need to start a memcached server inorder to run these tests +class MemCacheStoreTest < ActionController::IntegrationTest + class TestController < ActionController::Base + def no_session_access + head :ok + end + + def set_session_value + session[:foo] = "bar" + head :ok + end + + def get_session_value + render :text => "foo: #{session[:foo].inspect}" + end + + def get_session_id + session[:foo] + render :text => "#{request.session_options[:id]}" + end + + def call_reset_session + session[:bar] + reset_session + session[:bar] = "baz" + head :ok + end + + def rescue_action(e) raise end + end + + begin + DispatcherApp = ActionController::Dispatcher.new + MemCacheStoreApp = ActionDispatch::Session::MemCacheStore.new( + DispatcherApp, :key => '_session_id') + + + def setup + @integration_session = open_session(MemCacheStoreApp) + end + + def test_setting_and_getting_session_value + with_test_route_set do + get '/set_session_value' + assert_response :success + assert cookies['_session_id'] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: "bar"', response.body + end + end + + def test_getting_nil_session_value + with_test_route_set do + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + end + end + + def test_setting_session_value_after_session_reset + with_test_route_set do + get '/set_session_value' + assert_response :success + assert cookies['_session_id'] + session_id = cookies['_session_id'] + + get '/call_reset_session' + assert_response :success + assert_not_equal [], headers['Set-Cookie'] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + + get '/get_session_id' + assert_response :success + assert_not_equal session_id, response.body + end + end + + def test_getting_session_id + with_test_route_set do + get '/set_session_value' + assert_response :success + assert cookies['_session_id'] + session_id = cookies['_session_id'] + + get '/get_session_id' + assert_response :success + assert_equal session_id, response.body + end + end + + def test_prevents_session_fixation + with_test_route_set do + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + session_id = cookies['_session_id'] + + reset! + + get '/set_session_value', :_session_id => session_id + assert_response :success + assert_equal nil, cookies['_session_id'] + end + end + rescue LoadError, RuntimeError + $stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again." + end + + private + def with_test_route_set + with_routing do |set| + set.draw do |map| + map.with_options :controller => "mem_cache_store_test/test" do |c| + c.connect "/:action" + end + end + yield + end + end +end diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb new file mode 100644 index 0000000000..de6539e1cc --- /dev/null +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -0,0 +1,58 @@ +require 'abstract_unit' +require 'stringio' + +class ActionController::TestSessionTest < ActiveSupport::TestCase + + def test_calling_delete_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session + assert_deprecated(/use clear instead/){ ActionController::TestSession.new.delete } + end + + def test_calling_update_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session + assert_deprecated(/use replace instead/){ ActionController::TestSession.new.update } + end + + def test_calling_close_raises_deprecation_warning + assert_deprecated(/sessions should no longer be closed/){ ActionController::TestSession.new.close } + end + + def test_defaults + session = ActionController::TestSession.new + assert_equal({}, session.data) + assert_equal('', session.session_id) + end + + def test_ctor_allows_setting + session = ActionController::TestSession.new({:one => 'one', :two => 'two'}) + assert_equal('one', session[:one]) + assert_equal('two', session[:two]) + end + + def test_setting_session_item_sets_item + session = ActionController::TestSession.new + session[:key] = 'value' + assert_equal('value', session[:key]) + end + + def test_calling_delete_removes_item + session = ActionController::TestSession.new + session[:key] = 'value' + assert_equal('value', session[:key]) + session.delete(:key) + assert_nil(session[:key]) + end + + def test_calling_update_with_params_passes_to_attributes + session = ActionController::TestSession.new() + session.update('key' => 'value') + assert_equal('value', session[:key]) + end + + def test_clear_emptys_session + params = {:one => 'one', :two => 'two'} + session = ActionController::TestSession.new({:one => 'one', :two => 'two'}) + session.clear + assert_nil(session[:one]) + assert_nil(session[:two]) + end + +end \ No newline at end of file -- cgit v1.2.3 From 0b92bb97c185f426585af770dcf43b67b0253f50 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 21 Apr 2009 20:41:05 -0500 Subject: refactor some coupled rescue tests --- actionpack/test/controller/rescue_test.rb | 94 +++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 16 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 741b01caa8..cc5a724081 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -400,22 +400,6 @@ class RescueControllerTest < ActionController::TestCase assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body end - def test_rescue_dispatcher_exceptions - env = @request.env - env["action_controller.rescue.request"] = @request - env["action_controller.rescue.response"] = @response - - RescueController.call_with_exception(env, ActionController::RoutingError.new("Route not found")) - assert_equal "no way", @response.body - end - - def test_rescue_dispatcher_exceptions_without_request_set - @request.env['REQUEST_URI'] = '/no_way' - response = RescueController.call_with_exception(@request.env, ActionController::RoutingError.new("Route not found")) - assert_kind_of ActionDispatch::Response, response - assert_equal "no way", response.body - end - protected def with_all_requests_local(local = true) old_local, ActionController::Base.consider_all_requests_local = @@ -537,3 +521,81 @@ class ControllerInheritanceRescueControllerTest < ActionController::TestCase assert_response :created end end + +class RescueTest < ActionController::IntegrationTest + class TestController < ActionController::Base + class RecordInvalid < StandardError + def message + 'invalid' + end + end + rescue_from RecordInvalid, :with => :show_errors + + def foo + render :text => "foo" + end + + def invalid + raise RecordInvalid + end + + def b00m + raise 'b00m' + end + + protected + def show_errors(exception) + render :text => exception.message + end + end + + def setup + ActionController::Base.rescue_from ActionController::RoutingError do + render :text => 'no way' + end + end + + def teardown + ActionController::Base.rescue_handlers.clear + end + + test 'normal request' do + with_test_routing do + get '/foo' + assert_equal 'foo', response.body + end + end + + test 'rescue exceptions inside controller' do + with_test_routing do + get '/invalid' + assert_equal 'invalid', response.body + end + end + + test 'rescue routing exceptions' do + with_test_routing do + get '/no_way' + assert_equal 'no way', response.body + end + end + + test 'unrescued exception' do + with_test_routing do + get '/b00m' + assert_match(/Action Controller: Exception caught/, response.body) + end + end + + private + def with_test_routing + with_routing do |set| + set.draw do |map| + map.connect 'foo', :controller => "rescue_test/test", :action => 'foo' + map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid' + map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m' + end + yield + end + end +end -- cgit v1.2.3 From 380431e4ed12d184c4e4891fbb74fdc38a51d2f2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 21 Apr 2009 21:11:23 -0500 Subject: Fix test_rescue_routing_exceptions when running with rake --- actionpack/test/controller/rescue_test.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index cc5a724081..894420a910 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -522,6 +522,12 @@ class ControllerInheritanceRescueControllerTest < ActionController::TestCase end end +class ApplicationController < ActionController::Base + rescue_from ActionController::RoutingError do + render :text => 'no way' + end +end + class RescueTest < ActionController::IntegrationTest class TestController < ActionController::Base class RecordInvalid < StandardError @@ -549,16 +555,6 @@ class RescueTest < ActionController::IntegrationTest end end - def setup - ActionController::Base.rescue_from ActionController::RoutingError do - render :text => 'no way' - end - end - - def teardown - ActionController::Base.rescue_handlers.clear - end - test 'normal request' do with_test_routing do get '/foo' @@ -574,9 +570,15 @@ class RescueTest < ActionController::IntegrationTest end test 'rescue routing exceptions' do - with_test_routing do - get '/no_way' - assert_equal 'no way', response.body + assert_equal 1, ApplicationController.rescue_handlers.length + + begin + with_test_routing do + get '/no_way' + assert_equal 'no way', response.body + end + ensure + ActionController::Base.rescue_handlers.clear end end -- cgit v1.2.3 From 70c544df71dbea561d6136ecb13bee43cda64bd1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 00:22:07 -0700 Subject: Rack::Utils.body_to_s doesn't exist in 1.0 --- actionpack/lib/action_controller/abstract/renderer.rb | 14 +++++++++++++- actionpack/lib/action_controller/base/render.rb | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index 2a68f048bd..a86eef889e 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -40,7 +40,7 @@ module AbstractController # # :api: plugin def render_to_string(options = {}) - Rack::Utils.body_to_s(render_to_body(options)).to_ary.join + AbstractController::Renderer.body_to_s(render_to_body(options)) end def _render_template(template, options) @@ -49,6 +49,18 @@ module AbstractController def view_paths() _view_paths end + # Return a string representation of a Rack-compatible response body. + def self.body_to_s(body) + if body.respond_to?(:to_str) + body + else + strings = [] + body.each { |part| strings << part.to_s } + body.close if body.respond_to?(:close) + strings.join + end + end + module ClassMethods def append_view_path(path) diff --git a/actionpack/lib/action_controller/base/render.rb b/actionpack/lib/action_controller/base/render.rb index 604dd31930..606df58518 100644 --- a/actionpack/lib/action_controller/base/render.rb +++ b/actionpack/lib/action_controller/base/render.rb @@ -1,3 +1,5 @@ +require 'action_controller/abstract/renderer' + module ActionController DEFAULT_RENDER_STATUS_CODE = "200 OK" @@ -318,7 +320,7 @@ module ActionController end def render_to_string(options = {}) - Rack::Utils.body_to_s(render_to_body(options)).to_ary.join + AbstractController::Renderer.body_to_s(render_to_body(options)) end # Clears the rendered results, allowing for another render to be performed. -- cgit v1.2.3 From ab321268f86d9013cbd4ecd0b5f46e7b05ec55a9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 16:10:49 -0700 Subject: No more free lunch --- actionpack/lib/action_controller.rb | 1 + actionpack/lib/action_dispatch.rb | 1 + actionpack/lib/action_view.rb | 1 + 3 files changed, 3 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 100a0be1db..aee6b9dc9f 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -30,6 +30,7 @@ rescue LoadError require 'active_support' end end +require 'active_support/core/all' require File.join(File.dirname(__FILE__), "action_pack") diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index bd5a38cc82..5feb8a4863 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -30,6 +30,7 @@ rescue LoadError require 'active_support' end end +require 'active_support/core/all' $:.unshift "#{File.dirname(__FILE__)}/action_dispatch/vendor/rack-1.0" begin diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index e604c2a581..dd352f9ce0 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -30,6 +30,7 @@ rescue LoadError require 'active_support' end end +require 'active_support/core/all' require File.join(File.dirname(__FILE__), "action_pack") -- cgit v1.2.3 From f5d720fb96f2e085acc4ed17f63272c4d38e567e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 16:41:06 -0700 Subject: Opt in to Dependencies --- actionpack/lib/action_view/template/template.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index 0d2f201458..b6967a2013 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -1,3 +1,4 @@ +require 'set' require "action_view/template/path" module ActionView #:nodoc: -- cgit v1.2.3 From 6fee981fa4ea2654f825c58b58327fc15fddf3a6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 16:48:58 -0700 Subject: Opt in to JSON --- actionpack/lib/action_dispatch/middleware/params_parser.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index 6df572268c..abaee2829e 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -1,3 +1,5 @@ +require 'active_support/json' + module ActionDispatch class ParamsParser ActionController::Base.param_parsers[Mime::XML] = :xml_simple -- cgit v1.2.3