From a58e6608378c18f2722c1901b5c6480b03444bce Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Sat, 9 Mar 2013 19:04:57 +0100 Subject: Use "Fixes" in place of "Fix" in changelogs for consistency [ci skip]. --- railties/CHANGELOG.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4f7cb8254f..420ed476b2 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -39,13 +39,13 @@ *Amparo Luna* * Fixes database.yml when creating a new rails application with '.' - Fix #8304 + Fixes #8304. *Jeremy W. Rowe* * Restore Rails::Engine::Railties#engines with deprecation to ensure compatibility with gems such as Thinking Sphinx - Fix #8551 + Fixes #8551. *Tim Raymond* @@ -119,7 +119,7 @@ * Environment name can be a start substring of the default environment names (production, development, test). For example: tes, pro, prod, dev, devel. - Fix #8628. + Fixes #8628. *Mykola Kyryk* @@ -129,7 +129,7 @@ * Quote column names in generates fixture files. This prevents conflicts with reserved YAML keywords such as 'yes' and 'no' - Fix #8612. + Fixes #8612. *Yves Senn* @@ -162,19 +162,19 @@ * Add `db` to list of folders included by `rake notes` and `rake notes:custom`. *Antonio Cangiano* * Engines with a dummy app include the rake tasks of dependencies in the app namespace. - Fix #8229 + Fixes #8229. *Yves Senn* * Add `sqlserver.yml` template file to satisfy `-d sqlserver` being passed to `rails new`. - Fix #6882 + Fixes #6882. *Robert Nesius* * Rake test:uncommitted finds git directory in ancestors *Nicolas Despres* * Add dummy app Rake tasks when `--skip-test-unit` and `--dummy-path` is passed to the plugin generator. - Fix #8121 + Fixes #8121. *Yves Senn* -- cgit v1.2.3 From 9ae81be072ef392cadd291c92889e7ca7c878f32 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 9 Mar 2013 20:32:01 +0000 Subject: Fix race condition in test This should fix travis. For real this time! This is the one! The readpartial(100) meant that an earlier assert_stdout could chomp up the output that a later assert_stdout wants, meaning that the later assertion fails. Reading only 1 byte at a time ensure that we don't read any more than is necessary to verify the assertion. --- railties/test/application/console_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index f4450c8a3c..af495bb450 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -106,13 +106,13 @@ class FullStackConsoleTest < ActiveSupport::TestCase teardown_app end - def assert_output(expected, timeout = 5) + def assert_output(expected, timeout = 1) timeout = Time.now + timeout output = "" until output.include?(expected) || Time.now > timeout if IO.select([@master], [], [], 0.1) - output << @master.readpartial(100) + output << @master.read(1) end end -- cgit v1.2.3 From b4df25366a3c8f133f8329bc35f1d53926704b5a Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist and Chris Toomey Date: Fri, 25 Jan 2013 13:44:36 -0500 Subject: Add `rails test` command to run the test suite To run the whole test suite: $ rails test To run the test file(s): $ rails test test/unit/foo_test.rb [test/unit/bar_test.rb ...] To run the test suite $ rails test [models,helpers,units,controllers,mailers,...] For more information, see `rails test --help`. This command will eventually replacing `rake test:*`, and `rake test` command will actually invoking `rails test` instead. --- railties/CHANGELOG.md | 21 +++ railties/lib/rails/commands.rb | 15 +++ railties/lib/rails/commands/test_runner.rb | 92 +++++++++++++ railties/test/application/test_runner_test.rb | 183 ++++++++++++++++++++++++++ 4 files changed, 311 insertions(+) create mode 100644 railties/lib/rails/commands/test_runner.rb create mode 100644 railties/test/application/test_runner_test.rb (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 420ed476b2..6bf9b22a2d 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -19,6 +19,27 @@ *Terence Lee* +* Add `rails test` command to run the test suite + + To run the whole test suite: + + $ rails test + + To run the test file(s): + + $ rails test test/unit/foo_test.rb [test/unit/bar_test.rb ...] + + To run the test suite + + $ rails test [models,helpers,units,controllers,mailers,...] + + For more information, see `rails test --help`. + + This command will eventually replacing `rake test:*`, and `rake test` + command will actually invoking `rails test` instead. + + *Prem Sichanugrist and Chris Toomey* + * Add notice message for destroy action in scaffold generator. *Rahul P. Chaudhari* diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index aacde52cfc..c76af7d01f 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -5,6 +5,7 @@ aliases = { "d" => "destroy", "c" => "console", "s" => "server", + "t" => "test", "db" => "dbconsole", "r" => "runner" } @@ -16,6 +17,7 @@ The most common rails commands are: generate Generate new code (short-cut alias: "g") console Start the Rails console (short-cut alias: "c") server Start the Rails server (short-cut alias: "s") + test Running the test file (short-cut alias: "t") dbconsole Start a console for the database specified in config/database.yml (short-cut alias: "db") new Create a new Rails application. "rails new my_app" creates a @@ -78,6 +80,19 @@ when 'server' server.start end +when 'test' + $LOAD_PATH.unshift("./test") + require 'rails/commands/test_runner' + if ["-h", "--help"].include?(ARGV.first) + Rails::TestRunner.help_message + exit + else + require APP_PATH + Rails.application.require_environment! + Rails.application.load_tasks + Rails::TestRunner.start(ARGV) + end + when 'dbconsole' require 'rails/commands/dbconsole' Rails::DBConsole.start diff --git a/railties/lib/rails/commands/test_runner.rb b/railties/lib/rails/commands/test_runner.rb new file mode 100644 index 0000000000..a65b508505 --- /dev/null +++ b/railties/lib/rails/commands/test_runner.rb @@ -0,0 +1,92 @@ +require 'optparse' +require 'minitest/unit' + +module Rails + # Handling the all the logic behind +rails test+ command. + class TestRunner + class << self + # Parse the test suite name from the arguments array and pass in a list + # of file to a new +TestRunner+ object, then invoke the evaluation. If + # the argument is not a test suite name, it will be treated as a file + # name and passed to the +TestRunner+ instance right away. + def start(arguments) + case arguments.first + when nil + new(Dir['test/**/*_test.rb']).run + when 'models' + new(Dir['test/models/**/*_test.rb']).run + when 'helpers' + new(Dir['test/helpers/**/*_test.rb']).run + when 'units' + new(Dir['test/{models,helpers,unit}/**/*_test.rb']).run + when 'controllers' + new(Dir['test/controllers/**/*_test.rb']).run + when 'mailers' + new(Dir['test/mailers/**/*_test.rb']).run + when 'functionals' + new(Dir['test/{controllers,mailers,functional}/**/*_test.rb']).run + when 'integration' + new(Dir['test/integration/**/*_test.rb']).run + else + new(arguments).run + end + end + + # Print out the help message which listed all of the test suite names. + def help_message + puts "Usage: rails test [path to test file(s) or test suite type]" + puts "" + puts "Run single test file, or a test suite, under Rails'" + puts "environment. If the file name(s) or suit name is omitted," + puts "Rails will run all the test suites." + puts "" + puts "Support types of test suites:" + puts "-------------------------------------------------------------" + puts "* models (test/models/**/*)" + puts "* helpers (test/helpers/**/*)" + puts "* units (test/{models,helpers,unit}/**/*" + puts "* controllers (test/controllers/**/*)" + puts "* mailers (test/mailers/**/*)" + puts "* functionals (test/{controllers,mailers,functional}/**/*)" + puts "* integration (test/integration/**/*)" + puts "-------------------------------------------------------------" + end + end + + # Create a new +TestRunner+ object with a list of test file paths. + def initialize(files) + @files = files + Rake::Task['test:prepare'].invoke + MiniTest::Unit.output = SilentUntilSyncStream.new(MiniTest::Unit.output) + end + + # Run the test files by evaluate each of them. + def run + @files.each { |filename| load(filename) } + end + + # A null stream object which ignores everything until +sync+ has been set + # to true. This is only to be used to silence unnecessary output from + # MiniTest, as MiniTest calls +output.sync = true+ right before output the + # first test result. + class SilentUntilSyncStream < File + # Create a +SilentUntilSyncStream+ object by given a stream object that + # this stream should set +MiniTest::Unit.output+ to after +sync+ has been + # set to true. + def initialize(target_stream) + @target_stream = target_stream + super(File::NULL, 'w') + end + + # Swap +MiniTest::Unit.output+ to another stream when +sync+ is true. + def sync=(sync) + if sync + @target_stream.sync = true + MiniTest::Unit.output = @target_stream + end + + super + end + end + end +end diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb new file mode 100644 index 0000000000..49bce508ee --- /dev/null +++ b/railties/test/application/test_runner_test.rb @@ -0,0 +1,183 @@ +require 'isolation/abstract_unit' + +module ApplicationTests + class TestRunnerTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + create_schema + end + + def teardown + teardown_app + end + + def test_should_not_display_heading + create_test_file + run_test_command.tap do |output| + assert_no_match /Run options:/, output + assert_no_match /Running tests:/, output + end + end + + def test_run_shortcut + create_test_file :models, 'foo' + output = Dir.chdir(app_path) { `bundle exec rails t test/models/foo_test.rb` } + assert_match /1 tests, 1 assertions, 0 failures/, output + end + + def test_run_single_file + create_test_file :models, 'foo' + assert_match /1 tests, 1 assertions, 0 failures/, run_test_command("test/models/foo_test.rb") + end + + def test_run_multiple_files + create_test_file :models, 'foo' + create_test_file :models, 'bar' + assert_match /2 tests, 2 assertions, 0 failures/, run_test_command("test/models/foo_test.rb test/models/bar_test.rb") + end + + def test_run_file_with_syntax_error + app_file 'test/models/error_test.rb', <<-RUBY + require 'test_helper' + def; end + RUBY + + error_stream = Tempfile.new('error') + redirect_stderr(error_stream) { run_test_command('test/models/error_test.rb') } + assert_match /SyntaxError/, error_stream.read + end + + def test_invoke_rake_test_prepare + app_file "lib/tasks/test.rake", <<-RUBY + namespace :test do + task :prepare do + puts "Hello World" + end + end + RUBY + create_test_file + assert_match /Hello World/, run_test_command + end + + def test_run_models + create_test_file :models, 'foo' + create_test_file :models, 'bar' + create_test_file :controllers, 'foobar_controller' + run_test_command("models").tap do |output| + assert_match /FooTest/, output + assert_match /BarTest/, output + assert_match /2 tests, 2 assertions, 0 failures/, output + end + end + + def test_run_helpers + create_test_file :helpers, 'foo_helper' + create_test_file :helpers, 'bar_helper' + create_test_file :controllers, 'foobar_controller' + run_test_command('helpers').tap do |output| + assert_match /FooHelperTest/, output + assert_match /BarHelperTest/, output + assert_match /2 tests, 2 assertions, 0 failures/, output + end + end + + def test_run_units + create_test_file :models, 'foo' + create_test_file :helpers, 'bar_helper' + create_test_file :unit, 'baz_unit' + create_test_file :controllers, 'foobar_controller' + run_test_command('units').tap do |output| + assert_match /FooTest/, output + assert_match /BarHelperTest/, output + assert_match /BazUnitTest/, output + assert_match /3 tests, 3 assertions, 0 failures/, output + end + end + + def test_run_controllers + create_test_file :controllers, 'foo_controller' + create_test_file :controllers, 'bar_controller' + create_test_file :models, 'foo' + run_test_command('controllers').tap do |output| + assert_match /FooControllerTest/, output + assert_match /BarControllerTest/, output + assert_match /2 tests, 2 assertions, 0 failures/, output + end + end + + def test_run_mailers + create_test_file :mailers, 'foo_mailer' + create_test_file :mailers, 'bar_mailer' + create_test_file :models, 'foo' + run_test_command('mailers').tap do |output| + assert_match /FooMailerTest/, output + assert_match /BarMailerTest/, output + assert_match /2 tests, 2 assertions, 0 failures/, output + end + end + + def test_run_functionals + create_test_file :mailers, 'foo_mailer' + create_test_file :controllers, 'bar_controller' + create_test_file :functional, 'baz_functional' + create_test_file :models, 'foo' + run_test_command('functionals').tap do |output| + assert_match /FooMailerTest/, output + assert_match /BarControllerTest/, output + assert_match /BazFunctionalTest/, output + assert_match /3 tests, 3 assertions, 0 failures/, output + end + end + + def test_run_integration + create_test_file :integration, 'foo_integration' + create_test_file :models, 'foo' + run_test_command('integration').tap do |output| + assert_match /FooIntegration/, output + assert_match /1 tests, 1 assertions, 0 failures/, output + end + end + + def test_run_whole_suite + types = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration] + types.each { |type| create_test_file type, "foo_#{type}" } + run_test_command('') .tap do |output| + types.each { |type| assert_match /Foo#{type.to_s.camelize}Test/, output } + assert_match /7 tests, 7 assertions, 0 failures/, output + end + end + + private + def run_test_command(arguments = 'test/unit/test_test.rb') + Dir.chdir(app_path) { `bundle exec rails test #{arguments}` } + end + + def create_schema + app_file 'db/schema.rb', '' + end + + def redirect_stderr(target_stream) + previous_stderr = STDERR.dup + $stderr.reopen(target_stream) + yield + target_stream.rewind + ensure + $stderr = previous_stderr + end + + def create_test_file(path = :unit, name = 'test') + app_file "test/#{path}/#{name}_test.rb", <<-RUBY + require 'test_helper' + + class #{name.camelize}Test < ActiveSupport::TestCase + def test_truth + puts "#{name.camelize}Test" + assert true + end + end + RUBY + end + end +end -- cgit v1.2.3 From 176b57c5430ddae7668114994c35b3293b0a05a5 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 1 Feb 2013 17:21:09 -0500 Subject: Add support for MiniTest flags in TestRunner Any flags that got set will be passed through to MiniTest::Unit.runner, such as `-n`, `-s-, and `-v`. --- railties/lib/rails/commands.rb | 15 ++--- railties/lib/rails/commands/test_runner.rb | 91 ++++++++++++++++++--------- railties/test/application/test_runner_test.rb | 21 +++++++ 3 files changed, 88 insertions(+), 39 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index c76af7d01f..2984999a3c 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -83,15 +83,12 @@ when 'server' when 'test' $LOAD_PATH.unshift("./test") require 'rails/commands/test_runner' - if ["-h", "--help"].include?(ARGV.first) - Rails::TestRunner.help_message - exit - else - require APP_PATH - Rails.application.require_environment! - Rails.application.load_tasks - Rails::TestRunner.start(ARGV) - end + options = Rails::TestRunner.parse_arguments(ARGV) + + require APP_PATH + Rails.application.require_environment! + Rails.application.load_tasks + Rails::TestRunner.start(ARGV, options) when 'dbconsole' require 'rails/commands/dbconsole' diff --git a/railties/lib/rails/commands/test_runner.rb b/railties/lib/rails/commands/test_runner.rb index a65b508505..33c32bb94f 100644 --- a/railties/lib/rails/commands/test_runner.rb +++ b/railties/lib/rails/commands/test_runner.rb @@ -9,54 +9,85 @@ module Rails # of file to a new +TestRunner+ object, then invoke the evaluation. If # the argument is not a test suite name, it will be treated as a file # name and passed to the +TestRunner+ instance right away. - def start(arguments) - case arguments.first + def start(files, options) + case files.first when nil - new(Dir['test/**/*_test.rb']).run + new(Dir['test/**/*_test.rb'], options).run when 'models' - new(Dir['test/models/**/*_test.rb']).run + new(Dir['test/models/**/*_test.rb'], options).run when 'helpers' - new(Dir['test/helpers/**/*_test.rb']).run + new(Dir['test/helpers/**/*_test.rb'], options).run when 'units' - new(Dir['test/{models,helpers,unit}/**/*_test.rb']).run + new(Dir['test/{models,helpers,unit}/**/*_test.rb'], options).run when 'controllers' - new(Dir['test/controllers/**/*_test.rb']).run + new(Dir['test/controllers/**/*_test.rb'], options).run when 'mailers' - new(Dir['test/mailers/**/*_test.rb']).run + new(Dir['test/mailers/**/*_test.rb'], options).run when 'functionals' - new(Dir['test/{controllers,mailers,functional}/**/*_test.rb']).run + new(Dir['test/{controllers,mailers,functional}/**/*_test.rb'], options).run when 'integration' - new(Dir['test/integration/**/*_test.rb']).run + new(Dir['test/integration/**/*_test.rb'], options).run else - new(arguments).run + new(files, options).run end end - # Print out the help message which listed all of the test suite names. - def help_message - puts "Usage: rails test [path to test file(s) or test suite type]" - puts "" - puts "Run single test file, or a test suite, under Rails'" - puts "environment. If the file name(s) or suit name is omitted," - puts "Rails will run all the test suites." - puts "" - puts "Support types of test suites:" - puts "-------------------------------------------------------------" - puts "* models (test/models/**/*)" - puts "* helpers (test/helpers/**/*)" - puts "* units (test/{models,helpers,unit}/**/*" - puts "* controllers (test/controllers/**/*)" - puts "* mailers (test/mailers/**/*)" - puts "* functionals (test/{controllers,mailers,functional}/**/*)" - puts "* integration (test/integration/**/*)" - puts "-------------------------------------------------------------" + # Parse arguments and set them as option flags + def parse_arguments(arguments) + options = {} + orig_arguments = arguments.dup + + OptionParser.new do |opts| + opts.banner = "Usage: rails test [path to test file(s) or test suite type]" + + opts.separator "" + opts.separator "Run single test file, or a test suite, under Rails'" + opts.separator "environment. If the file name(s) or suit name is omitted," + opts.separator "Rails will run all the test suites." + opts.separator "" + opts.separator "Specific options:" + + opts.on '-h', '--help', 'Display this help.' do + puts opts + exit + end + + opts.on '-s', '--seed SEED', Integer, "Sets random seed" do |m| + options[:seed] = m.to_i + end + + opts.on '-v', '--verbose', "Verbose. Show progress processing files." do + options[:verbose] = true + end + + opts.on '-n', '--name PATTERN', "Filter test names on pattern (e.g. /foo/)" do |a| + options[:filter] = a + end + + opts.separator "" + opts.separator "Support types of test suites:" + opts.separator "-------------------------------------------------------------" + opts.separator "* models (test/models/**/*)" + opts.separator "* helpers (test/helpers/**/*)" + opts.separator "* units (test/{models,helpers,unit}/**/*" + opts.separator "* controllers (test/controllers/**/*)" + opts.separator "* mailers (test/mailers/**/*)" + opts.separator "* functionals (test/{controllers,mailers,functional}/**/*)" + opts.separator "* integration (test/integration/**/*)" + opts.separator "-------------------------------------------------------------" + + opts.parse! arguments + orig_arguments -= arguments + end + options end end # Create a new +TestRunner+ object with a list of test file paths. - def initialize(files) + def initialize(files, options) @files = files Rake::Task['test:prepare'].invoke + MiniTest::Unit.runner.options = options MiniTest::Unit.output = SilentUntilSyncStream.new(MiniTest::Unit.output) end diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 49bce508ee..249bfd1d5d 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -149,6 +149,27 @@ module ApplicationTests end end + def test_run_named_test + app_file 'test/unit/chu_2_koi_test.rb', <<-RUBY + require 'test_helper' + + class Chu2KoiTest < ActiveSupport::TestCase + def test_rikka + puts 'Rikka' + end + + def test_sanae + puts 'Sanae' + end + end + RUBY + + run_test_command('test/unit/chu_2_koi_test.rb -n test_rikka').tap do |output| + assert_match /Rikka/, output + assert_no_match /Sanae/, output + end + end + private def run_test_command(arguments = 'test/unit/test_test.rb') Dir.chdir(app_path) { `bundle exec rails test #{arguments}` } -- cgit v1.2.3 From 1a0c58b2988a24a783b4f9a658ac629922125551 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Wed, 6 Feb 2013 01:03:17 -0500 Subject: Load fixtures only when running suites, or `-f` * `rails test -f` will run the test suites with all fixtures loaded * New application will now generated without `fixtures :all` line enabled by default. --- railties/CHANGELOG.md | 8 ++++ railties/lib/rails/commands/test_runner.rb | 19 +++++++- .../rails/app/templates/test/test_helper.rb | 5 ++- railties/test/application/test_runner_test.rb | 51 ++++++++++++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 6bf9b22a2d..4145938063 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -19,6 +19,14 @@ *Terence Lee* +* Rails now generate a `test/test_helper.rb` file with `fixtures :all` commented out by default, + since we don't want to force loading all fixtures for user when a single test is run. However, + fixtures are still going to be loaded automatically for test suites. + + To force all fixtures to be create in your database, use `rails test -f` to run your test. + + *Prem Sichanugrist* + * Add `rails test` command to run the test suite To run the whole test suite: diff --git a/railties/lib/rails/commands/test_runner.rb b/railties/lib/rails/commands/test_runner.rb index 33c32bb94f..ae901f05f8 100644 --- a/railties/lib/rails/commands/test_runner.rb +++ b/railties/lib/rails/commands/test_runner.rb @@ -9,7 +9,10 @@ module Rails # of file to a new +TestRunner+ object, then invoke the evaluation. If # the argument is not a test suite name, it will be treated as a file # name and passed to the +TestRunner+ instance right away. - def start(files, options) + def start(files, options = {}) + original_fixtures_options = options.delete(:fixtures) + options[:fixtures] = true + case files.first when nil new(Dir['test/**/*_test.rb'], options).run @@ -28,6 +31,7 @@ module Rails when 'integration' new(Dir['test/integration/**/*_test.rb'], options).run else + options[:fixtures] = original_fixtures_options new(files, options).run end end @@ -52,6 +56,10 @@ module Rails exit end + opts.on '-f', '--fixtures', 'Load fixtures in test/fixtures/ before running the tests' do + options[:fixtures] = true + end + opts.on '-s', '--seed SEED', Integer, "Sets random seed" do |m| options[:seed] = m.to_i end @@ -87,6 +95,15 @@ module Rails def initialize(files, options) @files = files Rake::Task['test:prepare'].invoke + + if options.delete(:fixtures) + if defined?(ActiveRecord::Base) + ActiveSupport::TestCase.send :include, ActiveRecord::TestFixtures + ActiveSupport::TestCase.fixture_path = "#{Rails.root}/test/fixtures/" + ActiveSupport::TestCase.fixtures :all + end + end + MiniTest::Unit.runner.options = options MiniTest::Unit.output = SilentUntilSyncStream.new(MiniTest::Unit.output) end diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb index 9afda2d0df..754e99e09f 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb @@ -6,11 +6,12 @@ class ActiveSupport::TestCase <% unless options[:skip_active_record] -%> ActiveRecord::Migration.check_pending! - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + # Uncomment the `fixtures` line below to setup all fixtures in test/fixtures/*.yml for all tests + # in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting - fixtures :all + # fixtures :all <% end -%> # Add more helper methods to be used by all tests here... diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 249bfd1d5d..71e2b403af 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -1,4 +1,5 @@ require 'isolation/abstract_unit' +require 'active_support/core_ext/string/strip' module ApplicationTests class TestRunnerTest < ActiveSupport::TestCase @@ -170,11 +171,61 @@ module ApplicationTests end end + def test_not_load_fixtures_when_running_single_test + create_model_with_fixture + create_fixture_test :models, 'user' + assert_match /0 users/, run_test_command('test/models/user_test.rb') + assert_match /3 users/, run_test_command('test/models/user_test.rb -f') + end + + def test_load_fixtures_when_running_test_suites + create_model_with_fixture + types = [:models, :helpers, [:units, :unit], :controllers, :mailers, + [:functionals, :functional], :integration] + + types.each do |type, directory| + directory ||= type + create_fixture_test directory + assert_match /3 users/, run_test_command(type) + Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" } + end + end + private def run_test_command(arguments = 'test/unit/test_test.rb') Dir.chdir(app_path) { `bundle exec rails test #{arguments}` } end + def create_model_with_fixture + script 'generate model user name:string' + + app_file 'test/fixtures/users.yml', <<-YAML.strip_heredoc + vampire: + id: 1 + name: Koyomi Araragi + crab: + id: 2 + name: Senjougahara Hitagi + cat: + id: 3 + name: Tsubasa Hanekawa + YAML + + Dir.chdir(app_path) { `bundle exec rake db:migrate` } + end + + def create_fixture_test(path = :unit, name = 'test') + app_file "test/#{path}/#{name}_test.rb", <<-RUBY + require 'test_helper' + + class #{name.camelize}Test < ActiveSupport::TestCase + def test_fixture + puts "\#{User.count} users (\#{__FILE__})" + end + end + RUBY + end + def create_schema app_file 'db/schema.rb', '' end -- cgit v1.2.3 From df85dfa6fa6f7ae9a0b72eb9b9a254d2d5560f38 Mon Sep 17 00:00:00 2001 From: Dalibor Nasevic Date: Fri, 8 Feb 2013 00:53:11 +0100 Subject: Improve wording for rails test command --- railties/CHANGELOG.md | 19 +++++++----- railties/lib/rails/commands/test_runner.rb | 34 +++++++++++----------- .../rails/app/templates/test/test_helper.rb | 4 +-- railties/test/application/test_runner_test.rb | 16 +++++----- 4 files changed, 38 insertions(+), 35 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4145938063..e3b1bc37c6 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -19,7 +19,7 @@ *Terence Lee* -* Rails now generate a `test/test_helper.rb` file with `fixtures :all` commented out by default, +* Rails now generates a `test/test_helper.rb` file with `fixtures :all` commented out by default, since we don't want to force loading all fixtures for user when a single test is run. However, fixtures are still going to be loaded automatically for test suites. @@ -27,24 +27,27 @@ *Prem Sichanugrist* -* Add `rails test` command to run the test suite +* Add `rails test` command for running tests - To run the whole test suite: + To run all tests: $ rails test - To run the test file(s): + To run a test suite + + $ rails test [models,helpers,units,controllers,mailers,...] + + To run a selected test file(s): $ rails test test/unit/foo_test.rb [test/unit/bar_test.rb ...] - To run the test suite + To run a single test from a test file - $ rails test [models,helpers,units,controllers,mailers,...] + $ rails test test/unit/foo_test.rb -n test_the_truth For more information, see `rails test --help`. - This command will eventually replacing `rake test:*`, and `rake test` - command will actually invoking `rails test` instead. + This command will eventually replace `rake test:*` and `rake test` tasks *Prem Sichanugrist and Chris Toomey* diff --git a/railties/lib/rails/commands/test_runner.rb b/railties/lib/rails/commands/test_runner.rb index ae901f05f8..92c4d4e593 100644 --- a/railties/lib/rails/commands/test_runner.rb +++ b/railties/lib/rails/commands/test_runner.rb @@ -2,13 +2,13 @@ require 'optparse' require 'minitest/unit' module Rails - # Handling the all the logic behind +rails test+ command. + # Handles all logic behind +rails test+ command. class TestRunner class << self - # Parse the test suite name from the arguments array and pass in a list - # of file to a new +TestRunner+ object, then invoke the evaluation. If - # the argument is not a test suite name, it will be treated as a file - # name and passed to the +TestRunner+ instance right away. + # Creates a new +TestRunner+ object with an array of test files to run + # based on the arguments. When no arguments are provided, it runs all test + # files. When a suite argument is provided, it runs only the test files in + # that suite. Otherwise, it runs the specified test file(s). def start(files, options = {}) original_fixtures_options = options.delete(:fixtures) options[:fixtures] = true @@ -36,18 +36,18 @@ module Rails end end - # Parse arguments and set them as option flags + # Parses arguments and sets them as option flags def parse_arguments(arguments) options = {} orig_arguments = arguments.dup OptionParser.new do |opts| - opts.banner = "Usage: rails test [path to test file(s) or test suite type]" + opts.banner = "Usage: rails test [path to test file(s) or test suite]" opts.separator "" - opts.separator "Run single test file, or a test suite, under Rails'" + opts.separator "Run a specific test file(s) or a test suite, under Rails'" opts.separator "environment. If the file name(s) or suit name is omitted," - opts.separator "Rails will run all the test suites." + opts.separator "Rails will run all tests." opts.separator "" opts.separator "Specific options:" @@ -91,7 +91,7 @@ module Rails end end - # Create a new +TestRunner+ object with a list of test file paths. + # Creates a new +TestRunner+ object with a list of test file paths. def initialize(files, options) @files = files Rake::Task['test:prepare'].invoke @@ -108,25 +108,25 @@ module Rails MiniTest::Unit.output = SilentUntilSyncStream.new(MiniTest::Unit.output) end - # Run the test files by evaluate each of them. + # Runs test files by evaluating each of them. def run @files.each { |filename| load(filename) } end # A null stream object which ignores everything until +sync+ has been set - # to true. This is only to be used to silence unnecessary output from - # MiniTest, as MiniTest calls +output.sync = true+ right before output the - # first test result. + # to true. This is only used to silence unnecessary output from MiniTest, + # as MiniTest calls +output.sync = true+ right before it outputs the first + # test result. class SilentUntilSyncStream < File - # Create a +SilentUntilSyncStream+ object by given a stream object that - # this stream should set +MiniTest::Unit.output+ to after +sync+ has been + # Creates a +SilentUntilSyncStream+ object by giving it a target stream + # object that will be assigned to +MiniTest::Unit.output+ after +sync+ is # set to true. def initialize(target_stream) @target_stream = target_stream super(File::NULL, 'w') end - # Swap +MiniTest::Unit.output+ to another stream when +sync+ is true. + # Swaps +MiniTest::Unit.output+ to another stream when +sync+ is true. def sync=(sync) if sync @target_stream.sync = true diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb index 754e99e09f..f0aeeee827 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb @@ -6,8 +6,8 @@ class ActiveSupport::TestCase <% unless options[:skip_active_record] -%> ActiveRecord::Migration.check_pending! - # Uncomment the `fixtures` line below to setup all fixtures in test/fixtures/*.yml for all tests - # in alphabetical order. + # Uncomment the `fixtures :all` line below to setup all fixtures in test/fixtures/*.yml + # for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 71e2b403af..810748682a 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -141,11 +141,11 @@ module ApplicationTests end end - def test_run_whole_suite - types = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration] - types.each { |type| create_test_file type, "foo_#{type}" } + def test_run_all_suites + suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration] + suites.each { |suite| create_test_file suite, "foo_#{suite}" } run_test_command('') .tap do |output| - types.each { |type| assert_match /Foo#{type.to_s.camelize}Test/, output } + suites.each { |suite| assert_match /Foo#{suite.to_s.camelize}Test/, output } assert_match /7 tests, 7 assertions, 0 failures/, output end end @@ -180,13 +180,13 @@ module ApplicationTests def test_load_fixtures_when_running_test_suites create_model_with_fixture - types = [:models, :helpers, [:units, :unit], :controllers, :mailers, + suites = [:models, :helpers, [:units, :unit], :controllers, :mailers, [:functionals, :functional], :integration] - types.each do |type, directory| - directory ||= type + suites.each do |suite, directory| + directory ||= suite create_fixture_test directory - assert_match /3 users/, run_test_command(type) + assert_match /3 users/, run_test_command(suite) Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" } end end -- cgit v1.2.3 From b51673fbd9563bd3ffa22e22255ca1cef80cfb6d Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 25 Feb 2013 17:04:01 -0500 Subject: Update Rake tasks to call `rails test` instead Also, print out deprecation warning for other rake tasks except `rake test` and `rake` (default) --- railties/lib/rails/test_unit/testing.rake | 80 +++++++++++-------------------- railties/test/application/rake_test.rb | 23 +++++---- 2 files changed, 41 insertions(+), 62 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 44485d9b14..de44bf9e4d 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,6 +1,7 @@ require 'rbconfig' require 'rake/testtask' require 'rails/test_unit/sub_test_task' +require 'active_support/deprecation' TEST_CHANGES_SINCE = Time.now - 600 @@ -47,7 +48,11 @@ task default: :test desc 'Runs test:units, test:functionals, test:integration together' task :test do - Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke + if ENV['TEST'] + exec "bundle exec rails test #{ENV['TEST'].inspect}" + else + exec 'bundle exec rails test' + end end namespace :test do @@ -56,19 +61,8 @@ namespace :test do end task :run do - errors = %w(test:units test:functionals test:integration).collect do |task| - begin - Rake::Task[task].invoke - nil - rescue => e - { task: task, exception: e } - end - end.compact - - if errors.any? - puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n") - abort - end + ActiveSupport::Deprecation.warn "`rake test:run` is deprecated. Please use `rails test`." + exec 'bundle exec rails test' end # Inspired by: http://ngauthier.com/2012/02/quick-tests-with-bash.html @@ -83,7 +77,13 @@ namespace :test do task :db => %w[db:test:prepare test:all] end - Rake::TestTask.new(recent: "test:prepare") do |t| + # Display deprecation message + task :deprecated do + task_name = ARGV.first + ActiveSupport::Deprecation.warn "`rake #{ARGV.first}` is deprecated with no replacement." + end + + Rake::TestTask.new(recent: ["test:deprecated", "test:prepare"]) do |t| since = TEST_CHANGES_SINCE touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + recent_tests('app/models/**/*.rb', 'test/models', since) + @@ -94,9 +94,9 @@ namespace :test do t.libs << 'test' t.test_files = touched.uniq end - Rake::Task['test:recent'].comment = "Test recent changes" + Rake::Task['test:recent'].comment = "Deprecated; Test recent changes" - Rake::TestTask.new(uncommitted: "test:prepare") do |t| + Rake::TestTask.new(uncommitted: ["test:deprecated", "test:prepare"]) do |t| def t.file_list if File.directory?(".svn") changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] } @@ -118,44 +118,20 @@ namespace :test do t.libs << 'test' end - Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" - - Rake::TestTask.new(single: "test:prepare") do |t| - t.libs << "test" - end - - Rails::SubTestTask.new(models: "test:prepare") do |t| - t.libs << "test" - t.pattern = 'test/models/**/*_test.rb' - end - - Rails::SubTestTask.new(helpers: "test:prepare") do |t| - t.libs << "test" - t.pattern = 'test/helpers/**/*_test.rb' - end + Rake::Task['test:uncommitted'].comment = "Deprecated; Test changes since last checkin (only Subversion and Git)" - Rails::SubTestTask.new(units: "test:prepare") do |t| - t.libs << "test" - t.pattern = 'test/{models,helpers,unit}/**/*_test.rb' + desc "Deprecated; Please use `rails test \"#{ENV['TEST']}\"`" + task :single do + ActiveSupport::Deprecation.warn "`rake test:single` is deprecated. Please use `rails test \"#{ENV['TEST']}\"`." + exec "bundle exec rails test #{test_suit_name}" end - Rails::SubTestTask.new(controllers: "test:prepare") do |t| - t.libs << "test" - t.pattern = 'test/controllers/**/*_test.rb' - end + [:models, :helpers, :units, :controllers, :functionals, :integration].each do |test_suit_name| + desc "Deprecated; Please use `rails test #{test_suit_name}`" + task test_suit_name do + ActiveSupport::Deprecation.warn "`rake test:#{test_suit_name}` is deprecated. Please use `rails test #{test_suit_name}`." - Rails::SubTestTask.new(mailers: "test:prepare") do |t| - t.libs << "test" - t.pattern = 'test/mailers/**/*_test.rb' - end - - Rails::SubTestTask.new(functionals: "test:prepare") do |t| - t.libs << "test" - t.pattern = 'test/{controllers,mailers,functional}/**/*_test.rb' - end - - Rails::SubTestTask.new(integration: "test:prepare") do |t| - t.libs << "test" - t.pattern = 'test/integration/**/*_test.rb' + exec "bundle exec rails test #{test_suit_name}" + end end end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 09f2ad1209..a9e0e1bcb7 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -91,19 +91,9 @@ module ApplicationTests raise 'models' RUBY - app_file "test/controllers/one_controller_test.rb", <<-RUBY - raise 'controllers' - RUBY - - app_file "test/integration/one_integration_test.rb", <<-RUBY - raise 'integration' - RUBY - silence_stderr do output = Dir.chdir(app_path) { `rake test 2>&1` } assert_match 'models', output - assert_match 'controllers', output - assert_match 'integration', output end end @@ -135,6 +125,19 @@ module ApplicationTests end end + def test_rake_test_deprecation_messages + Dir.chdir(app_path){ `rails generate scaffold user name:string` } + Dir.chdir(app_path){ `rake db:migrate` } + + %w(run recent uncommitted models helpers units controllers functionals integration).each do |test_suit_name| + output = Dir.chdir(app_path) { `rake test:#{test_suit_name} 2>&1` } + assert_match /DEPRECATION WARNING: `rake test:#{test_suit_name}` is deprecated/, output + end + + assert_match /DEPRECATION WARNING: `rake test:single` is deprecated/, + Dir.chdir(app_path) { `rake test:single TEST=test/models/user_test.rb 2>&1` } + end + def test_rake_routes_calls_the_route_inspector app_file "config/routes.rb", <<-RUBY AppTemplate::Application.routes.draw do -- cgit v1.2.3 From 3ed41e579e45464aa6e6342783b77f9ec29e339c Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sat, 9 Mar 2013 16:03:09 -0500 Subject: Make sure that `rails test` load test in test env --- railties/lib/rails/commands.rb | 3 +- railties/lib/rails/commands/test_runner.rb | 12 ++++-- .../rails/app/templates/test/test_helper.rb | 2 +- railties/test/application/test_runner_test.rb | 45 +++++++++++++++++++++- 4 files changed, 55 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 2984999a3c..41d3722c18 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -84,10 +84,9 @@ when 'test' $LOAD_PATH.unshift("./test") require 'rails/commands/test_runner' options = Rails::TestRunner.parse_arguments(ARGV) + ENV['RAILS_ENV'] ||= options[:environment] || 'test' require APP_PATH - Rails.application.require_environment! - Rails.application.load_tasks Rails::TestRunner.start(ARGV, options) when 'dbconsole' diff --git a/railties/lib/rails/commands/test_runner.rb b/railties/lib/rails/commands/test_runner.rb index 92c4d4e593..d8857bd183 100644 --- a/railties/lib/rails/commands/test_runner.rb +++ b/railties/lib/rails/commands/test_runner.rb @@ -56,6 +56,10 @@ module Rails exit end + opts.on '-e', '--environment NAME', String, 'Specifies the environment to run this test under' do |e| + options[:environment] = e + end + opts.on '-f', '--fixtures', 'Load fixtures in test/fixtures/ before running the tests' do options[:fixtures] = true end @@ -68,8 +72,8 @@ module Rails options[:verbose] = true end - opts.on '-n', '--name PATTERN', "Filter test names on pattern (e.g. /foo/)" do |a| - options[:filter] = a + opts.on '-n', '--name PATTERN', "Filter test names on pattern (e.g. /foo/)" do |n| + options[:filter] = n end opts.separator "" @@ -94,7 +98,9 @@ module Rails # Creates a new +TestRunner+ object with a list of test file paths. def initialize(files, options) @files = files - Rake::Task['test:prepare'].invoke + + Rails.application.load_tasks + Rake::Task['db:test:load'].invoke if options.delete(:fixtures) if defined?(ActiveRecord::Base) diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb index f0aeeee827..ca40914d3b 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb @@ -1,4 +1,4 @@ -ENV["RAILS_ENV"] = "test" +ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 810748682a..7a5a428845 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -191,6 +191,39 @@ module ApplicationTests end end + def test_run_different_environment_using_env_var + app_file 'test/unit/env_test.rb', <<-RUBY + require 'test_helper' + + class EnvTest < ActiveSupport::TestCase + def test_env + puts Rails.env + end + end + RUBY + + assert_match /development/, Dir.chdir(app_path) { `RAILS_ENV=development bundle exec rails test test/unit/env_test.rb` } + end + + def test_run_different_environment_using_e_tag + app_file 'test/unit/env_test.rb', <<-RUBY + require 'test_helper' + + class EnvTest < ActiveSupport::TestCase + def test_env + puts Rails.env + end + end + RUBY + + assert_match /development/, run_test_command('-e development test/unit/env_test.rb') + end + + def test_generated_scaffold_works_with_rails_test + create_scaffold + assert_match /0 failures, 0 errors, 0 skips/, run_test_command('') + end + private def run_test_command(arguments = 'test/unit/test_test.rb') Dir.chdir(app_path) { `bundle exec rails test #{arguments}` } @@ -211,7 +244,7 @@ module ApplicationTests name: Tsubasa Hanekawa YAML - Dir.chdir(app_path) { `bundle exec rake db:migrate` } + run_migration end def create_fixture_test(path = :unit, name = 'test') @@ -251,5 +284,15 @@ module ApplicationTests end RUBY end + + def create_scaffold + script 'generate scaffold user name:string' + Dir.chdir(app_path) { File.exist?('app/models/user.rb') } + run_migration + end + + def run_migration + Dir.chdir(app_path) { `bundle exec rake db:migrate` } + end end end -- cgit v1.2.3 From 72cf273bfdbe5c322a915e81ceaaca3522c1f553 Mon Sep 17 00:00:00 2001 From: Teng Siong Ong Date: Sat, 9 Mar 2013 17:35:14 -0800 Subject: Make sure that debugger isn't included in production environment. --- railties/lib/rails/generators/rails/app/templates/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index b5db3d2187..f6bd107eba 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -23,5 +23,5 @@ gem 'jbuilder', '~> 1.0.1' <% unless defined?(JRUBY_VERSION) -%> # To use debugger -# gem 'debugger' +# gem 'debugger', group: [:development, :test] <% end -%> -- cgit v1.2.3 From 647a9abb02ceffc7002b94d46a290621280e8d67 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 11 Mar 2013 16:03:10 +0530 Subject: Cleanup tests for unused variables --- railties/test/railties/engine_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 37d0be107c..26b388b6f9 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -105,7 +105,7 @@ module RailtiesTest assert_not_nil bukkits_migration_order, "Expected migration to be skipped" migrations_count = Dir["#{app_path}/db/migrate/*.rb"].length - output = `bundle exec rake railties:install:migrations` + `bundle exec rake railties:install:migrations` assert_equal migrations_count, Dir["#{app_path}/db/migrate/*.rb"].length end -- cgit v1.2.3 From 1f8953382f9b7782cf9030f90a05bdefc9a27950 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 11 Mar 2013 11:58:36 -0400 Subject: Fix test failure introduced in 3ed41e57 I forgot to run the test suit after changing the task name. :bomb: --- railties/test/application/test_runner_test.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 7a5a428845..2d9d92602d 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -50,12 +50,10 @@ module ApplicationTests assert_match /SyntaxError/, error_stream.read end - def test_invoke_rake_test_prepare + def test_invoke_rake_db_test_load app_file "lib/tasks/test.rake", <<-RUBY - namespace :test do - task :prepare do - puts "Hello World" - end + task 'db:test:load' do + puts "Hello World" end RUBY create_test_file -- cgit v1.2.3 From dbd8bec525ea690daab15084330cabeab785f06d Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 11 Mar 2013 11:28:28 -0700 Subject: Mention that debugging can be slow. https://github.com/rails/rails/pull/3180\#issuecomment-14705821 has mention of rendering going from 1-2ms to 4 seconds with this on, which seems reasonable: debugging is slow. --- .../rails/app/templates/config/environments/development.rb.tt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') 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 d0e62d09cc..8b64881dbc 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 @@ -26,6 +26,8 @@ <%- unless options.skip_sprockets? -%> # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. config.assets.debug = true <%- end -%> end -- cgit v1.2.3 From 773425420f3884e0f3cba3e21f7ea13f2f80164a Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 11 Mar 2013 14:28:43 -0400 Subject: Make sure that the test case is run under test env * Unset $RAILS_ENV that got set by abstract_unit to trigger the default. * split out environment setting since Ruby 1.9.3 doesn't support inline ENV setting. --- railties/test/application/test_runner_test.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 2d9d92602d..7e719d50b2 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -7,6 +7,7 @@ module ApplicationTests def setup build_app + ENV['RAILS_ENV'] = nil create_schema end @@ -22,6 +23,20 @@ module ApplicationTests end end + def test_run_in_test_environment + app_file 'test/unit/env_test.rb', <<-RUBY + require 'test_helper' + + class EnvTest < ActiveSupport::TestCase + def test_env + puts "Current Environment: \#{Rails.env}" + end + end + RUBY + + assert_match /Current Environment: test/, run_test_command('test/unit/env_test.rb') + end + def test_run_shortcut create_test_file :models, 'foo' output = Dir.chdir(app_path) { `bundle exec rails t test/models/foo_test.rb` } @@ -200,7 +215,8 @@ module ApplicationTests end RUBY - assert_match /development/, Dir.chdir(app_path) { `RAILS_ENV=development bundle exec rails test test/unit/env_test.rb` } + ENV['RAILS_ENV'] = 'development' + assert_match /development/, run_test_command('test/unit/env_test.rb') end def test_run_different_environment_using_e_tag -- cgit v1.2.3 From 816e7d14492e2492f3b1431f657c6d7102ae1aff Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 11 Mar 2013 15:48:23 -0300 Subject: Replace assert_(no_)match args from regexps to strings to remove warnings Using regexps as arguments without parentheses end up raising: warning: ambiguous first argument; put parentheses or even spaces --- railties/test/application/test_runner_test.rb | 80 +++++++++++++-------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'railties') diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 7e719d50b2..56ca3bc1a9 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -18,8 +18,8 @@ module ApplicationTests def test_should_not_display_heading create_test_file run_test_command.tap do |output| - assert_no_match /Run options:/, output - assert_no_match /Running tests:/, output + assert_no_match "Run options:", output + assert_no_match "Running tests:", output end end @@ -34,24 +34,24 @@ module ApplicationTests end RUBY - assert_match /Current Environment: test/, run_test_command('test/unit/env_test.rb') + assert_match "Current Environment: test", run_test_command('test/unit/env_test.rb') end def test_run_shortcut create_test_file :models, 'foo' output = Dir.chdir(app_path) { `bundle exec rails t test/models/foo_test.rb` } - assert_match /1 tests, 1 assertions, 0 failures/, output + assert_match "1 tests, 1 assertions, 0 failures", output end def test_run_single_file create_test_file :models, 'foo' - assert_match /1 tests, 1 assertions, 0 failures/, run_test_command("test/models/foo_test.rb") + assert_match "1 tests, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb") end def test_run_multiple_files create_test_file :models, 'foo' create_test_file :models, 'bar' - assert_match /2 tests, 2 assertions, 0 failures/, run_test_command("test/models/foo_test.rb test/models/bar_test.rb") + assert_match "2 tests, 2 assertions, 0 failures", run_test_command("test/models/foo_test.rb test/models/bar_test.rb") end def test_run_file_with_syntax_error @@ -62,7 +62,7 @@ module ApplicationTests error_stream = Tempfile.new('error') redirect_stderr(error_stream) { run_test_command('test/models/error_test.rb') } - assert_match /SyntaxError/, error_stream.read + assert_match "SyntaxError", error_stream.read end def test_invoke_rake_db_test_load @@ -72,7 +72,7 @@ module ApplicationTests end RUBY create_test_file - assert_match /Hello World/, run_test_command + assert_match "Hello World", run_test_command end def test_run_models @@ -80,9 +80,9 @@ module ApplicationTests create_test_file :models, 'bar' create_test_file :controllers, 'foobar_controller' run_test_command("models").tap do |output| - assert_match /FooTest/, output - assert_match /BarTest/, output - assert_match /2 tests, 2 assertions, 0 failures/, output + assert_match "FooTest", output + assert_match "BarTest", output + assert_match "2 tests, 2 assertions, 0 failures", output end end @@ -91,9 +91,9 @@ module ApplicationTests create_test_file :helpers, 'bar_helper' create_test_file :controllers, 'foobar_controller' run_test_command('helpers').tap do |output| - assert_match /FooHelperTest/, output - assert_match /BarHelperTest/, output - assert_match /2 tests, 2 assertions, 0 failures/, output + assert_match "FooHelperTest", output + assert_match "BarHelperTest", output + assert_match "2 tests, 2 assertions, 0 failures", output end end @@ -103,10 +103,10 @@ module ApplicationTests create_test_file :unit, 'baz_unit' create_test_file :controllers, 'foobar_controller' run_test_command('units').tap do |output| - assert_match /FooTest/, output - assert_match /BarHelperTest/, output - assert_match /BazUnitTest/, output - assert_match /3 tests, 3 assertions, 0 failures/, output + assert_match "FooTest", output + assert_match "BarHelperTest", output + assert_match "BazUnitTest", output + assert_match "3 tests, 3 assertions, 0 failures", output end end @@ -115,9 +115,9 @@ module ApplicationTests create_test_file :controllers, 'bar_controller' create_test_file :models, 'foo' run_test_command('controllers').tap do |output| - assert_match /FooControllerTest/, output - assert_match /BarControllerTest/, output - assert_match /2 tests, 2 assertions, 0 failures/, output + assert_match "FooControllerTest", output + assert_match "BarControllerTest", output + assert_match "2 tests, 2 assertions, 0 failures", output end end @@ -126,9 +126,9 @@ module ApplicationTests create_test_file :mailers, 'bar_mailer' create_test_file :models, 'foo' run_test_command('mailers').tap do |output| - assert_match /FooMailerTest/, output - assert_match /BarMailerTest/, output - assert_match /2 tests, 2 assertions, 0 failures/, output + assert_match "FooMailerTest", output + assert_match "BarMailerTest", output + assert_match "2 tests, 2 assertions, 0 failures", output end end @@ -138,10 +138,10 @@ module ApplicationTests create_test_file :functional, 'baz_functional' create_test_file :models, 'foo' run_test_command('functionals').tap do |output| - assert_match /FooMailerTest/, output - assert_match /BarControllerTest/, output - assert_match /BazFunctionalTest/, output - assert_match /3 tests, 3 assertions, 0 failures/, output + assert_match "FooMailerTest", output + assert_match "BarControllerTest", output + assert_match "BazFunctionalTest", output + assert_match "3 tests, 3 assertions, 0 failures", output end end @@ -149,8 +149,8 @@ module ApplicationTests create_test_file :integration, 'foo_integration' create_test_file :models, 'foo' run_test_command('integration').tap do |output| - assert_match /FooIntegration/, output - assert_match /1 tests, 1 assertions, 0 failures/, output + assert_match "FooIntegration", output + assert_match "1 tests, 1 assertions, 0 failures", output end end @@ -158,8 +158,8 @@ module ApplicationTests suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration] suites.each { |suite| create_test_file suite, "foo_#{suite}" } run_test_command('') .tap do |output| - suites.each { |suite| assert_match /Foo#{suite.to_s.camelize}Test/, output } - assert_match /7 tests, 7 assertions, 0 failures/, output + suites.each { |suite| assert_match "Foo#{suite.to_s.camelize}Test", output } + assert_match "7 tests, 7 assertions, 0 failures", output end end @@ -179,16 +179,16 @@ module ApplicationTests RUBY run_test_command('test/unit/chu_2_koi_test.rb -n test_rikka').tap do |output| - assert_match /Rikka/, output - assert_no_match /Sanae/, output + assert_match "Rikka", output + assert_no_match "Sanae", output end end def test_not_load_fixtures_when_running_single_test create_model_with_fixture create_fixture_test :models, 'user' - assert_match /0 users/, run_test_command('test/models/user_test.rb') - assert_match /3 users/, run_test_command('test/models/user_test.rb -f') + assert_match "0 users", run_test_command('test/models/user_test.rb') + assert_match "3 users", run_test_command('test/models/user_test.rb -f') end def test_load_fixtures_when_running_test_suites @@ -199,7 +199,7 @@ module ApplicationTests suites.each do |suite, directory| directory ||= suite create_fixture_test directory - assert_match /3 users/, run_test_command(suite) + assert_match "3 users", run_test_command(suite) Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" } end end @@ -216,7 +216,7 @@ module ApplicationTests RUBY ENV['RAILS_ENV'] = 'development' - assert_match /development/, run_test_command('test/unit/env_test.rb') + assert_match "development", run_test_command('test/unit/env_test.rb') end def test_run_different_environment_using_e_tag @@ -230,12 +230,12 @@ module ApplicationTests end RUBY - assert_match /development/, run_test_command('-e development test/unit/env_test.rb') + assert_match "development", run_test_command('-e development test/unit/env_test.rb') end def test_generated_scaffold_works_with_rails_test create_scaffold - assert_match /0 failures, 0 errors, 0 skips/, run_test_command('') + assert_match "0 failures, 0 errors, 0 skips", run_test_command('') end private -- cgit v1.2.3 From d25a82280f977664e3b3d49c13bb68502718f6e2 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 12 Mar 2013 10:09:03 -0300 Subject: Stop calling "super" twice in Rails::Server#app Cache the value of "super" in a variable and use it instead. --- railties/lib/rails/commands/server.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index cdb29a8156..ddf45d196a 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -43,7 +43,10 @@ module Rails end def app - @app ||= super.respond_to?(:to_app) ? super.to_app : super + @app ||= begin + app = super + app.respond_to?(:to_app) ? app.to_app : app + end end def opt_parser -- cgit v1.2.3 From cd9f7508df9485ea7ec66d0172c1d6bcfe7ed5a8 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 13 Mar 2013 14:00:11 -0300 Subject: Move some railties changelog entries to the top [ci skip] --- railties/CHANGELOG.md | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index e3b1bc37c6..bbc7d31f33 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,24 +1,5 @@ ## Rails 4.0.0 (unreleased) ## - -## Rails 4.0.0.beta1 (February 25, 2013) ## -* Change Service pages(404, etc). *Stanislav Sobolev* - -* Improve `rake stats` for JavaScript and CoffeeScript: ignore block comments - and calculates number of functions. - - *Hendy Tanata* - -* Ability to use a custom builder by passing `--builder` (or `-b`) has been removed. Consider - using application template instead. See this guide for more detail: - http://guides.rubyonrails.org/rails_application_templates.html - - *Prem Sichanugrist* - -* fix rake db:* tasks to work with DATABASE_URL and without config/database.yml - - *Terence Lee* - * Rails now generates a `test/test_helper.rb` file with `fixtures :all` commented out by default, since we don't want to force loading all fixtures for user when a single test is run. However, fixtures are still going to be loaded automatically for test suites. @@ -47,10 +28,30 @@ For more information, see `rails test --help`. - This command will eventually replace `rake test:*` and `rake test` tasks + This command will eventually replace `rake test:*` and `rake test` tasks. *Prem Sichanugrist and Chris Toomey* +* Improve service pages with new layout (404, etc). *Stanislav Sobolev* + + +## Rails 4.0.0.beta1 (February 25, 2013) ## + +* Improve `rake stats` for JavaScript and CoffeeScript: ignore block comments + and calculates number of functions. + + *Hendy Tanata* + +* Ability to use a custom builder by passing `--builder` (or `-b`) has been removed. + Consider using application template instead. See this guide for more detail: + http://guides.rubyonrails.org/rails_application_templates.html + + *Prem Sichanugrist* + +* Fix `rake db:*` tasks to work with `DATABASE_URL` and without `config/database.yml`. + + *Terence Lee* + * Add notice message for destroy action in scaffold generator. *Rahul P. Chaudhari* -- cgit v1.2.3 From 3008994d1e29b7e59a64bf0a03b5408a2946db25 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Wed, 13 Mar 2013 08:08:56 -0400 Subject: Add support for generate scaffold password:digest * adds password_digest attribute to the migration * adds has_secure_password to the model * adds password and password_confirmation password_fields to _form.html * omits password entirely from index.html and show.html * adds password and password_confirmation to the controller * adds unencrypted password and password_confirmation to the controller test * adds encrypted password_digest to the fixture --- railties/CHANGELOG.md | 12 +++++++ .../erb/scaffold/templates/_form.html.erb | 9 +++++ .../erb/scaffold/templates/index.html.erb | 4 +-- .../erb/scaffold/templates/show.html.erb | 2 +- .../lib/rails/generators/generated_attribute.rb | 4 +++ railties/lib/rails/generators/named_base.rb | 1 + .../test_unit/model/templates/fixtures.yml | 16 ++++----- .../test_unit/scaffold/scaffold_generator.rb | 6 +++- .../test/generators/scaffold_generator_test.rb | 41 ++++++++++++++++++++++ 9 files changed, 82 insertions(+), 13 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index bbc7d31f33..60a823de15 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,17 @@ ## Rails 4.0.0 (unreleased) ## +* Add support for generate scaffold password:digest + + * adds password_digest attribute to the migration + * adds has_secure_password to the model + * adds password and password_confirmation password_fields to _form.html + * omits password from index.html and show.html + * adds password and password_confirmation to the controller + * adds unencrypted password and password_confirmation to the controller test + * adds encrypted password_digest to the fixture + + *Sam Ruby* + * Rails now generates a `test/test_helper.rb` file with `fixtures :all` commented out by default, since we don't want to force loading all fixtures for user when a single test is run. However, fixtures are still going to be loaded automatically for test suites. diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb index 32546936e3..85a1b01cc6 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb @@ -13,8 +13,17 @@ <% attributes.each do |attribute| -%>
+<% if attribute.password_digest? -%> + <%%= f.label :password %>
+ <%%= f.password_field :password %> +
+
+ <%%= f.label :password_confirmation %>
+ <%%= f.password_field :password_confirmation %> +<% else -%> <%%= f.label :<%= attribute.name %> %>
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> +<% end -%>
<% end -%>
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb index 90d8db1df5..d2fd99fdcb 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb @@ -3,7 +3,7 @@ -<% attributes.each do |attribute| -%> +<% attributes.reject(&:password_digest?).each do |attribute| -%> <% end -%> @@ -15,7 +15,7 @@ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %> -<% attributes.each do |attribute| -%> +<% attributes.reject(&:password_digest?).each do |attribute| -%> <% end -%> diff --git a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb index daae72270f..5e634153be 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb @@ -1,6 +1,6 @@

