railties 3.1.0.beta1 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG +47 -1
  2. data/guides/rails_guides/generator.rb +5 -4
  3. data/guides/source/action_controller_overview.textile +26 -0
  4. data/guides/source/active_support_core_extensions.textile +10 -0
  5. data/guides/source/association_basics.textile +2 -2
  6. data/guides/source/caching_with_rails.textile +30 -1
  7. data/guides/source/configuring.textile +40 -45
  8. data/guides/source/contributing_to_ruby_on_rails.textile +20 -11
  9. data/guides/source/generators.textile +23 -24
  10. data/guides/source/getting_started.textile +4 -4
  11. data/guides/source/layout.html.erb +1 -1
  12. data/guides/source/migrations.textile +1 -1
  13. data/guides/source/performance_testing.textile +159 -84
  14. data/guides/source/rails_on_rack.textile +0 -6
  15. data/guides/source/security.textile +5 -5
  16. data/guides/source/testing.textile +3 -3
  17. data/lib/rails/application.rb +12 -7
  18. data/lib/rails/application/bootstrap.rb +2 -1
  19. data/lib/rails/application/configuration.rb +1 -1
  20. data/lib/rails/commands.rb +2 -1
  21. data/lib/rails/commands/benchmarker.rb +28 -19
  22. data/lib/rails/commands/dbconsole.rb +1 -1
  23. data/lib/rails/commands/profiler.rb +27 -43
  24. data/lib/rails/commands/runner.rb +9 -15
  25. data/lib/rails/commands/server.rb +2 -1
  26. data/lib/rails/engine.rb +9 -2
  27. data/lib/rails/engine/configuration.rb +1 -0
  28. data/lib/rails/generators.rb +2 -2
  29. data/lib/rails/generators/actions.rb +1 -1
  30. data/lib/rails/generators/app_base.rb +24 -16
  31. data/lib/rails/generators/base.rb +2 -2
  32. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
  33. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
  34. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +1 -1
  35. data/lib/rails/generators/generated_attribute.rb +7 -6
  36. data/lib/rails/generators/named_base.rb +2 -0
  37. data/lib/rails/generators/rails/app/app_generator.rb +15 -6
  38. data/lib/rails/generators/rails/app/templates/Gemfile +2 -1
  39. data/lib/rails/generators/rails/app/templates/README +10 -5
  40. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +5 -2
  41. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -1
  42. data/lib/rails/generators/rails/app/templates/config/application.rb +3 -12
  43. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +4 -1
  44. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +3 -0
  45. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +3 -0
  46. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +4 -0
  47. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +4 -1
  48. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +5 -2
  49. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +4 -0
  50. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +3 -0
  51. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +0 -1
  52. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
  53. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
  54. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  55. data/lib/rails/generators/rails/app/templates/gitignore +1 -0
  56. data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +4 -1
  57. data/lib/rails/generators/rails/assets/USAGE +3 -3
  58. data/lib/rails/generators/rails/assets/assets_generator.rb +4 -4
  59. data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
  60. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +2 -1
  61. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -2
  62. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +1 -1
  63. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +1 -1
  64. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +3 -3
  65. data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +4 -1
  66. data/lib/rails/rack.rb +4 -4
  67. data/lib/rails/rack/content_length.rb +38 -0
  68. data/lib/rails/railtie.rb +1 -0
  69. data/lib/rails/tasks/framework.rake +2 -7
  70. data/lib/rails/tasks/routes.rake +1 -1
  71. data/lib/rails/version.rb +1 -1
  72. metadata +6 -6
  73. data/lib/rails/rack/static.rb +0 -5
@@ -117,8 +117,6 @@ You can add a new middleware to the middleware stack using any of the following
117
117
 
118
118
  * +config.middleware.insert_after(existing_middleware, new_middleware, args)+ - Adds the new middleware after the specified existing middleware in the middleware stack.
119
119
 
120
- <strong>Example:</strong>
121
-
122
120
  <ruby>
123
121
  # config/environment.rb
124
122
 
@@ -134,8 +132,6 @@ h5. Swapping a Middleware
134
132
 
135
133
  You can swap an existing middleware in the middleware stack using +config.middleware.swap+.
136
134
 
137
- <strong>Example:</strong>
138
-
139
135
  <ruby>
140
136
  # config/environment.rb
141
137
 
@@ -173,8 +169,6 @@ h4. Customizing Internal Middleware Stack
173
169
 
174
170
  It's possible to replace the entire middleware stack with a custom stack using +ActionController::Dispatcher.middleware=+.
