aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/engine.rb37
-rw-r--r--railties/lib/rails/tasks/railties.rake2
-rw-r--r--railties/test/railties/engine_test.rb4
-rw-r--r--railties/test/railties/shared_tests.rb4
4 files changed, 30 insertions, 17 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index e201aa591d..cbf09790ab 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -542,27 +542,30 @@ module Rails
rake_tasks do
next if self.is_a?(Rails::Application)
+ next unless has_migrations? or has_public?
namespace railtie_name do
- desc "Shortcut for running both rake #{railtie_name}:install:migrations and #{railtie_name}:install:assets"
+ desc "Shortcut for copying migrations and assets from #{railtie_name}"
task :install do
- Rake::Task["#{railtie_name}:install:migrations"].invoke
- Rake::Task["#{railtie_name}:install:assets"].invoke
+ Rake::Task["#{railtie_name}:install:migrations"].invoke if has_migrations?
+ Rake::Task["#{railtie_name}:install:public"].invoke if has_public?
end
namespace :install do
- # TODO Add assets copying to this list
- # TODO Skip this if there is no paths["db/migrate"] for the engine
- desc "Copy migrations from #{railtie_name} to application"
- task :migrations do
- ENV["FROM"] = railtie_name
- Rake::Task["railties:install:migrations"].invoke
+ if has_migrations?
+ desc "Copy migrations from #{railtie_name} to application"
+ task :migrations do
+ ENV["FROM"] = railtie_name
+ Rake::Task["railties:install:migrations"].invoke
+ end
end
- desc "Copy assets from #{railtie_name} to application"
- task :assets do
- ENV["FROM"] = railtie_name
- Rake::Task["railties:install:assets"].invoke
+ if has_public?
+ desc "Copy public from #{railtie_name} to application"
+ task :public do
+ ENV["FROM"] = railtie_name
+ Rake::Task["railties:install:public"].invoke
+ end
end
end
end
@@ -578,6 +581,14 @@ module Rails
defined?(@routes)
end
+ def has_migrations?
+ paths["db/migrate"].first.present?
+ end
+
+ def has_public?
+ paths["public"].first.present?
+ end
+
def find_root_with_flag(flag, default=nil)
root_path = self.class.called_from
diff --git a/railties/lib/rails/tasks/railties.rake b/railties/lib/rails/tasks/railties.rake
index 16703879cf..7d2170dd30 100644
--- a/railties/lib/rails/tasks/railties.rake
+++ b/railties/lib/rails/tasks/railties.rake
@@ -1,7 +1,7 @@
namespace :railties do
namespace :install do
# desc "Copies missing assets from Railties (e.g. plugins, engines). You can specify Railties to use with FROM=railtie1,railtie2"
- task :assets => :rails_env do
+ task :public => :rails_env do
require 'rails/generators/base'
Rails.application.initialize!
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index f7423cd566..530863fd08 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -199,6 +199,8 @@ module RailtiesTest
end
test "it allows to set asset_path" do
+ add_to_config("config.assets.enabled = false")
+
@plugin.write "lib/bukkits.rb", <<-RUBY
class Bukkits
class Engine < ::Rails::Engine
@@ -206,7 +208,6 @@ module RailtiesTest
end
RUBY
-
@plugin.write "config/routes.rb", <<-RUBY
Bukkits::Engine.routes.draw do
match "/foo" => "foo#index"
@@ -774,6 +775,7 @@ module RailtiesTest
test "ensure that engine properly sets assets directories" do
add_to_config("config.action_dispatch.show_exceptions = false")
add_to_config("config.serve_static_assets = true")
+ add_to_config("config.assets.enabled = false")
@plugin.write "lib/bukkits.rb", <<-RUBY
module Bukkits
diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb
index 5cd1818f4b..46bab2a47b 100644
--- a/railties/test/railties/shared_tests.rb
+++ b/railties/test/railties/shared_tests.rb
@@ -32,13 +32,13 @@ module RailtiesTest
end
end
- def test_copying_assets
+ def test_copying_public
@plugin.write "public/javascripts/foo.js", "doSomething()"
@plugin.write "public/stylesheets/foo.css", "h1 { font-size: 10000px }"
@plugin.write "public/images/img.png", ""
Dir.chdir(app_path) do
- `rake bukkits:install:assets --trace`
+ `rake bukkits:install:public --trace`
assert File.exists?(app_path("public/bukkits/javascripts/foo.js"))
assert_equal "doSomething()\n", File.read(app_path("public/bukkits/javascripts/foo.js"))