From bdcf70cca89df906a3510464ef46a44646fd29a3 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Tue, 8 Jun 2010 15:18:02 -0400 Subject: Memoize the object returned by _view in ActionView::TestCase::Behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4799 state:resolved] Signed-off-by: José Valim --- actionpack/lib/action_view/test_case.rb | 14 ++++++++------ actionpack/test/template/test_case_test.rb | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 4dbbd2eb6a..15d424be74 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -131,12 +131,14 @@ module ActionView end def _view - view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller) - view.singleton_class.send :include, _helpers - view.singleton_class.send :include, @controller._router.url_helpers - view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" - view.output_buffer = self.output_buffer - view + @_view ||= begin + view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller) + view.singleton_class.send :include, _helpers + view.singleton_class.send :include, @controller._router.url_helpers + view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" + view.output_buffer = self.output_buffer + view + end end EXCLUDE_IVARS = %w{ diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 16e5ee4f72..9b50ea8a42 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -37,6 +37,10 @@ module ActionView include SharedTests test_case = self + test "memoizes the _view" do + assert_same _view, _view + end + test "works without testing a helper module" do assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy')) end -- cgit v1.2.3 From 03be27092bf51e78d0d3f3ee7fd0213023d43e0d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 8 Jun 2010 16:20:46 -0400 Subject: Revert "Add shallow routes to the new router" for now. Needs more work. This reverts commit 67a60ee314f53abcde78f8ecd2a1f7c9ef8264e1. --- actionpack/CHANGELOG | 10 ------ actionpack/lib/action_dispatch/routing/mapper.rb | 29 ++---------------- actionpack/test/dispatch/routing_test.rb | 39 ------------------------ 3 files changed, 3 insertions(+), 75 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index c3609958bc..1796d11dcd 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,15 +1,5 @@ *Rails 3.0.0 [beta 4] (June 8th, 2010)* -* Add shallow routes back to the new router [Diego Carrion] - - resources :posts do - shallow do - resources :comments - end - end - - You can now use comment_path for /comments/1 instead of post_comment_path for /posts/1/comments/1. - * Remove middleware laziness [José Valim] * Make session stores rely on request.cookie_jar and change set_session semantics to return the cookie value instead of a boolean. [José Valim] diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e91a72cbe5..6db8d1aacc 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -350,10 +350,6 @@ module ActionDispatch scope(:constraints => constraints) { yield } end - def shallow - scope(:shallow => true) { yield } - end - def defaults(defaults = {}) scope(:defaults => defaults) { yield } end @@ -378,21 +374,12 @@ module ActionDispatch @scope_options ||= private_methods.grep(/^merge_(.+)_scope$/) { $1.to_sym } end - def merge_shallow_scope(parent, child) - parent or child - end - def merge_path_scope(parent, child) - parent_path = (@scope[:shallow] and child.eql?(':id')) ? parent.split('/').last : parent - Mapper.normalize_path "#{parent_path}/#{child}" + Mapper.normalize_path("#{parent}/#{child}") end def merge_name_prefix_scope(parent, child) - if @scope[:shallow] - child - else - parent ? "#{parent}_#{child}" : child - end + parent ? "#{parent}_#{child}" : child end def merge_module_scope(parent, child) @@ -535,10 +522,6 @@ module ActionDispatch options["#{singular}_id".to_sym] = id_constraint if id_constraint? options end - - def shallow? - options[:shallow] - end end class SingletonResource < Resource #:nodoc: @@ -620,12 +603,8 @@ module ActionDispatch resource = Resource.new(resources.pop, options) - scope(:path => resource.path, :controller => resource.controller, :shallow => resource.shallow?) do + scope(:path => resource.path, :controller => resource.controller) do with_scope_level(:resources, resource) do - if @scope[:shallow] && @scope[:name_prefix] - @scope[:path] = "/#{@scope[:name_prefix].pluralize}/:#{@scope[:name_prefix]}_id/#{resource.path}" - end - yield if block_given? with_scope_level(:collection) do @@ -639,8 +618,6 @@ module ActionDispatch with_scope_level(:member) do scope(':id') do scope(resource.options) do - @scope[:name_prefix] = nil if @scope[:shallow] - get :show if resource.actions.include?(:show) put :update if resource.actions.include?(:update) delete :destroy if resource.actions.include?(:destroy) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index a294535e88..5c46f9b971 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -34,33 +34,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - resources :users do - shallow do - resources :photos do - resources :types do - member do - post :preview - end - collection do - delete :erase - end - end - end - end - end - - shallow do - resources :teams do - resources :players - end - - resources :countries do - resources :cities do - resources :places - end - end - end - match 'account/logout' => redirect("/logout"), :as => :logout_redirect match 'account/login', :to => redirect("/login") @@ -779,18 +752,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - def test_shallow_routes - with_test_routes do - assert_equal '/photos/4', photo_path(4) - assert_equal '/types/10/edit', edit_type_path(10) - assert_equal '/types/5/preview', preview_type_path(5) - assert_equal '/photos/2/types', photo_types_path(2) - assert_equal '/cities/1/places', url_for(:controller => :places, :action => :index, :city_id => 1, :only_path => true) - assert_equal '/teams/new', url_for(:controller => :teams, :action => :new, :only_path => true) - assert_equal '/photos/11/types/erase', url_for(:controller => :types, :action => :erase, :photo_id => 11, :only_path => true) - end - end - def test_update_project_person with_test_routes do get '/projects/1/people/2/update' -- cgit v1.2.3 From db23a95a616860e4fefa4ef83b396abe7ec0ea71 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 7 May 2010 01:01:47 -0400 Subject: cache_sweeper yields blank output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#3914 state:open] Signed-off-by: José Valim --- actionpack/lib/action_controller/caching/sweeping.rb | 1 + actionpack/test/abstract_unit.rb | 3 +++ actionpack/test/controller/filters_test.rb | 6 ++++++ 3 files changed, 10 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb index cf16417e84..e9db0d97b6 100644 --- a/actionpack/lib/action_controller/caching/sweeping.rb +++ b/actionpack/lib/action_controller/caching/sweeping.rb @@ -57,6 +57,7 @@ module ActionController #:nodoc: def before(controller) self.controller = controller callback(:before) if controller.perform_caching + true # before method from sweeper should always return true end def after(controller) diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index d2e5d2e965..84c5395610 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -24,6 +24,9 @@ require 'action_view/testing/resolvers' require 'action_dispatch' require 'active_support/dependencies' require 'active_model' +require 'active_record' +require 'action_controller/caching' +require 'action_controller/caching/sweeping' begin require 'ruby-debug' diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index d5704eba78..25b78124e3 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -445,6 +445,12 @@ class FilterTest < ActionController::TestCase end + + def test_before_method_of_sweeper_should_always_return_true + sweeper = ActionController::Caching::Sweeper.send(:new) + assert sweeper.before(TestController.new) + end + def test_non_yielding_around_filters_not_returning_false_do_not_raise controller = NonYieldingAroundFilterController.new controller.instance_variable_set "@filter_return_value", true -- cgit v1.2.3 From 4560385fa4fa6925aa220bbaf6b2608c2bbd7039 Mon Sep 17 00:00:00 2001 From: Jan De Poorter Date: Wed, 14 Apr 2010 10:34:42 +0200 Subject: Make sure namespaces are nested within resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 ++++++++ actionpack/test/dispatch/routing_test.rb | 15 +++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 6db8d1aacc..0f267caefe 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -679,6 +679,14 @@ module ActionDispatch end end + def namespace(path) + if @scope[:scope_level] == :resources + nested { super } + else + super + end + end + def match(*args) options = args.extract_options! diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 5c46f9b971..c4e402afd3 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -144,6 +144,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :sheep + resources :clients do + namespace :google do + resource :account + end + end + match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp match 'people/:id/update', :to => 'people#update', :as => :update_person @@ -813,6 +819,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal '/account/admin/subscription', account_admin_subscription_path end end + + def test_namespace_nested_in_resources + with_test_routes do + get '/clients/1/google/account' + assert_equal '/clients/1/google/account', client_google_account_path(1) + + assert_equal 'google/accounts#show', @response.body + end + end def test_articles_with_id with_test_routes do -- cgit v1.2.3 From 5c9f27abaabba0d008ccd710ed1af5f6caa4e371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 8 Jun 2010 23:26:51 +0200 Subject: Add more cases to previous commit [#4394 state:resolved] --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- actionpack/test/dispatch/routing_test.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0f267caefe..7b79b6bde3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -680,7 +680,7 @@ module ActionDispatch end def namespace(path) - if @scope[:scope_level] == :resources + if resource_scope? nested { super } else super diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index c4e402afd3..e13960e0dc 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -146,7 +146,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :clients do namespace :google do - resource :account + resource :account do + namespace :secret do + resource :info + end + end end end @@ -824,8 +828,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest with_test_routes do get '/clients/1/google/account' assert_equal '/clients/1/google/account', client_google_account_path(1) - assert_equal 'google/accounts#show', @response.body + + get '/clients/1/google/account/secret/info' + assert_equal '/clients/1/google/account/secret/info', client_google_account_secret_info_path(1) + assert_equal 'google/secret/infos#show', @response.body end end -- cgit v1.2.3 From f48aa14bf43fb103e5d128151061549ba6bb8c23 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 8 Jun 2010 23:25:55 -0400 Subject: Better test for ticket [#3914 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/controller/filters_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 25b78124e3..14f1bd797a 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -445,6 +445,17 @@ class FilterTest < ActionController::TestCase end + class ::AppSweeper < ActionController::Caching::Sweeper; end + class SweeperTestController < ActionController::Base + cache_sweeper :app_sweeper + def show + render :text => 'hello world' + end + end + def test_sweeper_should_not_block_rendering + response = test_process(SweeperTestController) + assert_equal 'hello world', response.body + end def test_before_method_of_sweeper_should_always_return_true sweeper = ActionController::Caching::Sweeper.send(:new) -- cgit v1.2.3 From 0919c0dbca3df02f5cfff7dde4f61b85ef16d886 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 9 Jun 2010 00:28:42 -0300 Subject: Removed textilize, textilize_without_paragraph and markdown helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/CHANGELOG | 2 + actionpack/lib/action_view/helpers/text_helper.rb | 83 ----------------- actionpack/test/template/text_helper_test.rb | 108 ---------------------- 3 files changed, 2 insertions(+), 191 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 1796d11dcd..0ca2f86dae 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,3 +1,5 @@ +* Removed textilize, textilize_without_paragraph and markdown helpers. [Santiago Pastorino] + *Rails 3.0.0 [beta 4] (June 8th, 2010)* * Remove middleware laziness [José Valim] diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 8f63845d49..a06073ce66 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -220,89 +220,6 @@ module ActionView end * "\n" end - # Returns the text with all the Textile[http://www.textism.com/tools/textile] codes turned into HTML tags. - # - # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile]. - # This method is only available if RedCloth[http://redcloth.org/] is available. - # - # ==== Examples - # textilize("*This is Textile!* Rejoice!") - # # => "

This is Textile! Rejoice!

" - # - # textilize("I _love_ ROR(Ruby on Rails)!") - # # => "

I love ROR!

" - # - # textilize("h2. Textile makes markup -easy- simple!") - # # => "

Textile makes markup easy simple!

" - # - # textilize("Visit the Rails website "here":http://www.rubyonrails.org/.) - # # => "

Visit the Rails website here.

" - # - # textilize("This is worded strongly") - # # => "

This is worded strongly

" - # - # textilize("This is worded strongly", :filter_html) - # # => "

This is worded <strong>strongly</strong>

" - # - def textilize(text, *options) - options ||= [:hard_breaks] - text = sanitize(text) unless text.html_safe? || options.delete(:safe) - - if text.blank? - "" - else - textilized = RedCloth.new(text, options) - textilized.to_html - end.html_safe - end - - # Returns the text with all the Textile codes turned into HTML tags, - # but without the bounding

tag that RedCloth adds. - # - # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile]. - # This method is only available if RedCloth[http://redcloth.org/] is available. - # - # ==== Examples - # textilize_without_paragraph("*This is Textile!* Rejoice!") - # # => "This is Textile! Rejoice!" - # - # textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!") - # # => "I love ROR!" - # - # textilize_without_paragraph("h2. Textile makes markup -easy- simple!") - # # => "

Textile makes markup easy simple!

" - # - # textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.) - # # => "Visit the Rails website here." - def textilize_without_paragraph(text, *options) - textiled = textilize(text, *options) - if textiled[0..2] == "

" then textiled = textiled[3..-1] end - if textiled[-4..-1] == "

" then textiled = textiled[0..-5] end - return textiled - end - - # Returns the text with all the Markdown codes turned into HTML tags. - # This method requires BlueCloth[http://www.deveiate.org/projects/BlueCloth] - # to be available. - # - # ==== Examples - # markdown("We are using __Markdown__ now!") - # # => "

We are using Markdown now!

" - # - # markdown("We like to _write_ `code`, not just _read_ it!") - # # => "

We like to write code, not just read it!

" - # - # markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.") - # # => "