175
171
 
176
- <strong>Example:</strong>
177
-
178
172
  Put the following in an initializer:
179
173
 
180
174
  <ruby>
@@ -372,7 +372,7 @@ def signup
372
372
  end
373
373
  </ruby>
374
374
 
375
- Mass-assignment saves you much work, because you don't have to set each value individually. Simply pass a hash to the new() method, or assign attributes=(attributes) a hash value, to set the model's attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this:
375
+ Mass-assignment saves you much work, because you don't have to set each value individually. Simply pass a hash to the +new+ method, or +assign_attributes=+ a hash value, to set the model's attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this:
376
376
 
377
377
  <pre>
378
378
  "name":http://www.example.com/user/signup?user[name]=ow3ned&user[admin]=1
@@ -386,7 +386,7 @@ params[:user] # => {:name => “ow3ned”, :admin => true}
386
386
 
387
387
  So if you create a new user using mass-assignment, it may be too easy to become an administrator.
388
388
 
389
- Note that this vulnerability is not restricted to database columns. Any setter method, unless explicitly protected, is accessible via the <tt>attributes=</tt> method. In fact, this vulnerability is extended even further with the introduction of nested mass assignment (and nested object forms) in Rails 2.3. The +accepts_nested_attributes_for+ declaration provides us the ability to extend mass assignment to model associations (+has_many+, +has_one+, +has_and_belongs_to_many+). For example:
389
+ Note that this vulnerability is not restricted to database columns. Any setter method, unless explicitly protected, is accessible via the <tt>attributes=</tt> method. In fact, this vulnerability is extended even further with the introduction of nested mass assignment (and nested object forms) in Rails 2.3+. The +accepts_nested_attributes_for+ declaration provides us the ability to extend mass assignment to model associations (+has_many+, +has_one+, +has_and_belongs_to_many+). For example:
390
390
 
391
391
  <ruby>
392
392
  class Person < ActiveRecord::Base
@@ -410,7 +410,7 @@ To avoid this, Rails provides two class methods in your Active Record class to c
410
410
  attr_protected :admin
411
411
  </ruby>
412
412
 
413
- +attr_protected+ also optionally takes a scope option using :as which allows you to define multiple mass-assignment groupings. If no scope is defined then attributes will be added to the default group.
413
+ +attr_protected+ also optionally takes a role option using :as which allows you to define multiple mass-assignment groupings. If no role is defined then attributes will be added to the :default role.
414
414
 
415
415
  <ruby>
416
416
  attr_protected :last_login, :as => :admin
@@ -433,7 +433,7 @@ params[:user] # => {:name => "ow3ned", :admin => true}
433
433
  @user.admin # => true
434
434
  </ruby>
435
435
 
436
- When assigning attributes in Active Record using +attributes=+, or +update_attributes+ the :default scope will be used. To assign attributes using different scopes you should use +assign_attributes+ which accepts an optional :as options parameter. If no :as option is provided then the :default scope will be used. You can also bypass mass-assignment security by using the +:without_protection+ option. Here is an example:
436
+ When assigning attributes in Active Record using +attributes=+ the :default role will be used. To assign attributes using different roles you should use +assign_attributes+ which accepts an optional :as options parameter. If no :as option is provided then the :default role will be used. You can also bypass mass-assignment security by using the +:without_protection+ option. Here is an example:
437
437
 
438
438
  <ruby>
439
439
  @user = User.new
@@ -451,7 +451,7 @@ When assigning attributes in Active Record using +attributes=+, or +update_attri
451
451
  @user.is_admin # => true
452
452
  </ruby>
453
453
 
454
- In a similar way, +new+, +create+ and <tt>create!</tt> methods respect mass-assignment security and accepts either +:as+ or +:without_protection+ options. For example:
454
+ In a similar way, +new+, +create+, <tt>create!</tt>, +update_attributes+, and +update_attributes!+ methods all respect mass-assignment security and accept either +:as+ or +:without_protection+ options. For example:
455
455
 
456
456
  <ruby>
457
457
  @user = User.new({ :name => 'Sebastian', :is_admin => true }, :as => :admin)