<%%= notice %>

-<% attributes.each do |attribute| -%> +<% attributes.reject(&:password_digest?).each do |attribute| -%>

<%= attribute.human_name %>: <%%= @<%= singular_table_name %>.<%= attribute.name %> %> diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 4ae8756ed0..5e2784c4b0 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -130,6 +130,10 @@ module Rails @has_uniq_index end + def password_digest? + name == 'password' && type == :digest + end + def inject_options "".tap { |s| @attr_options.each { |k,v| s << ", #{k}: #{v.inspect}" } } end diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 9965db98de..8b4f52bb3b 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -163,6 +163,7 @@ module Rails def attributes_names @attributes_names ||= attributes.each_with_object([]) do |a, names| names << a.column_name + names << 'password_confirmation' if a.password_digest? names << "#{a.name}_type" if a.polymorphic? end end diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml index c9d505c84a..90a92e6982 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -1,22 +1,20 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - <% unless attributes.empty? -%> -one: +<% %w(one two).each do |name| %> +<%= name %>: <% attributes.each do |attribute| -%> + <%- if attribute.password_digest? -%> + password_digest: <%%= BCrypt::Password.create('secret') %> + <%- else -%> <%= yaml_key_value(attribute.column_name, attribute.default) %> - <%- if attribute.polymorphic? -%> - <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> -<% end -%> - -two: -<% attributes.each do |attribute| -%> - <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- if attribute.polymorphic? -%> <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> <% end -%> +<% end -%> <% else -%> + # This model initially had no columns defined. If you add columns to the # model remove the '{}' from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index 8f3ecaadea..2e1f55f2a6 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -21,7 +21,11 @@ module TestUnit # :nodoc: return if attributes_names.empty? attributes_names.map do |name| - "#{name}: @#{singular_table_name}.#{name}" + if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?) + "#{name}: 'secret'" + else + "#{name}: @#{singular_table_name}.#{name}" + end end.sort.join(', ') end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 357f472a3f..b29d1e018e 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -271,4 +271,45 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end end + + def test_scaffold_generator_password_digest + run_generator ["user", "name", "password:digest"] + + assert_file "app/models/user.rb", /has_secure_password/ + + assert_migration "db/migrate/create_users.rb" do |m| + assert_method :change, m do |up| + assert_match(/t\.string :name/, up) + assert_match(/t\.string :password_digest/, up) + end + end + + assert_file "app/controllers/users_controller.rb" do |content| + assert_instance_method :user_params, content do |m| + assert_match(/permit\(:name, :password, :password_confirmation\)/, m) + end + end + + assert_file "app/views/users/_form.html.erb" do |content| + assert_match(/<%= f\.password_field :password %>/, content) + assert_match(/<%= f\.password_field :password_confirmation %>/, content) + end + + assert_file "app/views/users/index.html.erb" do |content| + assert_no_match(/password/, content) + end + + assert_file "app/views/users/show.html.erb" do |content| + assert_no_match(/password/, content) + end + + assert_file "test/controllers/users_controller_test.rb" do |content| + assert_match(/password: 'secret'/, content) + assert_match(/password_confirmation: 'secret'/, content) + end + + assert_file "test/fixtures/users.yml" do |content| + assert_match(/password_digest: <%= BCrypt::Password.create\('secret'\) %>/, content) + end + end end -- cgit v1.2.3 From 106e15927f0dd8060fc37eff44b823a92fa94bd2 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 15 Mar 2013 13:33:07 +0100 Subject: Warning removed unused variable task_name warning: assigned but unused variable - task_name --- railties/lib/rails/test_unit/testing.rake | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index de44bf9e4d..3c247f32c0 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -79,7 +79,6 @@ namespace :test do # Display deprecation message task :deprecated do - task_name = ARGV.first ActiveSupport::Deprecation.warn "`rake #{ARGV.first}` is deprecated with no replacement." end -- cgit v1.2.3 From 9b5c0850778207998a5cb8e5fe5bde6599af81d5 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 11 Mar 2013 20:46:21 +0100 Subject: config.ru uses the effective Rack app We used to pass the Rails::Application subclass to #run. The Rails server then called #to_app to convert that class to the actual Rack application. if you surround `#run` with a call to `#map` the server no longer convertes the class to the instance and we end up with unnecessary delegation calls on every request. --- railties/lib/rails/commands/server.rb | 1 + railties/lib/rails/generators/rails/app/templates/config.ru | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index ddf45d196a..876d457359 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -42,6 +42,7 @@ module Rails set_environment end + # TODO: this is no longer required but we keep it for the moment to support older config.ru files. def app @app ||= begin app = super diff --git a/railties/lib/rails/generators/rails/app/templates/config.ru b/railties/lib/rails/generators/rails/app/templates/config.ru index fcfbc6b07a..5bc2a619e8 100644 --- a/railties/lib/rails/generators/rails/app/templates/config.ru +++ b/railties/lib/rails/generators/rails/app/templates/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -run <%= app_const %> +run Rails.application -- cgit v1.2.3 From b0557389de13103c32baee438bf2d58f40176f73 Mon Sep 17 00:00:00 2001 From: Gabe Kopley Date: Mon, 18 Mar 2013 10:42:24 -0700 Subject: More helpful message when starting server v2 of pull request based on feedback from @rafaelfranca, @schneems, and @carlosantoniodasilva --- railties/lib/rails/commands/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 876d457359..e3119ecf22 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -62,7 +62,7 @@ module Rails 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 #{url}" - puts "=> Call with -d to detach" unless options[:daemonize] + puts "=> Run `rails server -h` for more startup options" trap(:INT) { exit } puts "=> Ctrl-C to shutdown server" unless options[:daemonize] -- cgit v1.2.3 From c24528fbc94dea9946a563be3bed9559583bdc57 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 18 Mar 2013 20:35:49 +0100 Subject: instruct RDoc to only parse Ruby files under lib [Fixes #9779] --- railties/railties.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/railties.gemspec b/railties/railties.gemspec index a55bf012da..f55cbc309c 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.email = 'david@loudthinking.com' s.homepage = 'http://www.rubyonrails.org' - s.files = Dir['CHANGELOG.md', 'README.rdoc', 'bin/**/*', 'lib/**/{*,.[a-z]*}'] + s.files = Dir['CHANGELOG.md', 'README.rdoc', 'bin/**/*', 'lib/**/*.rb'] s.require_path = 'lib' s.bindir = 'bin' -- cgit v1.2.3 From ddd2c75b2668d4a22681c0c39221bbdfb516cd06 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 18 Mar 2013 21:18:36 +0100 Subject: Revert "instruct RDoc to only parse Ruby files under lib [Fixes #9779]" This reverts commit c24528fbc94dea9946a563be3bed9559583bdc57. --- railties/railties.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/railties.gemspec b/railties/railties.gemspec index f55cbc309c..a55bf012da 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.email = 'david@loudthinking.com' s.homepage = 'http://www.rubyonrails.org' - s.files = Dir['CHANGELOG.md', 'README.rdoc', 'bin/**/*', 'lib/**/*.rb'] + s.files = Dir['CHANGELOG.md', 'README.rdoc', 'bin/**/*', 'lib/**/{*,.[a-z]*}'] s.require_path = 'lib' s.bindir = 'bin' -- cgit v1.2.3 From 862389c9537dbb6f65fd26c4325e07607ed437b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 18 Mar 2013 21:00:39 -0600 Subject: Use @app_env_config instead of @env_config Check pull request #9789 for more information. --- railties/lib/rails/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 2417bdca21..0ebb8e0016 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -134,7 +134,7 @@ module Rails # * "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt # def env_config - @env_config ||= begin + @app_env_config ||= begin if config.secret_key_base.nil? ActiveSupport::Deprecation.warn "You didn't set config.secret_key_base in config/initializers/secret_token.rb file. " + "This should be used instead of the old deprecated config.secret_token in order to use the new EncryptedCookieStore. " + -- cgit v1.2.3 From f0d5e32f891dcfd49fb757cc8f3a0f221e3c06a8 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 19 Mar 2013 01:11:01 -0300 Subject: Initialize @app_env_config now that the var name has changed Check 862389c9537dbb6f65fd26c4325e07607ed437b5 for more background. --- railties/lib/rails/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 0ebb8e0016..0de44984d7 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -79,7 +79,7 @@ module Rails @initialized = false @reloaders = [] @routes_reloader = nil - @env_config = nil + @app_env_config = nil @ordered_railties = nil @railties = nil end -- cgit v1.2.3 From a3d7f2c4be0e28940ceba695b252cc852b95c4c3 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 19 Mar 2013 15:13:24 -0400 Subject: fix sentence [ci skip] --- .../rails/app/templates/config/initializers/secret_token.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt index e5caab3672..efccf72d3d 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -# Your secret key for verifying the integrity of signed cookies. +# Your secret key is used for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, -- cgit v1.2.3 From 2e5f49dcbfc7806afba9210e1758c54b42227e74 Mon Sep 17 00:00:00 2001 From: Kevin Glowacz Date: Wed, 20 Mar 2013 15:09:15 -0500 Subject: Don't generate a scaffold.css if no-assets --- railties/CHANGELOG.md | 4 ++++ railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb | 1 + railties/test/generators/scaffold_generator_test.rb | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 60a823de15..3a81e0861b 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* Don't generate a scaffold.css when --no-assets is specified + + *Kevin Glowacz* + * Add support for generate scaffold password:digest * adds password_digest attribute to the migration diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 36589d65e2..2a0522e81c 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -10,6 +10,7 @@ module Rails class_option :stylesheet_engine, desc: "Engine for Stylesheets" def handle_skip + @options = @options.merge(stylesheets: false) unless options[:assets] @options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index b29d1e018e..25f299118c 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -241,7 +241,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase def test_scaffold_generator_no_assets run_generator [ "posts", "--no-assets" ] - assert_file "app/assets/stylesheets/scaffold.css" + assert_no_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/posts.js" assert_no_file "app/assets/stylesheets/posts.css" end -- cgit v1.2.3 From c07e1515f7c66f5599cbb3c7e9fe42e166bf3edc Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Wed, 20 Mar 2013 20:42:05 +1100 Subject: Add version method to top level modules --- railties/lib/rails/version.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index 87fc7690ac..d1d02e086d 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -1,10 +1,11 @@ module Rails - module VERSION #:nodoc: - MAJOR = 4 - MINOR = 0 - TINY = 0 - PRE = "beta1" + # Returns the version of the currently loaded Rails as a Gem::Version + def self.version + Gem::Version.new "4.0.0.beta1" + end - STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') + module VERSION #:nodoc: + MAJOR, MINOR, TINY, PRE = Rails.version.segments + STRING = Rails.version.to_s end end -- cgit v1.2.3 From f0e6ab59f681cb400043d51cb259fbd84920df09 Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Wed, 20 Mar 2013 20:48:58 +1100 Subject: remove references to *::VERSION, replace with *.version --- railties/lib/rails.rb | 4 ---- railties/lib/rails/commands/application.rb | 2 +- railties/lib/rails/generators/app_base.rb | 4 ++-- .../lib/rails/generators/rails/plugin_new/templates/%name%.gemspec | 2 +- railties/lib/rails/generators/rails/plugin_new/templates/Gemfile | 2 +- railties/lib/rails/info.rb | 4 ++-- railties/test/generators/plugin_new_generator_test.rb | 4 ++-- railties/test/rails_info_test.rb | 2 +- 8 files changed, 10 insertions(+), 14 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index bb98bbe5bf..84f8b82ad5 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -82,10 +82,6 @@ module Rails groups end - def version - VERSION::STRING - end - def public_path application && Pathname.new(application.paths["public"].first) end diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index 2ff29418c6..d7b8ff4439 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -1,7 +1,7 @@ require 'rails/version' if ['--version', '-v'].include?(ARGV.first) - puts "Rails #{Rails::VERSION::STRING}" + puts "Rails #{Rails.version}" exit(0) end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 4e703151ba..e312afa091 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -1,7 +1,7 @@ require 'digest/md5' require 'securerandom' require 'active_support/core_ext/string/strip' -require 'rails/version' unless defined?(Rails::VERSION) +require 'rails/version' unless defined?(Rails.version) require 'rbconfig' require 'open-uri' require 'uri' @@ -142,7 +142,7 @@ module Rails else <<-GEMFILE.strip_heredoc # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' - gem 'rails', '#{Rails::VERSION::STRING}' + gem 'rails', '#{Rails.version}' GEMFILE end end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index f7c12e67dd..6373ca711e 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] <% end -%> - <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>" + <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails.version %>" <% unless options[:skip_active_record] -%> s.add_development_dependency "<%= gem_for_database %>" diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile index 3f2b78f2fd..de00ab057d 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" <% if options[:skip_gemspec] -%> -<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails::VERSION::STRING %>" +<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails.version %>" <% else -%> # Declare your gem's dependencies in <%= name %>.gemspec. # Bundler will treat runtime dependencies like base dependencies, and diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index 592e74726e..f06ce659c5 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -29,7 +29,7 @@ module Rails def framework_version(framework) if Object.const_defined?(framework.classify) require "#{framework}/version" - "#{framework.classify}::VERSION::STRING".constantize + framework.classify.constantize.version.to_s end end @@ -75,7 +75,7 @@ module Rails # The Rails version. property 'Rails version' do - Rails::VERSION::STRING + Rails.version.to_s end property 'JavaScript Runtime' do diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 34441ef679..48425cbf81 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -292,7 +292,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_file "bukkits.gemspec" assert_file "Gemfile" do |contents| assert_no_match('gemspec', contents) - assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents) + assert_match(/gem "rails", "~> #{Rails.version}"/, contents) assert_match(/group :development do\n gem "sqlite3"\nend/, contents) assert_no_match(/# gem "jquery-rails"/, contents) end @@ -303,7 +303,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_no_file "bukkits.gemspec" assert_file "Gemfile" do |contents| assert_no_match('gemspec', contents) - assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents) + assert_match(/gem "rails", "~> #{Rails.version}"/, contents) assert_match(/group :development do\n gem "sqlite3"\nend/, contents) end end diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index b9fb071d23..47a58a7ab6 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -38,7 +38,7 @@ class InfoTest < ActiveSupport::TestCase end def test_framework_version - assert_property 'Active Support version', ActiveSupport::VERSION::STRING + assert_property 'Active Support version', ActiveSupport.version end def test_frameworks_exist -- cgit v1.2.3 From 7748d64a76ae140cb80cd54d183bc1f94c192b9d Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 22 Mar 2013 12:04:29 +0000 Subject: Send SIGTERM, not SIGQUIT. SIGTERM is the correct signal for a graceful exit. This will hopefully resolve #9761. --- railties/test/application/console_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index af495bb450..d586822501 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -127,7 +127,7 @@ class FullStackConsoleTest < ActiveSupport::TestCase end def kill(pid) - Process.kill('QUIT', pid) + Process.kill('TERM', pid) Process.wait(pid) rescue Errno::ESRCH end -- cgit v1.2.3 From c91789c76b8cd403c299e28c98a6b046cc4f0af1 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 22 Mar 2013 14:24:36 +0000 Subject: Don't kill the console Use the "quit" command instead. This seems to prevents some weirdness on OS X. See #9761. --- railties/test/application/console_test.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index d586822501..80700a1d64 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -126,12 +126,6 @@ class FullStackConsoleTest < ActiveSupport::TestCase assert_output "> " end - def kill(pid) - Process.kill('TERM', pid) - Process.wait(pid) - rescue Errno::ESRCH - end - def spawn_console pid = Process.spawn( "#{app_path}/bin/rails console --sandbox", @@ -148,15 +142,13 @@ class FullStackConsoleTest < ActiveSupport::TestCase write_prompt "Post.count", "=> 0" write_prompt "Post.create" write_prompt "Post.count", "=> 1" - - kill pid + @master.puts "quit" pid = spawn_console write_prompt "Post.count", "=> 0" write_prompt "Post.transaction { Post.create; raise }" write_prompt "Post.count", "=> 0" - ensure - kill pid if pid + @master.puts "quit" end end -- cgit v1.2.3 From 93c498b2a827fa47dbb0493fc05afbf58ec3f50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 23 Mar 2013 17:36:55 -0300 Subject: Better styles for the CSS [ci skip] --- .../generators/rails/app/templates/public/404.html | 26 +++++++++++----------- .../generators/rails/app/templates/public/422.html | 24 ++++++++++---------- .../generators/rails/app/templates/public/500.html | 26 +++++++++++----------- 3 files changed, 38 insertions(+), 38 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/public/404.html b/railties/lib/rails/generators/rails/app/templates/public/404.html index 0ee82d3722..a0daa0c156 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/404.html +++ b/railties/lib/rails/generators/rails/app/templates/public/404.html @@ -2,16 +2,15 @@ The page you were looking for doesn't exist (404) - diff --git a/railties/lib/rails/generators/rails/app/templates/public/422.html b/railties/lib/rails/generators/rails/app/templates/public/422.html index f1f32b83ae..fbb4b84d72 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/422.html +++ b/railties/lib/rails/generators/rails/app/templates/public/422.html @@ -2,16 +2,15 @@ The change you wanted was rejected (422) - diff --git a/railties/lib/rails/generators/rails/app/templates/public/500.html b/railties/lib/rails/generators/rails/app/templates/public/500.html index 9417de0cc0..e9052d35bf 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/500.html +++ b/railties/lib/rails/generators/rails/app/templates/public/500.html @@ -2,16 +2,15 @@ We're sorry, but something went wrong (500) - -- cgit v1.2.3 From 8f05fee1ff26247d6fec8f06f711a60a3c4e48fc Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Sun, 24 Mar 2013 12:43:31 +1100 Subject: add changelog entry --- railties/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 3a81e0861b..fb030dab4a 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* `Rails.version` now returns an instance of `Gem::Version` + + *Charlie Somerville* + * Don't generate a scaffold.css when --no-assets is specified *Kevin Glowacz* -- cgit v1.2.3 From 1f1adb835a679551b23de8c18514b747ef146137 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 24 Mar 2013 00:41:13 -0500 Subject: Fix test: ActiveSupport.version is returning now a Gem::Version instead of a String --- railties/test/rails_info_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 47a58a7ab6..5b9088cb64 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -38,7 +38,7 @@ class InfoTest < ActiveSupport::TestCase end def test_framework_version - assert_property 'Active Support version', ActiveSupport.version + assert_property 'Active Support version', ActiveSupport.version.to_s end def test_frameworks_exist -- cgit v1.2.3 From a8df5bdc5d3cd5ad21758d8e421130bc9518b1dd Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sun, 24 Mar 2013 19:05:41 +0530 Subject: Fix some typos --- railties/test/application/configuration_test.rb | 2 +- railties/test/application/initializers/load_path_test.rb | 2 +- railties/test/application/middleware/cookies_test.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7b45623f6c..1acf03f35a 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -599,7 +599,7 @@ module ApplicationTests assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters end - test "config.action_controller.action_on_unpermitted_parameters is :log by defaul on test" do + test "config.action_controller.action_on_unpermitted_parameters is :log by default on test" do ENV["RAILS_ENV"] = "test" require "#{app_path}/config/environment" diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb index 31811e7f92..9b18c329ec 100644 --- a/railties/test/application/initializers/load_path_test.rb +++ b/railties/test/application/initializers/load_path_test.rb @@ -23,7 +23,7 @@ module ApplicationTests assert $:.include?("#{app_path}/app/models") end - test "initializing an application allows to load code on lib path inside application class definitation" do + test "initializing an application allows to load code on lib path inside application class definition" do app_file "lib/foo.rb", <<-RUBY module Foo; end RUBY diff --git a/railties/test/application/middleware/cookies_test.rb b/railties/test/application/middleware/cookies_test.rb index 18af7abafc..bbb7627be9 100644 --- a/railties/test/application/middleware/cookies_test.rb +++ b/railties/test/application/middleware/cookies_test.rb @@ -33,7 +33,7 @@ module ApplicationTests assert_equal false, ActionDispatch::Cookies::CookieJar.always_write_cookie end - test 'always_write_cookie can be overrided' do + test 'always_write_cookie can be overridden' do add_to_config <<-RUBY config.action_dispatch.always_write_cookie = false RUBY -- cgit v1.2.3 From 7a9a7007637b8279501770be03bd84ce83d61ab8 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sun, 24 Mar 2013 14:38:06 -0400 Subject: Use jquery-rails from github completes https://github.com/rails/rails/commit/6f3f0f86332004fcee5c2f05d52bbff08c22f980 --- railties/lib/rails/generators/app_base.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index e312afa091..ef39a4b6a8 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -210,9 +210,11 @@ module Rails end def javascript_gemfile_entry + args = {'jquery' => ", github: 'rails/jquery-rails'"} + unless options[:skip_javascript] <<-GEMFILE.strip_heredoc - gem '#{options[:javascript]}-rails' + gem '#{options[:javascript]}-rails'#{args[options[:javascript]]} # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' -- cgit v1.2.3 From 0190cba99c9d3367cfba9b2d1901633715fa314c Mon Sep 17 00:00:00 2001 From: Trevor Turk Date: Sun, 24 Mar 2013 18:20:24 -0500 Subject: Introduce UpgradeLegacySignedCookieJar to transparently upgrade existing signed cookies generated by Rails 3 to avoid invalidating them when upgrading to Rails 4 --- railties/lib/rails/application.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 0de44984d7..563905e8b3 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -149,6 +149,7 @@ module Rails "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.redirect_filter" => config.filter_redirect, "action_dispatch.secret_token" => config.secret_token, + "action_dispatch.secret_key_base" => config.secret_key_base, "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions, "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local, "action_dispatch.logger" => Rails.logger, -- cgit v1.2.3 From 940da7d9cbb39bc9589031df62e26edfc0c1f8bc Mon Sep 17 00:00:00 2001 From: Gabe Kopley Date: Sun, 24 Mar 2013 22:31:48 -0700 Subject: Put coffee-rails in top-level of generated Gemfile v3 of pull request based on additional feedback from @jeremy --- railties/CHANGELOG.md | 12 ++++++++ railties/lib/rails/generators/app_base.rb | 42 +++++++++++++++++--------- railties/test/generators/app_generator_test.rb | 5 ++- 3 files changed, 43 insertions(+), 16 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index fb030dab4a..2727f1a85d 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,17 @@ ## Rails 4.0.0 (unreleased) ## +* Allow vanilla apps to render CoffeeScript templates in production + + Vanilla apps already render CoffeeScript templates in development and test + environments. With this change, the production behavior matches that of + the other environments. + + Effectively, this meant moving coffee-rails (and the JavaScript runtime on + which it is dependent) from the :assets group to the top-level of the + generated Gemfile. + + *Gabe Kopley* + * `Rails.version` now returns an instance of `Gem::Version` *Charlie Somerville* diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index ef39a4b6a8..4e05c32f74 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -178,29 +178,25 @@ module Rails return if options[:skip_sprockets] gemfile = if options.dev? || options.edge? - <<-GEMFILE + <<-GEMFILE.gsub(/^ {12}/, '') # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sprockets-rails', github: 'rails/sprockets-rails' gem 'sass-rails', github: 'rails/sass-rails' - gem 'coffee-rails', github: 'rails/coffee-rails' - - # See https://github.com/sstephenson/execjs#readme for more supported runtimes - #{javascript_runtime_gemfile_entry} + #{coffee_gemfile_entry if options[:skip_javascript]} + #{javascript_runtime_gemfile_entry(2) if options[:skip_javascript]} gem 'uglifier', '>= 1.0.3' end GEMFILE else - <<-GEMFILE + <<-GEMFILE.gsub(/^ {12}/, '') # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 4.0.0.beta1' - gem 'coffee-rails', '~> 4.0.0.beta1' - - # See https://github.com/sstephenson/execjs#readme for more supported runtimes - #{javascript_runtime_gemfile_entry} + #{coffee_gemfile_entry if options[:skip_javascript]} + #{javascript_runtime_gemfile_entry(2) if options[:skip_javascript]} gem 'uglifier', '>= 1.0.3' end GEMFILE @@ -209,11 +205,23 @@ module Rails gemfile.strip_heredoc.gsub(/^[ \t]*$/, '') end + def coffee_gemfile_entry + if options.dev? || options.edge? + "gem 'coffee-rails', github: 'rails/coffee-rails'" + else + "gem 'coffee-rails', '~> 4.0.0.beta1'" + end + end + def javascript_gemfile_entry args = {'jquery' => ", github: 'rails/jquery-rails'"} unless options[:skip_javascript] - <<-GEMFILE.strip_heredoc + <<-GEMFILE.gsub(/^ {12}/, '').strip_heredoc + #{javascript_runtime_gemfile_entry} + # Use CoffeeScript for .js.coffee assets and views + #{coffee_gemfile_entry} + gem '#{options[:javascript]}-rails'#{args[options[:javascript]]} # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks @@ -222,12 +230,16 @@ module Rails end end - def javascript_runtime_gemfile_entry - if defined?(JRUBY_VERSION) - "gem 'therubyrhino'\n" + def javascript_runtime_gemfile_entry(n_spaces=0) + runtime = if defined?(JRUBY_VERSION) + "gem 'therubyrhino'" else - "# gem 'therubyracer', platforms: :ruby\n" + "# gem 'therubyracer', platforms: :ruby" end + <<-GEMFILE.gsub(/^ {10}/, '') + # See https://github.com/sstephenson/execjs#readme for more supported runtimes + #{" "*n_spaces}#{runtime} + GEMFILE end def bundle_command(command) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0697035871..0daea2fd0a 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -232,8 +232,8 @@ class AppGeneratorTest < Rails::Generators::TestCase end assert_file "Gemfile" do |content| assert_no_match(/sass-rails/, content) - assert_no_match(/coffee-rails/, content) assert_no_match(/uglifier/, content) + assert_match(/coffee-rails/, content) end assert_file "config/environments/development.rb" do |content| assert_no_match(/config\.assets\.debug = true/, content) @@ -293,6 +293,9 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "app/assets/javascripts/application.js" do |contents| assert_no_match %r{^//=\s+require\s}, contents end + assert_file "Gemfile" do |content| + assert_match(/coffee-rails/, content) + end end def test_inclusion_of_debugger -- cgit v1.2.3 From 3b2a2419469d7116d30f46fa801abe1b29d7dc24 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 25 Mar 2013 00:01:38 -0700 Subject: Fix jquery-as-default test to account for switch from gem to github source in #9904 --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0daea2fd0a..b813a7f6bb 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -276,7 +276,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require jquery}, contents assert_match %r{^//= require jquery_ujs}, contents end - assert_gem "jquery-rails" + assert_file "Gemfile", /^gem 'jquery-rails'/ end def test_other_javascript_libraries -- cgit v1.2.3 From 6a499cd97ff4ac12b76c435643bfa9b3ba02c1ac Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Mon, 25 Mar 2013 14:40:31 +0530 Subject: Controller name pluralized --- railties/test/application/assets_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 638df8ca23..e0cbe73fc4 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -86,8 +86,8 @@ module ApplicationTests def test_precompile_does_not_hit_the_database app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/javascripts/foo/application.js", "alert();" - app_file "app/controllers/user_controller.rb", <<-eoruby - class UserController < ApplicationController; end + app_file "app/controllers/users_controller.rb", <<-eoruby + class UsersController < ApplicationController; end eoruby app_file "app/models/user.rb", <<-eoruby class User < ActiveRecord::Base; end -- cgit v1.2.3 From 5546081c4f6d074b34e855ab76bcfb062cc80e76 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Mon, 25 Mar 2013 20:47:26 +0530 Subject: Fixed typo in railties/test --- railties/test/application/asset_debugging_test.rb | 2 +- railties/test/application/initializers/i18n_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb index 1eddfac664..b3b40448c0 100644 --- a/railties/test/application/asset_debugging_test.rb +++ b/railties/test/application/asset_debugging_test.rb @@ -48,7 +48,7 @@ module ApplicationTests assert_no_match(/

<%= attribute.human_name %>
<%%= <%= singular_table_name %>.<%= attribute.name %> %><%%= link_to 'Show', <%= singular_table_name %> %>