From 8d3cd530c4d165b1bbd2e551d491dd81e2c3bff0 Mon Sep 17 00:00:00 2001 From: Robert Glaser Date: Tue, 18 Oct 2011 15:29:16 +0200 Subject: Fixed DataMapper namings in symbols and constants. --- railties/lib/rails/engine/configuration.rb | 2 +- railties/lib/rails/generators/active_model.rb | 2 +- railties/test/application/generators_test.rb | 18 +++++++++--------- railties/test/railties/engine_test.rb | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index f424492bb4..99e0201e31 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -21,7 +21,7 @@ module Rails # Holds generators configuration: # # config.generators do |g| - # g.orm :datamapper, :migration => true + # g.orm :data_mapper, :migration => true # g.template_engine :haml # g.test_framework :rspec # end diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb index 4b828340d2..7af893e1fd 100644 --- a/railties/lib/rails/generators/active_model.rb +++ b/railties/lib/rails/generators/active_model.rb @@ -11,7 +11,7 @@ module Rails # ActiveRecord::Generators::ActiveModel.find(Foo, "params[:id]") # # => "Foo.find(params[:id])" # - # Datamapper::Generators::ActiveModel.find(Foo, "params[:id]") + # DataMapper::Generators::ActiveModel.find(Foo, "params[:id]") # # => "Foo.get(params[:id])" # # On initialization, the ActiveModel accepts the instance name that will diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 4365d00b1f..8718f27de1 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -45,10 +45,10 @@ module ApplicationTests test "generators set rails options" do with_bare_config do |c| - c.generators.orm = :datamapper + c.generators.orm = :data_mapper c.generators.test_framework = :rspec c.generators.helper = false - expected = { :rails => { :orm => :datamapper, :test_framework => :rspec, :helper => false } } + expected = { :rails => { :orm => :data_mapper, :test_framework => :rspec, :helper => false } } assert_equal(expected, c.generators.options) end end @@ -64,7 +64,7 @@ module ApplicationTests test "generators aliases, options, templates and fallbacks on initialization" do add_to_config <<-RUBY config.generators.rails :aliases => { :test_framework => "-w" } - config.generators.orm :datamapper + config.generators.orm :data_mapper config.generators.test_framework :rspec config.generators.fallbacks[:shoulda] = :test_unit config.generators.templates << "some/where" @@ -95,15 +95,15 @@ module ApplicationTests test "generators with hashes for options and aliases" do with_bare_config do |c| c.generators do |g| - g.orm :datamapper, :migration => false + g.orm :data_mapper, :migration => false g.plugin :aliases => { :generator => "-g" }, :generator => true end expected = { - :rails => { :orm => :datamapper }, + :rails => { :orm => :data_mapper }, :plugin => { :generator => true }, - :datamapper => { :migration => false } + :data_mapper => { :migration => false } } assert_equal expected, c.generators.options @@ -114,12 +114,12 @@ module ApplicationTests test "generators with string and hash for options should generate symbol keys" do with_bare_config do |c| c.generators do |g| - g.orm 'datamapper', :migration => false + g.orm 'data_mapper', :migration => false end expected = { - :rails => { :orm => :datamapper }, - :datamapper => { :migration => false } + :rails => { :orm => :data_mapper }, + :data_mapper => { :migration => false } } assert_equal expected, c.generators.options diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 06a60cd858..f8b84e49c9 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -524,7 +524,7 @@ module RailtiesTest module Bukkits class Engine < ::Rails::Engine config.generators do |g| - g.orm :datamapper + g.orm :data_mapper g.template_engine :haml g.test_framework :rspec end @@ -553,7 +553,7 @@ module RailtiesTest assert_equal :test_unit, app_generators[:test_framework] generators = Bukkits::Engine.config.generators.options[:rails] - assert_equal :datamapper, generators[:orm] + assert_equal :data_mapper, generators[:orm] assert_equal :haml , generators[:template_engine] assert_equal :rspec , generators[:test_framework] end -- cgit v1.2.3 From 7c95be54b4c3f8ad2273eea39afa233f8f8b31c1 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 20 May 2012 16:19:11 -0700 Subject: Fix generators to help with ambiguous `ApplicationController` issue In development mode, dependencies are loaded dynamically at runtime, using `const_missing`. Because of that, when one of the constants is already loaded and `const_missing` is not triggered, user can end up with unexpected results. Given such file in an Engine: ```ruby module Blog class PostsController < ApplicationController end end ``` If you load it first, before loading any application files, it will correctly load `Blog::ApplicationController`, because second line will hit `const_missing`. However if you load `ApplicationController` first, the constant will be loaded already, `const_missing` hook will not be fired and in result `PostsController` will inherit from `ApplicationController` instead of `Blog::ApplicationController`. Since it can't be fixed in `AS::Dependencies`, the easiest fix is to just explicitly load application controller. closes #6413 --- railties/lib/rails/generators/named_base.rb | 4 ++++ .../generators/rails/controller/templates/controller.rb | 4 ++++ .../rails/scaffold_controller/templates/controller.rb | 4 ++++ railties/test/generators/namespaced_generators_test.rb | 17 ++++++++++++----- 4 files changed, 24 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index e85d1b8fa2..63703176de 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -79,6 +79,10 @@ module Rails @class_path end + def namespaced_file_path + @namespaced_file_path ||= namespaced_class_path.join("/") + end + def namespaced_class_path @namespaced_class_path ||= begin namespace_path = namespace.name.split("::").map {|m| m.underscore } diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb index 52243f4a2f..9b04192126 100644 --- a/railties/lib/rails/generators/rails/controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb @@ -1,3 +1,7 @@ +<% if namespaced? -%> +require "<%= namespaced_file_path %>/application_controller" +<% end -%> + <% module_namespacing do -%> class <%= class_name %>Controller < ApplicationController <% actions.each do |action| -%> diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index b95aea5f19..5cd31bf2ee 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -1,3 +1,7 @@ +<% if namespaced? -%> +require "<%= namespaced_file_path %>/application_controller" +<% end -%> + <% module_namespacing do -%> class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %> diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index c495258343..903465392d 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -20,8 +20,14 @@ class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase def test_namespaced_controller_skeleton_is_created run_generator - assert_file "app/controllers/test_app/account_controller.rb", /module TestApp/, / class AccountController < ApplicationController/ - assert_file "test/functional/test_app/account_controller_test.rb", /module TestApp/, / class AccountControllerTest/ + assert_file "app/controllers/test_app/account_controller.rb", + /require "test_app\/application_controller"/, + /module TestApp/, + / class AccountController < ApplicationController/ + + assert_file "test/functional/test_app/account_controller_test.rb", + /module TestApp/, + / class AccountControllerTest/ end def test_skipping_namespace @@ -227,9 +233,10 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase end # Controller - assert_file "app/controllers/test_app/product_lines_controller.rb" do |content| - assert_match(/module TestApp\n class ProductLinesController < ApplicationController/, content) - end + assert_file "app/controllers/test_app/product_lines_controller.rb", + /require "test_app\/application_controller"/, + /module TestApp/, + /class ProductLinesController < ApplicationController/ assert_file "test/functional/test_app/product_lines_controller_test.rb", /module TestApp\n class ProductLinesControllerTest < ActionController::TestCase/ -- cgit v1.2.3 From edb87b19d42b2a47708a78e0762a9e761aaf1277 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 21 May 2012 16:20:18 -0700 Subject: using __method__ for the command method calls --- railties/lib/rails/configuration.rb | 10 ++-- .../configuration/middleware_stack_proxy_test.rb | 59 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 railties/test/configuration/middleware_stack_proxy_test.rb (limited to 'railties') diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 3d66019e5e..5fa7f043c6 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -39,25 +39,25 @@ module Rails end def insert_before(*args, &block) - @operations << [:insert_before, args, block] + @operations << [__method__, args, block] end alias :insert :insert_before def insert_after(*args, &block) - @operations << [:insert_after, args, block] + @operations << [__method__, args, block] end def swap(*args, &block) - @operations << [:swap, args, block] + @operations << [__method__, args, block] end def use(*args, &block) - @operations << [:use, args, block] + @operations << [__method__, args, block] end def delete(*args, &block) - @operations << [:delete, args, block] + @operations << [__method__, args, block] end def merge_into(other) #:nodoc: diff --git a/railties/test/configuration/middleware_stack_proxy_test.rb b/railties/test/configuration/middleware_stack_proxy_test.rb new file mode 100644 index 0000000000..5984c0b425 --- /dev/null +++ b/railties/test/configuration/middleware_stack_proxy_test.rb @@ -0,0 +1,59 @@ +require 'minitest/autorun' +require 'rails/configuration' +require 'active_support/test_case' + +module Rails + module Configuration + class MiddlewareStackProxyTest < ActiveSupport::TestCase + def setup + @stack = MiddlewareStackProxy.new + end + + def test_playback_insert_before + @stack.insert_before :foo + assert_playback :insert_before, :foo + end + + def test_playback_insert_after + @stack.insert_after :foo + assert_playback :insert_after, :foo + end + + def test_playback_swap + @stack.swap :foo + assert_playback :swap, :foo + end + + def test_playback_use + @stack.use :foo + assert_playback :use, :foo + end + + def test_playback_delete + @stack.delete :foo + assert_playback :delete, :foo + end + + def test_order + @stack.swap :foo + @stack.delete :foo + + mock = MiniTest::Mock.new + mock.expect :send, nil, [:swap, :foo] + mock.expect :send, nil, [:delete, :foo] + + @stack.merge_into mock + mock.verify + end + + private + + def assert_playback(msg_name, args) + mock = MiniTest::Mock.new + mock.expect :send, nil, [msg_name, args] + @stack.merge_into(mock) + mock.verify + end + end + end +end -- cgit v1.2.3 From a060c41ef77cf3a0e4d236a70f3fef260ff9a261 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Fri, 4 May 2012 12:54:20 +0400 Subject: Use relative path to sqlite3 db in `rails db` command Rails uses sqlit3 db file with a path relative to the rails root. It allows to execute server not from rails root only. For example you can fire `./spec/dummy/script/rails s` to start dummy application server if you develop some engine gem. Now the `rails db` command uses relative paths also and you can explore your dummy db via `./spec/dummy/script/rails db` command. --- railties/lib/rails/commands/dbconsole.rb | 2 +- railties/test/commands/dbconsole_test.rb | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index aaba47117f..cdff9c6f86 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -96,7 +96,7 @@ module Rails args << "-#{options['mode']}" if options['mode'] args << "-header" if options['header'] - args << config['database'] + args << File.expand_path(config['database'], Rails.root) find_cmd_and_exec('sqlite3', *args) diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 85a7edfacd..57074cd0ad 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -92,20 +92,25 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_sqlite3 - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', 'db') - start(adapter: 'sqlite3', database: 'db') + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', Rails.root.join('db.sqlite3').to_s) + start(adapter: 'sqlite3', database: 'db.sqlite3') assert !aborted end def test_sqlite3_mode - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', 'db') - start({adapter: 'sqlite3', database: 'db'}, ['--mode', 'html']) + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', Rails.root.join('db.sqlite3').to_s) + start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--mode', 'html']) assert !aborted end def test_sqlite3_header - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', 'db') - start({adapter: 'sqlite3', database: 'db'}, ['--header']) + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', Rails.root.join('db.sqlite3').to_s) + start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--header']) + end + + def test_sqlite3_db_absolute_path + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '/tmp/db.sqlite3') + start(adapter: 'sqlite3', database: '/tmp/db.sqlite3') assert !aborted end -- cgit v1.2.3 From 1fed1f14fc0ecb375d8a7c542669dad96541582d Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Fri, 4 May 2012 22:04:53 +0400 Subject: Fix `rails db -h` and cosmetic fixes in usage banners Ruby tries to use '-h' as short version of '--header' by default https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1372-1381. To force `rails db -h` prints an usage message we should add the `-h` options explicitly. --- railties/lib/rails/commands/console.rb | 2 +- railties/lib/rails/commands/dbconsole.rb | 7 ++++++- railties/lib/rails/commands/runner.rb | 2 +- railties/test/commands/dbconsole_test.rb | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index cd6a03fe51..b95df3e545 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -22,7 +22,7 @@ module Rails options = {} OptionParser.new do |opt| - opt.banner = "Usage: console [environment] [options]" + opt.banner = "Usage: rails console [environment] [options]" opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v } opt.on("-e", "--environment=name", String, "Specifies the environment to run this console under (test/development/production).", diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index cdff9c6f86..cc7caffc3d 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -42,7 +42,7 @@ module Rails include_password = false options = {} OptionParser.new do |opt| - opt.banner = "Usage: dbconsole [environment] [options]" + opt.banner = "Usage: rails dbconsole [environment] [options]" opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v| include_password = true end @@ -56,6 +56,11 @@ module Rails options['header'] = h end + opt.on("-h", "--help", "Show this help message.") do + puts opt + exit + end + opt.parse!(arguments) abort opt.to_s unless (0..1).include?(arguments.size) end diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 2802981e7a..77f1b15fb4 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -9,7 +9,7 @@ if ARGV.first.nil? end ARGV.clone.options do |opts| - opts.banner = "Usage: runner [options] ('Some.ruby(code)' or a filename)" + opts.banner = "Usage: rails runner [options] ('Some.ruby(code)' or a filename)" opts.separator "" diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 57074cd0ad..6d0f5ca073 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -132,6 +132,24 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase assert_match /Unknown command-line client for db/, output end + def test_print_help_short + stdout = capture(:stdout) do + start({}, ['-h']) + end + assert aborted + assert_equal '', output + assert_match /Usage:.*dbconsole/, stdout + end + + def test_print_help_long + stdout = capture(:stdout) do + start({}, ['--help']) + end + assert aborted + assert_equal '', output + assert_match /Usage:.*dbconsole/, stdout + end + private attr_reader :aborted, :output -- cgit v1.2.3 From 09be6921590a7e4ded515deb8ce77566fa41fed5 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 22 May 2012 11:45:59 +0400 Subject: Remove obsolete comment from generator gem method This comment about :env option for gem method was actual for rails 2.3 without bundler. Now bundler uses grups for this goal. --- railties/lib/rails/generators/actions.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 6cd2ea2bbd..703501e6f0 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -5,8 +5,7 @@ module Rails module Generators module Actions - # Adds an entry into Gemfile for the supplied gem. If env - # is specified, add the gem to the given environment. + # Adds an entry into Gemfile for the supplied gem. # # gem "rspec", :group => :test # gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/" -- cgit v1.2.3 From 29d17d3ab65633695babc9123463c78248e41a67 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 22 May 2012 01:40:51 -0700 Subject: Use require_dependency in generated controllers Using require in development mode will prevent required files from reloading, even if they're changed. In order to keep namespaced application_controller reloadable, we need to use require_dependency instead of require. --- .../lib/rails/generators/rails/controller/templates/controller.rb | 2 +- .../generators/rails/scaffold_controller/templates/controller.rb | 2 +- railties/test/generators/namespaced_generators_test.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb index 9b04192126..ece6bbba3b 100644 --- a/railties/lib/rails/generators/rails/controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb @@ -1,5 +1,5 @@ <% if namespaced? -%> -require "<%= namespaced_file_path %>/application_controller" +require_dependency "<%= namespaced_file_path %>/application_controller" <% end -%> <% module_namespacing do -%> diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index 5cd31bf2ee..0294bde582 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -1,5 +1,5 @@ <% if namespaced? -%> -require "<%= namespaced_file_path %>/application_controller" +require_dependency "<%= namespaced_file_path %>/application_controller" <% end -%> <% module_namespacing do -%> diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 903465392d..09169ef2d2 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -21,7 +21,7 @@ class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase def test_namespaced_controller_skeleton_is_created run_generator assert_file "app/controllers/test_app/account_controller.rb", - /require "test_app\/application_controller"/, + /require_dependency "test_app\/application_controller"/, /module TestApp/, / class AccountController < ApplicationController/ @@ -234,7 +234,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase # Controller assert_file "app/controllers/test_app/product_lines_controller.rb", - /require "test_app\/application_controller"/, + /require_dependency "test_app\/application_controller"/, /module TestApp/, /class ProductLinesController < ApplicationController/ -- cgit v1.2.3 From fe7038eac8c1a4df57a0aacf4dd77da5ef87f6df Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 22 May 2012 13:26:06 +0400 Subject: Use new hash syntax for generators gem method The Gemfile of new application uses ruby 1.9 hashes. Gem method of generators should use them too. It prevents from mixing two kinds of syntax in one file. --- railties/lib/rails/generators/actions.rb | 2 +- .../lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 2 +- railties/test/generators/actions_test.rb | 8 ++++++++ railties/test/generators/plugin_new_generator_test.rb | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 6cd2ea2bbd..92f40b9e31 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -27,7 +27,7 @@ module Rails log :gemfile, message options.each do |option, value| - parts << ":#{option} => #{value.inspect}" + parts << "#{option}: #{value.inspect}" end in_root do diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 722e37e20b..7088367462 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -139,7 +139,7 @@ task :default => :test gemfile_in_app_path = File.join(rails_app_path, "Gemfile") if File.exist? gemfile_in_app_path - entry = "gem '#{name}', :path => '#{relative_path}'" + entry = "gem '#{name}', path: '#{relative_path}'" append_file gemfile_in_app_path, entry end end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index a8c8fcd5b7..bc086c5986 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -67,6 +67,14 @@ class ActionsTest < Rails::Generators::TestCase assert_file 'Gemfile', /^gem "rspec-rails"$/ end + def test_gem_should_include_options + run_generator + + action :gem, 'rspec', github: 'dchelimsky/rspec', tag: '1.2.9.rc1' + + assert_file 'Gemfile', /gem "rspec", github: "dchelimsky\/rspec", tag: "1\.2\.9\.rc1"/ + end + def test_gem_group_should_wrap_gems_in_a_group run_generator diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 51374e5f3f..58740978aa 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -279,7 +279,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator [destination_root] - assert_file gemfile_path, /gem 'bukkits', :path => 'tmp\/bukkits'/ + assert_file gemfile_path, /gem 'bukkits', path: 'tmp\/bukkits'/ ensure Object.send(:remove_const, 'APP_PATH') FileUtils.rm gemfile_path @@ -294,7 +294,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip-gemfile-entry"] assert_file gemfile_path do |contents| - assert_no_match(/gem 'bukkits', :path => 'tmp\/bukkits'/, contents) + assert_no_match(/gem 'bukkits', path: 'tmp\/bukkits'/, contents) end ensure Object.send(:remove_const, 'APP_PATH') -- cgit v1.2.3 From 43fa48e5aa981bf86635fa31ace9eede24e93826 Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Tue, 22 May 2012 19:51:02 +0530 Subject: Move root method at TOP of routes file Made the change as per the following text in routing guide:- "You should put the root route at the top of the file, because it is the most popular route and should be matched first." However, if root is best left at bottom. We will change to fix that text --- railties/lib/rails/generators/rails/app/templates/config/routes.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb index 286e93c3cf..303e47877f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb @@ -1,6 +1,10 @@ <%= app_const %>.routes.draw do # The priority is based upon order of creation: # first created -> highest priority. + + # You can have the root of your site routed with "root" + # just remember to delete public/index.html. + # root :to => 'welcome#index' # Sample of regular route: # get 'products/:id' => 'catalog#view' @@ -46,9 +50,6 @@ # resources :products # end - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - # root :to => 'welcome#index' # See how all your routes lay out with "rake routes" end \ No newline at end of file -- cgit v1.2.3 From 8662722f4fea34259da4d37abd6c55ec717f9d2a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 22 May 2012 16:33:08 -0700 Subject: initialize our instance variables --- railties/lib/rails/engine.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 47856c87c6..33bd339b46 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -340,6 +340,18 @@ module Rails autoload :Configuration, "rails/engine/configuration" autoload :Railties, "rails/engine/railties" + def initialize + @_all_autoload_paths = nil + @_all_load_paths = nil + @app = nil + @config = nil + @env_config = nil + @helpers = nil + @railties = nil + @routes = nil + super + end + def load_generators(app=self) initialize_generators railties.all { |r| r.load_generators(app) } @@ -615,14 +627,14 @@ module Rails end end - protected + protected def initialize_generators require "rails/generators" end def routes? - defined?(@routes) && @routes + @routes end def has_migrations? -- cgit v1.2.3 From 580333fdc200eb7d2422f087e28d912bc324c42c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 22 May 2012 16:36:08 -0700 Subject: initialize instance variables --- railties/lib/rails/application.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index c4edbae55b..5c52235318 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -75,8 +75,12 @@ module Rails def initialize super - @initialized = false - @reloaders = [] + @initialized = false + @reloaders = [] + @routes_reloader = nil + @env_config = nil + @ordered_railties = nil + @queue = nil end # This method is called just after an application inherits from Rails::Application, -- cgit v1.2.3 From 1ca1b1ab9176c780989be7e5a11d27fb97fe663a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 22 May 2012 16:43:12 -0700 Subject: use RUBY_PLATFORM in case of cross compiled ruby --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 33bd339b46..3dc5a29d4a 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -652,7 +652,7 @@ module Rails root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root - RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? + RUBY_PLATFORM =~ /mswin|mingw/ ? Pathname.new(root).expand_path : Pathname.new(root).realpath end -- cgit v1.2.3 From 3f870f607d2c1f422d0699e85017e5289aebef97 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 22 May 2012 17:22:06 -0700 Subject: use File.realpath and avoid making Pathname objects --- railties/lib/rails/engine.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 3dc5a29d4a..b327dd1e4a 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -652,8 +652,7 @@ module Rails root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root - RUBY_PLATFORM =~ /mswin|mingw/ ? - Pathname.new(root).expand_path : Pathname.new(root).realpath + File.realpath root end def default_middleware_stack -- cgit v1.2.3 From d7de7a79c5a0c24373f90dcc569816c80501d456 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 22 May 2012 19:21:56 -0700 Subject: I guess we have to return a pathname object. o_O --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index b327dd1e4a..e0950c6929 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -652,7 +652,7 @@ module Rails root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root - File.realpath root + Pathname.new File.realpath root end def default_middleware_stack -- cgit v1.2.3 From bd9953f11e8e72f8a8a507182d7328f3c8802e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Wed, 23 May 2012 11:45:08 +0300 Subject: Remove unnecessary comment. --- railties/test/generators/assets_generator_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index d6338bd3da..a2b94f2e50 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -1,7 +1,6 @@ require 'generators/generators_test_helper' require 'rails/generators/rails/assets/assets_generator' -# FIXME: Silence the 'Could not find task "using_coffee?"' message in tests due to the public stub class AssetsGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments %w(posts) -- cgit v1.2.3 From 6c7b250ac0292001e293ee19157f3d58b7553f41 Mon Sep 17 00:00:00 2001 From: Matt Griffin Date: Fri, 21 Oct 2011 14:24:33 -0400 Subject: Add license field to gemspecs, by Matt Griffin --- railties/railties.gemspec | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/railties.gemspec b/railties/railties.gemspec index 7067253279..2a39826c8d 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -7,6 +7,7 @@ Gem::Specification.new do |s| s.summary = 'Tools for creating, working with, and running Rails applications.' s.description = 'Rails internals: application bootup, plugins, generators, and rake tasks.' s.required_ruby_version = '>= 1.9.3' + s.license = 'MIT' s.author = 'David Heinemeier Hansson' s.email = 'david@loudthinking.com' -- cgit v1.2.3 From 1ad0b378cc081937c117577ab628f2160fcc448d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 23 May 2012 22:43:08 +0530 Subject: Revert "Remove blank trailing comments" This reverts commit fa6d921e11363e9b8c4bc10f7aed0b9faffdc33a. Reason: Not a fan of such massive changes. We usually close such changes if made to Rails master as a pull request. Following the same principle here and reverting. [ci skip] --- railties/lib/rails/application.rb | 1 + railties/lib/rails/configuration.rb | 1 + railties/lib/rails/engine/configuration.rb | 1 + railties/lib/rails/generators/active_model.rb | 1 + railties/lib/rails/generators/base.rb | 1 + railties/lib/rails/generators/named_base.rb | 1 + railties/lib/rails/generators/resource_helpers.rb | 2 ++ railties/lib/rails/generators/test_case.rb | 13 +++++++++++++ railties/lib/rails/railtie.rb | 1 + railties/test/generators/shared_generator_tests.rb | 1 + 10 files changed, 23 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 6cd2c425c3..c4edbae55b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -48,6 +48,7 @@ module Rails # 10) Build the middleware stack and run to_prepare callbacks # 11) Run config.before_eager_load and eager_load if cache classes is true # 12) Run config.after_initialize callbacks + # class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' autoload :Configuration, 'rails/application/configuration' diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 57168eee83..3d66019e5e 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -32,6 +32,7 @@ module Rails # And finally they can also be removed from the stack completely: # # config.middleware.delete ActionDispatch::BestStandardsSupport + # class MiddlewareStackProxy def initialize @operations = [] diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index f4de5a4375..d3b42021fc 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -28,6 +28,7 @@ module Rails # If you want to disable color in console, do: # # config.generators.colorize_logging = false + # def generators #:nodoc: @generators ||= Rails::Configuration::Generators.new yield(@generators) if block_given? diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb index 3d3b50540a..454327f765 100644 --- a/railties/lib/rails/generators/active_model.rb +++ b/railties/lib/rails/generators/active_model.rb @@ -22,6 +22,7 @@ module Rails # # The only exception in ActiveModel for ActiveRecord is the use of self.build # instead of self.new. + # class ActiveModel attr_reader :name diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index f2ded6be84..28d7680669 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -161,6 +161,7 @@ module Rails # hook_for :resource_controller do |instance, controller| # instance.invoke controller, [ instance.name.pluralize ] # end + # def self.hook_for(*names, &block) options = names.extract_options! in_base = options.delete(:in) || base_name diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index e02f19508f..e85d1b8fa2 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -168,6 +168,7 @@ module Rails # # If the generator is invoked with class name Admin, it will check for # the presence of "AdminObserver". + # def self.check_class_collision(options={}) define_method :check_class_collision do name = if self.respond_to?(:controller_class_name) # for ScaffoldBase diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index 3c12da359b..48833869e5 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -4,6 +4,7 @@ module Rails module Generators # Deal with controller names on scaffold and add some helpers to deal with # ActiveModel. + # module ResourceHelpers mattr_accessor :skip_warn @@ -12,6 +13,7 @@ module Rails end # Set controller variables on initialization. + # def initialize(*args) #:nodoc: super diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index e8f5925ca5..ff9cf0087e 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -26,6 +26,7 @@ module Rails # destination File.expand_path("../tmp", File.dirname(__FILE__)) # setup :prepare_destination # end + # class TestCase < ActiveSupport::TestCase include FileUtils @@ -42,6 +43,7 @@ module Rails # Sets which generator should be tested: # # tests AppGenerator + # def self.tests(klass) self.generator_class = klass end @@ -50,6 +52,7 @@ module Rails # invoking it. # # arguments %w(app_name --skip-active-record) + # def self.arguments(array) self.default_arguments = array end @@ -57,6 +60,7 @@ module Rails # Sets the destination of generator files: # # destination File.expand_path("../tmp", File.dirname(__FILE__)) + # def self.destination(path) self.destination_root = path end @@ -79,6 +83,7 @@ module Rails # assert_match(/Product\.all/, index) # end # end + # def assert_file(relative, *contents) absolute = File.expand_path(relative, destination_root) assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not" @@ -101,6 +106,7 @@ module Rails # path relative to the configured destination: # # assert_no_file "config/random.rb" + # def assert_no_file(relative) absolute = File.expand_path(relative, destination_root) assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does" @@ -118,6 +124,7 @@ module Rails # assert_file "db/migrate/003_create_products.rb" # # Consequently, assert_migration accepts the same arguments has assert_file. + # def assert_migration(relative, *contents, &block) file_name = migration_file_name(relative) assert file_name, "Expected migration #{relative} to exist, but was not found" @@ -128,6 +135,7 @@ module Rails # path relative to the configured destination: # # assert_no_migration "db/migrate/create_products.rb" + # def assert_no_migration(relative) file_name = migration_file_name(relative) assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}" @@ -142,6 +150,7 @@ module Rails # assert_match(/create_table/, up) # end # end + # def assert_class_method(method, content, &block) assert_instance_method "self.#{method}", content, &block end @@ -154,6 +163,7 @@ module Rails # assert_match(/Product\.all/, index) # end # end + # def assert_instance_method(method, content) assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}" yield $2.strip if block_given? @@ -164,6 +174,7 @@ module Rails # properly: # # assert_field_type :date, :date_select + # def assert_field_type(attribute_type, field_type) assert_equal(field_type, create_generated_attribute(attribute_type).field_type) end @@ -171,6 +182,7 @@ module Rails # Asserts the given attribute type gets a proper default value: # # assert_field_default_value :string, "MyString" + # def assert_field_default_value(attribute_type, value) assert_equal(value, create_generated_attribute(attribute_type).default) end @@ -204,6 +216,7 @@ module Rails # attribute type and, optionally, the attribute name: # # create_generated_attribute(:string, 'name') + # def create_generated_attribute(attribute_type, name = 'test', index = nil) Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(':')) end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 8fbf58315a..2102f8a03c 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -110,6 +110,7 @@ module Rails # can be used in both. # # Be sure to look at the documentation of those specific classes for more information. + # class Railtie autoload :Configurable, "rails/railtie/configurable" autoload :Configuration, "rails/railtie/configuration" diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 6dc72f0fc0..e78e67725d 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -1,5 +1,6 @@ # # Tests, setup, and teardown common to the application and plugin generator suites. +# module SharedGeneratorTests def setup Rails.application = TestApp::Application -- cgit v1.2.3 From 4e5175e9570304a5efd148d11b062f15295bb11d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 May 2012 15:44:24 -0700 Subject: use File.join to decrease dependencies on Pathname --- railties/lib/rails/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 5c52235318..d44465e547 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -97,7 +97,7 @@ module Rails # Rails application, you will need to add lib to $LOAD_PATH on your own in case # you need to load files in lib/ during the application configuration as well. def add_lib_to_load_path! #:nodoc: - path = config.root.join('lib').to_s + path = File.join config.root, 'lib' $LOAD_PATH.unshift(path) if File.exists?(path) end -- cgit v1.2.3 From 4001835db00ce44cb75bca33ec02cd76b8ccc790 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 May 2012 15:56:49 -0700 Subject: removing more pathnameisms --- railties/lib/rails/engine.rb | 6 +++--- railties/lib/rails/paths.rb | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index e0950c6929..619c76206d 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -416,9 +416,9 @@ module Rails # Finds engine with given path def find(path) - expanded_path = File.expand_path path.to_s + expanded_path = File.expand_path path Rails::Engine::Railties.engines.find { |engine| - File.expand_path(engine.root.to_s) == expanded_path + File.expand_path(engine.root) == expanded_path } end end @@ -652,7 +652,7 @@ module Rails root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root - Pathname.new File.realpath root + File.realpath root end def default_middleware_stack diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index b787d91821..6cd9c7bc95 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -1,5 +1,3 @@ -require "pathname" - module Rails module Paths # This object is an extended hash that behaves as root of the Rails::Paths system. @@ -186,7 +184,7 @@ module Rails raise "You need to set a path root" unless @root.path map do |p| - Pathname.new(@root.path).join(p) + File.join @root.path, p end end -- cgit v1.2.3 From d77b576c0330d8b1c6189cb94814382ce32baab6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 May 2012 16:12:51 -0700 Subject: require the constants we use. ensure that root always returns a Pathname --- railties/lib/rails/engine/configuration.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index e31df807a6..f82c1d00fb 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -1,4 +1,5 @@ require 'rails/railtie/configuration' +require 'pathname' module Rails class Engine @@ -8,7 +9,7 @@ module Rails def initialize(root=nil) super() - @root = root + @root = root && Pathname.new(root) @generators = app_generators.dup end -- cgit v1.2.3 From 9875574bbfebfdca96a80cf1c29c83adcbbda8f8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 May 2012 16:41:40 -0700 Subject: Revert "require the constants we use. ensure that root always returns a Pathname" This reverts commit d77b576c0330d8b1c6189cb94814382ce32baab6. --- railties/lib/rails/engine/configuration.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index f82c1d00fb..e31df807a6 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -1,5 +1,4 @@ require 'rails/railtie/configuration' -require 'pathname' module Rails class Engine @@ -9,7 +8,7 @@ module Rails def initialize(root=nil) super() - @root = root && Pathname.new(root) + @root = root @generators = app_generators.dup end -- cgit v1.2.3 From 880481a355e0017c43d6ff14b2d1a657548d06bf Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 May 2012 16:43:16 -0700 Subject: use File.join rather than depend on Pathname --- railties/lib/rails/commands/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 4c4caad69f..e68d2e05c5 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -69,7 +69,7 @@ module Rails #Create required tmp directories if not found %w(cache pids sessions sockets).each do |dir_to_make| - FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make)) + FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make)) end unless options[:daemonize] -- cgit v1.2.3 From 66db0b9440e4db594c951d38f641e1910fd44db3 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Thu, 24 May 2012 16:29:08 +1200 Subject: Fixed backward incompatibility for engines. - Many engines rely on being able to join directories to the Rails root: Rails.root.join('somedir') - This was now impossible because Rails.root returned a String: NoMethodError: undefined method `join' for "/code/myrailsapp":String - This was broken in 4001835db00ce44cb75bca33ec02cd76b8ccc790 --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 619c76206d..4c7199a2e2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -652,7 +652,7 @@ module Rails root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root - File.realpath root + Pathname.new File.realpath root end def default_middleware_stack -- cgit v1.2.3 From cb44e0fed97d7cef024e9dd9cc113a75cc7d6f20 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 22 May 2012 18:23:17 -0500 Subject: /rails/info/routes path shows routing information Will show similar contents to the output of `$ rake routes` in the browser in development. This speeds the time required to generate routes, since the application is already initialized. --- railties/CHANGELOG.md | 2 ++ railties/lib/rails/application/finisher.rb | 2 ++ railties/lib/rails/application/route_inspector.rb | 2 +- railties/lib/rails/info_controller.rb | 32 +++++++++++++++++----- .../rails/templates/layouts/application.html.erb | 32 ++++++++++++++++++++++ .../rails/templates/rails/info/properties.html.erb | 1 + .../lib/rails/templates/rails/info/routes.html.erb | 9 ++++++ 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 railties/lib/rails/templates/layouts/application.html.erb create mode 100644 railties/lib/rails/templates/rails/info/properties.html.erb create mode 100644 railties/lib/rails/templates/rails/info/routes.html.erb (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index ccccc178c5..787bafea04 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Add `/rails/info/routes` path, displays same information as `rake routes` *Richard Schneeman & Andrew White* + * Improved `rake routes` output for redirects *Łukasz Strzałkowski & Andrew White* * Load all environments available in `config.paths["config/environments"]`. *Piotr Sarnacki* diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 84f2601f28..60aa40b92f 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -23,6 +23,8 @@ module Rails if Rails.env.development? app.routes.append do get '/rails/info/properties' => "rails/info#properties" + get '/rails/info/routes' => "rails/info#routes" + get '/rails/info' => "rails/info#index" end end end diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index b23fb3e920..942c4f4789 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -51,7 +51,7 @@ module Rails end def internal? - path =~ %r{/rails/info/properties|^#{Rails.application.config.assets.prefix}} + path =~ %r{/rails/info.*|^#{Rails.application.config.assets.prefix}} end def engine? diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index 6b4bdb2921..5081074395 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -1,15 +1,33 @@ +require 'rails/application/route_inspector' + class Rails::InfoController < ActionController::Base + self.view_paths = File.join(File.dirname(__FILE__), 'templates') + layout 'application' + + before_filter :require_local! + + def index + redirect_to '/rails/info/routes' + end + def properties - if consider_all_requests_local? || request.local? - render :inline => Rails::Info.to_html - else - render :text => '