@@ -38,7 +38,7 @@ When you do end up destroying your testing database (and it will happen, trust m
38
38
 
39
39
  h4. Rails Sets up for Testing from the Word Go
40
40
 
41
- Rails creates a +test+ folder for you as soon as you create a Rails project using +rails _application_name_+. If you list the contents of this folder then you shall see:
41
+ Rails creates a +test+ folder for you as soon as you create a Rails project using +rails new+ _application_name_. If you list the contents of this folder then you shall see:
42
42
 
43
43
  <shell>
44
44
  $ ls -F test/
@@ -54,7 +54,7 @@ For good tests, you'll need to give some thought to setting up test data. In Rai
54
54
 
55
55
  h5. What are Fixtures?
56
56
 
57
- _Fixtures_ is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume one of two formats: *YAML* or *CSV*. In this guide, we will use *YAML*, which is the preferred format.
57
+ _Fixtures_ is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume a single format: *YAML*.
58
58
 
59
59
  You'll find fixtures under your +test/fixtures+ directory. When you run +rails generate model+ to create a new model, fixture stubs will be automatically created and placed in this directory.
60
60
 
@@ -81,7 +81,7 @@ Each fixture is given a name followed by an indented list of colon-separated key
81
81
 
82
82
  h5. ERB'in It Up
83
83
 
84
- ERB allows you to embed ruby code within templates. Both the YAML and CSV fixture formats are pre-processed with ERB when you load fixtures. This allows you to use Ruby to help you generate some sample data.
84
+ ERB allows you to embed ruby code within templates. YAML fixture format is pre-processed with ERB when you load fixtures. This allows you to use Ruby to help you generate some sample data.
85
85
 
86
86
  <erb>
87
87
  <% earth_size = 20 %>
@@ -141,6 +141,8 @@ module Rails
141
141
 
142
142
  def default_middleware_stack
143
143
  ActionDispatch::MiddlewareStack.new.tap do |middleware|
144
+ middleware.use ::Rails::Rack::ContentLength, config.action_dispatch.x_sendfile_header
145
+
144
146
  if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
145
147
  require "action_dispatch/http/rack_cache"
146
148
  middleware.use ::Rack::Cache, rack_cache
@@ -157,7 +159,8 @@ module Rails
157
159
 
158
160
  middleware.use ::Rack::Lock unless config.allow_concurrency
159
161
  middleware.use ::Rack::Runtime
160
- middleware.use ::Rails::Rack::Logger
162
+ middleware.use ::Rack::MethodOverride
163
+ middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods
161
164
  middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local
162
165
  middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
163
166
  middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
@@ -171,7 +174,6 @@ module Rails
171
174
  end
172
175
 
173
176
  middleware.use ::ActionDispatch::ParamsParser
174
- middleware.use ::Rack::MethodOverride
175
177
  middleware.use ::ActionDispatch::Head
176
178
  middleware.use ::Rack::ConditionalGet
177
179
  middleware.use ::Rack::ETag, "no-cache"
@@ -183,10 +185,12 @@ module Rails
183
185
  end
184
186
 
185
187
  def initialize_tasks
186
- require "rails/tasks"
187
- task :environment do
188
- $rails_rake_task = true
189
- require_environment!
188
+ self.class.rake_tasks do
189
+ require "rails/tasks"
190
+ task :environment do
191
+ $rails_rake_task = true
192
+ require_environment!
193
+ end
190
194
  end
191
195
  end
192
196
 
@@ -195,8 +199,9 @@ module Rails
195
199
  end
196
200
 
197
201
  def initialize_console(sandbox=false)
202
+ require "pp"
198
203
  require "rails/console/app"
199
204
  require "rails/console/helpers"
200
205
  end
201
206
  end
202
- end
207
+ end
@@ -1,4 +1,5 @@
1
1
  require "active_support/notifications"
2
+ require "active_support/dependencies"
2
3
  require "active_support/descendants_tracker"
3
4
 
4
5
  module Rails
@@ -9,7 +10,6 @@ module Rails
9
10
  initializer :load_environment_hook do end
10
11
 
11
12
  initializer :load_active_support do
12
- require 'active_support/dependencies'
13
13
  require "active_support/all" unless config.active_support.bare
14
14
  end
15
15
 
@@ -37,6 +37,7 @@ module Rails
37
37
  )
38
38
  logger
39
39
  end
40
+ at_exit { Rails.logger.flush if Rails.logger.respond_to?(:flush) }
40
41
  end
41
42
 
42
43
  # Initialize cache early in the stack so railties can make use of it.
@@ -34,7 +34,7 @@ module Rails
34
34
  @assets = ActiveSupport::OrderedOptions.new
35
35
  @assets.enabled = false
36
36
  @assets.paths = []
