mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #15327 from alexbel/replace_double_quotes_with_single_quotes
Replace double quotes with single quotes while adding an entry into Gemfile
This commit is contained in:
commit
83cb356093
3 changed files with 32 additions and 11 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
* Replace double quotes with single quotes while adding an entry into Gemfile.
|
||||||
|
|
||||||
|
*Alexander Belaev*
|
||||||
|
|
||||||
* Default `config.assets.digest` to `true` in development.
|
* Default `config.assets.digest` to `true` in development.
|
||||||
|
|
||||||
*Dan Kang*
|
*Dan Kang*
|
||||||
|
|
|
@ -20,9 +20,9 @@ module Rails
|
||||||
|
|
||||||
# Set the message to be shown in logs. Uses the git repo if one is given,
|
# Set the message to be shown in logs. Uses the git repo if one is given,
|
||||||
# otherwise use name (version).
|
# otherwise use name (version).
|
||||||
parts, message = [ name.inspect ], name
|
parts, message = [ quote(name) ], name
|
||||||
if version ||= options.delete(:version)
|
if version ||= options.delete(:version)
|
||||||
parts << version.inspect
|
parts << quote(version)
|
||||||
message << " (#{version})"
|
message << " (#{version})"
|
||||||
end
|
end
|
||||||
message = options[:git] if options[:git]
|
message = options[:git] if options[:git]
|
||||||
|
@ -30,7 +30,7 @@ module Rails
|
||||||
log :gemfile, message
|
log :gemfile, message
|
||||||
|
|
||||||
options.each do |option, value|
|
options.each do |option, value|
|
||||||
parts << "#{option}: #{value.inspect}"
|
parts << "#{option}: #{quote(value)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
in_root do
|
in_root do
|
||||||
|
@ -68,7 +68,7 @@ module Rails
|
||||||
log :source, source
|
log :source, source
|
||||||
|
|
||||||
in_root do
|
in_root do
|
||||||
prepend_file "Gemfile", "source #{source.inspect}\n", verbose: false
|
prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -255,6 +255,15 @@ module Rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Surround string with single quotes if there is no quotes.
|
||||||
|
# Otherwise fall back to double quotes
|
||||||
|
def quote(str)
|
||||||
|
if str.include?("'")
|
||||||
|
str.inspect
|
||||||
|
else
|
||||||
|
"'#{str}'"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,13 +41,13 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
def test_add_source_adds_source_to_gemfile
|
def test_add_source_adds_source_to_gemfile
|
||||||
run_generator
|
run_generator
|
||||||
action :add_source, 'http://gems.github.com'
|
action :add_source, 'http://gems.github.com'
|
||||||
assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/
|
assert_file 'Gemfile', /source 'http:\/\/gems\.github\.com'/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_should_put_gem_dependency_in_gemfile
|
def test_gem_should_put_gem_dependency_in_gemfile
|
||||||
run_generator
|
run_generator
|
||||||
action :gem, 'will-paginate'
|
action :gem, 'will-paginate'
|
||||||
assert_file 'Gemfile', /gem "will\-paginate"/
|
assert_file 'Gemfile', /gem 'will\-paginate'/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_with_version_should_include_version_in_gemfile
|
def test_gem_with_version_should_include_version_in_gemfile
|
||||||
|
@ -55,7 +55,7 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
action :gem, 'rspec', '>=2.0.0.a5'
|
action :gem, 'rspec', '>=2.0.0.a5'
|
||||||
|
|
||||||
assert_file 'Gemfile', /gem "rspec", ">=2.0.0.a5"/
|
assert_file 'Gemfile', /gem 'rspec', '>=2.0.0.a5'/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_should_insert_on_separate_lines
|
def test_gem_should_insert_on_separate_lines
|
||||||
|
@ -66,8 +66,8 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
action :gem, 'rspec'
|
action :gem, 'rspec'
|
||||||
action :gem, 'rspec-rails'
|
action :gem, 'rspec-rails'
|
||||||
|
|
||||||
assert_file 'Gemfile', /^gem "rspec"$/
|
assert_file 'Gemfile', /^gem 'rspec'$/
|
||||||
assert_file 'Gemfile', /^gem "rspec-rails"$/
|
assert_file 'Gemfile', /^gem 'rspec-rails'$/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_should_include_options
|
def test_gem_should_include_options
|
||||||
|
@ -75,7 +75,15 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
action :gem, 'rspec', github: 'dchelimsky/rspec', tag: '1.2.9.rc1'
|
action :gem, 'rspec', github: 'dchelimsky/rspec', tag: '1.2.9.rc1'
|
||||||
|
|
||||||
assert_file 'Gemfile', /gem "rspec", github: "dchelimsky\/rspec", tag: "1\.2\.9\.rc1"/
|
assert_file 'Gemfile', /gem 'rspec', github: 'dchelimsky\/rspec', tag: '1\.2\.9\.rc1'/
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_gem_falls_back_to_inspect_if_string_contains_single_quote
|
||||||
|
run_generator
|
||||||
|
|
||||||
|
action :gem, 'rspec', ">=2.0'0"
|
||||||
|
|
||||||
|
assert_file 'Gemfile', /^gem 'rspec', ">=2\.0'0"$/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_group_should_wrap_gems_in_a_group
|
def test_gem_group_should_wrap_gems_in_a_group
|
||||||
|
@ -89,7 +97,7 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
gem 'fakeweb'
|
gem 'fakeweb'
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/
|
assert_file 'Gemfile', /\ngroup :development, :test do\n gem 'rspec-rails'\nend\n\ngroup :test do\n gem 'fakeweb'\nend/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_environment_should_include_data_in_environment_initializer_block
|
def test_environment_should_include_data_in_environment_initializer_block
|
||||||
|
|
Loading…
Reference in a new issue