For security purposes, this information is only available to local requests.

', :status => :forbidden - end + @info = Rails::Info.to_html + end + + def routes + inspector = Rails::Application::RouteInspector.new + @info = inspector.format(_routes.routes).join("\n") end protected - def consider_all_requests_local? - Rails.application.config.consider_all_requests_local + def require_local! + unless local_request? + render :text => '

For security purposes, this information is only available to local requests.

', :status => :forbidden + end + end + + def local_request? + Rails.application.config.consider_all_requests_local || request.local? end end diff --git a/railties/lib/rails/templates/layouts/application.html.erb b/railties/lib/rails/templates/layouts/application.html.erb new file mode 100644 index 0000000000..53276d3e7c --- /dev/null +++ b/railties/lib/rails/templates/layouts/application.html.erb @@ -0,0 +1,32 @@ + + + + + Routes + + + +

Your App: <%= link_to 'properties', '/rails/info/properties' %> | <%= link_to 'routes', '/rails/info/routes' %>

+<%= yield %> + + + diff --git a/railties/lib/rails/templates/rails/info/properties.html.erb b/railties/lib/rails/templates/rails/info/properties.html.erb new file mode 100644 index 0000000000..d47cbab202 --- /dev/null +++ b/railties/lib/rails/templates/rails/info/properties.html.erb @@ -0,0 +1 @@ +<%= @info.html_safe %> \ No newline at end of file diff --git a/railties/lib/rails/templates/rails/info/routes.html.erb b/railties/lib/rails/templates/rails/info/routes.html.erb new file mode 100644 index 0000000000..890f6f5b03 --- /dev/null +++ b/railties/lib/rails/templates/rails/info/routes.html.erb @@ -0,0 +1,9 @@ +