37
- @assets.precompile = [ /\w+\.(?!js|css)$/, "application.js", "application.css" ]
37
+ @assets.precompile = [ /\w+\.(?!js|css).+/, "application.js", "application.css" ]
38
38
  @assets.prefix = "/assets"
39
39
 
40
40
  @assets.js_compressor = nil
@@ -6,7 +6,8 @@ aliases = {
6
6
  "g" => "generate",
7
7
  "c" => "console",
8
8
  "s" => "server",
9
- "db" => "dbconsole"
9
+ "db" => "dbconsole",
10
+ "r" => "runner"
10
11
  }
11
12
 
12
13
  command = ARGV.shift
@@ -1,25 +1,34 @@
1
- require 'active_support/core_ext/object/inclusion'
1
+ require 'optparse'
2
+ require 'rails/test_help'
3
+ require 'rails/performance_test_help'
2
4
 
3
- if ARGV.first.in?([nil, "-h", "--help"])
4
- puts "Usage: rails benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..."
5
- exit 1
6
- end
5
+ ARGV.push('--benchmark') # HAX
6
+ require 'active_support/testing/performance'
7
+ ARGV.pop
7
8
 
8
- begin
9
- N = Integer(ARGV.first)
10
- ARGV.shift
11
- rescue ArgumentError
12
- N = 1
9
+ def options
10
+ options = {}
11
+ defaults = ActiveSupport::Testing::Performance::DEFAULTS
12
+
13
+ OptionParser.new do |opt|
14
+ opt.banner = "Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]"
15
+ opt.on('-r', '--runs N', Numeric, 'Number of runs.', "Default: #{defaults[:runs]}") { |r| options[:runs] = r }
16
+ opt.on('-o', '--output PATH', String, 'Directory to use when writing the results.', "Default: #{defaults[:output]}") { |o| options[:output] = o }
17
+ opt.on('-m', '--metrics a,b,c', Array, 'Metrics to use.', "Default: #{defaults[:metrics].join(",")}") { |m| options[:metrics] = m.map(&:to_sym) }
18
+ opt.parse!(ARGV)
19
+ end
20
+
21
+ options
13
22
  end
14
23
 
15
- require 'benchmark'
16
- include Benchmark
17
-
18
- # Don't include compilation in the benchmark
19
- ARGV.each { |expression| eval(expression) }
20
-
21
- bm(6) do |x|
22
- ARGV.each_with_index do |expression, idx|
23
- x.report("##{idx + 1}") { N.times { eval(expression) } }
24
+ class BenchmarkerTest < ActionDispatch::PerformanceTest
25
+ self.profile_options = options
26
+
27
+ ARGV.each do |expression|
28
+ eval <<-RUBY
29
+ def test_#{expression.parameterize('_')}
30
+ #{expression}
31
+ end
32
+ RUBY
24
33
  end
25
34
  end
@@ -23,7 +23,7 @@ module Rails
23
23
  include_password = false
24
24
  options = {}
25
25
  OptionParser.new do |opt|
26
- opt.banner = "Usage: dbconsole [options] [environment]"
26
+ opt.banner = "Usage: dbconsole [environment] [options]"
27
27
  opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v|
28
28
  include_password = true
29
29
  end
@@ -1,48 +1,32 @@
1
- require 'active_support/core_ext/object/inclusion'
1
+ require 'optparse'
2
+ require 'rails/test_help'
3
+ require 'rails/performance_test_help'
4
+ require 'active_support/testing/performance'
2
5
 
3
- if ARGV.first.in?([nil, "-h", "--help"])
4
- $stderr.puts "Usage: rails profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]"
5
- exit(1)
6
- end
7
-
8
- # Define a method to profile.
9
- if ARGV[1] and ARGV[1].to_i > 1
10
- eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
11
- else
12
- eval "def profile_me() #{ARGV[0]} end"
6
+ def options
7
+ options = {}
8
+ defaults = ActiveSupport::Testing::Performance::DEFAULTS
9
+
10
+ OptionParser.new do |opt|
11
+ opt.banner = "Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]"
12
+ opt.on('-r', '--runs N', Numeric, 'Number of runs.', "Default: #{defaults[:runs]}") { |r| options[:runs] = r }
13
+ opt.on('-o', '--output PATH', String, 'Directory to use when writing the results.', "Default: #{defaults[:output]}") { |o| options[:output] = o }
14
+ opt.on('-m', '--metrics a,b,c', Array, 'Metrics to use.', "Default: #{defaults[:metrics].join(",")}") { |m| options[:metrics] = m.map(&:to_sym) }
15
+ opt.on('-f', '--formats x,y,z', Array, 'Formats to output to.', "Default: #{defaults[:formats].join(",")}") { |m| options[:formats] = m.map(&:to_sym) }
16
+ opt.parse!(ARGV)
17
+ end
18
+
19
+ options
13
20
  end
