Skip to content
This repository
Browse code

properly require javascript libraries when generating mountable engine

  • Loading branch information...
commit baf2a9cb7fde7c6e787765ed86289fda164075b1 1 parent 96525d6
Justin Dewyea authored May 30, 2011
2  railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -118,7 +118,7 @@ def javascripts
118 118
       return if options.skip_javascript?
119 119
 
120 120
       if mountable?
121  
-        copy_file "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
  121
+        template "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
122 122
                   "app/assets/javascripts/application.js"
123 123
       elsif full?
124 124
         empty_directory_with_gitkeep "app/assets/javascripts"
4  railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -6,6 +6,10 @@ source "http://rubygems.org"
6 6
 <%= database_gemfile_entry -%>
7 7
 <% end -%>
8 8
 
  9
+<% if mountable? -%>
  10
+<%= gem_for_javascript -%>
  11
+<% end -%>
  12
+
9 13
 if RUBY_VERSION < '1.9'
10 14
   gem "ruby-debug", ">= 0.10.3"
11 15
 end
22  railties/test/generators/plugin_new_generator_test.rb
@@ -112,6 +112,28 @@ def test_javascripts_generation
112 112
     assert_file "app/assets/javascripts/application.js"
113 113
   end
114 114
 
  115
+  def test_jquery_is_the_default_javascript_library
  116
+    run_generator [destination_root, "--mountable"]
  117
+    assert_file "app/assets/javascripts/application.js" do |contents|
  118
+      assert_match %r{^//= require jquery}, contents
  119
+      assert_match %r{^//= require jquery_ujs}, contents
  120
+    end
  121
+    assert_file 'Gemfile' do |contents|
  122
+      assert_match(/^gem 'jquery-rails'/, contents)
  123
+    end
  124
+  end
  125
+
  126
+  def test_other_javascript_libraries
  127
+    run_generator [destination_root, "--mountable", '-j', 'prototype']
  128
+    assert_file "app/assets/javascripts/application.js" do |contents|
  129
+      assert_match %r{^//= require prototype}, contents
  130
+      assert_match %r{^//= require prototype_ujs}, contents
  131
+    end
  132
+    assert_file 'Gemfile' do |contents|
  133
+      assert_match(/^gem 'prototype-rails'/, contents)
  134
+    end
  135
+  end
  136
+
115 137
   def test_skip_javascripts
116 138
     run_generator [destination_root, "--skip-javascript", "--mountable"]
117 139
     assert_no_file "app/assets/javascripts/application.js"

0 notes on commit baf2a9c

Please sign in to comment.
Something went wrong with that request. Please try again.