Remove --freeze (since Rails will come bundled in all new apps) and update gem action to change Gemfile instead of config.environment.
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
3fb548cac3
commit
3b8e29fe56
|
@ -1,4 +1,5 @@
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
require 'active_support/deprecation'
|
||||||
|
|
||||||
module Rails
|
module Rails
|
||||||
module Generators
|
module Generators
|
||||||
|
@ -45,19 +46,56 @@ module Rails
|
||||||
#
|
#
|
||||||
# gem "rspec", :env => :test
|
# gem "rspec", :env => :test
|
||||||
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
|
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
|
||||||
|
# gem "rails", "3.0", :git => "git://github.com/rails/rails"
|
||||||
#
|
#
|
||||||
def gem(name, options={})
|
def gem(*args)
|
||||||
log :gem, name
|
options = args.extract_options!
|
||||||
env = options.delete(:env)
|
name, version = args
|
||||||
|
|
||||||
gems_code = "config.gem '#{name}'"
|
# Deal with deprecated options
|
||||||
|
{ :env => :only, :lib => :require_as }.each do |old, new|
|
||||||
if options.any?
|
next unless options[old]
|
||||||
opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ")
|
options[new] = options.delete(old)
|
||||||
gems_code << ", #{opts}"
|
ActiveSupport::Deprecation.warn "#{old.inspect} option in gem is deprecated, use #{new.inspect} instead"
|
||||||
end
|
end
|
||||||
|
|
||||||
environment gems_code, :env => env
|
# Deal with deprecated source
|
||||||
|
if source = options.delete(:source)
|
||||||
|
ActiveSupport::Deprecation.warn ":source option in gem is deprecated, use add_source method instead"
|
||||||
|
add_source(source)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set the message to be shown in logs. Uses the git repo if one is given,
|
||||||
|
# otherwise use name (version).
|
||||||
|
parts, message = [ name.inspect ], name
|
||||||
|
if version ||= options.delete(:version)
|
||||||
|
parts << version
|
||||||
|
message << " (#{version})"
|
||||||
|
end
|
||||||
|
message = options[:git] if options[:git]
|
||||||
|
|
||||||
|
log :gemfile, message
|
||||||
|
|
||||||
|
options.each do |option, value|
|
||||||
|
parts << ":#{option} => #{value.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
in_root do
|
||||||
|
append_file "Gemfile", "gem #{parts.join(", ")}", :verbose => false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Add the given source to Gemfile
|
||||||
|
#
|
||||||
|
# ==== Example
|
||||||
|
#
|
||||||
|
# source "http://gems.github.com/"
|
||||||
|
def add_source(source, options={})
|
||||||
|
log :source, source
|
||||||
|
|
||||||
|
in_root do
|
||||||
|
prepend_file "Gemfile", "source #{source.inspect}", :verbose => false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds a line inside the Initializer block for config/environment.rb.
|
# Adds a line inside the Initializer block for config/environment.rb.
|
||||||
|
@ -79,6 +117,7 @@ module Rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
alias :application :environment
|
||||||
|
|
||||||
# Run a command in git.
|
# Run a command in git.
|
||||||
#
|
#
|
||||||
|
@ -222,9 +261,8 @@ module Rails
|
||||||
#
|
#
|
||||||
# freeze!
|
# freeze!
|
||||||
#
|
#
|
||||||
def freeze!(args = {})
|
def freeze!(args={})
|
||||||
log :vendor, "rails"
|
ActiveSupport::Deprecation.warn "freeze! is deprecated since your rails app now comes bundled with Rails by default, please check your Gemfile"
|
||||||
in_root { run("#{extify(:rake)} rails:freeze:edge", :verbose => false) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make an entry in Rails routing file conifg/routes.rb
|
# Make an entry in Rails routing file conifg/routes.rb
|
||||||
|
|
|
@ -12,9 +12,6 @@ module Rails::Generators
|
||||||
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
|
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
|
||||||
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
|
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
|
||||||
|
|
||||||
class_option :freeze, :type => :boolean, :aliases => "-F", :default => false,
|
|
||||||
:desc => "Freeze Rails in vendor/rails from the gems"
|
|
||||||
|
|
||||||
class_option :template, :type => :string, :aliases => "-m",
|
class_option :template, :type => :string, :aliases => "-m",
|
||||||
:desc => "Path to an application template (can be a filesystem path or URL)."
|
:desc => "Path to an application template (can be a filesystem path or URL)."
|
||||||
|
|
||||||
|
@ -155,10 +152,6 @@ module Rails::Generators
|
||||||
raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
|
raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def freeze?
|
|
||||||
freeze! if options[:freeze]
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
attr_accessor :rails_template
|
attr_accessor :rails_template
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# Gemfile is where you list all of your application's dependencies
|
# Gemfile is where you list all of your application's dependencies
|
||||||
#
|
#
|
||||||
<%= "# " if options.freeze? %>gem "rails", "<%= Rails::VERSION::STRING %>"
|
gem "rails", "<%= Rails::VERSION::STRING %>"
|
||||||
#
|
#
|
||||||
# Bundling edge rails:
|
# Bundling edge rails:
|
||||||
<%= "# " unless options.freeze? %>gem "rails", "<%= Rails::VERSION::STRING %>", :git => "git://github.com/rails/rails.git"
|
# gem "rails", "<%= Rails::VERSION::STRING %>", :git => "git://github.com/rails/rails.git"
|
||||||
|
|
||||||
# Specify gemcutter as a gem source
|
# Specify gemcutter as a gem source
|
||||||
# source "http://gemcutter.org"
|
# source "http://gemcutter.org"
|
||||||
|
|
|
@ -54,37 +54,37 @@ class ActionsTest < GeneratorsTestCase
|
||||||
action :plugin, 'rest_auth', {}
|
action :plugin, 'rest_auth', {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_should_put_gem_dependency_in_enviroment
|
def test_add_source_adds_source_to_gemfile
|
||||||
|
run_generator
|
||||||
|
action :add_source, 'http://gems.github.com'
|
||||||
|
assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_gem_should_put_gem_dependency_in_gemfile
|
||||||
run_generator
|
run_generator
|
||||||
action :gem, 'will-paginate'
|
action :gem, 'will-paginate'
|
||||||
assert_file 'config/application.rb', /config\.gem 'will\-paginate'/
|
assert_file 'Gemfile', /gem "will\-paginate"/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_with_options_should_include_options_in_gem_dependency_in_environment
|
def test_gem_with_options_should_include_all_options_in_gemfile
|
||||||
run_generator
|
run_generator
|
||||||
action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'
|
|
||||||
|
|
||||||
regexp = /#{Regexp.escape("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'")}/
|
assert_deprecated do
|
||||||
assert_file 'config/application.rb', regexp
|
action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_file 'Gemfile', /gem "mislav\-will\-paginate", :require_as => "will\-paginate"/
|
||||||
|
assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment
|
def test_gem_with_env_should_include_all_dependencies_in_gemfile
|
||||||
run_generator
|
run_generator
|
||||||
action :gem, 'rspec', :env => 'test'
|
|
||||||
assert_file 'config/environments/test.rb', /config\.gem 'rspec'/
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_gem_with_env_array_should_put_gem_dependency_in_specified_environments
|
assert_deprecated do
|
||||||
run_generator
|
action :gem, 'rspec', :env => %w(development test)
|
||||||
action :gem, 'quietbacktrace', :env => %w[ development test ]
|
end
|
||||||
assert_file 'config/environments/development.rb', /config\.gem 'quietbacktrace'/
|
|
||||||
assert_file 'config/environments/test.rb', /config\.gem 'quietbacktrace'/
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly
|
assert_file 'Gemfile', /gem "rspec", :only => \["development", "test"\]/
|
||||||
run_generator
|
|
||||||
action :gem, 'mislav-will-paginate', :lib => false
|
|
||||||
assert_file 'config/application.rb', /config\.gem 'mislav\-will\-paginate'\, :lib => false/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_environment_should_include_data_in_environment_initializer_block
|
def test_environment_should_include_data_in_environment_initializer_block
|
||||||
|
@ -163,9 +163,10 @@ class ActionsTest < GeneratorsTestCase
|
||||||
action :capify!
|
action :capify!
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_freeze_should_freeze_rails_edge
|
def test_freeze_is_deprecated
|
||||||
generator.expects(:run).once.with('rake rails:freeze:edge', :verbose => false)
|
assert_deprecated do
|
||||||
action :freeze!
|
action :freeze!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_route_should_add_data_to_the_routes_block_in_config_routes
|
def test_route_should_add_data_to_the_routes_block_in_config_routes
|
||||||
|
|
|
@ -110,20 +110,6 @@ class AppGeneratorTest < GeneratorsTestCase
|
||||||
).each { |path| assert_file "script/#{path}", /#!\/usr\/bin\/env/ }
|
).each { |path| assert_file "script/#{path}", /#!\/usr\/bin\/env/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rails_is_frozen
|
|
||||||
generator(:freeze => true, :database => "sqlite3").expects(:run).
|
|
||||||
with("rake rails:freeze:edge", :verbose => false)
|
|
||||||
silence(:stdout){ generator.invoke }
|
|
||||||
|
|
||||||
assert_file 'Gemfile' do |content|
|
|
||||||
flag = %(gem "rails", "#{Rails::VERSION::STRING}", :git => "git://github.com/rails/rails.git")
|
|
||||||
assert_match /^#{Regexp.escape(flag)}$/, content
|
|
||||||
|
|
||||||
flag = %(# gem "rails", "#{Rails::VERSION::STRING}")
|
|
||||||
assert_match /^#{Regexp.escape(flag)}$/, content
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_template_from_dir_pwd
|
def test_template_from_dir_pwd
|
||||||
FileUtils.cd(Rails.root)
|
FileUtils.cd(Rails.root)
|
||||||
assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"])
|
assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"])
|
||||||
|
|
|
@ -17,7 +17,7 @@ require 'action_dispatch'
|
||||||
CURRENT_PATH = File.expand_path(Dir.pwd)
|
CURRENT_PATH = File.expand_path(Dir.pwd)
|
||||||
Rails::Generators.no_color!
|
Rails::Generators.no_color!
|
||||||
|
|
||||||
class GeneratorsTestCase < Test::Unit::TestCase
|
class GeneratorsTestCase < ActiveSupport::TestCase
|
||||||
include FileUtils
|
include FileUtils
|
||||||
|
|
||||||
def destination_root
|
def destination_root
|
||||||
|
|
Loading…
Reference in New Issue