aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2013-02-28 12:09:04 -0700
committerJosé Valim <jose.valim@plataformatec.com.br>2013-02-28 12:09:04 -0700
commitdc53fe92404910a83cfc056d126f45772dfa58fe (patch)
treec7bb1954415a9813f7c1f0b0af7ebeff45146244 /railties
parent8f6b70f1fd49b8520a744cc90102051043faf315 (diff)
downloadrails-dc53fe92404910a83cfc056d126f45772dfa58fe.tar.gz
rails-dc53fe92404910a83cfc056d126f45772dfa58fe.tar.bz2
rails-dc53fe92404910a83cfc056d126f45772dfa58fe.zip
Ensure plugins generated with plugin new can boot the dummy application
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb12
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec3
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/Gemfile8
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/rails/javascripts.js13
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/rails/stylesheets.css13
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb55
6 files changed, 51 insertions, 53 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 af00748037..5fe01d0961 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
@@ -94,6 +94,11 @@ task default: :test
end
end
+ def test_dummy_assets
+ template "rails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true
+ template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
+ end
+
def test_dummy_clean
inside dummy_path do
remove_file ".gitignore"
@@ -112,7 +117,7 @@ task default: :test
def stylesheets
if mountable?
- copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
+ copy_file "rails/stylesheets.css",
"app/assets/stylesheets/#{name}/application.css"
elsif full?
empty_directory_with_keep_file "app/assets/stylesheets/#{name}"
@@ -123,8 +128,8 @@ task default: :test
return if options.skip_javascript?
if mountable?
- template "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
- "app/assets/javascripts/#{name}/application.js"
+ template "rails/javascripts.js",
+ "app/assets/javascripts/#{name}/application.js"
elsif full?
empty_directory_with_keep_file "app/assets/javascripts/#{name}"
end
@@ -263,6 +268,7 @@ task default: :test
build(:generate_test_dummy)
store_application_definition!
build(:test_dummy_config)
+ build(:test_dummy_assets)
build(:test_dummy_clean)
# ensure that bin/rails has proper dummy_path
build(:bin, true)
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
index e956d13d8a..f7c12e67dd 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
@@ -19,9 +19,6 @@ Gem::Specification.new do |s|
<% end -%>
<%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
-<% if engine? && !options[:skip_javascript] -%>
- # s.add_dependency "<%= "#{options[:javascript]}-rails" %>"
-<% end -%>
<% unless options[:skip_active_record] -%>
s.add_development_dependency "<%= gem_for_database %>"
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
index a8b5bfaf3f..3f2b78f2fd 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -2,9 +2,6 @@ source "https://rubygems.org"
<% if options[:skip_gemspec] -%>
<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails::VERSION::STRING %>"
-<% if engine? && !options[:skip_javascript] -%>
-# gem "<%= "#{options[:javascript]}-rails" %>"
-<% end -%>
<% else -%>
# Declare your gem's dependencies in <%= name %>.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
@@ -12,11 +9,6 @@ source "https://rubygems.org"
gemspec
<% end -%>
-<% unless options[:javascript] == 'jquery' -%>
-# jquery-rails is used by the dummy application
-gem "jquery-rails"
-
-<% end -%>
<% if options[:skip_gemspec] -%>
group :development do
gem "<%= gem_for_database %>"
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/rails/javascripts.js b/railties/lib/rails/generators/rails/plugin_new/templates/rails/javascripts.js
new file mode 100644
index 0000000000..084d5d1c49
--- /dev/null
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/rails/javascripts.js
@@ -0,0 +1,13 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require_tree .
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/rails/stylesheets.css b/railties/lib/rails/generators/rails/plugin_new/templates/rails/stylesheets.css
new file mode 100644
index 0000000000..3192ec897b
--- /dev/null
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/rails/stylesheets.css
@@ -0,0 +1,13 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+ */
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index 904c1db57e..34441ef679 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -63,13 +63,24 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_no_directory "test/integration/"
assert_no_file "test"
- assert_no_match(/APP_RAKEFILE/, File.read(File.join(destination_root, "Rakefile")))
+ assert_file "Rakefile" do |contents|
+ assert_no_match(/APP_RAKEFILE/, contents)
+ end
end
def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
run_generator [destination_root, "-T", "--mountable", '--dummy-path', 'my_dummy_app']
+ assert_file "Rakefile", /APP_RAKEFILE/
+ end
+
+ def test_generating_adds_dummy_app_without_javascript_and_assets_deps
+ run_generator [destination_root]
+
+ assert_file "test/dummy/app/assets/stylesheets/application.css"
- assert_match(/APP_RAKEFILE/, File.read(File.join(destination_root, "Rakefile")))
+ assert_file "test/dummy/app/assets/javascripts/application.js" do |contents|
+ assert_no_match(/jquery/, contents)
+ end
end
def test_ensure_that_plugin_options_are_not_passed_to_app_generator
@@ -112,7 +123,9 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
def test_ensure_that_skip_active_record_option_is_passed_to_app_generator
run_generator [destination_root, "--skip_active_record"]
assert_no_file "test/dummy/config/database.yml"
- assert_no_match(/ActiveRecord/, File.read(File.join(destination_root, "test/test_helper.rb")))
+ assert_file "test/test_helper.rb" do |contents|
+ assert_no_match /ActiveRecord/, contents
+ end
end
def test_ensure_that_database_option_is_passed_to_app_generator
@@ -134,8 +147,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
def test_skipping_javascripts_without_mountable_option
run_generator
assert_no_file "app/assets/javascripts/bukkits/application.js"
- assert_no_file "vendor/assets/javascripts/jquery.js"
- assert_no_file "vendor/assets/javascripts/jquery_ujs.js"
end
def test_javascripts_generation
@@ -143,33 +154,9 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_file "app/assets/javascripts/bukkits/application.js"
end
- def test_jquery_is_the_default_javascript_library
- run_generator [destination_root, "--mountable"]
- assert_file "app/assets/javascripts/bukkits/application.js" do |contents|
- assert_match %r{^//= require jquery}, contents
- assert_match %r{^//= require jquery_ujs}, contents
- end
- assert_file 'bukkits.gemspec' do |contents|
- assert_match(/jquery-rails/, contents)
- end
- end
-
- def test_other_javascript_libraries
- run_generator [destination_root, "--mountable", '-j', 'prototype']
- assert_file "app/assets/javascripts/bukkits/application.js" do |contents|
- assert_match %r{^//= require prototype}, contents
- assert_match %r{^//= require prototype_ujs}, contents
- end
- assert_file 'bukkits.gemspec' do |contents|
- assert_match(/prototype-rails/, contents)
- end
- end
-
def test_skip_javascripts
run_generator [destination_root, "--skip-javascript", "--mountable"]
assert_no_file "app/assets/javascripts/bukkits/application.js"
- assert_no_file "vendor/assets/javascripts/jquery.js"
- assert_no_file "vendor/assets/javascripts/jquery_ujs.js"
end
def test_template_from_dir_pwd
@@ -318,16 +305,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_no_match('gemspec', contents)
assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents)
assert_match(/group :development do\n gem "sqlite3"\nend/, contents)
- assert_match(/# gem "jquery-rails"/, contents)
- assert_no_match(/# jquery-rails is used by the dummy application\ngem "jquery-rails"/, contents)
- end
- end
-
- def test_skipping_gemspec_in_full_mode_with_javascript_option
- run_generator [destination_root, "--skip-gemspec", "--full", "--javascript=prototype"]
- assert_file "Gemfile" do |contents|
- assert_match(/# gem "prototype-rails"/, contents)
- assert_match(/# jquery-rails is used by the dummy application\ngem "jquery-rails"/, contents)
end
end