The Markdown website - # # has more information.

" - # - # markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")') - # # => '

The ROR logo

' - def markdown(text, *options) - text = sanitize(text) unless text.html_safe? || options.delete(:safe) - (text.blank? ? "" : BlueCloth.new(text).to_html).html_safe - end - # Returns +text+ transformed into HTML using simple formatting rules. # Two or more consecutive newlines(\n\n) are considered as a # paragraph and wrapped in

tags. One newline (\n) is diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 64f1d46413..17fc8b6edd 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -1,17 +1,6 @@ # encoding: us-ascii require 'abstract_unit' require 'testing_sandbox' -begin - require 'redcloth' -rescue LoadError - $stderr.puts "Skipping textilize tests. `gem install RedCloth` to enable." -end - -begin - require 'bluecloth' -rescue LoadError - $stderr.puts "Skipping markdown tests. 'gem install bluecloth' to enable." -end class TextHelperTest < ActionView::TestCase tests ActionView::Helpers::TextHelper @@ -665,101 +654,4 @@ class TextHelperTest < ActionView::TestCase assert_equal("red", cycle("red", "blue")) assert_equal(%w{Specialized Fuji Giant}, @cycles) end - - # TODO test textilize_without_paragraph and markdown - if defined? RedCloth - def test_textilize_should_be_html_safe - assert textilize("*This is Textile!* Rejoice!").html_safe? - end - - def test_textilize - assert_equal("

