Permalink
Browse files

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.
  • Loading branch information...
1 parent e00ab2d commit c5034d60dba0cd31a6a8c612ee35d63b8127793a @tenderlove tenderlove committed Feb 11, 2014
Showing with 33 additions and 1 deletion.
  1. +1 −1 railties/lib/rails/tasks/framework.rake
  2. +32 −0 railties/test/application/rake/templates_test.rb
@@ -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
@@ -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
+

1 comment on commit c5034d6

@splattael

@tenderlove thor's no_commands (previous no_tasks) let you define a public method without adding it as a thor command:
https://github.com/erikhuda/thor/blob/master/lib/thor/base.rb#L392..L398

Please sign in to comment.