From 755fd79ff36fad1e41d93e6e49c3f5e486f6745a Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 13 Jan 2014 15:42:10 +0100 Subject: setup Bundler in engines `bin/rails` stub. This is necessary when bundling gems locally using `BUNDLE_PATH`. Without this patch `bin/rails` fails with: ``` /Users/senny/.rbenv/versions/2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- rails/all (LoadError) from /Users/senny/.rbenv/versions/2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from bin/rails:7:in `
' ``` --- railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt index c8de9f3e0f..3ea6c6d7d4 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt @@ -3,5 +3,9 @@ ENGINE_ROOT = File.expand_path('../..', __FILE__) ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) + require 'rails/all' require 'rails/engine/commands' -- cgit v1.2.3 From e05c7912646d375a8ceefcc2897bc8d3384dd648 Mon Sep 17 00:00:00 2001 From: Washington Luiz Date: Sat, 18 Jan 2014 20:22:51 -0300 Subject: spring gem moved to rails/spring --- railties/lib/rails/generators/app_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 1b50569c9e..55709b80ae 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -389,7 +389,7 @@ module Rails def spring_gemfile_entry return [] unless spring_install? - comment = 'Spring speeds up development by keeping your application running in the background. Read more: https://github.com/jonleighton/spring' + comment = 'Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring' GemfileEntry.new('spring', nil, comment, group: :development) end -- cgit v1.2.3 From 7671590fe28b2f9c25c3a1468c3f920a492e68e6 Mon Sep 17 00:00:00 2001 From: robertomiranda Date: Sun, 19 Jan 2014 08:46:43 -0500 Subject: Update Changelog, Spring is under rails/spring [ci skip] --- railties/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index da7a4ce59a..84f8ad59fb 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -87,7 +87,7 @@ *Rafael Mendonça França* * The [Spring application - preloader](https://github.com/jonleighton/spring) is now installed + preloader](https://github.com/rails/spring) is now installed by default for new applications. It uses the development group of the Gemfile, so will not be installed in production. -- cgit v1.2.3 From 41722dd4440c992b3fd4e6181e9ddd0c7c3709e6 Mon Sep 17 00:00:00 2001 From: anilmaurya Date: Mon, 20 Jan 2014 14:37:53 +0530 Subject: moving controller_name assignment before model name condition --- railties/lib/rails/generators/resource_helpers.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index a01eb57651..7329ee9f48 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -15,12 +15,10 @@ module Rails # Set controller variables on initialization. def initialize(*args) #:nodoc: super + controller_name = name if options[:model_name] - controller_name = name self.name = options[:model_name] assign_names!(self.name) - else - controller_name = name end if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural] -- cgit v1.2.3 From cf6c00d027e44a52bfd1df19e2a9cec52fea2c7c Mon Sep 17 00:00:00 2001 From: Byron Bischoff Date: Fri, 24 Jan 2014 10:00:31 -0800 Subject: app_rails_loader.rb should check if bin/rails is a File before calling File.read(exe); closes #13825 --- railties/lib/rails/app_rails_loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/app_rails_loader.rb b/railties/lib/rails/app_rails_loader.rb index 1610751844..56f05b3844 100644 --- a/railties/lib/rails/app_rails_loader.rb +++ b/railties/lib/rails/app_rails_loader.rb @@ -55,7 +55,7 @@ EOS end def self.find_executable - EXECUTABLES.find { |exe| File.exist?(exe) } + EXECUTABLES.find { |exe| File.file?(exe) } end end end -- cgit v1.2.3 From 0a43bf3146f0796fe23da50fa5c40e28b1398139 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Fri, 24 Jan 2014 14:10:46 -0500 Subject: Add a test-case for GH #13825 --- railties/test/app_rails_loader_test.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/app_rails_loader_test.rb b/railties/test/app_rails_loader_test.rb index 92cb3233d8..1d3b80253a 100644 --- a/railties/test/app_rails_loader_test.rb +++ b/railties/test/app_rails_loader_test.rb @@ -22,8 +22,14 @@ class AppRailsLoaderTest < ActiveSupport::TestCase exe = "#{script_dir}/rails" test "is not in a Rails application if #{exe} is not found in the current or parent directories" do - File.stubs(:exist?).with('bin/rails').returns(false) - File.stubs(:exist?).with('script/rails').returns(false) + File.stubs(:file?).with('bin/rails').returns(false) + File.stubs(:file?).with('script/rails').returns(false) + + assert !Rails::AppRailsLoader.exec_app_rails + end + + test "is not in a Rails application if #{exe} exists but is a folder" do + FileUtils.mkdir_p(exe) assert !Rails::AppRailsLoader.exec_app_rails end -- cgit v1.2.3 From fe63933ceec7223beef06ff6f8d1e5b795e17f20 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sat, 25 Jan 2014 22:12:28 +0100 Subject: Add a missing changelog entry for #13825 [ci skip] --- railties/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 84f8ad59fb..01c80d3f58 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Ensure that `bin/rails` is a file before trying to execute it. + + Fixes #13825. + + *bronzle* + * Use single quotes in generated files. *Cristian Mircea Messel*, *Chulki Lee* -- cgit v1.2.3 From 9d0fceb55da9a0b421c81091388d8484e2aedfd6 Mon Sep 17 00:00:00 2001 From: Adrien Lamothe Date: Sat, 25 Jan 2014 23:04:36 -0800 Subject: Correct grammar from '... allowing both thread web servers ...' to '... allowing both threaded web servers ...'. --- .../generators/rails/app/templates/config/environments/production.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') 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 3baa382bd6..d2f041aa27 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 @@ -5,7 +5,7 @@ Rails.application.configure do config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both thread web servers + # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true -- cgit v1.2.3 From 433628a45c2f5dd04b115af1b5579dac75255c67 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Sun, 26 Jan 2014 20:05:34 -0200 Subject: Rails config for raise on missing translations Add a config to setup whether raise exception for missing translation or not. --- .../rails/app/templates/config/environments/development.rb.tt | 3 +++ .../generators/rails/app/templates/config/environments/test.rb.tt | 3 +++ 2 files changed, 6 insertions(+) (limited to 'railties') 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 cce4743a33..de12565a73 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,4 +35,7 @@ Rails.application.configure do # Raises helpful error messages. config.assets.raise_runtime_errors = true <%- end -%> + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index a90361725b..053f5b66d7 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -33,4 +33,7 @@ Rails.application.configure do # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end -- cgit v1.2.3 From 7a372c84290d8e911ca594af90e79dbec4993ead Mon Sep 17 00:00:00 2001 From: Teo Ljungberg Date: Mon, 27 Jan 2014 22:21:28 +0100 Subject: Replace File.exists? with File.exist? To quell warnings on ruby 2.1 --- railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt index 3ea6c6d7d4..c3314d7e68 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt @@ -5,7 +5,7 @@ ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) require 'rails/all' require 'rails/engine/commands' -- cgit v1.2.3 From 3858a247bdab01c62d99a4d1307311ee346aa76e Mon Sep 17 00:00:00 2001 From: Gert Goet Date: Mon, 6 Jan 2014 12:01:15 +0100 Subject: Add CreateMigration action This Thor-action isolates the logic whether to (over-)write migration and what is shown to the user. It's modelled after Thor's CreateFile-action. This solves the issue that removing a non-existing migration, tried to remove the template-path (#13588). Related issues: #12674 --- railties/CHANGELOG.md | 6 + .../rails/generators/actions/create_migration.rb | 68 +++++++++++ railties/lib/rails/generators/migration.rb | 38 +++--- railties/test/generators/create_migration_test.rb | 134 +++++++++++++++++++++ 4 files changed, 230 insertions(+), 16 deletions(-) create mode 100644 railties/lib/rails/generators/actions/create_migration.rb create mode 100644 railties/test/generators/create_migration_test.rb (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 01c80d3f58..4ac6a99662 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Added Thor-action for creation of migrations. + + Fixes #13588 and #12674. + + *Gert Goet* + * Ensure that `bin/rails` is a file before trying to execute it. Fixes #13825. diff --git a/railties/lib/rails/generators/actions/create_migration.rb b/railties/lib/rails/generators/actions/create_migration.rb new file mode 100644 index 0000000000..9c3332927f --- /dev/null +++ b/railties/lib/rails/generators/actions/create_migration.rb @@ -0,0 +1,68 @@ +require 'thor/actions/create_file' + +module Rails + module Generators + module Actions + class CreateMigration < Thor::Actions::CreateFile + + def migration_dir + File.dirname(@destination) + end + + def migration_file_name + @base.migration_file_name + end + + def identical? + exists? && File.binread(existing_migration) == render + end + + def revoke! + say_destination = exists? ? relative_existing_migration : relative_destination + say_status :remove, :red, say_destination + return unless exists? + ::FileUtils.rm_rf(existing_migration) unless pretend? + existing_migration + end + + def relative_existing_migration + base.relative_to_original_destination_root(existing_migration) + end + + def existing_migration + @existing_migration ||= begin + @base.class.migration_exists?(migration_dir, migration_file_name) || + File.exist?(@destination) && @destination + end + end + alias :exists? :existing_migration + + protected + + def on_conflict_behavior(&block) + options = base.options.merge(config) + if identical? + say_status :identical, :blue, relative_existing_migration + elsif options[:force] + say_status :remove, :green, relative_existing_migration + say_status :create, :green + unless pretend? + ::FileUtils.rm_rf(existing_migration) + block.call + end + elsif options[:skip] + say_status :skip, :yellow + else + say_status :conflict, :red + raise Error, "Another migration is already named #{migration_file_name}: " + + "#{existing_migration}. Use --force to replace this migration file." + end + end + + def say_status(status, color, message = relative_destination) + base.shell.say_status(status, message, color) if config[:verbose] + end + end + end + end +end diff --git a/railties/lib/rails/generators/migration.rb b/railties/lib/rails/generators/migration.rb index 3566f96f5e..cd388e590a 100644 --- a/railties/lib/rails/generators/migration.rb +++ b/railties/lib/rails/generators/migration.rb @@ -1,4 +1,5 @@ require 'active_support/concern' +require 'rails/generators/actions/create_migration' module Rails module Generators @@ -29,6 +30,19 @@ module Rails end end + def create_migration(destination, data, config = {}, &block) + action Rails::Generators::Actions::CreateMigration.new(self, destination, block || data.to_s, config) + end + + def set_migration_assigns!(destination) + destination = File.expand_path(destination, self.destination_root) + + migration_dir = File.dirname(destination) + @migration_number = self.class.next_migration_number(migration_dir) + @migration_file_name = File.basename(destination, '.rb') + @migration_class_name = @migration_file_name.camelize + end + # Creates a migration template at the given destination. The difference # to the default template method is that the migration version is appended # to the destination file name. @@ -37,26 +51,18 @@ module Rails # available as instance variables in the template to be rendered. # # migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb" - def migration_template(source, destination=nil, config={}) - destination = File.expand_path(destination || source, self.destination_root) + def migration_template(source, destination, config = {}) + source = File.expand_path(find_in_source_paths(source.to_s)) - migration_dir = File.dirname(destination) - @migration_number = self.class.next_migration_number(migration_dir) - @migration_file_name = File.basename(destination).sub(/\.rb$/, '') - @migration_class_name = @migration_file_name.camelize + set_migration_assigns!(destination) + context = instance_eval('binding') - destination = self.class.migration_exists?(migration_dir, @migration_file_name) + dir, base = File.split(destination) + numbered_destination = File.join(dir, ["%migration_number%", base].join('_')) - if !(destination && options[:skip]) && behavior == :invoke - if destination && options.force? - remove_file(destination) - elsif destination - raise Error, "Another migration is already named #{@migration_file_name}: #{destination}. Use --force to remove the old migration file and replace it." - end - destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb") + create_migration numbered_destination, nil, config do + ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context) end - - template(source, destination, config) end end end diff --git a/railties/test/generators/create_migration_test.rb b/railties/test/generators/create_migration_test.rb new file mode 100644 index 0000000000..e16a77479a --- /dev/null +++ b/railties/test/generators/create_migration_test.rb @@ -0,0 +1,134 @@ +require 'generators/generators_test_helper' +require 'rails/generators/rails/migration/migration_generator' + +class CreateMigrationTest < Rails::Generators::TestCase + include GeneratorsTestHelper + + class Migrator < Rails::Generators::MigrationGenerator + include Rails::Generators::Migration + + def self.next_migration_number(dirname) + current_migration_number(dirname) + 1 + end + end + + tests Migrator + + def default_destination_path + "db/migrate/create_articles.rb" + end + + def create_migration(destination_path = default_destination_path, config = {}, generator_options = {}, &block) + migration_name = File.basename(destination_path, '.rb') + generator([migration_name], generator_options) + generator.set_migration_assigns!(destination_path) + + dir, base = File.split(destination_path) + timestamped_destination_path = File.join(dir, ["%migration_number%", base].join('_')) + + @migration = Rails::Generators::Actions::CreateMigration.new(generator, timestamped_destination_path, block || "contents", config) + end + + def migration_exists!(*args) + @existing_migration = create_migration(*args) + invoke! + @generator = nil + end + + def invoke! + capture(:stdout) { @migration.invoke! } + end + + def revoke! + capture(:stdout) { @migration.revoke! } + end + + def test_invoke + create_migration + + assert_match(/create db\/migrate\/1_create_articles.rb\n/, invoke!) + assert_file @migration.destination + end + + def test_invoke_pretended + create_migration(default_destination_path, {}, { pretend: true }) + + assert_no_file @migration.destination + end + + def test_invoke_when_exists + migration_exists! + create_migration + + assert_equal @existing_migration.destination, @migration.existing_migration + end + + def test_invoke_when_exists_identical + migration_exists! + create_migration + + assert_match(/identical db\/migrate\/1_create_articles.rb\n/, invoke!) + assert @migration.identical? + end + + def test_invoke_when_exists_not_identical + migration_exists! + create_migration { "different content" } + + assert_raise(Rails::Generators::Error) { invoke! } + end + + def test_invoke_forced_when_exists_not_identical + dest = "db/migrate/migration.rb" + migration_exists!(dest) + create_migration(dest, force: true) { "different content" } + + stdout = invoke! + assert_match(/remove db\/migrate\/1_migration.rb\n/, stdout) + assert_match(/create db\/migrate\/2_migration.rb\n/, stdout) + assert_file @migration.destination + assert_no_file @existing_migration.destination + end + + def test_invoke_forced_pretended_when_exists_not_identical + migration_exists! + create_migration(default_destination_path, { force: true }, { pretend: true }) do + "different content" + end + + stdout = invoke! + assert_match(/remove db\/migrate\/1_create_articles.rb\n/, stdout) + assert_match(/create db\/migrate\/2_create_articles.rb\n/, stdout) + assert_no_file @migration.destination + end + + def test_invoke_skipped_when_exists_not_identical + migration_exists! + create_migration(default_destination_path, {}, { skip: true }) { "different content" } + + assert_match(/skip db\/migrate\/2_create_articles.rb\n/, invoke!) + assert_no_file @migration.destination + end + + def test_revoke + migration_exists! + create_migration + + assert_match(/remove db\/migrate\/1_create_articles.rb\n/, revoke!) + assert_no_file @existing_migration.destination + end + + def test_revoke_pretended + migration_exists! + create_migration(default_destination_path, {}, { pretend: true }) + + assert_match(/remove db\/migrate\/1_create_articles.rb\n/, revoke!) + assert_file @existing_migration.destination + end + + def test_revoke_when_no_exists + create_migration + + assert_match(/remove db\/migrate\/1_create_articles.rb\n/, revoke!) + end +end -- cgit v1.2.3 From b23ffd0dac895aa3fd3afd8d9be36794941731b2 Mon Sep 17 00:00:00 2001 From: Lukasz Sarnacki Date: Fri, 10 Jan 2014 12:57:50 +0100 Subject: Allow session serializer key in config.session_store MessageEncryptor has :serializer option, where any serializer object can be passed. This commit make it possible to set this serializer from configuration level. There are predefined serializers (:marshal_serializer, :json_serialzier) and custom serializer can be passed as String, Symbol (camelized and constantized in ActionDispatch::Session namepspace) or serializer object. Default :json_serializer was also added to generators to provide secure defalt. --- railties/lib/rails/application.rb | 3 ++- .../rails/app/templates/config/initializers/session_store.rb.tt | 2 +- railties/test/generators/app_generator_test.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 05acd78d98..36432e56ba 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -205,7 +205,8 @@ module Rails "action_dispatch.http_auth_salt" => config.action_dispatch.http_auth_salt, "action_dispatch.signed_cookie_salt" => config.action_dispatch.signed_cookie_salt, "action_dispatch.encrypted_cookie_salt" => config.action_dispatch.encrypted_cookie_salt, - "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt + "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt, + "action_dispatch.session_serializer" => config.session_options[:serializer] }) end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt index 2bb9b82c61..923d423287 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %> +Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>, serializer: :json_serializer diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index ddecee2ca1..8aa306c8e0 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -433,7 +433,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_new_hash_style run_generator [destination_root] assert_file "config/initializers/session_store.rb" do |file| - assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file) + assert_match(/config.session_store :cookie_store, key: '_.+_session', serializer: :json_serializer/, file) end end -- cgit v1.2.3 From 7d6592ebd0b04aab2415fce8098e21212bc8c5c3 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 29 Jan 2014 14:16:39 -0600 Subject: Enhance errors while retrieving database config Right now if there is an error retrieving database configuration the intent of the error (what the code was trying to do while you got the error) could be more explicit. Instead of this error: ``` Invalid DATABASE_URL: nil (erb):9:in `rescue in
' (erb):6:in `
' /Users/schneems/.rbenv/versions/2.1.0/lib/ruby/2.1.0/erb.rb:850:in `eval' /Users/schneems/.rbenv/versions/2.1.0/lib/ruby/2.1.0/erb.rb:850:in `result' /Users/schneems/Documents/projects/rails/railties/lib/rails/application/configuration.rb:98:in `database_configuration' /Users/schneems/Documents/projects/rails/activerecord/lib/active_record/railtie.rb:41:in `block in ' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `instance_exec' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `block in run_tasks_blocks' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `each' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `run_tasks_blocks' /Users/schneems/Documents/projects/rails/railties/lib/rails/application.rb:339:in `block in run_tasks_blocks' /Users/schneems/Documents/projects/rails/railties/lib/rails/engine/railties.rb:13:in `each' ``` I propose we issue this error: ``` Cannot load `Rails.application.database_configuration`: Invalid DATABASE_URL: nil (erb):9:in `rescue in
' (erb):6:in `
' /Users/schneems/.rbenv/versions/2.1.0/lib/ruby/2.1.0/erb.rb:850:in `eval' /Users/schneems/.rbenv/versions/2.1.0/lib/ruby/2.1.0/erb.rb:850:in `result' /Users/schneems/Documents/projects/rails/railties/lib/rails/application/configuration.rb:98:in `database_configuration' /Users/schneems/Documents/projects/rails/activerecord/lib/active_record/railtie.rb:41:in `block in ' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `instance_exec' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `block in run_tasks_blocks' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `each' /Users/schneems/Documents/projects/rails/railties/lib/rails/railtie.rb:237:in `run_tasks_blocks' /Users/schneems/Documents/projects/rails/railties/lib/rails/application.rb:339:in `block in run_tasks_blocks' /Users/schneems/Documents/projects/rails/railties/lib/rails/engine/railties.rb:13:in `each' ``` --- railties/lib/rails/application/configuration.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index e902205a13..20e3de32aa 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -109,6 +109,8 @@ module Rails raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ "Error: #{e.message}" + rescue => e + raise e, "Cannot load `Rails.application.database_configuration`:\n#{e.message}", e.backtrace end def log_level -- cgit v1.2.3 From fd487860db3097104cdb8d589f3931d75b767721 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 30 Jan 2014 01:12:23 -0500 Subject: Modify the session serializer implementation Rename allowed options to :marshal and :json, for custom serializers only allow the use of custom classes. --- .../rails/app/templates/config/initializers/session_store.rb.tt | 2 +- railties/test/generators/app_generator_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt index 923d423287..097fcb4bb0 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>, serializer: :json_serializer +Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>, serializer: :json diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8aa306c8e0..700935fd8d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -433,7 +433,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_new_hash_style run_generator [destination_root] assert_file "config/initializers/session_store.rb" do |file| - assert_match(/config.session_store :cookie_store, key: '_.+_session', serializer: :json_serializer/, file) + assert_match(/config.session_store :cookie_store, key: '_.+_session', serializer: :json/, file) end end -- cgit v1.2.3 From 580f0b61dc99c6854fa930a761d28a3ab08163f7 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 6 Feb 2014 11:43:16 +0100 Subject: synchronize 4.1 release notes with CHANGELOGS. [ci skip] /cc @chancancode --- railties/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4ac6a99662..5ea025924b 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,6 +1,6 @@ * Added Thor-action for creation of migrations. - Fixes #13588 and #12674. + Fixes #13588, #12674. *Gert Goet* -- cgit v1.2.3 From 8806768e9f1a2648085f7826d9a0032457182bdb Mon Sep 17 00:00:00 2001 From: Emil Soman Date: Wed, 5 Feb 2014 13:02:38 +0530 Subject: Add config to disable schema dump after migration * Add a config on Active Record named `dump_schema_after_migration` * Schema dump doesn't happen if the config is set to false * Set default value of the config to true * Set config in generated production environment file to false * Update configuration guide * Update CHANGELOG --- railties/CHANGELOG.md | 7 +++++ .../templates/config/environments/production.rb.tt | 5 ++++ railties/test/application/configuration_test.rb | 17 ++++++++++++ railties/test/application/rake/migrations_test.rb | 31 ++++++++++++++++++++++ 4 files changed, 60 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4ac6a99662..7aeabf735f 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,10 @@ +* Set `dump_schema_after_migration` config values in production. + + Set `config.active_record.dump_schema_after_migration` as false + in the generated `config/environments/production.rb` file. + + *Emil Soman* + * Added Thor-action for creation of migrations. Fixes #13588 and #12674. 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 d2f041aa27..d9cc60d656 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 @@ -81,4 +81,9 @@ Rails.application.configure do # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + <%- unless options.skip_active_record? -%> + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + <%- end -%> end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 02d8b2c91d..b814479540 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -781,5 +781,22 @@ module ApplicationTests assert_not Rails.configuration.respond_to?(:method_missing) assert Rails.configuration.respond_to?(:method_missing, true) end + + test "config.active_record.dump_schema_after_migration is false on production" do + build_app + ENV["RAILS_ENV"] = "production" + + require "#{app_path}/config/environment" + + assert_not ActiveRecord::Base.dump_schema_after_migration + end + + test "config.active_record.dump_schema_after_migration is true by default on development" do + ENV["RAILS_ENV"] = "development" + + require "#{app_path}/config/environment" + + assert ActiveRecord::Base.dump_schema_after_migration + end end end diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb index 33c753868c..b7fd5d02c5 100644 --- a/railties/test/application/rake/migrations_test.rb +++ b/railties/test/application/rake/migrations_test.rb @@ -153,6 +153,37 @@ module ApplicationTests assert_match(/up\s+\d{3,}\s+Add email to users/, output) end end + + test 'schema generation when dump_schema_after_migration is set' do + add_to_config('config.active_record.dump_schema_after_migration = false') + + Dir.chdir(app_path) do + `rails generate model book title:string; + bundle exec rake db:migrate` + + assert !File.exist?("db/schema.rb") + end + + add_to_config('config.active_record.dump_schema_after_migration = true') + + Dir.chdir(app_path) do + `rails generate model author name:string; + bundle exec rake db:migrate` + + structure_dump = File.read("db/schema.rb") + assert_match(/create_table "authors"/, structure_dump) + end + end + + test 'default schema generation after migration' do + Dir.chdir(app_path) do + `rails generate model book title:string; + bundle exec rake db:migrate` + + structure_dump = File.read("db/schema.rb") + assert_match(/create_table "books"/, structure_dump) + end + end end end end -- cgit v1.2.3 From b927d67decb9d4e5103b5991b7e26a4dab4eca92 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 4 Feb 2014 09:31:48 -0800 Subject: Renamed session_serializer option to cookies_serializer --- 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 36432e56ba..d018247c5a 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -206,7 +206,7 @@ module Rails "action_dispatch.signed_cookie_salt" => config.action_dispatch.signed_cookie_salt, "action_dispatch.encrypted_cookie_salt" => config.action_dispatch.encrypted_cookie_salt, "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt, - "action_dispatch.session_serializer" => config.session_options[:serializer] + "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer }) end end -- cgit v1.2.3 From 3a89386fcf8a87c93aaf1571ca8ee4a234086ea8 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 9 Feb 2014 11:05:25 -0500 Subject: Remove serializer option from session_store.rb template --- .../rails/app/templates/config/initializers/session_store.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt index 097fcb4bb0..2bb9b82c61 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>, serializer: :json +Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %> -- cgit v1.2.3 From cd5960e9761c8618a89bf40a3048e330fd08143c Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 9 Feb 2014 11:47:38 -0500 Subject: Fix AppGeneratorTest: serializer option was removed from session_store --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 700935fd8d..ddecee2ca1 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -433,7 +433,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_new_hash_style run_generator [destination_root] assert_file "config/initializers/session_store.rb" do |file| - assert_match(/config.session_store :cookie_store, key: '_.+_session', serializer: :json/, file) + assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file) end end -- cgit v1.2.3 From 0b86a6e950ed78822470793deddbec41c6d105f5 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 11 Feb 2014 02:13:09 -0800 Subject: Updated CHANGELOG, docs, guides and release notes. Also added a `cookies_serializer.rb` initializer to the app template. --- .../rails/app/templates/config/initializers/cookies_serializer.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb (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 new file mode 100644 index 0000000000..7a06a89f0f --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb @@ -0,0 +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 -- cgit v1.2.3 From c5034d60dba0cd31a6a8c612ee35d63b8127793a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 11 Feb 2014 14:08:12 -0800 Subject: add a send so `apply` can be called. Fixes #13510 THIS IS A HUGE HACK. Thor does not allow us to define public methods without turning them in to "thor tasks". That means we cannot subclass the `apply` method and make it public, so we have to make the method private and call `send` on it. --- railties/lib/rails/tasks/framework.rake | 2 +- railties/test/application/rake/templates_test.rb | 32 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 railties/test/application/rake/templates_test.rb (limited to 'railties') diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index e669315934..94e8f83e86 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -10,7 +10,7 @@ namespace :rails do require 'rails/generators' require 'rails/generators/rails/app/app_generator' generator = Rails::Generators::AppGenerator.new [Rails.root], {}, destination_root: Rails.root - generator.apply template, verbose: false + generator.send :apply, template, verbose: false end namespace :templates do diff --git a/railties/test/application/rake/templates_test.rb b/railties/test/application/rake/templates_test.rb new file mode 100644 index 0000000000..1fca80debd --- /dev/null +++ b/railties/test/application/rake/templates_test.rb @@ -0,0 +1,32 @@ +require "isolation/abstract_unit" + +module ApplicationTests + module RakeTests + class TemplatesTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + require "rails/all" + super + end + + def teardown + super + teardown_app + end + + def test_rake_template + Dir.chdir(app_path) do + cmd = "bundle exec rake rails:template LOCATION=foo" + r,w = IO.pipe + Process.waitpid Process.spawn(cmd, out: w, err: w) + w.close + assert_match(/Could not find.*foo/, r.read) + r.close + end + end + end + end +end + -- cgit v1.2.3 From 2c7471a95dd818fbad80bd4925ac7c9745884363 Mon Sep 17 00:00:00 2001 From: Christian Wesselhoeft Date: Tue, 11 Feb 2014 23:11:02 -0800 Subject: Hide bundler output for `rails new` if quiet option is specified. --- railties/lib/rails/generators/app_base.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 55709b80ae..815894144a 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -412,7 +412,8 @@ module Rails require 'bundler' Bundler.with_clean_env do - print `"#{Gem.ruby}" "#{_bundle_command}" #{command}` + output = `"#{Gem.ruby}" "#{_bundle_command}" #{command}` + print output unless options[:quiet] end end -- cgit v1.2.3 From 37e30d2548e586a5080554a5d5065dd82289fbfe Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 12 Feb 2014 17:17:00 +0100 Subject: do not crash when `config/secrets.yml` is blank. --- railties/CHANGELOG.md | 4 ++++ railties/lib/rails/application.rb | 3 ++- railties/test/application/configuration_test.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index a57d56f4aa..bade9ef543 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Do not crash when `config/secrets.yml` is empty. + + *Yves Senn* + * Set `dump_schema_after_migration` config values in production. Set `config.active_record.dump_schema_after_migration` as false diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 36432e56ba..314a789b96 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -308,7 +308,8 @@ module Rails yaml = config.paths["config/secrets"].first if File.exist?(yaml) require "erb" - env_secrets = YAML.load(ERB.new(IO.read(yaml)).result)[Rails.env] + all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {} + env_secrets = all_secrets[Rails.env] secrets.merge!(env_secrets.symbolize_keys) if env_secrets end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index b814479540..b2d0e7e202 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -336,6 +336,14 @@ module ApplicationTests assert_equal 'myamazonsecretaccesskey', app.secrets.aws_secret_access_key end + test "blank config/secrets.yml does not crash the loading process" do + app_file 'config/secrets.yml', <<-YAML + YAML + require "#{app_path}/config/environment" + + assert_nil app.secrets.not_defined + end + test "protect from forgery is the default in a new app" do make_basic_app -- cgit v1.2.3 From aae455f636774ee1e4c706eb41520bf83be6a8c0 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Fri, 14 Feb 2014 14:17:12 -0200 Subject: fix path shown in mailer's templates --- railties/lib/rails/generators/erb/mailer/templates/view.html.erb | 2 +- railties/lib/rails/generators/erb/mailer/templates/view.text.erb | 2 +- railties/test/generators/mailer_generator_test.rb | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/erb/mailer/templates/view.html.erb b/railties/lib/rails/generators/erb/mailer/templates/view.html.erb index 8bb7c2b768..b5045671b3 100644 --- a/railties/lib/rails/generators/erb/mailer/templates/view.html.erb +++ b/railties/lib/rails/generators/erb/mailer/templates/view.html.erb @@ -1,5 +1,5 @@