14
21
 
15
- # Use the ruby-prof extension if available. Fall back to stdlib profiler.
16
- begin
17
- begin
18
- require "ruby-prof"
19
- $stderr.puts 'Using the ruby-prof extension.'
20
- RubyProf.measure_mode = RubyProf::WALL_TIME
21
- RubyProf.start
22
- profile_me
23
- results = RubyProf.stop
24
- if ARGV[2]
25
- printer_class = RubyProf.const_get((ARGV[2] + "_printer").classify)
26
- else
27
- printer_class = RubyProf::FlatPrinter
28
- end
29
- printer = printer_class.new(results)
30
- printer.print($stderr)
31
- rescue LoadError
32
- require "prof"
33
- $stderr.puts 'Using the old ruby-prof extension.'
34
- Prof.clock_mode = Prof::GETTIMEOFDAY
35
- Prof.start
36
- profile_me
37
- results = Prof.stop
38
- require 'rubyprof_ext'
39
- Prof.print_profile(results, $stderr)
22
+ class ProfilerTest < ActionDispatch::PerformanceTest
23
+ self.profile_options = options
24
+
25
+ ARGV.each do |expression|
26
+ eval <<-RUBY
27
+ def test_#{expression.parameterize('_')}
28
+ #{expression}
29
+ end
30
+ RUBY
40
31
  end
41
- rescue LoadError
42
- require 'profiler'
43
- $stderr.puts 'Using the standard Ruby profiler.'
44
- Profiler__.start_profile
45
- profile_me
46
- Profiler__.stop_profile
47
- Profiler__.print_profile($stderr)
48
32
  end
@@ -25,7 +25,7 @@ ARGV.clone.options do |opts|
25
25
  opts.separator "-------------------------------------------------------------"
26
26
  opts.separator "#!/usr/bin/env #{File.expand_path($0)} runner"
27
27
  opts.separator ""
28
- opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
28
+ opts.separator "Product.all.each { |p| p.price *= 2 ; p.save! }"
29
29
  opts.separator "-------------------------------------------------------------"
30
30
  end
31
31
 
@@ -39,18 +39,12 @@ ENV["RAILS_ENV"] = options[:environment]
39
39
  require APP_PATH
40
40
  Rails.application.require_environment!
41
41
 
42
- begin
43
- if code_or_file.nil?
44
- $stderr.puts "Run '#{$0} -h' for help."
45
- exit 1
46
- elsif File.exist?(code_or_file)
47
- $0 = code_or_file
48
- eval(File.read(code_or_file), nil, code_or_file)
49
- else
50
- eval(code_or_file)
51
- end
52
- ensure
53
- if defined? Rails
54
- Rails.logger.flush if Rails.logger.respond_to?(:flush)
55
- end
42
+ if code_or_file.nil?
43
+ $stderr.puts "Run '#{$0} -h' for help."
44
+ exit 1
45
+ elsif File.exist?(code_or_file)
46
+ $0 = code_or_file
47
+ eval(File.read(code_or_file), nil, code_or_file)
48
+ else
49
+ eval(code_or_file)
56
50
  end
@@ -55,8 +55,9 @@ module Rails
55
55
  end
56
56
 
57
57
  def start
58
+ url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
58
59
  puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
59
- puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}"
60
+ puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
60
61
  puts "=> Call with -d to detach" unless options[:daemonize]
61
62
  trap(:INT) { exit }
62
63
  puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
@@ -522,8 +522,15 @@ module Rails
522
522
  end
523
523
 
524
524
  initializer :append_assets_path do |app|
525
- app.config.assets.paths.unshift *paths["vendor/assets"].existent
526
- app.config.assets.paths.unshift *paths["app/assets"].existent
525
+ if app.config.assets.respond_to?(:prepend_path)
526
+ app.config.assets.prepend_path(*paths["vendor/assets"].existent)
527
+ app.config.assets.prepend_path(*paths["lib/assets"].existent)
528
+ app.config.assets.prepend_path(*paths["app/assets"].existent)
529
+ else
530
+ app.config.assets.paths.unshift(*paths["vendor/assets"].existent)
531
+ app.config.assets.paths.unshift(*paths["lib/assets"].existent)
532
+ app.config.assets.paths.unshift(*paths["app/assets"].existent)
533
+ end
527
534
  end
