diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/application/routes_inspector.rb | 121 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/generators/erb/scaffold/templates/index.html.erb | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt | 2 | ||||
-rw-r--r-- | railties/lib/rails/info_controller.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/queueing.rb | 27 | ||||
-rw-r--r-- | railties/lib/rails/tasks/routes.rake | 4 | ||||
-rw-r--r-- | railties/lib/rails/test_help.rb | 5 |
10 files changed, 53 insertions, 136 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index d5ec2cbfd9..048219002d 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -177,7 +177,7 @@ module Rails end def queue #:nodoc: - @queue ||= build_queue + @queue ||= Queueing::Container.new(build_queue) end def build_queue #:nodoc: @@ -267,6 +267,7 @@ module Rails def default_middleware_stack #:nodoc: ActionDispatch::MiddlewareStack.new.tap do |middleware| + app = self if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache require "action_dispatch/http/rack_cache" middleware.use ::Rack::Cache, rack_cache @@ -290,11 +291,10 @@ module Rails middleware.use ::ActionDispatch::RequestId middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions, config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path) - middleware.use ::ActionDispatch::DebugExceptions + middleware.use ::ActionDispatch::DebugExceptions, app middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies unless config.cache_classes - app = self middleware.use ::ActionDispatch::Reloader, lambda { app.reload_dependencies? } end @@ -310,7 +310,7 @@ module Rails end middleware.use ::ActionDispatch::ParamsParser - middleware.use ::ActionDispatch::Head + middleware.use ::Rack::Head middleware.use ::Rack::ConditionalGet middleware.use ::Rack::ETag, "no-cache" diff --git a/railties/lib/rails/application/routes_inspector.rb b/railties/lib/rails/application/routes_inspector.rb deleted file mode 100644 index 6b2caf8277..0000000000 --- a/railties/lib/rails/application/routes_inspector.rb +++ /dev/null @@ -1,121 +0,0 @@ -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 ActionDispatch::Routing::Redirect === app || 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.*|^#{Rails.application.config.assets.prefix}} - 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. - class RoutesInspector # :nodoc: - def initialize - @engines = Hash.new - end - - def format(all_routes, filter = nil) - if filter - all_routes = all_routes.select{ |route| route.defaults[:controller] == filter } - end - - routes = collect_routes(all_routes) - - formatted_routes(routes) + - formatted_routes_for_engines - end - - def collect_routes(routes) - routes = routes.collect do |route| - RouteWrapper.new(route) - end.reject do |route| - route.internal? - end.collect do |route| - collect_engine_routes(route) - - {:name => route.name, :verb => route.verb, :path => route.path, :reqs => route.reqs } - end - end - - def collect_engine_routes(route) - name = route.endpoint - return unless route.engine? - return if @engines[name] - - routes = route.rack_app.routes - if routes.is_a?(ActionDispatch::Routing::RouteSet) - @engines[name] = collect_routes(routes.routes) - end - end - - def formatted_routes_for_engines - @engines.map do |name, routes| - ["\nRoutes for #{name}:"] + formatted_routes(routes) - end.flatten - end - - def formatted_routes(routes) - name_width = routes.map{ |r| r[:name].length }.max - verb_width = routes.map{ |r| r[:verb].length }.max - path_width = routes.map{ |r| r[:path].length }.max - - routes.map do |r| - "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" - end - end - end - end -end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 383c159d3d..f469c334a7 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -176,8 +176,7 @@ module Rails # # * routes: when you mount an Engine with <tt>mount(MyEngine::Engine => '/my_engine')</tt>, # it's used as default :as option - # * some of the rake tasks are based on engine name, e.g. <tt>my_engine:install:migrations</tt>, - # <tt>my_engine:install:assets</tt> + # * rake task for installing migrations <tt>my_engine:install:migrations</tt> # # Engine name is set by default based on class name. For <tt>MyEngine::Engine</tt> it will be # <tt>my_engine_engine</tt>. You can change it manually using the <tt>engine_name</tt> method: diff --git a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb index d78d97b2b4..f5182bcc50 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb @@ -19,7 +19,7 @@ <% end -%> <td><%%= link_to 'Show', <%= singular_table_name %> %></td> <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td> - <td><%%= link_to 'Destroy', <%= singular_table_name %>, confirm: 'Are you sure?', method: :delete %></td> + <td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td> <%% end %> </tbody> </table> diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index d480fc12b5..d2c2abf40c 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -8,6 +8,7 @@ module Rails attr_accessor :name, :type attr_reader :attr_options + attr_writer :index_name class << self def parse(column_definition) @@ -89,18 +90,26 @@ module Rails end end + def plural_name + name.sub(/_id$/, '').pluralize + end + def human_name - name.to_s.humanize + name.humanize end def index_name - if reference? + @index_name ||= if reference? polymorphic? ? %w(id type).map { |t| "#{name}_#{t}" } : "#{name}_id" else name end end + def foreign_key? + !!(name =~ /_id$/) + end + def reference? self.class.reference?(type) end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 01f9396403..fee9eb9456 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -35,7 +35,7 @@ # Do not compress assets. config.assets.compress = false - # Expands the lines which load the assets. + # Debug mode disables concatenation and preprocessing of assets. config.assets.debug = true <%- end -%> diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index bacdcbf3aa..512803aeac 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -1,4 +1,4 @@ -require 'rails/application/routes_inspector' +require 'action_dispatch/routing/inspector' class Rails::InfoController < ActionController::Base self.view_paths = File.join(File.dirname(__FILE__), 'templates') @@ -15,7 +15,7 @@ class Rails::InfoController < ActionController::Base end def routes - inspector = Rails::Application::RoutesInspector.new + inspector = ActionDispatch::Routing::RoutesInspector.new @info = inspector.format(_routes.routes).join("\n") end diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb index 8a76914548..baf6811d3e 100644 --- a/railties/lib/rails/queueing.rb +++ b/railties/lib/rails/queueing.rb @@ -1,7 +1,34 @@ require "thread" +require 'delegate' module Rails module Queueing + # A container for multiple queues. This class delegates to a default Queue + # so that <tt>Rails.queue.push</tt> and friends will Just Work. To use this class + # with multiple queues: + # + # # In your configuration: + # Rails.queue[:image_queue] = SomeQueue.new + # Rails.queue[:mail_queue] = SomeQueue.new + # + # # In your app code: + # Rails.queue[:mail_queue].push SomeJob.new + # + class Container < DelegateClass(::Queue) + def initialize(default_queue) + @queues = { :default => default_queue } + super(default_queue) + end + + def [](queue_name) + @queues[queue_name] + end + + def []=(queue_name, queue) + @queues[queue_name] = queue + end + end + # A Queue that simply inherits from STDLIB's Queue. Everytime this # queue is used, Rails automatically sets up a ThreadedConsumer # to consume it. diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 4ade825616..95f47566ef 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,7 +1,7 @@ desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' task :routes => :environment do all_routes = Rails.application.routes.routes - require 'rails/application/routes_inspector' - inspector = Rails::Application::RoutesInspector.new + require 'action_dispatch/routing/inspector' + inspector = ActionDispatch::Routing::RoutesInspector.new puts inspector.format(all_routes, ENV['CONTROLLER']).join "\n" end diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 46bf3bbe48..581ceaf9ce 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -10,7 +10,10 @@ require 'action_dispatch/testing/integration' # Enable turn if it is available begin require 'turn' - MiniTest::Unit.use_natural_language_case_names = true + + Turn.config do |c| + c.natural = true + end rescue LoadError end |