diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-09-06 10:50:08 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-06 14:38:36 +0200 |
commit | 24d2d6726ef5d5d6c50605f4d718223944d33336 (patch) | |
tree | dd49251f34f3fc9279fb2032ce401c69f4704fd4 /railties | |
parent | c915ddd38642333cd0f28d188c5d7c51ba517c03 (diff) | |
download | rails-24d2d6726ef5d5d6c50605f4d718223944d33336.tar.gz rails-24d2d6726ef5d5d6c50605f4d718223944d33336.tar.bz2 rails-24d2d6726ef5d5d6c50605f4d718223944d33336.zip |
Added task for creating symlinks to engines' public directories
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/tasks.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/tasks/railties.rake | 20 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 57 |
3 files changed, 78 insertions, 0 deletions
diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index 9807000578..af52014728 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -11,6 +11,7 @@ $VERBOSE = nil routes statistics tmp + railties ).each do |task| load "rails/tasks/#{task}.rake" end diff --git a/railties/lib/rails/tasks/railties.rake b/railties/lib/rails/tasks/railties.rake new file mode 100644 index 0000000000..7cf31f84a0 --- /dev/null +++ b/railties/lib/rails/tasks/railties.rake @@ -0,0 +1,20 @@ +namespace :railties do + desc "Create symlinks to railties public directories in application's public directory." + task :create_symlinks => :environment do + paths = Rails.application.config.static_asset_paths.dup + app_public_path = Rails.application.config.paths.public.to_a.first + + paths.each do |mount_path, path| + symlink_path = File.join(app_public_path, mount_path) + if File.exist?(symlink_path) + File.symlink?(symlink_path) ? FileUtils.rm(symlink_path) : next + end + + next unless File.exist?(path) + + File.symlink(path, symlink_path) + + puts "Created symlink #{symlink_path} -> #{path}" + end + end +end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 0cc729907e..fabd561bd2 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -544,5 +544,62 @@ module RailtiesTest response = AppTemplate::Application.call(env) assert response[2].body =~ /name="post\[title\]"/ end + + test "creating symlinks" do + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + namespace(Bukkits) + end + end + RUBY + + @plugin.write "public/hello.txt", "foo" + @plugin.write "alternate_public/hello.txt", "bar" + + Dir.chdir(app_path) do + output = `rake railties:create_symlinks` + + assert_match /Created symlink/, output + assert_match /#{app_path}\/public\/bukkits/, output + assert_match /#{@plugin.path}\/public/, output + + assert File.symlink?(File.join(app_path, 'public/bukkits')) + assert_equal "foo\n", File.read(File.join(app_path, 'public/bukkits/hello.txt')) + + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + namespace(Bukkits) + config.paths.public = "#{File.join(@plugin.path, "alternate_public")}" + end + end + RUBY + + output = `rake railties:create_symlinks` + + assert_match /Created symlink/, output + assert_match /#{app_path}\/public\/bukkits/, output + assert_match /#{@plugin.path}\/alternate_public/, output + + assert File.symlink?(File.join(app_path, 'public/bukkits')) + assert_equal "bar\n", File.read(File.join(app_path, 'public/bukkits/hello.txt')) + + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + namespace(Bukkits) + config.paths.public = "#{File.join(@plugin.path, "not_existing")}" + end + end + RUBY + + FileUtils.rm File.join(app_path, 'public/bukkits') + + output = `rake railties:create_symlinks` + assert_no_match /Created symlink/, output + assert !File.exist?(File.join(app_path, 'public/bukkits')) + end + end end end |