aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJ. Edward Dewyea <jed@commuterdesign.com>2011-05-30 05:58:39 -0400
committerJ. Edward Dewyea <jed@commuterdesign.com>2011-05-30 05:58:39 -0400
commitbaf2a9cb7fde7c6e787765ed86289fda164075b1 (patch)
tree899d66379fdbb593be6689667a51afaad274f409 /railties
parent96525d632d47847ae5a8d6658ad396b74ecfb6f1 (diff)
downloadrails-baf2a9cb7fde7c6e787765ed86289fda164075b1.tar.gz
rails-baf2a9cb7fde7c6e787765ed86289fda164075b1.tar.bz2
rails-baf2a9cb7fde7c6e787765ed86289fda164075b1.zip
properly require javascript libraries when generating mountable engine
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/Gemfile4
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb22
3 files changed, 27 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index 00f90f9498..11867a4cd7 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -118,7 +118,7 @@ task :default => :test
return if options.skip_javascript?
if mountable?
- copy_file "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
+ template "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
"app/assets/javascripts/application.js"
elsif full?
empty_directory_with_gitkeep "app/assets/javascripts"
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
index 29900c93dc..c28e568711 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -6,6 +6,10 @@ source "http://rubygems.org"
<%= database_gemfile_entry -%>
<% end -%>
+<% if mountable? -%>
+<%= gem_for_javascript -%>
+<% end -%>
+
if RUBY_VERSION < '1.9'
gem "ruby-debug", ">= 0.10.3"
end
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index 528c73ffaf..b272638026 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -112,6 +112,28 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_file "app/assets/javascripts/application.js"
end
+ def test_jquery_is_the_default_javascript_library
+ run_generator [destination_root, "--mountable"]
+ assert_file "app/assets/javascripts/application.js" do |contents|
+ assert_match %r{^//= require jquery}, contents
+ assert_match %r{^//= require jquery_ujs}, contents
+ end
+ assert_file 'Gemfile' do |contents|
+ assert_match(/^gem 'jquery-rails'/, contents)
+ end
+ end
+
+ def test_other_javascript_libraries
+ run_generator [destination_root, "--mountable", '-j', 'prototype']
+ assert_file "app/assets/javascripts/application.js" do |contents|
+ assert_match %r{^//= require prototype}, contents
+ assert_match %r{^//= require prototype_ujs}, contents
+ end
+ assert_file 'Gemfile' do |contents|
+ assert_match(/^gem 'prototype-rails'/, contents)
+ end
+ end
+
def test_skip_javascripts
run_generator [destination_root, "--skip-javascript", "--mountable"]
assert_no_file "app/assets/javascripts/application.js"