From 5913dd478150710fc0b72a0568f68e13c958d6bc Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 15:54:37 -0700 Subject: Reinstate old default_url_options method signature --- actionpack/lib/action_dispatch/routing/url_for.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index ec78f53fa6..9a64979074 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -100,7 +100,7 @@ module ActionDispatch end def url_options - default_url_options + default_url_options({}) end # Generate a url based on the options provided, default_url_options and the -- cgit v1.2.3 From 1f5e2f2bad3c33ec52312a1700bacf06a71875a5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 16:49:03 -0700 Subject: Revert "Reinstate old default_url_options method signature" This reverts commit 5913dd478150710fc0b72a0568f68e13c958d6bc. --- actionpack/lib/action_dispatch/routing/url_for.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 9a64979074..ec78f53fa6 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -100,7 +100,7 @@ module ActionDispatch end def url_options - default_url_options({}) + default_url_options end # Generate a url based on the options provided, default_url_options and the -- cgit v1.2.3 From 2a50eabf4576580dff9b43c3d830cd78e8fbb353 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 19:26:58 -0700 Subject: Integration test url options should account for :protocol not just https? --- actionpack/lib/action_dispatch/testing/integration.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 0aff4250c1..31067e56b4 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -177,14 +177,8 @@ module ActionDispatch reset! end - def url_options - opts = super.reverse_merge( - :host => host, - :protocol => https? ? "https" : "http" - ) - - opts.merge!(:port => 443) if !opts.key?(:port) && https? - opts + def default_url_options + { :host => host, :protocol => https? ? "https" : "http" } end # Resets the instance. This can be used to reset the state information -- cgit v1.2.3 From 3abf5ad7f8b23d955225ba96e82fd5565dd2571d Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 16 Mar 2010 12:38:37 -0700 Subject: Make RouteSet#finalize! a NOOP if it's been called already. Call finalize! the first time call() and url_for() are called if the RouteSet has not been finalized yet. --- actionpack/lib/action_dispatch/routing/route_set.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 722be432c7..048764263e 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -219,6 +219,8 @@ module ActionDispatch end def finalize! + return if @finalized + @finalized = true @set.add_route(NotFound) install_helpers @set.freeze @@ -227,6 +229,7 @@ module ActionDispatch def clear! # Clear the controller cache so we may discover new ones @controller_constraints = nil + @finalized = false routes.clear named_routes.clear @set = ::Rack::Mount::RouteSet.new(:parameters_key => PARAMETERS_KEY) @@ -406,6 +409,7 @@ module ActionDispatch RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash] def url_for(options) + finalize! options = default_url_options.merge(options || {}) handle_positional_args(options) @@ -437,6 +441,7 @@ module ActionDispatch end def call(env) + finalize! @set.call(env) end -- cgit v1.2.3 From 23b6def0eb76ac0719e420fce91ba862f880a37b Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 16 Mar 2010 14:55:42 -0700 Subject: Do not always include the named URL helpers into AC::Base and AV::Base. --- actionpack/lib/action_dispatch/routing/route_set.rb | 1 - .../lib/action_dispatch/testing/assertions/routing.rb | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 048764263e..5537bbbbe8 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -222,7 +222,6 @@ module ActionDispatch return if @finalized @finalized = true @set.add_route(NotFound) - install_helpers @set.freeze end diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 1d7e8090e4..eb28cd5107 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -145,11 +145,25 @@ module ActionDispatch old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new old_controller, @controller = @controller, @controller.clone if @controller _router = @router - @controller.singleton_class.send(:send, :include, @router.url_helpers) if @controller + + # Unfortunately, there is currently an abstraction leak between AC::Base + # and AV::Base which requires having the URL helpers in both AC and AV. + # To do this safely at runtime for tests, we need to bump up the helper serial + # to that the old AV subclass isn't cached. + # + # TODO: Make this unnecessary + if @controller + @controller.singleton_class.send(:include, @router.url_helpers) + @controller.class._helper_serial += 1 + @controller.view_context.singleton_class.send(:include, @router.url_helpers) + end yield @router ensure @router = old_routes - @controller = old_controller if @controller + if @controller + @controller = old_controller + @controller.class._helper_serial += 1 if @controller + end end # ROUTES TODO: These assertions should really work in an integration context -- cgit v1.2.3 From 7c49b1adbbe1ffd42c8cd6fc0439d53895c861cf Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 16 Mar 2010 17:28:44 -0700 Subject: Make sure options[:anchor] is correct in shorthand cases --- actionpack/lib/action_dispatch/routing/mapper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f9b27a5a03..668abb5fdf 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -51,7 +51,9 @@ module ActionDispatch options.merge!(:to => to).delete(path) if path when using_match_shorthand?(args, options) path = args.first - options = { :to => path.gsub("/", "#"), :as => path.gsub("/", "_") } + options = { :to => path.gsub("/", "#"), + :as => path.gsub("/", "_") + }.merge(options || {}) else path = args.first end @@ -301,7 +303,6 @@ module ActionDispatch options = args.extract_options! options = (@scope[:options] || {}).merge(options) - options[:anchor] = true unless options.key?(:anchor) if @scope[:name_prefix] && !options[:as].blank? options[:as] = "#{@scope[:name_prefix]}_#{options[:as]}" @@ -563,6 +564,8 @@ module ActionDispatch def match(*args) options = args.extract_options! + options[:anchor] = true unless options.key?(:anchor) + if args.length > 1 args.each { |path| match(path, options) } return self -- cgit v1.2.3 From c7388124153e1b1f85965998e5d1c20eed670da8 Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 16 Mar 2010 21:37:43 -0700 Subject: Another missing require --- actionpack/lib/action_dispatch/routing.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index 5bc3205c51..c6e942555f 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/regexp' +require 'action_controller/polymorphic_routes' module ActionDispatch # == Routing -- cgit v1.2.3 From cd9ffd11e13ef6e62eba2cbd5c3760ff04132820 Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 16 Mar 2010 23:24:00 -0700 Subject: Eliminate warnings for AM on 1.8 --- actionpack/lib/action_dispatch/http/filter_parameters.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/http/filter_parameters.rb b/actionpack/lib/action_dispatch/http/filter_parameters.rb index 451b79b190..e42b4d09b0 100644 --- a/actionpack/lib/action_dispatch/http/filter_parameters.rb +++ b/actionpack/lib/action_dispatch/http/filter_parameters.rb @@ -25,7 +25,6 @@ module ActionDispatch module FilterParameters extend ActiveSupport::Concern - mattr_reader :compiled_parameter_filter_for @@compiled_parameter_filter_for = {} # Return a hash of parameters with all sensitive data replaced. -- cgit v1.2.3 From 13a783672aad338b9c7ade5319ec7967768905d7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 17 Mar 2010 16:04:41 -0500 Subject: Install url helpers on module instance so they can be accessed globally --- actionpack/lib/action_dispatch/routing/route_set.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 5537bbbbe8..8936d7659a 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -65,7 +65,7 @@ module ActionDispatch # named routes. class NamedRouteCollection #:nodoc: include Enumerable - attr_reader :routes, :helpers + attr_reader :routes, :helpers, :module def initialize clear! @@ -241,21 +241,29 @@ module ActionDispatch def url_helpers @url_helpers ||= begin - router = self + routes = self - Module.new do + helpers = Module.new do extend ActiveSupport::Concern include UrlFor + @routes = routes + class << self + delegate :url_for, :to => '@routes' + end + extend routes.named_routes.module + # ROUTES TODO: install_helpers isn't great... can we make a module with the stuff that # we can include? # Yes plz - JP included do - router.install_helpers(self) + routes.install_helpers(self) end - define_method(:_router) { router } + define_method(:_router) { routes } end + + helpers end end -- cgit v1.2.3 From 947f86c699b33bd44703b3554db58e4cfca37c86 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 17 Mar 2010 14:19:42 -0700 Subject: Modify assert_template to use instrumentation --- .../action_dispatch/testing/assertions/response.rb | 52 ---------------------- 1 file changed, 52 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 937c9f48d2..ec5e9efe44 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -73,58 +73,6 @@ module ActionDispatch end end - # Asserts that the request was rendered with the appropriate template file or partials - # - # ==== Examples - # - # # assert that the "new" view template was rendered - # assert_template "new" - # - # # assert that the "_customer" partial was rendered twice - # assert_template :partial => '_customer', :count => 2 - # - # # assert that no partials were rendered - # assert_template :partial => false - # - def assert_template(options = {}, message = nil) - validate_request! - - case options - when NilClass, String - rendered = (@controller.template.rendered[:template] || []).map { |t| t.identifier } - msg = build_message(message, - "expecting but rendering with ", - options, rendered.join(', ')) - assert_block(msg) do - if options.nil? - @controller.template.rendered[:template].blank? - else - rendered.any? { |t| t.match(options) } - end - end - when Hash - if expected_partial = options[:partial] - partials = @controller.template.rendered[:partials] - if expected_count = options[:count] - found = partials.detect { |p, _| p.identifier.match(expected_partial) } - actual_count = found.nil? ? 0 : found.second - msg = build_message(message, - "expecting ? to be rendered ? time(s) but rendered ? time(s)", - expected_partial, expected_count, actual_count) - assert(actual_count == expected_count.to_i, msg) - else - msg = build_message(message, - "expecting partial but action rendered ", - options[:partial], partials.keys) - assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg) - end - else - assert @controller.template.rendered[:partials].empty?, - "Expected no partials to be rendered" - end - end - end - private # Proxy to to_param if the object will respond to it. def parameterize(value) -- cgit v1.2.3 From 6c0c0f41a3bad10c3c1acaf3124746f891f9ccbf Mon Sep 17 00:00:00 2001 From: Mathias Biilmann Christensen Date: Tue, 16 Mar 2010 12:26:14 +0100 Subject: Fix for missing dependency in ActionDispatch::Integration When running cucumber features from a new rails 3 app requiring 'cucumber/rails/world' would raise: uninitialized constant ActionDispatch::Integration::Session::Test (NameError) Fixed by requiring 'test/unit/assertions' in action_dispatch/integration Signed-off-by: Jeremy Kemper --- actionpack/lib/action_dispatch/testing/integration.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 31067e56b4..305c2bfc32 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -2,6 +2,7 @@ require 'stringio' require 'uri' require 'active_support/core_ext/object/singleton_class' require 'rack/test' +require 'test/unit/assertions' module ActionDispatch module Integration #:nodoc: -- cgit v1.2.3 From 0e15f07b75d04ddc349a93ad7fdfcbc502ef535d Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 17 Mar 2010 17:52:16 -0700 Subject: Get modules back into integration tests --- actionpack/lib/action_dispatch/testing/integration.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 305c2bfc32..4ed62a6ac4 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -288,6 +288,8 @@ module ActionDispatch end module Runner + include ActionDispatch::Assertions + def app @app end @@ -455,6 +457,7 @@ module ActionDispatch # end class IntegrationTest < ActiveSupport::TestCase include Integration::Runner + include ActionController::TemplateAssertions @@app = nil -- cgit v1.2.3 From c8dd6f224c9345b7e95cc0203b636e49412b71dc Mon Sep 17 00:00:00 2001 From: Mathias Biilmann Christensen Date: Thu, 18 Mar 2010 01:15:52 +0100 Subject: Deleting and setting a cookie in the same request was broken Made sure to remove a cookie from @deleted_cookies when set [#4211 state:committed] Signed-off-by: Jeremy Kemper --- actionpack/lib/action_dispatch/middleware/cookies.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 0dc03a1a7e..ab7130ab08 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -84,6 +84,7 @@ module ActionDispatch options[:path] ||= "/" @set_cookies[key] = options + @delete_cookies.delete(key) value end -- cgit v1.2.3 From 71c9337f45f9c5461cbc6ddf6cab764ad0f82c3b Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 15:52:43 -0700 Subject: All tests pass without memoizing view_context --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index eb28cd5107..de833bb3ca 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -154,15 +154,14 @@ module ActionDispatch # TODO: Make this unnecessary if @controller @controller.singleton_class.send(:include, @router.url_helpers) - @controller.class._helper_serial += 1 - @controller.view_context.singleton_class.send(:include, @router.url_helpers) + @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 end yield @router ensure @router = old_routes if @controller @controller = old_controller - @controller.class._helper_serial += 1 if @controller + @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 if @controller end end -- cgit v1.2.3 From a5d80f84d269bba6b0f0802612f29df1ee09d720 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 18:12:04 -0700 Subject: Each controller class has it's own view context subclass. This removes the need for ActionView::Base.for_controller --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index de833bb3ca..1bb81ede3b 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -153,15 +153,16 @@ module ActionDispatch # # TODO: Make this unnecessary if @controller - @controller.singleton_class.send(:include, @router.url_helpers) - @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 + @controller.singleton_class.send(:include, _router.url_helpers) + @controller.view_context_class = Class.new(@controller.view_context_class) do + include _router.url_helpers + end end yield @router ensure @router = old_routes if @controller @controller = old_controller - @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 if @controller end end -- cgit v1.2.3 From 995f57033f5a36d9ddd3aa65f0f01cccbb6baf6e Mon Sep 17 00:00:00 2001 From: wycats Date: Thu, 18 Mar 2010 22:21:25 -0700 Subject: We seem to have removed the URL helpers from ActionView subclasses... --- actionpack/lib/action_dispatch/routing/route_set.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 8936d7659a..52f3fd1610 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -258,6 +258,7 @@ module ActionDispatch # Yes plz - JP included do routes.install_helpers(self) + singleton_class.send(:define_method, :_router) { routes } end define_method(:_router) { routes } -- cgit v1.2.3 From 525382f638bce6addc3f77074770c4141864137b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 20 Mar 2010 00:28:27 +0100 Subject: Clean up Mime::Type and remove deprecated stuff (from 2.3). --- actionpack/lib/action_dispatch/http/mime_type.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 13c0f2bad0..3f1a77295d 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -52,12 +52,6 @@ module Mime cattr_reader :browser_generated_types attr_reader :symbol - @@unverifiable_types = Set.new [:text, :json, :csv, :xml, :rss, :atom, :yaml] - def self.unverifiable_types - ActiveSupport::Deprecation.warn("unverifiable_types is deprecated and has no effect", caller) - @@unverifiable_types - end - # A simple helper class used in parsing the accept header class AcceptItem #:nodoc: attr_accessor :order, :name, :q @@ -100,7 +94,7 @@ module Mime end def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false) - Mime.instance_eval { const_set symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms) } + Mime.const_set(symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms)) SET << Mime.const_get(symbol.to_s.upcase) -- cgit v1.2.3 From 4998e097cc597f26cbe292552bcf5608b87cb1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 22 Mar 2010 21:03:43 +0100 Subject: Make router shortcuts more polite to URLs starting with a leading slash. --- actionpack/lib/action_dispatch/routing/mapper.rb | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 668abb5fdf..ddee742021 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -45,20 +45,23 @@ module ActionDispatch def extract_path_and_options(args) options = args.extract_options! - case - when using_to_shorthand?(args, options) + if using_to_shorthand?(args, options) path, to = options.find { |name, value| name.is_a?(String) } options.merge!(:to => to).delete(path) if path - when using_match_shorthand?(args, options) - path = args.first - options = { :to => path.gsub("/", "#"), - :as => path.gsub("/", "_") - }.merge(options || {}) else path = args.first end - [ normalize_path(path), options ] + path = normalize_path(path) + + if using_match_shorthand?(path, options) + options = { + :to => path[1..-1].sub(%r{/([^/]*)$}, '#\1'), + :as => path[1..-1].gsub("/", "_") + }.merge!(options) + end + + [ path, options ] end # match "account" => "account#index" @@ -67,14 +70,13 @@ module ActionDispatch end # match "account/overview" - def using_match_shorthand?(args, options) - args.present? && options.except(:via, :anchor).empty? && !args.first.include?(':') + def using_match_shorthand?(path, options) + path && options.except(:via, :anchor).empty? && !path.include?(':') end def normalize_path(path) - path = "#{@scope[:path]}/#{path}" - raise ArgumentError, "path is required" if path.empty? - Mapper.normalize_path(path) + raise ArgumentError, "path is required" if @scope[:path].blank? && path.blank? + Mapper.normalize_path("#{@scope[:path]}/#{path}") end def app @@ -146,8 +148,8 @@ module ActionDispatch def segment_keys @segment_keys ||= Rack::Mount::RegexpWithNamedGroups.new( - Rack::Mount::Strexp.compile(@path, requirements, SEPARATORS) - ).names + Rack::Mount::Strexp.compile(@path, requirements, SEPARATORS) + ).names end def to -- cgit v1.2.3 From 15c31c7639b4329eba341bbe894abc9b79edc5c3 Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 22 Mar 2010 17:04:56 -0700 Subject: open_session can just return the a dup of the current context. At this point, its entire purpose in the open_session {} case was to delegate back to the IntegrationTest anyway. --- .../lib/action_dispatch/testing/integration.rb | 27 +++------------------- 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 4ed62a6ac4..621d63c5e2 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -297,7 +297,7 @@ module ActionDispatch # Reset the current session. This is useful for testing multiple sessions # in a single test case. def reset! - @integration_session = open_session + @integration_session = Integration::Session.new(app) end %w(get post put head delete cookies assigns @@ -323,30 +323,9 @@ module ActionDispatch # can use this method to open multiple sessions that ought to be tested # simultaneously. def open_session(app = nil) - session = Integration::Session.new(app || self.app) - - # delegate the fixture accessors back to the test instance - extras = Module.new { attr_accessor :delegate, :test_result } - if self.class.respond_to?(:fixture_table_names) - self.class.fixture_table_names.each do |table_name| - name = table_name.tr(".", "_") - next unless respond_to?(name) - extras.__send__(:define_method, name) { |*args| - delegate.send(name, *args) - } - end + dup.tap do |session| + yield session if block_given? end - - # delegate add_assertion to the test case - extras.__send__(:define_method, :add_assertion) { - test_result.add_assertion - } - session.extend(extras) - session.delegate = self - session.test_result = @_result - - yield session if block_given? - session end # Copy the instance variables from the current session instance into the -- cgit v1.2.3 From cc0e402aa870fa710d6b6189dc090244b4462308 Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 23 Mar 2010 14:08:31 -0700 Subject: Protect routes again so they don't end up as actions. We need a better solution than this. --- actionpack/lib/action_dispatch/routing/route_set.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 52f3fd1610..bb689beed9 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -179,6 +179,7 @@ module ActionDispatch url_for(options) end + protected :#{selector} END_EVAL helpers << selector end -- cgit v1.2.3 From b2c2b0ce459a215d389f3ab8bb9e33718460cf51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 26 Mar 2010 15:41:05 +0100 Subject: Rails router automatically calculated for you the controller and named routes in the following scenarios: match "home/about" #=> maps to home#about with named route home_about_path match "about" #=> does not work because it cannot guess the controller match "about" => "home#about" #=> maps to home#about with named route home_about_path match "home/about", :as => "about" #=> maps to home#about with named route about_path --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ddee742021..278cf383ee 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -55,10 +55,8 @@ module ActionDispatch path = normalize_path(path) if using_match_shorthand?(path, options) - options = { - :to => path[1..-1].sub(%r{/([^/]*)$}, '#\1'), - :as => path[1..-1].gsub("/", "_") - }.merge!(options) + options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1') + options[:as] ||= path[1..-1].gsub("/", "_") end [ path, options ] @@ -71,7 +69,7 @@ module ActionDispatch # match "account/overview" def using_match_shorthand?(path, options) - path && options.except(:via, :anchor).empty? && !path.include?(':') + path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w\/]+$} end def normalize_path(path) -- cgit v1.2.3 From 395d6648ce7549f71dd0a76dc061e87f608aaaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 26 Mar 2010 18:47:55 +0100 Subject: Move application configuration to the application configuration object, remove railtie_name and engine_name and allow to set the configuration object. --- actionpack/lib/action_dispatch/railtie.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index e486bd4079..430c90e515 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -3,8 +3,7 @@ require "rails" module ActionDispatch class Railtie < Rails::Railtie - railtie_name :action_dispatch - + config.action_dispatch = ActiveSupport::OrderedOptions.new config.action_dispatch.x_sendfile_header = "X-Sendfile" config.action_dispatch.ip_spoofing_check = true -- cgit v1.2.3