This is Textile! Rejoice!

", textilize("*This is Textile!* Rejoice!")) - end - - def test_textilize_with_blank - assert_equal("", textilize("")) - end - - def test_textilize_with_options - assert_equal("

This is worded <strong>strongly</strong>

", textilize("This is worded strongly", :filter_html)) - end - - def test_textilize_should_sanitize_unsafe_input - assert_equal("

This is worded strongly

", textilize("This is worded strongly")) - end - - def test_textilize_should_not_sanitize_input_if_safe_option - assert_equal("

This is worded strongly

", textilize("This is worded strongly", :safe)) - end - - def test_textilize_should_not_sanitize_safe_input - assert_equal("

This is worded strongly

", textilize("This is worded strongly".html_safe)) - end - - def test_textilize_with_hard_breaks - assert_equal("

This is one scary world.
\n True.

", textilize("This is one scary world.\n True.")) - end - - def test_textilize_without_paragraph_should_be_html_safe - textilize_without_paragraph("*This is Textile!* Rejoice!").html_safe? - end - - def test_textilize_without_paragraph - assert_equal("This is Textile! Rejoice!", textilize_without_paragraph("*This is Textile!* Rejoice!")) - end - - def test_textilize_without_paragraph_with_blank - assert_equal("", textilize_without_paragraph("")) - end - - def test_textilize_without_paragraph_with_options - assert_equal("This is worded <strong>strongly</strong>", textilize_without_paragraph("This is worded strongly", :filter_html)) - end - - def test_textilize_without_paragraph_should_sanitize_unsafe_input - assert_equal("This is worded strongly", textilize_without_paragraph("This is worded strongly")) - end - - def test_textilize_without_paragraph_should_not_sanitize_input_if_safe_option - assert_equal("This is worded strongly", textilize_without_paragraph("This is worded strongly", :safe)) - end - - def test_textilize_without_paragraph_should_not_sanitize_safe_input - assert_equal("This is worded strongly", textilize_without_paragraph("This is worded strongly".html_safe)) - end - - def test_textilize_without_paragraph_with_hard_breaks - assert_equal("This is one scary world.
\n True.", textilize_without_paragraph("This is one scary world.\n True.")) - end - end - - if defined? BlueCloth - def test_markdown_should_be_html_safe - assert markdown("We are using __Markdown__ now!").html_safe? - end - - def test_markdown - assert_equal("