+ Routes +

+ +

+ Routes match in priority from top to bottom +

+ +

<%= @info %>

\ No newline at end of file -- cgit v1.2.3 From c3e3102904c98a6e05bee33616288323278692b8 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 23 May 2012 14:42:28 -0500 Subject: Rails::InfoController tests passing This includes new tests for /rails/info/routes --- railties/test/application/route_inspect_test.rb | 9 +++++++++ railties/test/application/routing_test.rb | 12 ++++++++++++ railties/test/rails_info_controller_test.rb | 17 +++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb index 3b8c874b5b..e453cdb074 100644 --- a/railties/test/application/route_inspect_test.rb +++ b/railties/test/application/route_inspect_test.rb @@ -164,5 +164,14 @@ module ApplicationTests assert_equal " bar GET /bar(.:format) redirect(307, path: /foo/bar)", output[1] assert_equal "foobar GET /foobar(.:format) redirect(301)", output[2] end + + def test_presenter + output = draw do + get "/foo" => redirect("/foo/bar"), :constraints => { :subdomain => "admin" } + get "/bar" => redirect(path: "/foo/bar", status: 307) + get "/foobar" => redirect{ "/foo/bar" } + end + assert_equal output.join("\n"), Rails::Application::RoutePresenter.display_routes(@set.routes) + end end end diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 977a5fc7e8..d1373ba202 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -15,12 +15,24 @@ module ApplicationTests teardown_app end + test "rails/info/routes in development" do + app("development") + get "/rails/info/routes" + assert_equal 200, last_response.status + end + test "rails/info/properties in development" do app("development") get "/rails/info/properties" assert_equal 200, last_response.status end + test "rails/info/routes in production" do + app("production") + get "/rails/info/routes" + assert_equal 404, last_response.status + end + test "rails/info/properties in production" do app("production") get "/rails/info/properties" diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index f7a30a16d2..cfb32b7d35 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -12,29 +12,28 @@ class InfoControllerTest < ActionController::TestCase def setup Rails.application.routes.draw do get '/rails/info/properties' => "rails/info#properties" + get '/rails/info/routes' => "rails/info#routes" end - @request.stubs(:local? => true) - @controller.stubs(:consider_all_requests_local? => false) + @controller.stubs(:local_request? => true) @routes = Rails.application.routes Rails::InfoController.send(:include, @routes.url_helpers) end test "info controller does not allow remote requests" do - @request.stubs(:local? => false) + @controller.stubs(:local_request? => false) get :properties assert_response :forbidden end test "info controller renders an error message when request was forbidden" do - @request.stubs(:local? => false) + @controller.stubs(:local_request? => false) get :properties assert_select 'p' end test "info controller allows requests when all requests are considered local" do - @request.stubs(:local? => false) - @controller.stubs(:consider_all_requests_local? => true) + @controller.stubs(:local_request? => true) get :properties assert_response :success end @@ -48,4 +47,10 @@ class InfoControllerTest < ActionController::TestCase get :properties assert_select 'table' end + + test "info controller renders with routes" do + get :routes + assert_select 'pre' + end + end -- cgit v1.2.3 From d5dc462cd28c7787735ff9f571869eeb097e25f7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 24 May 2012 14:55:38 -0700 Subject: `name` should be public. --- .../rails/plugin_new/plugin_new_generator.rb | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 7088367462..ab0e440bc4 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -232,6 +232,18 @@ task :default => :test public_task :apply_rails_template, :run_bundle + def name + @name ||= begin + # same as ActiveSupport::Inflector#underscore except not replacing '-' + underscored = original_name.dup + underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') + underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + underscored.downcase! + + underscored + end + end + protected def app_templates_dir @@ -268,18 +280,6 @@ task :default => :test @original_name ||= File.basename(destination_root) end - def name - @name ||= begin - # same as ActiveSupport::Inflector#underscore except not replacing '-' - underscored = original_name.dup - underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') - underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2') - underscored.downcase! - - underscored - end - end - def camelized @camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize end -- cgit v1.2.3 From d476129691b1dd1e356f386af0532dcb2cd885ee Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 24 May 2012 15:54:30 -0700 Subject: do not set the ENGINE_PATH to nil --- railties/lib/rails/tasks/engine.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake index eea8abe7d2..70370be3f5 100644 --- a/railties/lib/rails/tasks/engine.rake +++ b/railties/lib/rails/tasks/engine.rake @@ -60,7 +60,7 @@ namespace :db do end def find_engine_path(path) - return if path == "/" + return File.expand_path(Dir.pwd) if path == "/" if Rails::Engine.find(path) path -- cgit v1.2.3 From 44591250189fd2dadc8303d094b72552d7d06543 Mon Sep 17 00:00:00 2001 From: schneems Date: Thu, 24 May 2012 21:31:09 -0500 Subject: remove unnecessary test from route_inspect_test --- railties/test/application/route_inspect_test.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'railties') diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb index e453cdb074..3b8c874b5b 100644 --- a/railties/test/application/route_inspect_test.rb +++ b/railties/test/application/route_inspect_test.rb @@ -164,14 +164,5 @@ module ApplicationTests assert_equal " bar GET /bar(.:format) redirect(307, path: /foo/bar)", output[1] assert_equal "foobar GET /foobar(.:format) redirect(301)", output[2] end - - def test_presenter - output = draw do - get "/foo" => redirect("/foo/bar"), :constraints => { :subdomain => "admin" } - get "/bar" => redirect(path: "/foo/bar", status: 307) - get "/foobar" => redirect{ "/foo/bar" } - end - assert_equal output.join("\n"), Rails::Application::RoutePresenter.display_routes(@set.routes) - end end end -- cgit v1.2.3 From baa336364da932ccaee6bb724ab615145e63c4d3 Mon Sep 17 00:00:00 2001 From: Waseem Ahmad Date: Fri, 25 May 2012 09:49:34 +0530 Subject: Fixes build 4008.1 This fixex build 4008.1[1] because of the changes made in 4001835db00ce44cb75bca33ec02cd76b8ccc790 [1] http://travis-ci.org/#!/rails/rails/jobs/1429671 --- railties/test/paths_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index aa04cad033..5d6b6f9f72 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -29,7 +29,7 @@ class PathsTest < ActiveSupport::TestCase test "creating a root level path" do @root.add "app" assert_equal ["/foo/bar/app"], @root["app"].to_a - assert_equal [Pathname.new("/foo/bar/app")], @root["app"].paths + assert_equal ["/foo/bar/app"], @root["app"].paths end test "creating a root level path with options" do @@ -192,7 +192,7 @@ class PathsTest < ActiveSupport::TestCase @root["app"] = "/app" @root["app"].glob = "*.rb" assert_equal "*.rb", @root["app"].glob - assert_equal [Pathname.new("/app")], @root["app"].paths + assert_equal ["/foo/bar/app"], @root["app"].paths end test "it should be possible to override a path's default glob without assignment" do -- cgit v1.2.3 From cf992fba95eb5d6282b0d04a52a3595f1c089512 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 27 May 2012 12:28:26 +0200 Subject: Fix railties_order when application object is passed railites_order method, introduced in 40b19e0, had a bug that was causing loading application instance twice in initializers if railties_order already included application instance. So for example railties_order = [Foo::Engine, :main_app, Bar::Engine] would result in such railties array: [MyApp::Application, Foo::Engine, MyAppApplication, Bar::Engine] In order to fix it, we need to check for existence of application in both railties_order and railties arrays. --- railties/lib/rails/application.rb | 2 +- railties/test/railties/engine_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index d44465e547..660e864d2a 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -185,7 +185,7 @@ module Rails end all = (railties.all - order) - all.push(self) unless all.include?(self) + all.push(self) unless (all + order).include?(self) order.push(:all) unless order.include?(:all) index = order.index(:all) diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 7a047ef93a..4437e2c8af 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1098,6 +1098,10 @@ YAML get("/assets/bar.js") assert_equal "// App's bar js\n;", last_response.body.strip + + # ensure that railties are not added twice + railties = Rails.application.ordered_railties.map(&:class) + assert_equal railties, railties.uniq end test "railties_order adds :all with lowest priority if not given" do -- cgit v1.2.3