add fixed file
add framework_test add another test
This commit is contained in:
parent
3e36db4406
commit
ae5c3c3514
@ -32,35 +32,39 @@ namespace :rails do
|
|||||||
FileUtils.cp_r src_name, dst_name
|
FileUtils.cp_r src_name, dst_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :update do
|
namespace :update do
|
||||||
def invoke_from_app_generator(method)
|
class RailsUpdate
|
||||||
app_generator.send(method)
|
|
||||||
end
|
|
||||||
|
|
||||||
def app_generator
|
def self.invoke_from_app_generator(method)
|
||||||
@app_generator ||= begin
|
RailsUpdate.app_generator.send(method)
|
||||||
require 'rails/generators'
|
|
||||||
require 'rails/generators/rails/app/app_generator'
|
|
||||||
gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
|
|
||||||
destination_root: Rails.root
|
|
||||||
File.exist?(Rails.root.join("config", "application.rb")) ?
|
|
||||||
gen.send(:app_const) : gen.send(:valid_const?)
|
|
||||||
gen
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.app_generator
|
||||||
|
@app_generator ||= begin
|
||||||
|
require 'rails/generators'
|
||||||
|
require 'rails/generators/rails/app/app_generator'
|
||||||
|
gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
|
||||||
|
destination_root: Rails.root
|
||||||
|
File.exist?(Rails.root.join("config", "application.rb")) ?
|
||||||
|
gen.send(:app_const) : gen.send(:valid_const?)
|
||||||
|
gen
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# desc "Update config/boot.rb from your current rails install"
|
# desc "Update config/boot.rb from your current rails install"
|
||||||
task :configs do
|
task :configs do
|
||||||
invoke_from_app_generator :create_boot_file
|
RailsUpdate.invoke_from_app_generator :create_boot_file
|
||||||
invoke_from_app_generator :update_config_files
|
RailsUpdate.invoke_from_app_generator :update_config_files
|
||||||
end
|
end
|
||||||
|
|
||||||
# desc "Adds new executables to the application bin/ directory"
|
# desc "Adds new executables to the application bin/ directory"
|
||||||
task :bin do
|
task :bin do
|
||||||
invoke_from_app_generator :create_bin_files
|
RailsUpdate.invoke_from_app_generator :create_bin_files
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
46
railties/test/application/rake/framework_test.rb
Normal file
46
railties/test/application/rake/framework_test.rb
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
require "isolation/abstract_unit"
|
||||||
|
require "active_support/core_ext/string/strip"
|
||||||
|
|
||||||
|
module ApplicationTests
|
||||||
|
module RakeTests
|
||||||
|
class FrameworkTest < ActiveSupport::TestCase
|
||||||
|
include ActiveSupport::Testing::Isolation
|
||||||
|
|
||||||
|
|
||||||
|
def setup
|
||||||
|
build_app
|
||||||
|
boot_rails
|
||||||
|
FileUtils.rm_rf("#{app_path}/config/environments")
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
teardown_app
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_tasks
|
||||||
|
require 'rake'
|
||||||
|
require 'rdoc/task'
|
||||||
|
require 'rake/testtask'
|
||||||
|
|
||||||
|
Rails.application.load_tasks
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'requiring the rake task should not define method .app_generator on Object' do
|
||||||
|
require "#{app_path}/config/environment"
|
||||||
|
load_tasks
|
||||||
|
assert_raise NameError do
|
||||||
|
Object.method(:app_generator)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'requiring the rake task should not define method .invoke_from_app_generator on Object' do
|
||||||
|
require "#{app_path}/config/environment"
|
||||||
|
load_tasks
|
||||||
|
|
||||||
|
assert_raise NameError do
|
||||||
|
Object.method(:invoke_from_app_generator)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user