We are using Markdown now!

", markdown("We are using __Markdown__ now!")) - end - - def test_markdown_with_blank - assert_equal("", markdown("")) - end - - def test_markdown_should_sanitize_unsafe_input - assert_equal("

This is worded strongly

", markdown("This is worded strongly")) - end - - def test_markdown_should_not_sanitize_input_if_safe_option - assert_equal("

This is worded strongly

", markdown("This is worded strongly", :safe)) - end - - def test_markdown_should_not_sanitize_safe_input - assert_equal("

This is worded strongly

", markdown("This is worded strongly".html_safe)) - end - - def test_markdown_with_hard_breaks - assert_equal("

This is one scary world.

\n\n

True.

", markdown("This is one scary world.\n\nTrue.")) - end - end end -- cgit v1.2.3 From 211799450d25c3e6a42a48a5146af5bed78cd66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 9 Jun 2010 22:48:50 +0200 Subject: Ensure show exceptions middleware properly filters backtrace before logging. --- actionpack/lib/action_dispatch/middleware/show_exceptions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 8a2d8cd077..0a6d2bfc8a 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -135,7 +135,7 @@ module ActionDispatch ActiveSupport::Deprecation.silence do message = "\n#{exception.class} (#{exception.message}):\n" message << exception.annoted_source_code if exception.respond_to?(:annoted_source_code) - message << exception.backtrace.join("\n ") + message << " " << application_trace(exception).join("\n ") logger.fatal("#{message}\n\n") end end -- cgit v1.2.3 From c4d6245e875bbb276c122a5a401422d341dac4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20A=CC=81lvarez?= Date: Thu, 10 Jun 2010 11:41:32 +0200 Subject: Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. [#4818 state:resolved] Signed-off-by: David Heinemeier Hansson --- actionpack/CHANGELOG | 5 ++++ .../middleware/session/abstract_store.rb | 7 +++++- .../middleware/session/cookie_store.rb | 8 ++++++ .../test/dispatch/session/cookie_store_test.rb | 29 ++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 0ca2f86dae..967bd76025 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,10 @@ +*Rails 3.0.0 [Release Candidate] (unreleased)* + +* Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. #4818 [Guillermo Álvarez] + * Removed textilize, textilize_without_paragraph and markdown helpers. [Santiago Pastorino] + *Rails 3.0.0 [beta 4] (June 8th, 2010)* * Remove middleware laziness [José Valim] diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 3e8d64b0c6..040a83f7a6 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -121,7 +121,12 @@ module ActionDispatch unless options[:expire_after].nil? cookie[:expires] = Time.now + options.delete(:expire_after) end - + + if options[:domain] == :all + top_level_domain = env["HTTP_HOST"].split('.')[-2..-1].join('.') + options[:domain] = ".#{top_level_domain}" + end + request = ActionDispatch::Request.new(env) set_cookie(request, cookie.merge!(options)) end diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 92a86ee229..0fc63d026f 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -34,6 +34,14 @@ module ActionDispatch # integrity defaults to 'SHA1' but may be any digest provided by OpenSSL, # such as 'MD5', 'RIPEMD160', 'SHA256', etc. # + # * :domain: Restrict the session cookie to certain domain level. + # If you use a schema like www.example.com and wants to share session + # with user.example.com set :domain to :all + # + # :domain => nil # Does not sets cookie domain. (default) + # :domain => :all # Allow the cookie for the top most level + # domain and subdomains. + # # To generate a secret key for an existing application, run # "rake secret" and set the key in config/environment.rb. # diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index 21d11ff31c..b542824789 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -185,6 +185,35 @@ class CookieStoreTest < ActionController::IntegrationTest end end + def test_session_store_with_explicit_domain + with_test_route_set(:domain => "example.es") do + get '/set_session_value' + assert_match /domain=example\.es/, headers['Set-Cookie'] + headers['Set-Cookie'] + end + end + + def test_session_store_without_domain + with_test_route_set do + get '/set_session_value' + assert_no_match /domain\=/, headers['Set-Cookie'] + end + end + + def test_session_store_with_nil_domain + with_test_route_set(:domain => nil) do + get '/set_session_value' + assert_no_match /domain\=/, headers['Set-Cookie'] + end + end + + def test_session_store_with_all_domains + with_test_route_set(:domain => :all) do + get '/set_session_value' + assert_match /domain=\.example\.com/, headers['Set-Cookie'] + end + end + private # Overwrite get to send SessionSecret in env hash -- cgit v1.2.3 From b67ec8ba20099c8b39bf344f385bbbd2b9c8f47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Jun 2010 19:39:09 +0200 Subject: class_attribute is not a direct replacement of class_inheritable_*. If you are setting a hash or an array in class_attribute or you need to freeze it, to ensure people won't modify it in place or you need to dup it on inheritance. --- actionpack/lib/abstract_controller/view_paths.rb | 3 ++- actionpack/lib/action_controller/metal/hide_actions.rb | 6 +++--- actionpack/lib/action_view/base.rb | 17 +++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/view_paths.rb b/actionpack/lib/abstract_controller/view_paths.rb index b331eb51b6..b552a649d1 100644 --- a/actionpack/lib/abstract_controller/view_paths.rb +++ b/actionpack/lib/abstract_controller/view_paths.rb @@ -5,6 +5,7 @@ module AbstractController included do class_attribute :_view_paths self._view_paths = ActionView::PathSet.new + self._view_paths.freeze end delegate :find_template, :template_exists?, :view_paths, :formats, :formats=, @@ -61,7 +62,7 @@ module AbstractController # paths:: If a ViewPathSet is provided, use that; # otherwise, process the parameter into a ViewPathSet. def view_paths=(paths) - self._view_paths = paths.is_a?(ActionView::PathSet) ? paths : ActionView::Base.process_view_paths(paths) + self._view_paths = ActionView::Base.process_view_paths(paths) self._view_paths.freeze end end diff --git a/actionpack/lib/action_controller/metal/hide_actions.rb b/actionpack/lib/action_controller/metal/hide_actions.rb index 3358d80c35..32d7a96701 100644 --- a/actionpack/lib/action_controller/metal/hide_actions.rb +++ b/actionpack/lib/action_controller/metal/hide_actions.rb @@ -8,7 +8,7 @@ module ActionController included do class_attribute :hidden_actions - self.hidden_actions = Set.new + self.hidden_actions = Set.new.freeze end private @@ -25,7 +25,7 @@ module ActionController # ==== Parameters # *args<#to_s>:: A list of actions def hide_action(*args) - self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)) + self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze end def inherited(klass) @@ -41,7 +41,7 @@ module ActionController # Overrides AbstractController::Base#action_methods to remove any methods # that are listed as hidden methods. def action_methods - @action_methods ||= Set.new(super.reject {|name| hidden_actions.include?(name)}) + @action_methods ||= Set.new(super.reject { |name| hidden_actions.include?(name) }) end end end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 7dd9dea358..2efc575081 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -158,7 +158,6 @@ module ActionView #:nodoc: end include Helpers, Rendering, Partials, Layouts, ::ERB::Util, Context - extend ActiveSupport::Memoizable # Specify whether RJS responses should be wrapped in a try/catch block # that alert()s the caught exception (and then re-raises it). @@ -170,9 +169,6 @@ module ActionView #:nodoc: @@field_error_proc = Proc.new{ |html_tag, instance| "
#{html_tag}
".html_safe } class_attribute :helpers - remove_method :helpers - attr_reader :helpers - class_attribute :_router class << self @@ -201,20 +197,21 @@ module ActionView #:nodoc: end def self.process_view_paths(value) - return value.dup if value.is_a?(PathSet) - ActionView::PathSet.new(Array.wrap(value)) + value.is_a?(PathSet) ? + value.dup : ActionView::PathSet.new(Array.wrap(value)) end def initialize(lookup_context = nil, assigns_for_first_render = {}, controller = nil, formats = nil) #:nodoc: - @config = nil - @assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) } - @helpers = self.class.helpers || Module.new + self.assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) } + self.helpers = self.class.helpers || Module.new if @_controller = controller @_request = controller.request if controller.respond_to?(:request) end - @_config = ActiveSupport::InheritableOptions.new(controller.config) if controller && controller.respond_to?(:config) + config = controller && controller.respond_to?(:config) ? controller.config : {} + @_config = ActiveSupport::InheritableOptions.new(config) + @_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } @_virtual_path = nil @output_buffer = nil -- cgit v1.2.3 From 51590ad1756183f84a3df4790d0b07bcf1e74ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Jun 2010 19:49:10 +0200 Subject: Remove punctuate_body! No code in lib was using it and it had no documentation. --- actionpack/lib/action_view/base.rb | 6 ------ actionpack/test/template/body_parts_test.rb | 25 ------------------------- 2 files changed, 31 deletions(-) delete mode 100644 actionpack/test/template/body_parts_test.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 2efc575081..5fa1b5619b 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -225,12 +225,6 @@ module ActionView #:nodoc: @controller_path ||= controller && controller.controller_path end - def punctuate_body!(part) - flush_output_buffer - response.body_parts << part - nil - end - ActiveSupport.run_load_hooks(:action_view, self) end end diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb deleted file mode 100644 index 69cf684083..0000000000 --- a/actionpack/test/template/body_parts_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'abstract_unit' - -class BodyPartsTest < ActionController::TestCase - RENDERINGS = [Object.new, Object.new, Object.new] - - class TestController < ActionController::Base - def response_body() "" end - - def index - RENDERINGS.each do |rendering| - view_context.punctuate_body! rendering - end - end - end - - tests TestController - - def test_body_parts - get :index - # TestProcess buffers body_parts into body - # TODO: Rewrite test w/o going through process - assert_equal RENDERINGS, @response.body_parts - assert_equal RENDERINGS.join, @response.body - end -end -- cgit v1.2.3 From 566967eaf3a66ff6a7e31f43894e21a1940ba9e7 Mon Sep 17 00:00:00 2001 From: Alan Harper Date: Mon, 19 Apr 2010 12:48:35 +1000 Subject: Missing method error doesn't specify which controller it is missing from [#4436 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error page shown when the method you are requesting on a controller doesn't specify which controller the method is missing from Signed-off-by: José Valim --- actionpack/lib/abstract_controller/base.rb | 2 +- actionpack/test/controller/base_test.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index ff97a7e76a..e1027840ef 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -106,7 +106,7 @@ module AbstractController @_action_name = action_name = action.to_s unless action_name = method_for_action(action_name) - raise ActionNotFound, "The action '#{action}' could not be found" + raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}" end @_response_body = nil diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 49f79681f6..4f58b5d968 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -90,6 +90,7 @@ class RecordIdentifierController < ActionController::Base end class ControllerClassTests < ActiveSupport::TestCase + def test_controller_path assert_equal 'empty', EmptyController.controller_path assert_equal EmptyController.controller_path, EmptyController.new.controller_path @@ -166,7 +167,15 @@ class PerformActionTest < ActionController::TestCase rescue_action_in_public! end - + + def test_process_should_be_precise + use_controller EmptyController + exception = assert_raise AbstractController::ActionNotFound do + get :non_existent + end + assert_equal exception.message, "The action 'non_existent' could not be found for EmptyController" + end + def test_get_on_priv_should_show_selector use_controller MethodMissingController get :shouldnt_be_called -- cgit v1.2.3 From 330a89072a493aafef1e07c3558964477f85adf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Jun 2010 20:05:48 +0200 Subject: Revert "Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. [#4818 state:resolved]" It does not work for domains like co.uk and com.br. This reverts commit c4d6245e875bbb276c122a5a401422d341dac4df. --- actionpack/CHANGELOG | 5 +--- .../middleware/session/abstract_store.rb | 7 +----- .../middleware/session/cookie_store.rb | 8 ------ .../test/dispatch/session/cookie_store_test.rb | 29 ---------------------- 4 files changed, 2 insertions(+), 47 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 967bd76025..562b1dba3d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,10 +1,7 @@ -*Rails 3.0.0 [Release Candidate] (unreleased)* - -* Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. #4818 [Guillermo Álvarez] +Rails 3.0.0 [Release Candidate] (unreleased)* * Removed textilize, textilize_without_paragraph and markdown helpers. [Santiago Pastorino] - *Rails 3.0.0 [beta 4] (June 8th, 2010)* * Remove middleware laziness [José Valim] diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 040a83f7a6..3e8d64b0c6 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -121,12 +121,7 @@ module ActionDispatch unless options[:expire_after].nil? cookie[:expires] = Time.now + options.delete(:expire_after) end - - if options[:domain] == :all - top_level_domain = env["HTTP_HOST"].split('.')[-2..-1].join('.') - options[:domain] = ".#{top_level_domain}" - end - + request = ActionDispatch::Request.new(env) set_cookie(request, cookie.merge!(options)) end diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 0fc63d026f..92a86ee229 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -34,14 +34,6 @@ module ActionDispatch # integrity defaults to 'SHA1' but may be any digest provided by OpenSSL, # such as 'MD5', 'RIPEMD160', 'SHA256', etc. # - # * :domain: Restrict the session cookie to certain domain level. - # If you use a schema like www.example.com and wants to share session - # with user.example.com set :domain to :all - # - # :domain => nil # Does not sets cookie domain. (default) - # :domain => :all # Allow the cookie for the top most level - # domain and subdomains. - # # To generate a secret key for an existing application, run # "rake secret" and set the key in config/environment.rb. # diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index b542824789..21d11ff31c 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -185,35 +185,6 @@ class CookieStoreTest < ActionController::IntegrationTest end end - def test_session_store_with_explicit_domain - with_test_route_set(:domain => "example.es") do - get '/set_session_value' - assert_match /domain=example\.es/, headers['Set-Cookie'] - headers['Set-Cookie'] - end - end - - def test_session_store_without_domain - with_test_route_set do - get '/set_session_value' - assert_no_match /domain\=/, headers['Set-Cookie'] - end - end - - def test_session_store_with_nil_domain - with_test_route_set(:domain => nil) do - get '/set_session_value' - assert_no_match /domain\=/, headers['Set-Cookie'] - end - end - - def test_session_store_with_all_domains - with_test_route_set(:domain => :all) do - get '/set_session_value' - assert_match /domain=\.example\.com/, headers['Set-Cookie'] - end - end - private # Overwrite get to send SessionSecret in env hash -- cgit v1.2.3