From 7901ae13a1d8187c1b620b51df7d840818fd759d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez=20de=20Dios?= Date: Tue, 8 Apr 2014 20:55:23 +0200 Subject: Keep debugger support only for rubies < 2.0.0 --- railties/lib/rails/commands/console.rb | 18 ++++++++++++++---- railties/lib/rails/commands/server.rb | 13 +++++++++++-- railties/lib/rails/rack.rb | 2 +- railties/test/commands/console_test.rb | 6 +++--- 4 files changed, 29 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index f6bdf129d6..fdc8662bcd 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -18,7 +18,14 @@ module Rails opt.on("-e", "--environment=name", String, "Specifies the environment to run this console under (test/development/production).", "Default: development") { |v| options[:environment] = v.strip } - opt.on("--debugger", 'Enable the debugger.') { |v| options[:debugger] = v } + opt.on("--debugger", 'Enable the debugger.') do |v| + if RUBY_VERSION < '2.0.0' + options[:debugger] = v + else + puts "=> Notice: debugger option is ignored since ruby 2.0 and " \ + "it will be removed in future versions" + end + end opt.parse!(arguments) end @@ -71,10 +78,13 @@ module Rails def debugger? options[:debugger] - end + end if RUBY_VERSION < '2.0.0' def start - require_debugger if debugger? + if RUBY_VERSION < '2.0.0' + require_debugger if debugger? + end + set_environment! if environment? if sandbox? @@ -96,6 +106,6 @@ module Rails rescue LoadError puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle it and try again." exit(1) - end + end if RUBY_VERSION < '2.0.0' end end diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index fec4962fb5..6146b6c1db 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -18,7 +18,14 @@ module Rails opts.on("-c", "--config=file", String, "Use custom rackup configuration file") { |v| options[:config] = v } opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:daemonize] = true } - opts.on("-u", "--debugger", "Enable the debugger") { options[:debugger] = true } + opts.on("-u", "--debugger", "Enable the debugger") do + if RUBY_VERSION < '2.0.0' + options[:debugger] = true + else + puts "=> Notice: debugger option is ignored since ruby 2.0 and " \ + "it will be removed in future versions" + end + end opts.on("-e", "--environment=name", String, "Specifies the environment to run this server under (test/development/production).", "Default: development") { |v| options[:environment] = v } @@ -75,7 +82,9 @@ module Rails def middleware middlewares = [] - middlewares << [Rails::Rack::Debugger] if options[:debugger] + if RUBY_VERSION < '2.0.0' + middlewares << [Rails::Rack::Debugger] if options[:debugger] + end middlewares << [::Rack::ContentLength] # FIXME: add Rack::Lock in the case people are using webrick. diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index d1ee96f7fd..886f0e52e1 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -1,6 +1,6 @@ module Rails module Rack - autoload :Debugger, "rails/rack/debugger" + autoload :Debugger, "rails/rack/debugger" if RUBY_VERSION < '2.0.0' autoload :Logger, "rails/rack/logger" autoload :LogTailer, "rails/rack/log_tailer" end diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index a34beaedb3..87c5527b81 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -22,11 +22,11 @@ class Rails::ConsoleTest < ActiveSupport::TestCase def test_debugger_option console = Rails::Console.new(app, parse_arguments(["--debugger"])) assert console.debugger? - end + end if RUBY_VERSION < '2.0.0' def test_no_options console = Rails::Console.new(app, parse_arguments([])) - assert !console.debugger? + assert !console.debugger? if RUBY_VERSION < '2.0.0' assert !console.sandbox? end @@ -41,7 +41,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase rails_console.expects(:require_debugger).returns(nil) silence_stream(STDOUT) { rails_console.start } - end + end if RUBY_VERSION < '2.0.0' def test_start_with_sandbox app.expects(:sandbox=).with(true) -- cgit v1.2.3 From d8a4e482202bc8d42a16b2311598d49d34304bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez=20de=20Dios?= Date: Tue, 8 Apr 2014 20:57:12 +0200 Subject: Update Gemfile templates to provide correct debugger --- railties/lib/rails/generators/rails/app/templates/Gemfile | 6 +++++- railties/lib/rails/generators/rails/plugin/templates/Gemfile | 8 ++++++-- railties/test/generators/app_generator_test.rb | 7 +++++-- railties/test/generators/plugin_generator_test.rb | 7 +++++-- 4 files changed, 21 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index a9b6787894..faca76f150 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -23,8 +23,12 @@ source 'https://rubygems.org' # gem 'capistrano-rails', group: :development <% unless defined?(JRUBY_VERSION) -%> -# Use debugger +# To use a debugger + <% if RUBY_VERSION < '2.0.0' -%> # gem 'debugger', group: [:development, :test] + <% else -%> +# gem 'byebug', group: [:development, :test] + <% end -%> <% end -%> <% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince/) -%> diff --git a/railties/lib/rails/generators/rails/plugin/templates/Gemfile b/railties/lib/rails/generators/rails/plugin/templates/Gemfile index f0a832f783..5313cb6c0f 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin/templates/Gemfile @@ -38,6 +38,10 @@ end <% end -%> <% unless defined?(JRUBY_VERSION) -%> -# To use debugger -# gem 'debugger' +# To use a debugger + <% if RUBY_VERSION < '2.0.0' -%> +# gem 'debugger', group: [:development, :test] + <% else -%> +# gem 'byebug', group: [:development, :test] + <% end -%> <% end -%> diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8e1aeddb2b..68b71e9927 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -305,14 +305,17 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile", /gem 'jbuilder'/ end - def test_inclusion_of_debugger + def test_inclusion_of_a_debugger run_generator if defined?(JRUBY_VERSION) assert_file "Gemfile" do |content| + assert_no_match(/byebug/, content) assert_no_match(/debugger/, content) end - else + elsif RUBY_VERSION < '2.0.0' assert_file "Gemfile", /# gem 'debugger'/ + else + assert_file "Gemfile", /# gem 'byebug'/ end end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 7a2701f813..853af80111 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -64,14 +64,17 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "test/integration/navigation_test.rb", /ActionDispatch::IntegrationTest/ end - def test_inclusion_of_debugger + def test_inclusion_of_a_debugger run_generator [destination_root, '--full'] if defined?(JRUBY_VERSION) assert_file "Gemfile" do |content| + assert_no_match(/byebug/, content) assert_no_match(/debugger/, content) end - else + elsif RUBY_VERSION < '2.0.0' assert_file "Gemfile", /# gem 'debugger'/ + else + assert_file "Gemfile", /# gem 'byebug'/ end end -- cgit v1.2.3 From bb63e9c5902f4f6374e9c3fa5bd8041d7be9fa91 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 10 Apr 2014 15:44:38 +0900 Subject: +EOL --- .../rails/app/templates/config/initializers/cookies_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb index 7a06a89f0f..7f70458dee 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file +Rails.application.config.action_dispatch.cookies_serializer = :json -- cgit v1.2.3 From 6fae9ac58147948474c3fa472f0eb04525737d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez=20de=20Dios?= Date: Thu, 10 Apr 2014 16:02:13 +0200 Subject: Isolate debugger related code --- railties/lib/rails/commands/console.rb | 24 +++++++++++++----------- railties/test/commands/console_test.rb | 32 +++++++++++++++++++------------- 2 files changed, 32 insertions(+), 24 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index fdc8662bcd..555d8f31e1 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -76,9 +76,19 @@ module Rails Rails.env = environment end - def debugger? - options[:debugger] - end if RUBY_VERSION < '2.0.0' + if RUBY_VERSION < '2.0.0' + def debugger? + options[:debugger] + end + + def require_debugger + require 'debugger' + puts "=> Debugger enabled" + rescue LoadError + puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle it and try again." + exit(1) + end + end def start if RUBY_VERSION < '2.0.0' @@ -99,13 +109,5 @@ module Rails end console.start end - - def require_debugger - require 'debugger' - puts "=> Debugger enabled" - rescue LoadError - puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle it and try again." - exit(1) - end if RUBY_VERSION < '2.0.0' end end diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index 87c5527b81..1273f9d4c2 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -19,14 +19,8 @@ class Rails::ConsoleTest < ActiveSupport::TestCase assert console.sandbox? end - def test_debugger_option - console = Rails::Console.new(app, parse_arguments(["--debugger"])) - assert console.debugger? - end if RUBY_VERSION < '2.0.0' - def test_no_options console = Rails::Console.new(app, parse_arguments([])) - assert !console.debugger? if RUBY_VERSION < '2.0.0' assert !console.sandbox? end @@ -36,13 +30,6 @@ class Rails::ConsoleTest < ActiveSupport::TestCase assert_match(/Loading \w+ environment \(Rails/, output) end - def test_start_with_debugger - rails_console = Rails::Console.new(app, parse_arguments(["--debugger"])) - rails_console.expects(:require_debugger).returns(nil) - - silence_stream(STDOUT) { rails_console.start } - end if RUBY_VERSION < '2.0.0' - def test_start_with_sandbox app.expects(:sandbox=).with(true) FakeConsole.expects(:start) @@ -52,6 +39,25 @@ class Rails::ConsoleTest < ActiveSupport::TestCase assert_match(/Loading \w+ environment in sandbox \(Rails/, output) end + if RUBY_VERSION < '2.0.0' + def test_debugger_option + console = Rails::Console.new(app, parse_arguments(["--debugger"])) + assert console.debugger? + end + + def test_no_options_does_not_set_debugger_flag + console = Rails::Console.new(app, parse_arguments([])) + assert !console.debugger? + end + + def test_start_with_debugger + rails_console = Rails::Console.new(app, parse_arguments(["--debugger"])) + rails_console.expects(:require_debugger).returns(nil) + + silence_stream(STDOUT) { rails_console.start } + end + end + def test_console_with_environment start ["-e production"] assert_match(/\sproduction\s/, output) -- cgit v1.2.3 From 7fe49a4545d5b580ccd324ec86889eeb166c50f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez=20de=20Dios?= Date: Thu, 10 Apr 2014 16:20:46 +0200 Subject: Prevent generation of extra whitespace in templates --- railties/lib/rails/generators/rails/app/templates/Gemfile | 6 +++--- railties/lib/rails/generators/rails/plugin/templates/Gemfile | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index faca76f150..756c334772 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -24,11 +24,11 @@ source 'https://rubygems.org' <% unless defined?(JRUBY_VERSION) -%> # To use a debugger - <% if RUBY_VERSION < '2.0.0' -%> + <%- if RUBY_VERSION < '2.0.0' -%> # gem 'debugger', group: [:development, :test] - <% else -%> + <%- else -%> # gem 'byebug', group: [:development, :test] - <% end -%> + <%- end -%> <% end -%> <% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince/) -%> diff --git a/railties/lib/rails/generators/rails/plugin/templates/Gemfile b/railties/lib/rails/generators/rails/plugin/templates/Gemfile index 5313cb6c0f..1f704db510 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin/templates/Gemfile @@ -39,9 +39,9 @@ end <% end -%> <% unless defined?(JRUBY_VERSION) -%> # To use a debugger - <% if RUBY_VERSION < '2.0.0' -%> + <%- if RUBY_VERSION < '2.0.0' -%> # gem 'debugger', group: [:development, :test] - <% else -%> + <%- else -%> # gem 'byebug', group: [:development, :test] - <% end -%> + <%- end -%> <% end -%> -- cgit v1.2.3 From 53610e5140149aca3a15a27ef103350a5969f7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 10 Apr 2014 14:57:46 -0300 Subject: Require action_controller before any other action_controller file This will load properly the loading hooks. Closes rails/sass-rails#205 --- railties/lib/rails/test_help.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 2e6356343d..c837fadb40 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -4,6 +4,7 @@ abort("Abort testing: Your Rails environment is running in production mode!") if require 'active_support/testing/autorun' require 'active_support/test_case' +require 'action_controller' require 'action_controller/test_case' require 'action_dispatch/testing/integration' require 'rails/generators/test_case' -- cgit v1.2.3 From f612c2b0526e326eb6c25a7bbf375ac3ac793a3c Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Fri, 11 Apr 2014 02:28:35 +0930 Subject: Move assets precompile (and version) to an initializer sprockets-rails 2.1 needs the precompile list to be available in all environments. --- railties/CHANGELOG.md | 4 ++++ railties/lib/rails/generators/rails/app/app_generator.rb | 6 ++++++ .../rails/app/templates/config/environments/production.rb.tt | 7 +------ .../rails/app/templates/config/initializers/assets.rb.tt | 8 ++++++++ railties/test/generators/app_generator_test.rb | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index afbebf5b95..8d22f8bc48 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Move configuration of asset precompile list and version to an initializer. + + *Matthew Draper* + * Do not set the Rails environment to test by default when using test_unit Railtie. *Konstantin Shabanov* diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index abf6909a7f..8675d8bc1e 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -231,6 +231,12 @@ module Rails end end + def delete_assets_initializer_skipping_sprockets + if options[:skip_sprockets] + remove_file 'config/initializers/assets.rb' + end + end + def finish_template build(:leftovers) end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index b789ed9a94..9ed71687ea 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -33,12 +33,7 @@ Rails.application.configure do # Generate digests for assets URLs. config.assets.digest = true - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' - - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) + # `config.assets.precompile` has moved to config/initializers/assets.rb <%- end -%> # Specifies the header that your server uses for sending files. diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt new file mode 100644 index 0000000000..d2f4ec33a6 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8e1aeddb2b..b7bc721247 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -237,6 +237,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_sprockets_is_given run_generator [destination_root, "--skip-sprockets"] + assert_no_file "config/initializers/assets.rb" assert_file "config/application.rb" do |content| assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) end @@ -252,7 +253,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/config\.assets\.digest = true/, content) assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) assert_no_match(/config\.assets\.css_compressor = :sass/, content) - assert_no_match(/config\.assets\.version = '1\.0'/, content) end end -- cgit v1.2.3 From c8ccab05277dd5639cea509c2911af6ee35b0cf9 Mon Sep 17 00:00:00 2001 From: Phil Ross Date: Sat, 12 Apr 2014 18:44:50 +0100 Subject: Bundle tzinfo-data on :x64_mingw (64-bit Ruby on Windows). --- railties/lib/rails/generators/rails/app/templates/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 756c334772..448b6f4845 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -33,5 +33,5 @@ source 'https://rubygems.org' <% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince/) -%> # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin] +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] <% end -%> -- cgit v1.2.3