528
535
 
529
536
  initializer :prepend_helpers_path do |app|
@@ -47,6 +47,7 @@ module Rails
47
47
  paths.add "app/mailers", :eager_load => true
48
48
  paths.add "app/views"
49
49
  paths.add "lib", :load_path => true
50
+ paths.add "lib/assets", :glob => "*"
50
51
  paths.add "lib/tasks", :glob => "**/*.rake"
51
52
  paths.add "config"
52
53
  paths.add "config/environments", :glob => "#{Rails.env}.rb"
@@ -52,13 +52,13 @@ module Rails
52
52
  :integration_tool => nil,
53
53
  :javascripts => true,
54
54
  :javascript_engine => nil,
55
- :orm => nil,
55
+ :orm => false,
56
56
  :performance_tool => nil,
57
57
  :resource_controller => :controller,
58
58
  :scaffold_controller => :scaffold_controller,
59
59
  :stylesheets => true,
60
60
  :stylesheet_engine => nil,
61
- :test_framework => nil,
61
+ :test_framework => false,
62
62
  :template_engine => :erb
63
63
  },
64
64
 
@@ -278,7 +278,7 @@ module Rails
278
278
  say args.first.to_s unless options.quiet?
279
279
  else
280
280
  args << (self.behavior == :invoke ? :green : :red)
281
- say_status *args
281
+ say_status(*args)
282
282
  end
283
283
  end
284
284
 
@@ -28,6 +28,9 @@ module Rails
28
28
  class_option :skip_gemfile, :type => :boolean, :default => false,
29
29
  :desc => "Don't create a Gemfile"
30
30
 
31
+ class_option :skip_bundle, :type => :boolean, :default => false,
32
+ :desc => "Don't run bundle install"
33
+
31
34
  class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
32
35
  :desc => "Skip Git ignores and keeps"
33
36
 
@@ -117,15 +120,15 @@ module Rails
117
120
  end
118
121
 
119
122
  def database_gemfile_entry
120
- entry = options[:skip_active_record] ? "" : "gem '#{gem_for_database}'"
121
- if options[:database] == 'mysql'
122
- if options.dev? || options.edge?
123
- entry += ", :git => 'git://github.com/brianmario/mysql2.git'"
124
- else
125
- entry += "\n# gem 'mysql2', :git => 'git://github.com/brianmario/mysql2.git'"
126
- end
127
- end
128
- entry + "\n"
123
+ options[:skip_active_record] ? "" : "gem '#{gem_for_database}'\n"
124
+ end
125
+
126
+ def include_all_railties?
127
+ !options[:skip_active_record] && !options[:skip_test_unit]
128
+ end
129
+
130
+ def comment_if(value)
131
+ options[value] ? '#' : ''
129
132
  end
130
133
 
131
134
  def rails_gemfile_entry
@@ -162,7 +165,7 @@ module Rails
162
165
  end
163
166
 
164
167
  def gem_for_ruby_debugger
165
- if RUBY_VERSION < "1.9.2"
168
+ if RUBY_VERSION < "1.9"
166
169
  "gem 'ruby-debug'"
167
170
  else
168
171
  "gem 'ruby-debug19', :require => 'ruby-debug'"
@@ -170,7 +173,7 @@ module Rails
170
173
  end
171
174
 
172
175
  def gem_for_turn
173
- unless RUBY_VERSION < "1.9.2"
176
+ unless RUBY_VERSION < "1.9.2" || options[:skip_test_unit]
174
177
  <<-GEMFILE.strip_heredoc
175
178
  group :test do
176
179
  # Pretty printed test output
@@ -184,13 +187,18 @@ module Rails
184
187
  "gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
185
188
  end
186
189
 
187
- def bundle_if_dev_or_edge
188
- bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
189
- run "#{bundle_command} install" if dev_or_edge?
190
+ def bundle_command(command)
191
+ require 'bundler'
192
+ require 'bundler/cli'
193
+
194
+ say_status :run, "bundle #{command}"
195
+ Bundler::CLI.new.send(command)
196
+ rescue
197
+ say_status :failure, "bundler raised an exception, are you offline?", :red
190
198
  end
191
199
 
192
- def dev_or_edge?
193
- options.dev? || options.edge?
200
+ def run_bundle
201
+ bundle_command('install') unless options[:skip_gemfile] || options[:skip_bundle]
194
202
  end
195
203
 
196
204
  def empty_directory_with_gitkeep(destination, config = {})