2016-08-06 13:16:09 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/core_ext/module/remove_method"
|
|
|
|
require "active_support/testing/stream"
|
|
|
|
require "active_support/testing/method_call_assertions"
|
|
|
|
require "rails/generators"
|
|
|
|
require "rails/generators/test_case"
|
2009-11-02 21:08:33 -05:00
|
|
|
|
|
|
|
module Rails
|
2013-12-15 15:04:54 -05:00
|
|
|
class << self
|
|
|
|
remove_possible_method :root
|
|
|
|
def root
|
2016-08-06 13:16:09 -04:00
|
|
|
@root ||= Pathname.new(File.expand_path("../../fixtures", __FILE__))
|
2013-12-15 15:04:54 -05:00
|
|
|
end
|
2009-11-02 21:08:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
Rails.application.config.root = Rails.root
|
2010-02-06 11:32:06 -05:00
|
|
|
Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "templates")]
|
2009-11-02 21:08:33 -05:00
|
|
|
|
2010-06-02 02:45:03 -04:00
|
|
|
# Call configure to load the settings from
|
|
|
|
# Rails.application.config.generators to Rails::Generators
|
2011-05-25 03:43:24 -04:00
|
|
|
Rails.application.load_generators
|
2010-01-29 11:41:10 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "active_record"
|
|
|
|
require "action_dispatch"
|
|
|
|
require "action_view"
|
2009-07-03 08:55:37 -04:00
|
|
|
|
2010-01-18 18:07:11 -05:00
|
|
|
module GeneratorsTestHelper
|
2015-01-15 01:42:33 -05:00
|
|
|
include ActiveSupport::Testing::Stream
|
2015-08-15 08:08:18 -04:00
|
|
|
include ActiveSupport::Testing::MethodCallAssertions
|
2015-01-15 01:42:33 -05:00
|
|
|
|
2010-01-18 18:07:11 -05:00
|
|
|
def self.included(base)
|
|
|
|
base.class_eval do
|
|
|
|
destination File.join(Rails.root, "tmp")
|
|
|
|
setup :prepare_destination
|
2009-06-25 04:44:46 -04:00
|
|
|
|
2010-01-18 18:07:11 -05:00
|
|
|
begin
|
2016-08-06 13:16:09 -04:00
|
|
|
base.tests Rails::Generators.const_get(base.name.sub(/Test$/, ""))
|
2010-01-18 18:07:11 -05:00
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
2010-01-03 18:31:53 -05:00
|
|
|
end
|
2010-03-19 13:11:37 -04:00
|
|
|
|
|
|
|
def copy_routes
|
2010-03-23 08:40:19 -04:00
|
|
|
routes = File.expand_path("../../../lib/rails/generators/rails/app/templates/config/routes.rb", __FILE__)
|
2010-03-19 13:11:37 -04:00
|
|
|
destination = File.join(destination_root, "config")
|
|
|
|
FileUtils.mkdir_p(destination)
|
2011-02-23 08:40:08 -05:00
|
|
|
FileUtils.cp routes, destination
|
2010-03-19 13:11:37 -04:00
|
|
|
end
|
2010-09-23 13:13:07 -04:00
|
|
|
end
|