Permalink
Browse files

Don't add jQuery by default in new apps and use rails-ujs as UJS adap…

…ter instead
  • Loading branch information...
guilleiguaran committed Nov 19, 2016
1 parent 6cd6586 commit a865e3b2620197641e6ae519647ad81098182dec
@@ -30,7 +30,7 @@ def self.add_shared_options_for(name)
class_option :database, type: :string, aliases: "-d", default: "sqlite3",
desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
class_option :javascript, type: :string, aliases: "-j", default: "jquery",
class_option :javascript, type: :string, aliases: "-j",
desc: "Preconfigure for selected JavaScript library"
class_option :skip_gemfile, type: :boolean, default: false,
@@ -328,8 +328,13 @@ def javascript_gemfile_entry
gems = [javascript_runtime_gemfile_entry]
gems << coffee_gemfile_entry unless options[:skip_coffee]
gems << GemfileEntry.version("#{options[:javascript]}-rails", nil,
"Use #{options[:javascript]} as the JavaScript library")
if options[:javascript]
gems << GemfileEntry.version("#{options[:javascript]}-rails", nil,
"Use #{options[:javascript]} as the JavaScript library")
end
gems << GemfileEntry.github("rails-ujs", "rails/rails-ujs", nil,
"Unobstrusive JavaScript adapter for Rails")
unless options[:skip_turbolinks]
gems << GemfileEntry.version("turbolinks", "~> 5",
@@ -11,8 +11,10 @@
// about supported directives.
//
<% unless options[:skip_javascript] -%>
<% if options[:javascript] -%>
//= require <%= options[:javascript] %>
//= require <%= options[:javascript] %>_ujs
<% end -%>
//= require rails-ujs
<% unless options[:skip_turbolinks] -%>
//= require turbolinks
<% end -%>
@@ -35,7 +35,7 @@ def test_api_modified_files
assert_file "Gemfile" do |content|
assert_no_match(/gem 'coffee-rails'/, content)
assert_no_match(/gem 'jquery-rails'/, content)
assert_no_match(/gem 'rails-ujs'/, content)
assert_no_match(/gem 'sass-rails'/, content)
assert_no_match(/gem 'web-console'/, content)
assert_match(/# gem 'jbuilder'/, content)
@@ -405,7 +405,6 @@ def test_generator_if_skip_sprockets_is_given
assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content)
end
assert_file "Gemfile" do |content|
assert_no_match(/jquery-rails/, content)
assert_no_match(/sass-rails/, content)
assert_no_match(/uglifier/, content)
assert_no_match(/coffee-rails/, content)
@@ -448,22 +447,20 @@ def test_inclusion_of_javascript_runtime
end
end
def test_jquery_is_the_default_javascript_library
def test_rails_ujs_is_the_default_ujs_library
run_generator
assert_file "app/assets/javascripts/application.js" do |contents|
assert_match %r{^//= require jquery}, contents
assert_match %r{^//= require jquery_ujs}, contents
assert_match %r{^//= require rails-ujs}, contents
end
assert_gem "jquery-rails"
assert_gem "rails-ujs"
end
def test_other_javascript_libraries
run_generator [destination_root, "-j", "prototype"]
def test_inclusion_of_javascript_libraries_if_required
run_generator [destination_root, "-j", "jquery"]
assert_file "app/assets/javascripts/application.js" do |contents|
assert_match %r{^//= require prototype}, contents
assert_match %r{^//= require prototype_ujs}, contents
assert_match %r{^//= require jquery}, contents
end
assert_gem "prototype-rails"
assert_gem "jquery-rails"
end
def test_javascript_is_skipped_if_required
@@ -479,8 +476,8 @@ def test_javascript_is_skipped_if_required
assert_file "Gemfile" do |content|
assert_no_match(/coffee-rails/, content)
assert_no_match(/jquery-rails/, content)
assert_no_match(/uglifier/, content)
assert_no_match(/rails-ujs/, content)
end
assert_file "config/environments/production.rb" do |content|
@@ -493,7 +490,6 @@ def test_coffeescript_is_skipped_if_required
assert_file "Gemfile" do |content|
assert_no_match(/coffee-rails/, content)
assert_match(/jquery-rails/, content)
assert_match(/uglifier/, content)
end
end
@@ -507,7 +507,6 @@ def test_skipping_gemspec
assert_no_match("gemspec", contents)
assert_match(/gem 'rails'/, contents)
assert_match_sqlite3(contents)
assert_no_match(/# gem "jquery-rails"/, contents)
end
end

0 comments on commit a865e3b

Please sign in to comment.