<%= class_name %>#<%= @action %>

- <%%= @greeting %>, find me in app/views/<%= @path %> + <%%= @greeting %>, find me in <%= @path %>

diff --git a/railties/lib/rails/generators/erb/mailer/templates/view.text.erb b/railties/lib/rails/generators/erb/mailer/templates/view.text.erb index 6d597256a6..342285df19 100644 --- a/railties/lib/rails/generators/erb/mailer/templates/view.text.erb +++ b/railties/lib/rails/generators/erb/mailer/templates/view.text.erb @@ -1,3 +1,3 @@ <%= class_name %>#<%= @action %> -<%%= @greeting %>, find me in app/views/<%= @path %> +<%%= @greeting %>, find me in <%= @path %> diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index d209801f60..25649881eb 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -69,12 +69,12 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_invokes_default_text_template_engine run_generator assert_file "app/views/notifier/foo.text.erb" do |view| - assert_match(%r(app/views/notifier/foo\.text\.erb), view) + assert_match(%r(\sapp/views/notifier/foo\.text\.erb), view) assert_match(/<%= @greeting %>/, view) end assert_file "app/views/notifier/bar.text.erb" do |view| - assert_match(%r(app/views/notifier/bar\.text\.erb), view) + assert_match(%r(\sapp/views/notifier/bar\.text\.erb), view) assert_match(/<%= @greeting %>/, view) end end @@ -82,12 +82,12 @@ class MailerGeneratorTest < Rails::Generators::TestCase def test_invokes_default_html_template_engine run_generator assert_file "app/views/notifier/foo.html.erb" do |view| - assert_match(%r(app/views/notifier/foo\.html\.erb), view) + assert_match(%r(\sapp/views/notifier/foo\.html\.erb), view) assert_match(/<%= @greeting %>/, view) end assert_file "app/views/notifier/bar.html.erb" do |view| - assert_match(%r(app/views/notifier/bar\.html\.erb), view) + assert_match(%r(\sapp/views/notifier/bar\.html\.erb), view) assert_match(/<%= @greeting %>/, view) end end -- cgit v1.2.3 From 22a1a5ac8c4631f29cfeac451c361e8da1dd2261 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Feb 2014 11:38:26 -0800 Subject: remove railties changes. fixes #14054 Squashed commit of the following: commit 96991e8e919edfb20cc4120bca4e36ed51175d57 Author: Aaron Patterson Date: Fri Feb 14 11:29:24 2014 -0800 Revert "gems can be added or skipped from the template" This reverts commit 8beb42cfbc41753ae4dbb91e16abcd1fb7d00356. Conflicts: railties/lib/rails/generators/rails/app/app_generator.rb railties/test/generators/app_generator_test.rb commit 35599c0e657245ef14ac0f28c9189ad16acf40e6 Author: Aaron Patterson Date: Fri Feb 14 11:26:53 2014 -0800 Revert "oops, template replay needs to happen after bundle. :orz:" This reverts commit 9104702be61253f9448ca070a22fc86bb4299555. Conflicts: railties/lib/rails/generators/rails/app/app_generator.rb commit f519c3902c313db8e906a49251c91643b8e6499e Author: Aaron Patterson Date: Fri Feb 14 11:25:51 2014 -0800 Revert "only ask for these ivars if the target responds to them" This reverts commit 656d412546cd97d5660c634c2a41c799d3f9e211. commit aa524a9428e3e4c45fe221f10a66a08efb827ab5 Author: Aaron Patterson Date: Fri Feb 14 11:25:39 2014 -0800 Revert "refactor generator tests to use block form of Tempfile" This reverts commit 65251820ef0ab7f3cffb38130de3dd41af8d72be. commit 7d3740549fa4dfa62e3761f8d4bc6d6d441256e7 Author: Aaron Patterson Date: Fri Feb 14 11:25:25 2014 -0800 Revert "add a more restricted codepath for templates fixes #13390" This reverts commit 2875b4a66e38e4333da887a4afbed33358999298. commit 525df0af1001918986cdfce59539fd2d52c4f32c Author: Aaron Patterson Date: Fri Feb 14 11:25:11 2014 -0800 Revert "add a send so `apply` can be called. Fixes #13510" This reverts commit c5034d60dba0cd31a6a8c612ee35d63b8127793a. --- railties/lib/rails/generators/app_base.rb | 95 ++-------------------- .../rails/generators/rails/app/app_generator.rb | 4 +- railties/lib/rails/tasks/framework.rake | 2 +- railties/test/application/rake/templates_test.rb | 32 -------- railties/test/generators/app_generator_test.rb | 67 --------------- railties/test/generators/generator_test.rb | 1 - 6 files changed, 10 insertions(+), 191 deletions(-) delete mode 100644 railties/test/application/rake/templates_test.rb (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 815894144a..f1f79d8378 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -14,7 +14,6 @@ module Rails DATABASES.concat(JDBC_DATABASES) attr_accessor :rails_template - attr_accessor :app_template add_shebang_option! argument :app_path, type: :string @@ -27,9 +26,6 @@ module Rails class_option :template, type: :string, aliases: '-m', desc: "Path to some #{name} template (can be a filesystem path or URL)" - class_option :app_template, type: :string, aliases: '-n', - desc: "Path to some #{name} template (can be a filesystem path or URL)" - class_option :skip_gemfile, type: :boolean, default: false, desc: "Don't create a Gemfile" @@ -126,10 +122,6 @@ module Rails }.curry[@gem_filter] end - def remove_gem(name) - add_gem_entry_filter { |gem| gem.name != name } - end - def builder @builder ||= begin builder_class = get_builder_class @@ -149,92 +141,21 @@ module Rails FileUtils.cd(destination_root) unless options[:pretend] end - class TemplateRecorder < ::BasicObject # :nodoc: - attr_reader :gems - - def initialize(target) - @target = target - # unfortunately, instance eval has access to these ivars - @app_const = target.send :app_const if target.respond_to?(:app_const, true) - @app_const_base = target.send :app_const_base if target.respond_to?(:app_const_base, true) - @app_name = target.send :app_name if target.respond_to?(:app_name, true) - @commands = [] - @gems = [] - end - - def gemfile_entry(*args) - @target.send :gemfile_entry, *args - end - - def add_gem_entry_filter(*args, &block) - @target.send :add_gem_entry_filter, *args, &block - end - - def remove_gem(*args, &block) - @target.send :remove_gem, *args, &block - end - - def method_missing(name, *args, &block) - @commands << [name, args, block] - end - - def respond_to_missing?(method, priv = false) - super || @target.respond_to?(method, priv) - end - - def replay! - @commands.each do |name, args, block| - @target.send name, *args, &block - end - end - end - def apply_rails_template - @recorder = TemplateRecorder.new self - - apply(rails_template, target: self) if rails_template - apply(app_template, target: @recorder) if app_template + apply rails_template if rails_template rescue Thor::Error, LoadError, Errno::ENOENT => e raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}" end - def replay_template - @recorder.replay! if @recorder - end - - def apply(path, config={}) - verbose = config.fetch(:verbose, true) - target = config.fetch(:target, self) - is_uri = path =~ /^https?\:\/\// - path = find_in_source_paths(path) unless is_uri - - say_status :apply, path, verbose - shell.padding += 1 if verbose - - if is_uri - contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read } - else - contents = open(path) {|io| io.read } - end - - target.instance_eval(contents, path) - shell.padding -= 1 if verbose - end - def set_default_accessors! self.destination_root = File.expand_path(app_path, destination_root) - self.rails_template = expand_template options[:template] - self.app_template = expand_template options[:app_template] - end - - def expand_template(name) - case name - when /^https?:\/\// - name - when String - File.expand_path(name, Dir.pwd) - else - name + self.rails_template = case options[:template] + when /^https?:\/\// + options[:template] + when String + File.expand_path(options[:template], Dir.pwd) + else + options[:template] end end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index d2eca5b2fb..83cb1dc0d5 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -166,7 +166,6 @@ module Rails end public_task :set_default_accessors! - public_task :apply_rails_template public_task :create_root def create_root_files @@ -236,8 +235,7 @@ module Rails build(:leftovers) end - public_task :run_bundle - public_task :replay_template + public_task :apply_rails_template, :run_bundle public_task :generate_spring_binstubs protected diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 94e8f83e86..e669315934 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -10,7 +10,7 @@ namespace :rails do require 'rails/generators' require 'rails/generators/rails/app/app_generator' generator = Rails::Generators::AppGenerator.new [Rails.root], {}, destination_root: Rails.root - generator.send :apply, template, verbose: false + generator.apply template, verbose: false end namespace :templates do diff --git a/railties/test/application/rake/templates_test.rb b/railties/test/application/rake/templates_test.rb deleted file mode 100644 index 1fca80debd..0000000000 --- a/railties/test/application/rake/templates_test.rb +++ /dev/null @@ -1,32 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - module RakeTests - class TemplatesTest < ActiveSupport::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - require "rails/all" - super - end - - def teardown - super - teardown_app - end - - def test_rake_template - Dir.chdir(app_path) do - cmd = "bundle exec rake rails:template LOCATION=foo" - r,w = IO.pipe - Process.waitpid Process.spawn(cmd, out: w, err: w) - w.close - assert_match(/Could not find.*foo/, r.read) - r.close - end - end - end - end -end - diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index ddecee2ca1..5811379e35 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -163,73 +163,6 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_arbitrary_code - output = Tempfile.open('my_template') do |template| - template.puts 'puts "You are using Rails version #{Rails::VERSION::STRING}."' - template.close - run_generator([destination_root, "-m", template.path]) - end - assert_match 'You are using', output - end - - def test_add_gemfile_entry - Tempfile.open('my_template') do |template| - template.puts 'gemfile_entry "tenderlove"' - template.flush - template.close - run_generator([destination_root, "-n", template.path]) - assert_file "Gemfile", /tenderlove/ - end - end - - def test_add_skip_entry - Tempfile.open 'my_template' do |template| - template.puts 'add_gem_entry_filter { |gem| gem.name != "jbuilder" }' - template.close - - run_generator([destination_root, "-n", template.path]) - assert_file "Gemfile" do |contents| - assert_no_match 'jbuilder', contents - end - end - end - - def test_remove_gem - Tempfile.open 'my_template' do |template| - template.puts 'remove_gem "jbuilder"' - template.close - - run_generator([destination_root, "-n", template.path]) - assert_file "Gemfile" do |contents| - assert_no_match 'jbuilder', contents - end - end - end - - def test_skip_turbolinks_when_it_is_not_on_gemfile - Tempfile.open 'my_template' do |template| - template.puts 'add_gem_entry_filter { |gem| gem.name != "turbolinks" }' - template.flush - - run_generator([destination_root, "-n", template.path]) - assert_file "Gemfile" do |contents| - assert_no_match 'turbolinks', contents - end - - assert_file "app/views/layouts/application.html.erb" do |contents| - assert_no_match 'turbolinks', contents - end - - assert_file "app/views/layouts/application.html.erb" do |contents| - assert_no_match('data-turbolinks-track', contents) - end - - assert_file "app/assets/javascripts/application.js" do |contents| - assert_no_match 'turbolinks', contents - end - end - end - def test_config_another_database run_generator([destination_root, "-d", "mysql"]) assert_file "config/database.yml", /mysql/ diff --git a/railties/test/generators/generator_test.rb b/railties/test/generators/generator_test.rb index 94d2c1bf50..7871399dd7 100644 --- a/railties/test/generators/generator_test.rb +++ b/railties/test/generators/generator_test.rb @@ -1,7 +1,6 @@ require 'active_support/test_case' require 'active_support/testing/autorun' require 'rails/generators/app_base' -require 'rails/generators/rails/app/app_generator' module Rails module Generators -- cgit v1.2.3 From 5f07366bed77116dbfbb5b98d1cdf6c61b3dfc9b Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 15 Feb 2014 11:26:17 +0100 Subject: Revert "Fixed plugin_generator test" This reverts commit fefa8ae9a172835fb6b8aef7d1dd46d58eecd49f. --- railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index dbe1e37d8e..f6f529b80a 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -185,7 +185,6 @@ task default: :test end public_task :set_default_accessors! - public_task :apply_rails_template public_task :create_root def create_root_files @@ -242,6 +241,7 @@ task default: :test build(:leftovers) end + public_task :apply_rails_template, :run_bundle def name @name ||= begin @@ -255,9 +255,6 @@ task default: :test end end - public_task :run_bundle - public_task :replay_template - protected def app_templates_dir -- cgit v1.2.3