diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 2 | ||||
-rw-r--r-- | railties/guides/rails_guides/generator.rb | 6 | ||||
-rw-r--r-- | railties/guides/source/_welcome.html.erb | 12 | ||||
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 14 | ||||
-rw-r--r-- | railties/lib/rails/application/route_inspector.rb | 92 | ||||
-rw-r--r-- | railties/lib/rails/generators/actions.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/generators/base.rb | 6 | ||||
-rw-r--r-- | railties/test/application/route_inspect_test.rb | 17 | ||||
-rw-r--r-- | railties/test/application/test_test.rb | 17 |
9 files changed, 100 insertions, 67 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 9b9be5eea4..1e7ed17f33 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -47,7 +47,7 @@ *José Valim* -## Rails 3.1.1 ## +## Rails 3.1.1 (October 07, 2011) ## * Add jquery-rails to Gemfile of plugins, test/dummy app needs it. Closes #3091. *Santiago Pastorino* diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index b5f1a471ef..49ad8f7769 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -49,8 +49,8 @@ # # KINDLE # Set to "1" to generate the .mobi with all the guides. The kindlegen -# executable must be in your PATH. Google for it if you do not have it -# locally, it is available from Amazon for free. +# executable must be in your PATH. You can get it for free from +# http://www.amazon.com/kindlepublishing # # --------------------------------------------------------------------------- @@ -199,7 +199,7 @@ module RailsGuides layout = kindle? ? 'kindle/layout' : 'layout' File.open(output_path, 'w') do |f| - view = ActionView::Base.new(source_dir, :version => @version, :mobi => "kindle/#{mobi}") + view = ActionView::Base.new(source_dir, :edge => @edge, :version => @version, :mobi => "kindle/#{mobi}") view.extend(Helpers) if guide =~ /\.(\w+)\.erb$/ diff --git a/railties/guides/source/_welcome.html.erb b/railties/guides/source/_welcome.html.erb index a5ceeee5f2..bcbb49a0ec 100644 --- a/railties/guides/source/_welcome.html.erb +++ b/railties/guides/source/_welcome.html.erb @@ -2,20 +2,18 @@ <% if @edge %> <p> - These are <b>Edge Guides</b>, based on the current - <a href="https://github.com/rails/rails/tree/master">master branch</a>. + These are <b>Edge Guides</b>, based on the current <a href="https://github.com/rails/rails/tree/<%= @version %>">master</a> branch. </p> <p> - If you are looking for the ones for the stable version please check + If you are looking for the ones for the stable version, please check <a href="http://guides.rubyonrails.org">http://guides.rubyonrails.org</a> instead. </p> <% else %> <p> - These are the new guides for Rails 3. The guides for Rails 2.3 are still available - at <a href="http://guides.rubyonrails.org/v2.3.11/">http://guides.rubyonrails.org/v2.3.11/</a>. + These are the new guides for Rails 3.1 based on <a href="https://github.com/rails/rails/tree/<%= @version %>"><%= @version %></a>. + These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together. </p> <% end %> <p> - These guides are designed to make you immediately productive with Rails, - and to help you understand how all of the pieces fit together. + The guides for Rails 2.3.x are available at <a href="http://guides.rubyonrails.org/v2.3.11/">http://guides.rubyonrails.org/v2.3.11/</a>. </p> diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index e912de974a..1c82a2941f 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -822,7 +822,7 @@ M.name # => "M" N = Module.new N.name # => "N" -Module.new.name # => "" in 1.8, nil in 1.9 +Module.new.name # => nil </ruby> You can check whether a module has a name with the predicate +anonymous?+: @@ -935,18 +935,6 @@ In the previous example the macro generates +avatar_size+ rather than +size+. NOTE: Defined in +active_support/core_ext/module/delegation.rb+ -h4. Method Names - -The builtin methods +instance_methods+ and +methods+ return method names as strings or symbols depending on the Ruby version. Active Support defines +instance_method_names+ and +method_names+ to be equivalent to them, respectively, but always getting strings back. - -For example, +ActionView::Helpers::FormBuilder+ knows this array difference is going to work no matter the Ruby version: - -<ruby> -self.field_helpers = (FormHelper.instance_method_names - ['form_for']) -</ruby> - -NOTE: Defined in +active_support/core_ext/module/method_names.rb+ - h4. Redefining Methods There are cases where you need to define a method with +define_method+, but don't know whether a method with that name already exists. If it does, a warning is issued if they are enabled. No big deal, but not clean either. diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index 26652a8e5e..5ca366c5f2 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -1,5 +1,64 @@ +require 'delegate' + module Rails class Application + class RouteWrapper < SimpleDelegator + def endpoint + rack_app ? rack_app.inspect : "#{controller}##{action}" + end + + def constraints + requirements.except(:controller, :action) + end + + def rack_app(app = self.app) + @rack_app ||= begin + class_name = app.class.name.to_s + if class_name == "ActionDispatch::Routing::Mapper::Constraints" + rack_app(app.app) + elsif class_name !~ /^ActionDispatch::Routing/ + app + end + end + end + + def verb + super.source.gsub(/[$^]/, '') + end + + def path + super.spec.to_s + end + + def name + super.to_s + end + + def reqs + @reqs ||= begin + reqs = endpoint + reqs += " #{constraints.inspect}" unless constraints.empty? + reqs + end + end + + def controller + requirements[:controller] || ':controller' + end + + def action + requirements[:action] || ':action' + end + + def internal? + path =~ %r{/rails/info/properties|^/assets} + end + + def engine? + rack_app && rack_app.respond_to?(:routes) + end + end + ## # This class is just used for displaying route information when someone # executes `rake routes`. People should not use this class. @@ -21,35 +80,22 @@ module Rails def collect_routes(routes) routes = routes.collect do |route| - route_reqs = route.requirements + RouteWrapper.new(route) + end.reject do |route| + route.internal? + end.collect do |route| + collect_engine_routes(route) - rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ - - controller = route_reqs[:controller] || ':controller' - action = route_reqs[:action] || ':action' - - endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}" - constraints = route_reqs.except(:controller, :action) - - reqs = endpoint - reqs += " #{constraints.inspect}" unless constraints.empty? - - verb = route.verb.source.gsub(/[$^]/, '') - - collect_engine_routes(reqs, rack_app) - - {:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs } + {:name => route.name, :verb => route.verb, :path => route.path, :reqs => route.reqs } end - - # Skip the route if it's internal info route - routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } end - def collect_engine_routes(name, rack_app) - return unless rack_app && rack_app.respond_to?(:routes) + def collect_engine_routes(route) + name = route.endpoint + return unless route.engine? return if @engines[name] - routes = rack_app.routes + routes = route.rack_app.routes if routes.is_a?(ActionDispatch::Routing::RouteSet) @engines[name] = collect_routes(routes.routes) end diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index ca93f9ef9d..781d7bf47c 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -1,5 +1,6 @@ require 'open-uri' require 'rbconfig' +require 'active_support/core_ext/array/wrap' module Rails module Generators diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index af743a9c51..a98244c525 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -91,7 +91,7 @@ module Rails # # The lookup in this case for test_unit as input is: # - # "test_framework:awesome", "test_framework" + # "test_unit:awesome", "test_unit" # # Which is not the desired the lookup. You can change it by providing the # :as option: @@ -102,7 +102,7 @@ module Rails # # And now it will lookup at: # - # "test_framework:controller", "test_framework" + # "test_unit:controller", "test_unit" # # Similarly, if you want it to also lookup in the rails namespace, you just # need to provide the :base value: @@ -113,7 +113,7 @@ module Rails # # And the lookup is exactly the same as previously: # - # "rails:test_framework", "test_framework:controller", "test_framework" + # "rails:test_unit", "test_unit:controller", "test_unit" # # ==== Switches # diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb index 2ad5ee6c4c..6503251b9f 100644 --- a/railties/test/application/route_inspect_test.rb +++ b/railties/test/application/route_inspect_test.rb @@ -127,5 +127,22 @@ module ApplicationTests output = @inspector.format @set.routes assert_equal [" /foo/:id(.:format) #{RackApp.name} {:id=>/[A-Z]\\d{5}/}"], output end + + def test_rake_routes_shows_route_with_rack_app_nested_with_dynamic_constraints + constraint = Class.new do + def to_s + "( my custom constraint )" + end + end + + @set.draw do + scope :constraint => constraint.new do + mount RackApp => '/foo' + end + end + + output = @inspector.format @set.routes + assert_equal [" /foo #{RackApp.name} {:constraint=>( my custom constraint )}"], output + end end end diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb index a06facc04b..aa55a3cf1e 100644 --- a/railties/test/application/test_test.rb +++ b/railties/test/application/test_test.rb @@ -27,23 +27,6 @@ module ApplicationTests run_test_file 'unit/foo_test.rb' end - # Run just in Ruby < 1.9 - if defined?(Test::Unit::Util::BacktraceFilter) - test "adds backtrace cleaner" do - app_file 'test/unit/backtrace_test.rb', <<-RUBY - require 'test_helper' - - class FooTest < ActiveSupport::TestCase - def test_truth - assert Test::Unit::Util::BacktraceFilter.ancestors.include?(Rails::BacktraceFilterForTestUnit) - end - end - RUBY - - run_test_file 'unit/backtrace_test.rb' - end - end - test "integration test" do controller 'posts', <<-RUBY class PostsController < ActionController::Base |