aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG48
-rw-r--r--railties/guides/source/active_support_core_extensions.textile8
-rw-r--r--railties/guides/source/security.textile10
-rw-r--r--railties/guides/source/testing.textile4
-rw-r--r--railties/lib/rails/application.rb6
-rw-r--r--railties/lib/rails/application/bootstrap.rb3
-rw-r--r--railties/lib/rails/application/configuration.rb2
-rw-r--r--railties/lib/rails/commands.rb3
-rw-r--r--railties/lib/rails/commands/dbconsole.rb2
-rw-r--r--railties/lib/rails/commands/runner.rb24
-rw-r--r--railties/lib/rails/commands/server.rb3
-rw-r--r--railties/lib/rails/engine.rb1
-rw-r--r--railties/lib/rails/engine/configuration.rb1
-rw-r--r--railties/lib/rails/generators.rb4
-rw-r--r--railties/lib/rails/generators/app_base.rb36
-rw-r--r--railties/lib/rails/generators/named_base.rb1
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb19
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile5
-rw-r--r--railties/lib/rails/generators/rails/app/templates/README15
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt7
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb15
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt1
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/gitignore1
-rw-r--r--railties/lib/rails/generators/rails/assets/assets_generator.rb8
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb2
-rw-r--r--railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb4
-rw-r--r--railties/lib/rails/tasks/framework.rake9
-rw-r--r--railties/lib/rails/tasks/routes.rake3
-rw-r--r--railties/lib/rails/version.rb2
-rw-r--r--railties/railties.gemspec2
-rw-r--r--railties/test/application/assets_test.rb27
-rw-r--r--railties/test/application/configuration_test.rb47
-rw-r--r--railties/test/application/initializers/frameworks_test.rb2
-rw-r--r--railties/test/application/middleware_test.rb6
-rw-r--r--railties/test/application/rack/logger_test.rb40
-rw-r--r--railties/test/application/rake_test.rb22
-rw-r--r--railties/test/application/routing_test.rb4
-rw-r--r--railties/test/application/test_test.rb25
-rw-r--r--railties/test/generators/app_generator_test.rb24
-rw-r--r--railties/test/generators/mailer_generator_test.rb28
-rw-r--r--railties/test/generators/namespaced_generators_test.rb6
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb8
-rw-r--r--railties/test/generators/shared_generator_tests.rb56
-rw-r--r--railties/test/railties/engine_test.rb28
-rw-r--r--railties/test/railties/shared_tests.rb3
47 files changed, 435 insertions, 146 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 0def5bcf6c..c465b08594 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,19 @@
*Rails 3.1.0 (unreleased)*
+* Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]
+
+* Fixed database tasks for jdbc* adapters #jruby
+
+ [Rashmi Yadav]
+
+* Template generation for jdbcpostgresql #jruby
+
+ [Vishnu Atrai]
+
+* Template generation for jdbcmysql and jdbcsqlite3 #jruby
+
+ [Arun Agrawal]
+
* The -j option of the application generator accepts an arbitrary string. If passed "foo",
the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest
requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails"
@@ -16,7 +30,7 @@ by the prototype-rails gem. [fxn]
* jQuery is the new default JavaScript library. [fxn]
-* Changed scaffold and app generator to create Ruby 1.9 style hash when running on Ruby 1.9 [Prem Sichanugrist]
+* Changed scaffold, application, and mailer generator to create Ruby 1.9 style hash when running on Ruby 1.9 [Prem Sichanugrist]
So instead of creating something like:
@@ -62,10 +76,42 @@ by the prototype-rails gem. [fxn]
* Include all helpers from plugins and shared engines in application [Piotr Sarnacki]
+
+*Rails 3.0.7 (April 18, 2011)*
+
+*No changes.
+
+
+*Rails 3.0.6 (April 5, 2011)
+
+* No changes.
+
+
+*Rails 3.0.5 (February 26, 2011)*
+
+* No changes.
+
+
+*Rails 3.0.4 (February 8, 2011)*
+
+* No changes.
+
+
+*Rails 3.0.3 (November 16, 2010)*
+
+* No changes.
+
+
+*Rails 3.0.2 (November 15, 2010)*
+
+* No changes.
+
+
*Rails 3.0.1 (October 15, 2010)*
* No Changes, just a version bump.
+
*Rails 3.0.0 (August 29, 2010)*
* Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit and --skip-active-record respectively. [fxn]
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 8f98c71aa0..66869b4eeb 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -417,6 +417,14 @@ silence_stream(STDOUT) do
end
</ruby>
+The +quietly+ method addresses the common use case where you want to silence STDOUT and STDERR, even in subprocesses:
+
+<ruby>
+quietly { system 'bundle install' }
+</ruby>
+
+For example, the railties test suite uses that one in a few places to prevent command messages from being echoed intermixed with the progress status.
+
Silencing exceptions is also possible with +suppress+. This method receives an arbitrary number of exception classes. If an exception is raised during the execution of the block and is +kind_of?+ any of the arguments, +suppress+ captures it and returns silently. Otherwise the exception is reraised:
<ruby>
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index 8c408ec06b..e0ccc7a6e6 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -372,7 +372,7 @@ def signup
end
</ruby>
-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:
+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:
<pre>
"name":http://www.example.com/user/signup?user[name]=ow3ned&user[admin]=1
@@ -386,7 +386,7 @@ params[:user] # => {:name => “ow3ned”, :admin => true}
So if you create a new user using mass-assignment, it may be too easy to become an administrator.
-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:
+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:
<ruby>
class Person < ActiveRecord::Base
@@ -410,7 +410,7 @@ To avoid this, Rails provides two class methods in your Active Record class to c
attr_protected :admin
</ruby>
-+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.
++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.
<ruby>
attr_protected :last_login, :as => :admin
@@ -433,7 +433,7 @@ params[:user] # => {:name => "ow3ned", :admin => true}
@user.admin # => true
</ruby>
-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:
+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:
<ruby>
@user = User.new
@@ -451,7 +451,7 @@ When assigning attributes in Active Record using +attributes=+, or +update_attri
@user.is_admin # => true
</ruby>
-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:
+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:
<ruby>
@user = User.new({ :name => 'Sebastian', :is_admin => true }, :as => :admin)
diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile
index 01badebd41..7a93c3a1e6 100644
--- a/railties/guides/source/testing.textile
+++ b/railties/guides/source/testing.textile
@@ -54,7 +54,7 @@ For good tests, you'll need to give some thought to setting up test data. In Rai
h5. What are Fixtures?
-_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.
+_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*.
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.
@@ -81,7 +81,7 @@ Each fixture is given a name followed by an indented list of colon-separated key
h5. ERB'in It Up
-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.
+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.
<erb>
<% earth_size = 20 %>
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index dd01bbab1d..1e4d25f18c 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -157,7 +157,8 @@ module Rails
middleware.use ::Rack::Lock unless config.allow_concurrency
middleware.use ::Rack::Runtime
- middleware.use ::Rails::Rack::Logger
+ middleware.use ::Rack::MethodOverride
+ middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods
middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
@@ -171,7 +172,6 @@ module Rails
end
middleware.use ::ActionDispatch::ParamsParser
- middleware.use ::Rack::MethodOverride
middleware.use ::ActionDispatch::Head
middleware.use ::Rack::ConditionalGet
middleware.use ::Rack::ETag, "no-cache"
@@ -199,4 +199,4 @@ module Rails
require "rails/console/helpers"
end
end
-end \ No newline at end of file
+end
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index 9c9d85eed6..9f21d273e6 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -1,4 +1,5 @@
require "active_support/notifications"
+require "active_support/dependencies"
require "active_support/descendants_tracker"
module Rails
@@ -9,7 +10,6 @@ module Rails
initializer :load_environment_hook do end
initializer :load_active_support do
- require 'active_support/dependencies'
require "active_support/all" unless config.active_support.bare
end
@@ -37,6 +37,7 @@ module Rails
)
logger
end
+ at_exit { Rails.logger.flush if Rails.logger.respond_to?(:flush) }
end
# Initialize cache early in the stack so railties can make use of it.
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 29b9c27a13..3b74de690a 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -34,7 +34,7 @@ module Rails
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
@assets.paths = []
- @assets.precompile = [ /\w+\.(?!js|css)$/, "application.js", "application.css" ]
+ @assets.precompile = [ /\w+\.(?!js|css).+/, "application.js", "application.css" ]
@assets.prefix = "/assets"
@assets.js_compressor = nil
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 4182757346..4a082aedb8 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -6,7 +6,8 @@ aliases = {
"g" => "generate",
"c" => "console",
"s" => "server",
- "db" => "dbconsole"
+ "db" => "dbconsole",
+ "r" => "runner"
}
command = ARGV.shift
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index f0d6ea1687..b0ba76217a 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -23,7 +23,7 @@ module Rails
include_password = false
options = {}
OptionParser.new do |opt|
- opt.banner = "Usage: dbconsole [options] [environment]"
+ opt.banner = "Usage: dbconsole [environment] [options]"
opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v|
include_password = true
end
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index 1a91d477ec..f8b00e7249 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -25,7 +25,7 @@ ARGV.clone.options do |opts|
opts.separator "-------------------------------------------------------------"
opts.separator "#!/usr/bin/env #{File.expand_path($0)} runner"
opts.separator ""
- opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
+ opts.separator "Product.all.each { |p| p.price *= 2 ; p.save! }"
opts.separator "-------------------------------------------------------------"
end
@@ -39,18 +39,12 @@ ENV["RAILS_ENV"] = options[:environment]
require APP_PATH
Rails.application.require_environment!
-begin
- if code_or_file.nil?
- $stderr.puts "Run '#{$0} -h' for help."
- exit 1
- elsif File.exist?(code_or_file)
- $0 = code_or_file
- eval(File.read(code_or_file), nil, code_or_file)
- else
- eval(code_or_file)
- end
-ensure
- if defined? Rails
- Rails.logger.flush if Rails.logger.respond_to?(:flush)
- end
+if code_or_file.nil?
+ $stderr.puts "Run '#{$0} -h' for help."
+ exit 1
+elsif File.exist?(code_or_file)
+ $0 = code_or_file
+ eval(File.read(code_or_file), nil, code_or_file)
+else
+ eval(code_or_file)
end
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index e447209242..505a4ca2bd 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -55,8 +55,9 @@ module Rails
end
def start
+ url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
- puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}"
+ puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
puts "=> Call with -d to detach" unless options[:daemonize]
trap(:INT) { exit }
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 2015a944f0..6a125685d0 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -523,6 +523,7 @@ module Rails
initializer :append_assets_path do |app|
app.config.assets.paths.unshift *paths["vendor/assets"].existent
+ app.config.assets.paths.unshift *paths["lib/assets"].existent
app.config.assets.paths.unshift *paths["app/assets"].existent
end
diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb
index 241db4b0a9..f424492bb4 100644
--- a/railties/lib/rails/engine/configuration.rb
+++ b/railties/lib/rails/engine/configuration.rb
@@ -47,6 +47,7 @@ module Rails
paths.add "app/mailers", :eager_load => true
paths.add "app/views"
paths.add "lib", :load_path => true
+ paths.add "lib/assets", :glob => "*"
paths.add "lib/tasks", :glob => "**/*.rake"
paths.add "config"
paths.add "config/environments", :glob => "#{Rails.env}.rb"
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 9be395e989..85c67af19a 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -52,13 +52,13 @@ module Rails
:integration_tool => nil,
:javascripts => true,
:javascript_engine => nil,
- :orm => nil,
+ :orm => false,
:performance_tool => nil,
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
:stylesheets => true,
:stylesheet_engine => nil,
- :test_framework => nil,
+ :test_framework => false,
:template_engine => :erb
},
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 998957f313..a5743762e5 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -28,6 +28,9 @@ module Rails
class_option :skip_gemfile, :type => :boolean, :default => false,
:desc => "Don't create a Gemfile"
+ class_option :skip_bundle, :type => :boolean, :default => false,
+ :desc => "Don't run bundle install"
+
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
:desc => "Skip Git ignores and keeps"
@@ -117,15 +120,15 @@ module Rails
end
def database_gemfile_entry
- entry = options[:skip_active_record] ? "" : "gem '#{gem_for_database}'"
- if options[:database] == 'mysql'
- if options.dev? || options.edge?
- entry += ", :git => 'git://github.com/brianmario/mysql2.git'"
- else
- entry += "\n# gem 'mysql2', :git => 'git://github.com/brianmario/mysql2.git'"
- end
- end
- entry + "\n"
+ options[:skip_active_record] ? "" : "gem '#{gem_for_database}'\n"
+ end
+
+ def include_all_railties?
+ !options[:skip_active_record] && !options[:skip_test_unit]
+ end
+
+ def comment_if(value)
+ options[value] ? '#' : ''
end
def rails_gemfile_entry
@@ -184,13 +187,18 @@ module Rails
"gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
end
- def bundle_if_dev_or_edge
- bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
- run "#{bundle_command} install" if dev_or_edge?
+ def bundle_command(command)
+ require 'bundler'
+ require 'bundler/cli'
+
+ say_status :run, "bundle #{command}"
+ Bundler::CLI.new.send(command)
+ rescue
+ say_status :failure, "bundler raised an exception, are you offline?", :red
end
- def dev_or_edge?
- options.dev? || options.edge?
+ def run_bundle
+ bundle_command('install') unless options[:skip_gemfile] || options[:skip_bundle]
end
def empty_directory_with_gitkeep(destination, config = {})
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 36bc9e055c..cf317eb21f 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/module/introspection'
require 'rails/generators/base'
require 'rails/generators/generated_attribute'
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 6562667782..5f9fb9685c 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -9,11 +9,20 @@ module Rails
@options = generator.options
end
- private
+ private
+ %w(template copy_file directory empty_directory inside
+ empty_directory_with_gitkeep create_file chmod shebang).each do |method|
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{method}(*args, &block)
+ @generator.send(:#{method}, *args, &block)
+ end
+ RUBY
+ end
- def method_missing(meth, *args, &block)
- @generator.send(meth, *args, &block)
- end
+ # TODO: Remove once this is fully in place
+ def method_missing(meth, *args, &block)
+ @generator.send(meth, *args, &block)
+ end
end
# The application builder allows you to override elements of the application
@@ -215,7 +224,7 @@ module Rails
build(:leftovers)
end
- public_task :apply_rails_template, :bundle_if_dev_or_edge
+ public_task :apply_rails_template, :run_bundle
protected
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index b046edd5b7..20bd9db624 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -4,11 +4,12 @@ source 'http://rubygems.org'
<%= database_gemfile_entry -%>
+<%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) && JRUBY_VERSION < "1.6" -%>
# Asset template engines
<%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%>
gem 'sass'
gem 'coffee-script'
-gem 'uglifier'
+# gem 'uglifier'
<%= gem_for_javascript %>
@@ -21,4 +22,4 @@ gem 'uglifier'
# To use debugger
# <%= gem_for_ruby_debugger %>
-<%= gem_for_turn -%> \ No newline at end of file
+<%= gem_for_turn -%>
diff --git a/railties/lib/rails/generators/rails/app/templates/README b/railties/lib/rails/generators/rails/app/templates/README
index 9f0f1d0e38..7c36f2356e 100644
--- a/railties/lib/rails/generators/rails/app/templates/README
+++ b/railties/lib/rails/generators/rails/app/templates/README
@@ -156,6 +156,10 @@ PostgreSQL and SQLite 3.
The default directory structure of a generated Ruby on Rails application:
|-- app
+ | |-- assets
+ | |-- images
+ | |-- javascripts
+ | `-- stylesheets
| |-- controllers
| |-- helpers
| |-- mailers
@@ -172,9 +176,6 @@ The default directory structure of a generated Ruby on Rails application:
| `-- tasks
|-- log
|-- public
- | |-- images
- | |-- javascripts
- | `-- stylesheets
|-- script
|-- test
| |-- fixtures
@@ -188,11 +189,16 @@ The default directory structure of a generated Ruby on Rails application:
| |-- sessions
| `-- sockets
`-- vendor
+ |-- assets
+ `-- stylesheets
`-- plugins
app
Holds all the code that's specific to this particular application.
+app/assets
+ Contains subdirectories for images, stylesheets, and JavaScript files.
+
app/controllers
Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from
@@ -237,8 +243,7 @@ lib
the load path.
public
- The directory available for the web server. Contains subdirectories for
- images, stylesheets, and javascripts. Also contains the dispatchers and the
+ The directory available for the web server. Also contains the dispatchers and the
default HTML files. This should be set as the DOCUMENT_ROOT of your web
server.
diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
index 612c614f2e..19294b3478 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
+++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
@@ -1,5 +1,8 @@
-// FIXME: Tell people that this is a manifest file, real code should go into discrete files
-// FIXME: Tell people how Sprockets and CoffeeScript works
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
//
<% unless options[:skip_javascript] -%>
//= require <%= options[:javascript] %>
diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css
index f4b082ccc0..fc25b5723f 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css
+++ b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css
@@ -1,5 +1,7 @@
/*
- * FIXME: Introduce SCSS & Sprockets
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. 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 .
*/ \ No newline at end of file
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index 3723addf2b..8ff80c6fd3 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -1,14 +1,14 @@
require File.expand_path('../boot', __FILE__)
-<% unless options[:skip_active_record] -%>
+<% if include_all_railties? -%>
require 'rails/all'
<% else -%>
# Pick the frameworks you want:
-# require "active_record/railtie"
+<%= comment_if :skip_active_record %> require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
-require "rails/test_unit/railtie"
+<%= comment_if :skip_test_unit %> require "rails/test_unit/railtie"
<% end -%>
# If you have a Gemfile, require the gems listed there, including any gems
@@ -50,21 +50,12 @@ module <%= app_const_base %>
# config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs)
<% end -%>
-<% if options[:skip_test_unit] -%>
- config.generators.test_framework = false
-<% end -%>
-
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
-<% unless options[:skip_active_record] -%>
- # Enable IdentityMap for Active Record, to disable set to false or remove the line below.
- config.active_record.identity_map = true
-<% end -%>
-
# Enable the asset pipeline
config.assets.enabled = true
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 41b2374eda..066aa54862 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -22,4 +22,3 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
end
-
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
index 32ffbee7a1..e56195da80 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
@@ -4,7 +4,7 @@
# which will be enabled by default in the upcoming version of Ruby on Rails.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
-ActionController::Base.wrap_parameters :format => [:json]
+ActionController::Base.wrap_parameters <%= key_value :format, "[:json]" %>
# Disable root element in JSON by default.
if defined?(ActiveRecord)
diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore
index f0fa30c536..923b697662 100644
--- a/railties/lib/rails/generators/rails/app/templates/gitignore
+++ b/railties/lib/rails/generators/rails/app/templates/gitignore
@@ -2,3 +2,4 @@
db/*.sqlite3
log/*.log
tmp/
+.sass-cache/
diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb
index 80beb7abfe..2d52da77eb 100644
--- a/railties/lib/rails/generators/rails/assets/assets_generator.rb
+++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb
@@ -1,11 +1,11 @@
module Rails
module Generators
class AssetsGenerator < NamedBase
- class_option :javascripts, :type => :boolean, :desc => "Generate javascripts"
- class_option :stylesheets, :type => :boolean, :desc => "Generate stylesheets"
+ class_option :javascripts, :type => :boolean, :desc => "Generate JavaScripts"
+ class_option :stylesheets, :type => :boolean, :desc => "Generate Stylesheets"
- class_option :javascript_engine, :desc => "Engine for javascripts"
- class_option :stylesheet_engine, :desc => "Engine for stylesheets"
+ class_option :javascript_engine, :desc => "Engine for JavaScripts"
+ class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
def create_javascript_files
return unless options.javascripts?
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 6201595308..939c0cd727 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
@@ -209,7 +209,7 @@ task :default => :test
build(:leftovers)
end
- public_task :apply_rails_template, :bundle_if_dev_or_edge
+ public_task :apply_rails_template, :run_bundle
protected
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index 6eef0dbe5b..aa9b45c5a5 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -6,8 +6,8 @@ module Rails
remove_hook_for :resource_controller
remove_class_option :actions
- class_option :stylesheets, :type => :boolean, :desc => "Generate stylesheets"
- class_option :stylesheet_engine, :desc => "Engine for stylesheets"
+ class_option :stylesheets, :type => :boolean, :desc => "Generate Stylesheets"
+ class_option :stylesheet_engine, :desc => "Engine for Stylesheets"
hook_for :scaffold_controller, :required => true
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
index 5222b7bf50..77a5c4dc6c 100644
--- a/railties/lib/rails/tasks/framework.rake
+++ b/railties/lib/rails/tasks/framework.rake
@@ -1,6 +1,6 @@
namespace :rails do
- desc "Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs)"
- task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ]
+ desc "Update configs and some other initially generated files (or use just update:configs, update:scripts, or update:application_controller)"
+ task :update => [ "update:configs", "update:scripts", "update:application_controller" ]
desc "Applies the template supplied by LOCATION=/path/to/template"
task :template do
@@ -58,11 +58,6 @@ namespace :rails do
invoke_from_app_generator :create_config_files
end
- # desc "Update Prototype javascripts from your current rails install"
- task :javascripts do
- invoke_from_app_generator :create_javascript_files
- end
-
# desc "Adds new scripts to the application script/ directory"
task :scripts do
invoke_from_app_generator :create_script_files
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
index 02e22361e0..a0c953967c 100644
--- a/railties/lib/rails/tasks/routes.rake
+++ b/railties/lib/rails/tasks/routes.rake
@@ -16,7 +16,8 @@ task :routes => :environment do
{:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
end
- routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route
+ # Skip the route if it's internal info route
+ routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
name_width = routes.map{ |r| r[:name].length }.max
verb_width = routes.map{ |r| r[:verb].length }.max
diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb
index b076881c21..fc6c0a0204 100644
--- a/railties/lib/rails/version.rb
+++ b/railties/lib/rails/version.rb
@@ -3,7 +3,7 @@ module Rails
MAJOR = 3
MINOR = 1
TINY = 0
- PRE = "beta"
+ PRE = "beta1"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
diff --git a/railties/railties.gemspec b/railties/railties.gemspec
index cd0646b8ed..4404838670 100644
--- a/railties/railties.gemspec
+++ b/railties/railties.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.rdoc_options << '--exclude' << '.'
s.add_dependency('rake', '>= 0.8.7')
- s.add_dependency('thor', '~> 0.14.4')
+ s.add_dependency('thor', '~> 0.14.6')
s.add_dependency('rack-ssl', '~> 1.3.2')
s.add_dependency('activesupport', version)
s.add_dependency('actionpack', version)
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
new file mode 100644
index 0000000000..b03dc3132b
--- /dev/null
+++ b/railties/test/application/assets_test.rb
@@ -0,0 +1,27 @@
+require 'isolation/abstract_unit'
+require 'rack/test'
+
+module ApplicationTests
+ class RoutingTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+ include Rack::Test::Methods
+
+ def setup
+ build_app
+ boot_rails
+ end
+
+ test "assets routes have higher priority" do
+ app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match '*path', :to => lambda { |env| [200, { "Content-Type" => "text/html" }, "Not an asset"] }
+ end
+ RUBY
+
+ get "/assets/demo.js"
+ assert_match "alert()", last_response.body
+ end
+ end
+end
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index b1f7076776..43876c0a72 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -12,7 +12,6 @@ end
class ::MyOtherMailObserver < ::MyMailObserver; end
-
module ApplicationTests
class ConfigurationTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
@@ -226,8 +225,6 @@ module ApplicationTests
make_basic_app
class ::OmgController < ActionController::Base
- protect_from_forgery
-
def index
render :inline => "<%= csrf_meta_tags %>"
end
@@ -237,6 +234,21 @@ module ApplicationTests
assert last_response.body =~ /csrf\-param/
end
+ test "request forgery token param can be changed" do
+ make_basic_app do
+ app.config.action_controller.request_forgery_protection_token = '_xsrf_token_here'
+ end
+
+ class ::OmgController < ActionController::Base
+ def index
+ render :inline => "<%= csrf_meta_tags %>"
+ end
+ end
+
+ get "/"
+ assert last_response.body =~ /_xsrf_token_here/
+ end
+
test "config.action_controller.perform_caching = true" do
make_basic_app do |app|
app.config.action_controller.perform_caching = true
@@ -437,10 +449,35 @@ module ApplicationTests
app_file 'config/initializers/wrap_parameters.rb', <<-RUBY
ActionController::Base.wrap_parameters :format => [:json]
RUBY
+
+ app_file 'app/models/post.rb', <<-RUBY
+ class Post
+ def self.column_names
+ %w(title)
+ end
+ end
+ RUBY
+
+ app_file 'app/controllers/posts_controller.rb', <<-RUBY
+ class PostsController < ApplicationController
+ def index
+ render :text => params[:post].inspect
+ end
+ end
+ RUBY
+
+ add_to_config <<-RUBY
+ routes.append do
+ resources :posts
+ end
+ RUBY
+
require "#{app_path}/config/environment"
- require 'action_controller/base'
+ require "rack/test"
+ extend Rack::Test::Methods
- assert_equal [:json], ActionController::Base._wrapper_options[:format]
+ post "/posts.json", '{ "title": "foo", "name": "bar" }', "CONTENT_TYPE" => "application/json"
+ assert_equal '{"title"=>"foo"}', last_response.body
end
test "config.action_dispatch.ignore_accept_header" do
diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb
index 19311a7fa0..196d121c14 100644
--- a/railties/test/application/initializers/frameworks_test.rb
+++ b/railties/test/application/initializers/frameworks_test.rb
@@ -166,7 +166,7 @@ module ApplicationTests
require "#{app_path}/config/environment"
- expects = [ActiveRecord::IdentityMap::Middleware, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
+ expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 01e6c49d9c..8bfde00af5 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -23,20 +23,19 @@ module ApplicationTests
"Rack::Lock",
"ActiveSupport::Cache::Strategy::LocalCache",
"Rack::Runtime",
- "Rails::Rack::Logger",
+ "Rack::MethodOverride",
+ "Rails::Rack::Logger", # must come after Rack::MethodOverride to properly log overridden methods
"ActionDispatch::ShowExceptions",
"ActionDispatch::RemoteIp",
"Rack::Sendfile",
"ActionDispatch::Reloader",
"ActionDispatch::Callbacks",
- "ActiveRecord::IdentityMap::Middleware",
"ActiveRecord::ConnectionAdapters::ConnectionManagement",
"ActiveRecord::QueryCache",
"ActionDispatch::Cookies",
"ActionDispatch::Session::CookieStore",
"ActionDispatch::Flash",
"ActionDispatch::ParamsParser",
- "Rack::MethodOverride",
"ActionDispatch::Head",
"Rack::ConditionalGet",
"Rack::ETag",
@@ -121,6 +120,7 @@ module ApplicationTests
end
test "identity map is inserted" do
+ add_to_config "config.active_record.identity_map = true"
boot!
assert middleware.include?("ActiveRecord::IdentityMap::Middleware")
end
diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb
new file mode 100644
index 0000000000..a29244357c
--- /dev/null
+++ b/railties/test/application/rack/logger_test.rb
@@ -0,0 +1,40 @@
+require "isolation/abstract_unit"
+require "active_support/log_subscriber/test_helper"
+require "rack/test"
+
+module ApplicationTests
+ module RackTests
+ class LoggerTest < Test::Unit::TestCase
+ include ActiveSupport::LogSubscriber::TestHelper
+ include Rack::Test::Methods
+
+ def setup
+ build_app
+ require "#{app_path}/config/environment"
+ super
+ end
+
+ def logs
+ @logs ||= @logger.logged(:info)
+ end
+
+ test "logger logs proper HTTP verb and path" do
+ get "/blah"
+ wait
+ assert_match /^Started GET "\/blah"/, logs[0]
+ end
+
+ test "logger logs HTTP verb override" do
+ post "/", {:_method => 'put'}
+ wait
+ assert_match /^Started PUT "\/"/, logs[0]
+ end
+
+ test "logger logs HEAD requests" do
+ post "/", {:_method => 'head'}
+ wait
+ assert_match /^Started HEAD "\/"/, logs[0]
+ end
+ end
+ end
+end
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb
index 59e5ef4dee..d77c2d14ab 100644
--- a/railties/test/application/rake_test.rb
+++ b/railties/test/application/rake_test.rb
@@ -64,6 +64,28 @@ module ApplicationTests
assert_match 'cart GET /cart(.:format)', Dir.chdir(app_path){ `rake routes` }
end
+ def test_rake_routes_shows_custom_assets
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ get '/custom/assets', :to => 'custom_assets#show'
+ end
+ RUBY
+ assert_match 'custom_assets GET /custom/assets(.:format)', Dir.chdir(app_path){ `rake routes` }
+ end
+
+ def test_logger_is_flushed_when_exiting_production_rake_tasks
+ add_to_config <<-RUBY
+ rake_tasks do
+ task :log_something => :environment do
+ Rails.logger.error("Sample log message")
+ end
+ end
+ RUBY
+
+ output = Dir.chdir(app_path){ `rake log_something RAILS_ENV=production && cat log/production.log` }
+ assert_match "Sample log message", output
+ end
+
def test_model_and_migration_generator_with_change_syntax
Dir.chdir(app_path) do
`rails generate model user username:string password:string`
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index 62589c998d..e3a7f8a63c 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -1,14 +1,14 @@
require 'isolation/abstract_unit'
+require 'rack/test'
module ApplicationTests
class RoutingTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
+ include Rack::Test::Methods
def setup
build_app
boot_rails
- require 'rack/test'
- extend Rack::Test::Methods
end
test "rails/info/properties in development" do
diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb
index 1fbbb40132..f96319f472 100644
--- a/railties/test/application/test_test.rb
+++ b/railties/test/application/test_test.rb
@@ -65,6 +65,31 @@ module ApplicationTests
run_test 'integration/posts_test.rb'
end
+ test "performance test" do
+ controller 'posts', <<-RUBY
+ class PostsController < ActionController::Base
+ end
+ RUBY
+
+ app_file 'app/views/posts/index.html.erb', <<-HTML
+ Posts#index
+ HTML
+
+ app_file 'test/performance/posts_test.rb', <<-RUBY
+ require 'test_helper'
+ require 'rails/performance_test_help'
+
+ class PostsTest < ActionDispatch::PerformanceTest
+ def test_index
+ get '/posts'
+ assert_response :success
+ end
+ end
+ RUBY
+
+ run_test 'performance/posts_test.rb'
+ end
+
private
def run_test(name)
result = ruby '-Itest', "#{app_path}/test/#{name}"
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 81263a6ce9..9e1d47cd2f 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -39,6 +39,8 @@ DEFAULT_APP_FILES = %w(
class AppGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
arguments [destination_root]
+
+ # brings setup, teardown, and some tests
include SharedGeneratorTests
def default_files
@@ -64,8 +66,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
def test_application_new_exits_with_non_zero_code_on_invalid_application_name
- # TODO: Suppress the output of this (it's because of a Thor::Error)
- `rails new test`
+ quietly { system 'rails new test' }
assert_equal false, $?.success?
end
@@ -95,7 +96,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
:destination_root => app_moved_root, :shell => @shell
generator.send(:app_const)
- silence(:stdout){ generator.send(:create_config_files) }
+ quietly { generator.send(:create_config_files) }
assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/
assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/
end
@@ -110,7 +111,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => app_root, :shell => @shell
generator.send(:app_const)
- silence(:stdout){ generator.send(:create_config_files) }
+ quietly { generator.send(:create_config_files) }
assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/
end
@@ -135,6 +136,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
run_generator([destination_root, "-d", "jdbcmysql"])
assert_file "config/database.yml", /jdbcmysql/
assert_file "Gemfile", /^gem\s+["']activerecord-jdbcmysql-adapter["']$/
+ assert_file "Gemfile", /^gem\s+["']jruby-openssl["']$/ if defined?(JRUBY_VERSION) && JRUBY_VERSION < "1.6"
end
def test_config_jdbcsqlite3_database
@@ -226,9 +228,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_test_unit_is_removed_from_frameworks_if_skip_test_unit_is_given
run_generator [destination_root, "--skip-test-unit"]
- assert_file "config/application.rb" do |file|
- assert_match /config.generators.test_framework = false/, file
- end
+ assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/
+ end
+
+ def test_no_active_record_or_test_unit_if_skips_given
+ run_generator [destination_root, "--skip-test-unit", "--skip-active-record"]
+ assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/
+ assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
end
def test_new_hash_style
@@ -252,7 +258,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
protected
def action(*args, &block)
- silence(:stdout){ generator.send(*args, &block) }
+ silence(:stdout) { generator.send(*args, &block) }
end
end
@@ -278,6 +284,6 @@ protected
end
def action(*args, &block)
- silence(:stdout){ generator.send(*args, &block) }
+ silence(:stdout) { generator.send(*args, &block) }
end
end
diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb
index f4fdc46328..bf1cfe5305 100644
--- a/railties/test/generators/mailer_generator_test.rb
+++ b/railties/test/generators/mailer_generator_test.rb
@@ -10,7 +10,11 @@ class MailerGeneratorTest < Rails::Generators::TestCase
run_generator
assert_file "app/mailers/notifier.rb" do |mailer|
assert_match /class Notifier < ActionMailer::Base/, mailer
- assert_match /default :from => "from@example.com"/, mailer
+ if RUBY_VERSION < "1.9"
+ assert_match /default :from => "from@example.com"/, mailer
+ else
+ assert_match /default from: "from@example.com"/, mailer
+ end
end
end
@@ -73,15 +77,33 @@ class MailerGeneratorTest < Rails::Generators::TestCase
assert_file "app/mailers/notifier.rb" do |mailer|
assert_instance_method :foo, mailer do |foo|
- assert_match /mail :to => "to@example.org"/, foo
+ if RUBY_VERSION < "1.9"
+ assert_match /mail :to => "to@example.org"/, foo
+ else
+ assert_match /mail to: "to@example.org"/, foo
+ end
assert_match /@greeting = "Hi"/, foo
end
assert_instance_method :bar, mailer do |bar|
- assert_match /mail :to => "to@example.org"/, bar
+ if RUBY_VERSION < "1.9"
+ assert_match /mail :to => "to@example.org"/, bar
+ else
+ assert_match /mail to: "to@example.org"/, bar
+ end
assert_match /@greeting = "Hi"/, bar
end
end
+ end
+ def test_force_old_style_hash
+ run_generator ["notifier", "foo", "--old-style-hash"]
+ assert_file "app/mailers/notifier.rb" do |mailer|
+ assert_match /default :from => "from@example.com"/, mailer
+
+ assert_instance_method :foo, mailer do |foo|
+ assert_match /mail :to => "to@example.org"/, foo
+ end
+ end
end
end
diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb
index eb56e8d1a4..38f024f061 100644
--- a/railties/test/generators/namespaced_generators_test.rb
+++ b/railties/test/generators/namespaced_generators_test.rb
@@ -163,7 +163,11 @@ class NamespacedMailerGeneratorTest < NamespacedGeneratorTestCase
assert_file "app/mailers/test_app/notifier.rb" do |mailer|
assert_match /module TestApp/, mailer
assert_match /class Notifier < ActionMailer::Base/, mailer
- assert_match /default :from => "from@example.com"/, mailer
+ if RUBY_VERSION < "1.9"
+ assert_match /default :from => "from@example.com"/, mailer
+ else
+ assert_match /default from: "from@example.com"/, mailer
+ end
end
end
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index 33c8d83f9c..2af728e766 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -22,6 +22,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
destination File.join(Rails.root, "tmp/bukkits")
arguments [destination_root]
+
+ # brings setup, teardown, and some tests
include SharedGeneratorTests
def default_files
@@ -117,17 +119,17 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]))
end
- def test_ensure_that_tests_works
+ def test_ensure_that_tests_work
run_generator
FileUtils.cd destination_root
- `bundle install`
+ quietly { system 'bundle install' }
assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`)
end
def test_ensure_that_tests_works_in_full_mode
run_generator [destination_root, "--full", "--skip_active_record"]
FileUtils.cd destination_root
- `bundle install`
+ quietly { system 'bundle install' }
assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`)
end
diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb
index c9c5d2fad2..be9aef8a41 100644
--- a/railties/test/generators/shared_generator_tests.rb
+++ b/railties/test/generators/shared_generator_tests.rb
@@ -1,9 +1,11 @@
+#
+# Tests, setup, and teardown common to the application and plugin generator suites.
+#
module SharedGeneratorTests
def setup
Rails.application = TestApp::Application
super
Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
- @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
Kernel::silence_warnings do
Thor::Base.shell.send(:attr_accessor, :always_force)
@@ -21,7 +23,12 @@ module SharedGeneratorTests
def test_skeleton_is_created
run_generator
- default_files.each{ |path| assert_file path }
+ default_files.each { |path| assert_file path }
+ end
+
+ def test_generation_runs_bundle_install
+ generator([destination_root]).expects(:bundle_command).with('install').once
+ quietly { generator.invoke_all }
end
def test_plugin_new_generate_pretend
@@ -81,20 +88,7 @@ module SharedGeneratorTests
template.instance_eval "def read; self; end" # Make the string respond to read
generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
- assert_match(/It works!/, silence(:stdout){ generator.invoke_all })
- end
-
- def test_dev_option
- generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install")
- silence(:stdout){ generator.invoke_all }
- rails_path = File.expand_path('../../..', Rails.root)
- assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
- end
-
- def test_edge_option
- generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install")
- silence(:stdout){ generator.invoke_all }
- assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$}
+ assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end
def test_template_raises_an_error_with_invalid_path
@@ -109,7 +103,7 @@ module SharedGeneratorTests
template.instance_eval "def read; self; end" # Make the string respond to read
generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
- assert_match(/It works!/, silence(:stdout){ generator.invoke_all })
+ assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end
def test_template_is_executed_when_supplied_an_https_path
@@ -118,21 +112,36 @@ module SharedGeneratorTests
template.instance_eval "def read; self; end" # Make the string respond to read
generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
- assert_match(/It works!/, silence(:stdout){ generator.invoke_all })
+ assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end
def test_dev_option
- generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install")
- silence(:stdout){ generator.invoke_all }
+ generator([destination_root], :dev => true).expects(:bundle_command).with('install').once
+ quietly { generator.invoke_all }
rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
- generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install")
- silence(:stdout){ generator.invoke_all }
+ generator([destination_root], :edge => true).expects(:bundle_command).with('install').once
+ quietly { generator.invoke_all }
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$}
end
+
+ def test_skip_gemfile
+ generator([destination_root], :skip_gemfile => true).expects(:bundle_command).never
+ quietly { generator.invoke_all }
+ assert_no_file 'Gemfile'
+ end
+
+ def test_skip_bundle
+ generator([destination_root], :skip_bundle => true).expects(:bundle_command).never
+ quietly { generator.invoke_all }
+
+ # skip_bundle is only about running bundle install, ensure the Gemfile is still
+ # generated.
+ assert_file 'Gemfile'
+ end
end
module SharedCustomGeneratorTests
@@ -140,7 +149,6 @@ module SharedCustomGeneratorTests
Rails.application = TestApp::Application
super
Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
- @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
end
def teardown
@@ -188,7 +196,7 @@ module SharedCustomGeneratorTests
template.instance_eval "def read; self; end" # Make the string respond to read
generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
- capture(:stdout) { generator.invoke_all }
+ quietly { generator.invoke_all }
default_files.each{ |path| assert_no_file(path) }
end
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 0c588ba773..b5b21f9ebe 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -93,6 +93,34 @@ module RailtiesTest
assert_equal "HELLO WORLD", last_response.body
end
+ test "pass the value of the segment" do
+ controller "foo", <<-RUBY
+ class FooController < ActionController::Base
+ def index
+ render :text => params[:username]
+ end
+ end
+ RUBY
+
+ @plugin.write "config/routes.rb", <<-RUBY
+ Bukkits::Engine.routes.draw do
+ root :to => "foo#index"
+ end
+ RUBY
+
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ mount(Bukkits::Engine => "/:username")
+ end
+ RUBY
+
+ boot_rails
+
+ get("/arunagw")
+ assert_equal "arunagw", last_response.body
+
+ end
+
test "it provides routes as default endpoint" do
@plugin.write "lib/bukkits.rb", <<-RUBY
class Bukkits
diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb
index e975950b85..e5debf29ae 100644
--- a/railties/test/railties/shared_tests.rb
+++ b/railties/test/railties/shared_tests.rb
@@ -15,11 +15,10 @@ module RailtiesTest
boot_rails
require 'rack/test'
- require 'coffee_script'
extend Rack::Test::Methods
get "/assets/engine.js"
- assert_match "alert();", last_response.body
+ assert_match "alert()", last_response.body
end
def test_copying_migrations