1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

remove railties changes. fixes #14054

Squashed commit of the following:

commit 96991e8e919edfb20cc4120bca4e36ed51175d57
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:29:24 2014 -0800

    Revert "gems can be added or skipped from the template"

    This reverts commit 8beb42cfbc.

    Conflicts:
    	railties/lib/rails/generators/rails/app/app_generator.rb
    	railties/test/generators/app_generator_test.rb

commit 35599c0e657245ef14ac0f28c9189ad16acf40e6
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:26:53 2014 -0800

    Revert "oops, template replay needs to happen after bundle. :orz:"

    This reverts commit 9104702be6.

    Conflicts:
    	railties/lib/rails/generators/rails/app/app_generator.rb

commit f519c3902c313db8e906a49251c91643b8e6499e
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:51 2014 -0800

    Revert "only ask for these ivars if the target responds to them"

    This reverts commit 656d412546.

commit aa524a9428e3e4c45fe221f10a66a08efb827ab5
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:39 2014 -0800

    Revert "refactor generator tests to use block form of Tempfile"

    This reverts commit 65251820ef.

commit 7d3740549fa4dfa62e3761f8d4bc6d6d441256e7
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:25 2014 -0800

    Revert "add a more restricted codepath for templates fixes #13390"

    This reverts commit 2875b4a66e.

commit 525df0af1001918986cdfce59539fd2d52c4f32c
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Fri Feb 14 11:25:11 2014 -0800

    Revert "add a send so `apply` can be called.  Fixes #13510"

    This reverts commit c5034d60db.
This commit is contained in:
Aaron Patterson 2014-02-14 11:38:26 -08:00
parent a8775bba58
commit 22a1a5ac8c
6 changed files with 10 additions and 191 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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/

View file

@ -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