From 9ce03d15428fee6f63e72a3de7b60f5e1ab8a97a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 8 Oct 2011 12:56:06 -0700 Subject: Skip broken asset precompilation test on Macs. Issues with NFD vs NFC normalization on the asset filename. Major red flag with asset lookups! --- railties/test/application/assets_test.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 63427c7792..3a8add3d3e 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -289,16 +289,20 @@ module ApplicationTests end test "precompile should handle utf8 filenames" do - app_file "app/assets/images/レイルズ.png", "not a image really" + if `uname` =~ /Darwin/ + skip 'Asset lookup with Unicode filenames is a problematic due to different normalization forms. Mac uses NKD for filenames; Windows and Linux use NFC. So your asset lookups may mysteriously fail. Sprockets should handle these platform issues transparently.' + end + + filename = "レイルズ.png" + app_file "app/assets/images/#{filename}", "not a image really" add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" precompile! - assert File.exists?("#{app_path}/public/assets/レイルズ.png") + assert File.exists?("#{app_path}/public/assets/#{filename}") manifest = "#{app_path}/public/assets/manifest.yml" - assets = YAML.load_file(manifest) - assert_equal "レイルズ.png", assets["レイルズ.png"] + assert_equal filename, assets[filename], assets.inspect end test "assets are cleaned up properly" do -- cgit v1.2.3 From 4888aba15f98b630d624645f7bba5a53bfdabb2f Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 8 Oct 2011 13:09:28 -0700 Subject: The generator invokes rake with either the :env option, ENV['RAILS_ENV'], or development. So if Travis has exported RAILS_ENV=test, it'll be used instead of development, breaking these brittle expectations. --- railties/test/generators/actions_test.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index e621f7f6f7..d5301dcdb2 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -179,8 +179,9 @@ class ActionsTest < Rails::Generators::TestCase action :generate, 'model', 'MyModel' end - def test_rake_should_run_rake_command_with_development_env - generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', :verbose => false) + def test_rake_should_run_rake_command_with_default_env + expected_env = ENV['RAILS_ENV'] || 'development' + generator.expects(:run).once.with("rake log:clear RAILS_ENV=#{expected_env}", :verbose => false) action :rake, 'log:clear' end @@ -206,7 +207,8 @@ class ActionsTest < Rails::Generators::TestCase end def test_rake_with_sudo_option_should_run_rake_command_with_sudo - generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false) + expected_env = ENV['RAILS_ENV'] || 'development' + generator.expects(:run).once.with("sudo rake log:clear RAILS_ENV=#{expected_env}", :verbose => false) action :rake, 'log:clear', :sudo => true end -- cgit v1.2.3 From b111b41d131fd5d90d88052bb6e95676c29a9d8d Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 8 Oct 2011 15:24:52 -0500 Subject: Test utf8 assets filenames with request instead of manifest lookup --- railties/test/application/assets_test.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 3a8add3d3e..2c9ebbf327 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -289,20 +289,16 @@ module ApplicationTests end test "precompile should handle utf8 filenames" do - if `uname` =~ /Darwin/ - skip 'Asset lookup with Unicode filenames is a problematic due to different normalization forms. Mac uses NKD for filenames; Windows and Linux use NFC. So your asset lookups may mysteriously fail. Sprockets should handle these platform issues transparently.' - end - filename = "レイルズ.png" app_file "app/assets/images/#{filename}", "not a image really" add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" precompile! - assert File.exists?("#{app_path}/public/assets/#{filename}") + require "#{app_path}/config/environment" - manifest = "#{app_path}/public/assets/manifest.yml" - assets = YAML.load_file(manifest) - assert_equal filename, assets[filename], assets.inspect + get "/assets/#{URI.escape(filename)}" + assert_match "not a image really", last_response.body + assert File.exists?("#{app_path}/public/assets/#{filename}") end test "assets are cleaned up properly" do -- cgit v1.2.3 From f655895e87c8e013caac649986510eff4d3b03d9 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 8 Oct 2011 16:27:22 -0500 Subject: Isolate rake action tests that should be run under default env --- railties/test/generators/actions_test.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index d5301dcdb2..51fa2fe16f 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -180,9 +180,11 @@ class ActionsTest < Rails::Generators::TestCase end def test_rake_should_run_rake_command_with_default_env - expected_env = ENV['RAILS_ENV'] || 'development' - generator.expects(:run).once.with("rake log:clear RAILS_ENV=#{expected_env}", :verbose => false) + generator.expects(:run).once.with("rake log:clear RAILS_ENV=development", :verbose => false) + old_env, ENV['RAILS_ENV'] = ENV["RAILS_ENV"], nil action :rake, 'log:clear' + ensure + ENV["RAILS_ENV"] = old_env end def test_rake_with_env_option_should_run_rake_command_in_env @@ -207,9 +209,11 @@ class ActionsTest < Rails::Generators::TestCase end def test_rake_with_sudo_option_should_run_rake_command_with_sudo - expected_env = ENV['RAILS_ENV'] || 'development' - generator.expects(:run).once.with("sudo rake log:clear RAILS_ENV=#{expected_env}", :verbose => false) + generator.expects(:run).once.with("sudo rake log:clear RAILS_ENV=development", :verbose => false) + old_env, ENV['RAILS_ENV'] = ENV["RAILS_ENV"], nil action :rake, 'log:clear', :sudo => true + ensure + ENV["RAILS_ENV"] = old_env end def test_capify_should_run_the_capify_command -- cgit v1.2.3 From 2886513aea90257d69c02bf77a50884a5b2ba82b Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 9 Oct 2011 15:27:35 +0530 Subject: URI.escape is obsolete : warning removed --- railties/test/application/assets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 2c9ebbf327..2710498fd0 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -296,7 +296,7 @@ module ApplicationTests precompile! require "#{app_path}/config/environment" - get "/assets/#{URI.escape(filename)}" + get "/assets/#{URI.parser.escape(filename)}" assert_match "not a image really", last_response.body assert File.exists?("#{app_path}/public/assets/#{filename}") end -- cgit v1.2.3 From ca219a21b60ea20868deab20afaa0335d32f1c17 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 9 Oct 2011 17:15:55 +0530 Subject: Warnings removed when running with 1.9.3 --- railties/test/generators/assets_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index 044e0b6bc6..d6338bd3da 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -13,7 +13,7 @@ class AssetsGeneratorTest < Rails::Generators::TestCase end def test_skipping_assets - content = run_generator ["posts", "--no-stylesheets", "--no-javascripts"] + run_generator ["posts", "--no-stylesheets", "--no-javascripts"] assert_no_file "app/assets/javascripts/posts.js" assert_no_file "app/assets/stylesheets/posts.css" end -- cgit v1.2.3 From 6d05597d0f03030a429d8154daf99a1226e6cbbd Mon Sep 17 00:00:00 2001 From: kennyj Date: Mon, 10 Oct 2011 01:54:54 +0900 Subject: fix invalid regex --- railties/test/application/assets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 2c9ebbf327..d4168ac090 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -291,7 +291,7 @@ module ApplicationTests test "precompile should handle utf8 filenames" do filename = "レイルズ.png" app_file "app/assets/images/#{filename}", "not a image really" - add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" + add_to_config "config.assets.precompile = [ /\.png$/, /application.(css|js)$/ ]" precompile! require "#{app_path}/config/environment" -- cgit v1.2.3 From 84672b0c9d8ff67d5c15c74adc7d02f758b46558 Mon Sep 17 00:00:00 2001 From: Sasha Gerrand Date: Tue, 11 Oct 2011 18:48:51 +1100 Subject: Added test to check that the vendor/assets/javascripts directory is created --- railties/test/generators/app_generator_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 1b48c80042..f951f4f633 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -203,6 +203,11 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file 'test' end + def test_creation_of_vendor_assets_javascripts_directory + run_generator + assert_file "vendor/assets/javascripts" + end + def test_jquery_is_the_default_javascript_library run_generator assert_file "app/assets/javascripts/application.js" do |contents| -- cgit v1.2.3 From dc3f33eb608c796bc4ce6b403891d6f2efe1f35f Mon Sep 17 00:00:00 2001 From: Rahul Chaudhari Date: Thu, 13 Oct 2011 12:17:19 +0530 Subject: Added test to check that the vendor/assets/stylesheets directory is created --- railties/test/generators/app_generator_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f951f4f633..133efb872f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -208,6 +208,11 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "vendor/assets/javascripts" end + def test_creation_of_vendor_assets_stylesheets_directory + run_generator + assert_file "vendor/assets/stylesheets" + end + def test_jquery_is_the_default_javascript_library run_generator assert_file "app/assets/javascripts/application.js" do |contents| -- cgit v1.2.3 From d21405a07ce9264ed92b9c7385141e05ccea565c Mon Sep 17 00:00:00 2001 From: "Rahul P. Chaudhari" Date: Mon, 17 Oct 2011 00:30:07 +0530 Subject: Added test case for postgresql database --- railties/test/generators/app_generator_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 133efb872f..2dcce4e884 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -143,6 +143,16 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_config_postgresql_database + run_generator([destination_root, "-d", "postgresql"]) + assert_file "config/database.yml", /postgresql/ + unless defined?(JRUBY_VERSION) + assert_file "Gemfile", /^gem\s+["']pg["']$/ + else + assert_file "Gemfile", /^gem\s+["']activerecord-jdbcpostgresql-adapter["']$/ + end + end + def test_config_jdbcmysql_database run_generator([destination_root, "-d", "jdbcmysql"]) assert_file "config/database.yml", /mysql/ -- cgit v1.2.3 From 40d1555091433d827e23e92e9f816e11a2db679b Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 18 Oct 2011 17:06:32 +0100 Subject: Added test for rake environment in an engine --- railties/test/railties/shared_tests.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'railties/test') diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 21fde49ff7..7653e52d26 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -21,6 +21,23 @@ module RailtiesTest assert_match "alert()", last_response.body end + def test_rake_environment_can_be_called_in_the_engine_or_plugin + boot_rails + + @plugin.write "Rakefile", <<-RUBY + APP_RAKEFILE = '#{app_path}/Rakefile' + load 'rails/tasks/engine.rake' + task :foo => :environment do + puts "Task ran" + end + RUBY + + Dir.chdir(@plugin.path) do + output = `bundle exec rake foo` + assert_match "Task ran", output + end + end + def test_copying_migrations @plugin.write "db/migrate/1_create_users.rb", <<-RUBY class CreateUsers < ActiveRecord::Migration -- cgit v1.2.3 From 5c5d5b3d2510d20998eafdd87a4458e0406e1690 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Thu, 20 Oct 2011 12:59:27 +0530 Subject: Adding ActionDispatch::RequestId in middleware test --- railties/test/application/middleware_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 093cb6ca2a..4703a59326 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -30,6 +30,7 @@ module ApplicationTests "ActiveSupport::Cache::Strategy::LocalCache", "Rack::Runtime", "Rack::MethodOverride", + "ActionDispatch::RequestId", "Rails::Rack::Logger", # must come after Rack::MethodOverride to properly log overridden methods "ActionDispatch::ShowExceptions", "ActionDispatch::RemoteIp", -- cgit v1.2.3 From a458833705cd3e9a0909d0710da84e2009f097ba Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 22 Oct 2011 14:34:05 -0500 Subject: Remove Turn from default Gemfile. We still looking for a best presentation for tests output. --- railties/test/generators/app_generator_test.rb | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 133efb872f..4b74bd6a4b 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -242,21 +242,6 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_inclusion_of_turn_gem_in_gemfile - run_generator - assert_file "Gemfile" do |contents| - assert_match(/gem 'turn'/, contents) unless RUBY_VERSION < '1.9.2' - assert_no_match(/gem 'turn'/, contents) if RUBY_VERSION < '1.9.2' - end - end - - def test_turn_gem_is_not_included_in_gemfile_if_skipping_test_unit - run_generator [destination_root, "--skip-test-unit"] - assert_file "Gemfile" do |contents| - assert_no_match(/gem 'turn'/, contents) unless RUBY_VERSION < '1.9.2' - end - end - def test_inclusion_of_ruby_debug run_generator assert_file "Gemfile" do |contents| -- cgit v1.2.3 From 20c59dd214b771efd978c7b35b314a785ffc176a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 26 Oct 2011 09:17:14 +0200 Subject: Fix failing tests. --- railties/test/application/rack/logger_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb index 8b2b2f1802..387eb25525 100644 --- a/railties/test/application/rack/logger_test.rb +++ b/railties/test/application/rack/logger_test.rb @@ -12,6 +12,8 @@ module ApplicationTests build_app require "#{app_path}/config/environment" super + @logger = MockLogger.new + Rails.stubs(:logger).returns(@logger) end def teardown -- cgit v1.2.3 From 177f893a28ca2bdf2bdb204e8af139ed90f3266d Mon Sep 17 00:00:00 2001 From: Denis Odorcic Date: Thu, 27 Oct 2011 02:16:59 -0400 Subject: Fix railtie configuration test calling PostsController#create which didn't exist --- railties/test/application/configuration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 97ad47ac14..f356805d6e 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -476,7 +476,7 @@ module ApplicationTests app_file 'app/controllers/posts_controller.rb', <<-RUBY class PostsController < ApplicationController - def index + def create render :text => params[:post].inspect end end -- cgit v1.2.3 From 010622bb989cb9fa3aac600a7fa7bcb894bb081a Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Sat, 15 Oct 2011 17:20:54 +0800 Subject: On inpsect routes, show :controller and :action to indicate dynamic. --- railties/test/application/route_inspect_test.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb index add8256b5d..78980705ed 100644 --- a/railties/test/application/route_inspect_test.rb +++ b/railties/test/application/route_inspect_test.rb @@ -49,12 +49,20 @@ module ApplicationTests assert_equal ["root / pages#main"], output end + def test_inspect_routes_shows_dynamic_action_route + @set.draw do + match 'api/:action' => 'api' + end + output = @inspector.format @set.routes + assert_equal [" /api/:action(.:format) api#:action"], output + end + def test_inspect_routes_shows_controller_and_action_only_route @set.draw do match ':controller/:action' end output = @inspector.format @set.routes - assert_equal [" /:controller/:action(.:format) "], output + assert_equal [" /:controller/:action(.:format) :controller#:action"], output end def test_inspect_routes_shows_controller_and_action_route_with_constraints @@ -62,7 +70,7 @@ module ApplicationTests match ':controller(/:action(/:id))', :id => /\d+/ end output = @inspector.format @set.routes - assert_equal [" /:controller(/:action(/:id))(.:format) {:id=>/\\d+/}"], output + assert_equal [" /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/\\d+/}"], output end def test_rake_routes_shows_route_with_defaults -- cgit v1.2.3 From eabda416b7c66f3b8d03237e7334bd2d14ff9190 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 29 Oct 2011 14:14:13 -0700 Subject: Removing db/seeds.rb is fine. Don't blow up. --- railties/test/railties/engine_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 06a60cd858..22dbcf9644 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -455,12 +455,18 @@ module RailtiesTest Rails.application.load_seed assert Rails.application.config.app_seeds_loaded - assert_raise(NoMethodError) do Bukkits::Engine.config.bukkits_seeds_loaded end + assert_raise(NoMethodError) { Bukkits::Engine.config.bukkits_seeds_loaded } Bukkits::Engine.load_seed assert Bukkits::Engine.config.bukkits_seeds_loaded end + test "skips nonexistent seed data" do + FileUtils.rm "#{app_path}/db/seeds.rb" + boot_rails + assert_nil Rails.application.load_seed + end + test "using namespace more than once on one module should not overwrite _railtie method" do @plugin.write "lib/bukkits.rb", <<-RUBY module AppTemplate -- cgit v1.2.3 From 5745a5e85e1900c52d169f79ec0802060e110e21 Mon Sep 17 00:00:00 2001 From: Colin MacKenzie IV Date: Wed, 2 Nov 2011 09:00:18 -0400 Subject: treat USAGE as an ERB template --- railties/test/fixtures/lib/generators/usage_template/USAGE | 1 + .../lib/generators/usage_template/usage_template_generator.rb | 5 +++++ railties/test/generators_test.rb | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 railties/test/fixtures/lib/generators/usage_template/USAGE create mode 100644 railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/lib/generators/usage_template/USAGE b/railties/test/fixtures/lib/generators/usage_template/USAGE new file mode 100644 index 0000000000..bcd63c52e2 --- /dev/null +++ b/railties/test/fixtures/lib/generators/usage_template/USAGE @@ -0,0 +1 @@ +:: <%= 1 + 1 %> :: \ No newline at end of file diff --git a/railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb b/railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb new file mode 100644 index 0000000000..078b0f9412 --- /dev/null +++ b/railties/test/fixtures/lib/generators/usage_template/usage_template_generator.rb @@ -0,0 +1,5 @@ +require 'rails/generators' + +class UsageTemplateGenerator < Rails::Generators::Base + source_root File.expand_path("templates", File.dirname(__FILE__)) +end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 56329f3183..5f9ee220dc 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -201,4 +201,10 @@ class GeneratorsTest < Rails::Generators::TestCase mspec = Rails::Generators.find_by_namespace :fixjour assert mspec.source_paths.include?(File.join(Rails.root, "lib", "templates", "fixjour")) end + + def test_usage_with_embedded_ruby + require File.expand_path("fixtures/lib/generators/usage_template/usage_template_generator", File.dirname(__FILE__)) + output = capture(:stdout) { Rails::Generators.invoke :usage_template, ['--help'] } + assert_match /:: 2 ::/, output + end end -- cgit v1.2.3 From 7102a3d7fc55067b6cda1a7eeb3b3452050d9b6b Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 4 Nov 2011 04:50:53 +0900 Subject: move Rails console top level methods to IRB context --- railties/test/application/console_test.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 1528d5dd87..5a1f71ddad 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -18,16 +18,20 @@ class ConsoleTest < Test::Unit::TestCase Rails.application.load_console end + def irb_context + Object.new.extend(IRB::ExtendCommandBundle) + end + def test_app_method_should_return_integration_session TestHelpers::Rack.send :remove_method, :app load_environment - console_session = app + console_session = irb_context.app assert_instance_of ActionDispatch::Integration::Session, console_session end def test_new_session_should_return_integration_session load_environment - session = new_session + session = irb_context.new_session assert_instance_of ActionDispatch::Integration::Session, session end @@ -41,7 +45,7 @@ class ConsoleTest < Test::Unit::TestCase ActionDispatch::Reloader.to_prepare { c = 3 } # Hide Reloading... output - silence_stream(STDOUT) { reload! } + silence_stream(STDOUT) { irb_context.reload! } assert_equal 1, a assert_equal 2, b @@ -66,12 +70,14 @@ class ConsoleTest < Test::Unit::TestCase MODEL assert !User.new.respond_to?(:age) - silence_stream(STDOUT) { reload! } + silence_stream(STDOUT) { irb_context.reload! } + session = irb_context.new_session assert User.new.respond_to?(:age) end def test_access_to_helpers load_environment + helper = irb_context.helper assert_not_nil helper assert_instance_of ActionView::Base, helper assert_equal 'Once upon a time in a world...', -- cgit v1.2.3 From 6d09f275c6e3224a8ea9a738512c90ee5334e20d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 9 Nov 2011 15:42:19 +0900 Subject: Modulize Rails console methods so that other console libraries such as Pry can include these methods --- railties/test/application/console_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 5a1f71ddad..b3745f194e 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -19,7 +19,7 @@ class ConsoleTest < Test::Unit::TestCase end def irb_context - Object.new.extend(IRB::ExtendCommandBundle) + Object.new.extend(Rails::ConsoleMethods) end def test_app_method_should_return_integration_session -- cgit v1.2.3 From 49349089ad38b403bf3f395ebf8fbc44cd232b49 Mon Sep 17 00:00:00 2001 From: Tyler Coville Date: Wed, 9 Nov 2011 23:22:26 -0800 Subject: Fixed error with 'rails generate new plugin' where the .gitignore was not properly generated if --dummy-path was used and added test case --- railties/test/generators/plugin_new_generator_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 9183945619..b70f9f4d9c 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -236,6 +236,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "spec/dummy/config/application.rb" assert_no_file "test" end + + def test_ensure_that_gitignore_can_be_generated_from_a_template_for_dummy_path + FileUtils.cd(Rails.root) + run_generator([destination_root, "--dummy_path", "spec/dummy" "--skip-test-unit"]) + assert_file ".gitignore" do |contents| + assert_match(/spec\/dummy/, contents) + end + end def test_skipping_test_unit run_generator [destination_root, "--skip-test-unit"] -- cgit v1.2.3 From 49cd6a0ff7a3f5b0e85707961c952bdc3b0a178f Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Mon, 14 Nov 2011 07:07:38 -0500 Subject: Added therubyrhino to default Gemfile under JRuby --- railties/test/generators/app_generator_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 955ed09361..a1bd2fbaa5 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -208,6 +208,13 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "test/performance/browsing_test.rb" end + def test_inclusion_of_therubyrhino_under_jruby + if defined?(JRUBY_VERSION) + run_generator([destination_root]) + assert_file "Gemfile", /gem\s+["']therubyrhino["']$/ + end + end + def test_creation_of_a_test_directory run_generator assert_file 'test' -- cgit v1.2.3 From 76b6027cd80685617b5bf5ceb986fd5dc8e213b2 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 11 Nov 2011 15:34:47 +0530 Subject: Unused variable removed --- railties/test/application/console_test.rb | 1 - railties/test/application/rackup_test.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index b3745f194e..2073c780bf 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -71,7 +71,6 @@ class ConsoleTest < Test::Unit::TestCase assert !User.new.respond_to?(:age) silence_stream(STDOUT) { irb_context.reload! } - session = irb_context.new_session assert User.new.respond_to?(:age) end diff --git a/railties/test/application/rackup_test.rb b/railties/test/application/rackup_test.rb index ff9cdcadc7..86e1995def 100644 --- a/railties/test/application/rackup_test.rb +++ b/railties/test/application/rackup_test.rb @@ -6,7 +6,7 @@ module ApplicationTests def rackup require "rack" - app, options = Rack::Builder.parse_file("#{app_path}/config.ru") + app, _ = Rack::Builder.parse_file("#{app_path}/config.ru") app end -- cgit v1.2.3 From 39d2251d8a3e50bf004b6361e0079679466b2280 Mon Sep 17 00:00:00 2001 From: lest Date: Sat, 19 Nov 2011 19:03:44 +0200 Subject: fix rails plugin new CamelCasedName bug refs #3684 --- railties/test/generators/plugin_new_generator_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index b70f9f4d9c..826eac904e 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -37,6 +37,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "things-43/lib/things-43.rb", /module Things43/ end + def test_camelcase_plugin_name_underscores_filenames + run_generator [File.join(destination_root, "CamelCasedName")] + assert_no_file "CamelCasedName/lib/CamelCasedName.rb" + assert_file "CamelCasedName/lib/camel_cased_name.rb", /module CamelCasedName/ + end + def test_generating_without_options run_generator assert_file "README.rdoc", /Bukkits/ -- cgit v1.2.3 From fd86a1b6b068df87164d5763bdcd4a323a1e76f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 19:06:45 +0000 Subject: Rely on a public contract between railties instead of accessing railtie methods directly. --- railties/test/railties/engine_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 22dbcf9644..e8081c977f 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -323,7 +323,7 @@ module RailtiesTest assert_equal "bukkits_", Bukkits.table_name_prefix assert_equal "bukkits", Bukkits::Engine.engine_name - assert_equal Bukkits._railtie, Bukkits::Engine + assert_equal Bukkits.railtie_namespace, Bukkits::Engine assert ::Bukkits::MyMailer.method_defined?(:foo_path) assert !::Bukkits::MyMailer.method_defined?(:bar_path) @@ -467,7 +467,7 @@ module RailtiesTest assert_nil Rails.application.load_seed end - test "using namespace more than once on one module should not overwrite _railtie method" do + test "using namespace more than once on one module should not overwrite railtie_namespace method" do @plugin.write "lib/bukkits.rb", <<-RUBY module AppTemplate class Engine < ::Rails::Engine @@ -484,7 +484,7 @@ module RailtiesTest boot_rails - assert_equal AppTemplate._railtie, AppTemplate::Engine + assert_equal AppTemplate.railtie_namespace, AppTemplate::Engine end test "properly reload routes" do -- cgit v1.2.3 From 40b19e063592fc30705f17aafe6a458e7b622ff2 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 22 Nov 2011 23:26:27 +0100 Subject: Allow to change engine's loading priority with config.railties_order= --- railties/test/railties/engine_test.rb | 126 ++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) (limited to 'railties/test') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index e8081c977f..400cae98b2 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -667,6 +667,132 @@ module RailtiesTest assert_equal expected, methods end + test "setting priority for engines with config.railties_order" do + @blog = engine "blog" do |plugin| + plugin.write "lib/blog.rb", <<-RUBY + module Blog + class Engine < ::Rails::Engine + end + end + RUBY + end + + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + isolate_namespace Bukkits + end + end + RUBY + + controller "main", <<-RUBY + class MainController < ActionController::Base + def foo + render :inline => '<%= render :partial => "shared/foo" %>' + end + + def bar + render :inline => '<%= render :partial => "shared/bar" %>' + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + match "/foo" => "main#foo" + match "/bar" => "main#bar" + end + RUBY + + @plugin.write "app/views/shared/_foo.html.erb", <<-RUBY + Bukkit's foo partial + RUBY + + app_file "app/views/shared/_foo.html.erb", <<-RUBY + App's foo partial + RUBY + + @blog.write "app/views/shared/_bar.html.erb", <<-RUBY + Blog's bar partial + RUBY + + app_file "app/views/shared/_bar.html.erb", <<-RUBY + App's bar partial + RUBY + + @plugin.write "app/assets/javascripts/foo.js", <<-RUBY + // Bukkit's foo js + RUBY + + app_file "app/assets/javascripts/foo.js", <<-RUBY + // App's foo js + RUBY + + @blog.write "app/assets/javascripts/bar.js", <<-RUBY + // Blog's bar js + RUBY + + app_file "app/assets/javascripts/bar.js", <<-RUBY + // App's bar js + RUBY + + add_to_config("config.railties_order = [:all, :main_app, Blog::Engine]") + + boot_rails + require "#{rails_root}/config/environment" + + get("/foo") + assert_equal "Bukkit's foo partial", last_response.body.strip + + get("/bar") + assert_equal "App's bar partial", last_response.body.strip + + get("/assets/foo.js") + assert_equal "// Bukkit's foo js\n;", last_response.body.strip + + get("/assets/bar.js") + assert_equal "// App's bar js\n;", last_response.body.strip + end + + test "railties_order adds :all with lowest priority if not given" do + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + end + end + RUBY + + controller "main", <<-RUBY + class MainController < ActionController::Base + def foo + render :inline => '<%= render :partial => "shared/foo" %>' + end + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + match "/foo" => "main#foo" + end + RUBY + + @plugin.write "app/views/shared/_foo.html.erb", <<-RUBY + Bukkit's foo partial + RUBY + + app_file "app/views/shared/_foo.html.erb", <<-RUBY + App's foo partial + RUBY + + add_to_config("config.railties_order = [Bukkits::Engine]") + + boot_rails + require "#{rails_root}/config/environment" + + get("/foo") + assert_equal "Bukkit's foo partial", last_response.body.strip + end + private def app Rails.application -- cgit v1.2.3 From 98a1717e7c094d011c89ea1ed88673a595af2de8 Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 23 Nov 2011 23:36:56 +0300 Subject: configuration option to always write cookie --- .../test/application/middleware/cookies_test.rb | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 railties/test/application/middleware/cookies_test.rb (limited to 'railties/test') diff --git a/railties/test/application/middleware/cookies_test.rb b/railties/test/application/middleware/cookies_test.rb new file mode 100644 index 0000000000..13556cbed2 --- /dev/null +++ b/railties/test/application/middleware/cookies_test.rb @@ -0,0 +1,47 @@ +require 'isolation/abstract_unit' + +module ApplicationTests + class CookiesTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def new_app + File.expand_path("#{app_path}/../new_app") + end + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + end + + def teardown + teardown_app + FileUtils.rm_rf(new_app) if File.directory?(new_app) + end + + test 'always_write_cookie is true by default in development' do + require 'rails' + Rails.env = 'development' + require "#{app_path}/config/environment" + assert_equal true, ActionDispatch::Cookies::CookieJar.always_write_cookie + end + + test 'always_write_cookie is false by default in production' do + require 'rails' + Rails.env = 'production' + require "#{app_path}/config/environment" + assert_equal false, ActionDispatch::Cookies::CookieJar.always_write_cookie + end + + test 'always_write_cookie can be overrided' do + add_to_config <<-RUBY + config.action_dispatch.always_write_cookie = false + RUBY + + require 'rails' + Rails.env = 'development' + require "#{app_path}/config/environment" + assert_equal false, ActionDispatch::Cookies::CookieJar.always_write_cookie + end + end +end -- cgit v1.2.3 From 0cd3bf84068dd2b2d0bbb26062f2cdc7093a1b04 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 24 Nov 2011 01:45:50 +0100 Subject: Allow to display engine's routes when running `rake routes ENGINES=true` --- railties/test/application/route_inspect_test.rb | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb index 78980705ed..130d4e52f8 100644 --- a/railties/test/application/route_inspect_test.rb +++ b/railties/test/application/route_inspect_test.rb @@ -1,6 +1,7 @@ require 'test/unit' require 'rails/application/route_inspector' require 'action_controller' +require 'rails/engine' module ApplicationTests class RouteInspectTest < Test::Unit::TestCase @@ -9,6 +10,35 @@ module ApplicationTests @inspector = Rails::Application::RouteInspector.new end + def test_displaying_routes_for_engines + ENV["ENGINES"] = "true" + + engine = Class.new(Rails::Engine) do + def self.to_s + "Blog::Engine" + end + end + engine.routes.draw do + get '/cart', :to => 'cart#show' + end + + @set.draw do + get '/custom/assets', :to => 'custom_assets#show' + mount engine => "/blog", :as => "blog" + end + + output = @inspector.format @set.routes + expected = [ + "custom_assets GET /custom/assets(.:format) custom_assets#show", + " blog /blog Blog::Engine", + "\nRoutes for Blog::Engine:", + "cart GET /cart(.:format) cart#show" + ] + assert_equal expected, output + ensure + ENV["ENGINES"] = nil + end + def test_cart_inspect @set.draw do get '/cart', :to => 'cart#show' -- cgit v1.2.3 From ebb8ea22f30dc029f4a868a550828443b160f639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 09:13:19 +0000 Subject: Add generators for serializers. --- .../test/generators/serializer_generator_test.rb | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 railties/test/generators/serializer_generator_test.rb (limited to 'railties/test') diff --git a/railties/test/generators/serializer_generator_test.rb b/railties/test/generators/serializer_generator_test.rb new file mode 100644 index 0000000000..2afaa65693 --- /dev/null +++ b/railties/test/generators/serializer_generator_test.rb @@ -0,0 +1,63 @@ +require 'generators/generators_test_helper' +require 'rails/generators/rails/serializer/serializer_generator' + +class SerializerGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + arguments %w(account name:string description:text business:references) + + def test_generates_a_serializer + run_generator + assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer/ + end + + def test_generates_a_namespaced_serializer + run_generator ["admin/account"] + assert_file "app/serializers/admin/account_serializer.rb", /class Admin::AccountSerializer < ActiveModel::Serializer/ + end + + def test_uses_application_serializer_if_one_exists + Object.const_set(:ApplicationSerializer, Class.new) + run_generator + assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ApplicationSerializer/ + ensure + Object.send :remove_const, :ApplicationSerializer + end + + def test_uses_namespace_application_serializer_if_one_exists + Object.const_set(:SerializerNamespace, Module.new) + SerializerNamespace.const_set(:ApplicationSerializer, Class.new) + Rails::Generators.namespace = SerializerNamespace + run_generator + assert_file "app/serializers/serializer_namespace/account_serializer.rb", + /module SerializerNamespace\n class AccountSerializer < ApplicationSerializer/ + ensure + Object.send :remove_const, :SerializerNamespace + Rails::Generators.namespace = nil + end + + def test_uses_given_parent + Object.const_set(:ApplicationSerializer, Class.new) + run_generator ["Account", "--parent=MySerializer"] + assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < MySerializer/ + ensure + Object.send :remove_const, :ApplicationSerializer + end + + def test_generates_attributes_and_associations + run_generator + assert_file "app/serializers/account_serializer.rb" do |serializer| + assert_match(/^ attributes :name, :description$/, serializer) + assert_match(/^ has_one :business$/, serializer) + end + end + + def test_with_no_attributes_does_not_add_extra_space + run_generator ["account"] + assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer\nend/ + end + + def test_invokes_default_test_framework + run_generator + assert_file "test/unit/account_serializer_test.rb", /class AccountSerializerTest < ActiveSupport::TestCase/ + end +end -- cgit v1.2.3 From 6d9f9b3b05f6ea55aad9853888912bcca4d81c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 09:17:32 +0000 Subject: Add a hook for serializers in the scaffold generator (off for now). --- railties/test/generators/scaffold_generator_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 2db8090621..2e8b03fbef 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -264,6 +264,15 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/assets/stylesheets/posts.css" end + def test_scaffold_also_generators_serializer + run_generator [ "posts", "name:string", "author:references", "--serializer" ] + assert_file "app/serializers/post_serializer.rb" do |serializer| + assert_match /class PostSerializer < ActiveModel::Serializer/, serializer + assert_match /^ attributes :name$/, serializer + assert_match /^ has_one :author$/, serializer + end + end + def test_scaffold_generator_outputs_error_message_on_missing_attribute_type run_generator ["post", "title", "body:text", "author"] -- cgit v1.2.3 From c8d7291b6b5736562b112007365317648ae2b790 Mon Sep 17 00:00:00 2001 From: ganesh Date: Fri, 25 Nov 2011 14:55:28 +0530 Subject: Added tests for #3751 --- railties/test/generators/actions_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 51fa2fe16f..917b196777 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -113,7 +113,7 @@ class ActionsTest < Rails::Generators::TestCase gem 'fakeweb' end - assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/ + assert_file 'Gemfile', /\ngroup :development, :test do\n \ngem "rspec-rails"\nend\n\ngroup :test do\n \ngem "fakeweb"\nend/ end def test_environment_should_include_data_in_environment_initializer_block -- cgit v1.2.3 From cd9d28d6fdff6819dac3c6643fe882eb568b5a39 Mon Sep 17 00:00:00 2001 From: lest Date: Thu, 24 Nov 2011 22:37:48 +0300 Subject: middlewares should use logger from env --- railties/test/application/configuration_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index f356805d6e..f37a024a0b 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -524,6 +524,7 @@ module ApplicationTests assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions + assert_equal app.env_config['action_dispatch.logger'], Rails.logger end end end -- cgit v1.2.3 From c9bb099318dd3bc293a6cb4672333147c1cce4b9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 25 Nov 2011 12:42:11 +0100 Subject: Display mounted engines in `rake routes` by default --- railties/test/application/route_inspect_test.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb index 130d4e52f8..2ad5ee6c4c 100644 --- a/railties/test/application/route_inspect_test.rb +++ b/railties/test/application/route_inspect_test.rb @@ -11,8 +11,6 @@ module ApplicationTests end def test_displaying_routes_for_engines - ENV["ENGINES"] = "true" - engine = Class.new(Rails::Engine) do def self.to_s "Blog::Engine" @@ -35,8 +33,6 @@ module ApplicationTests "cart GET /cart(.:format) cart#show" ] assert_equal expected, output - ensure - ENV["ENGINES"] = nil end def test_cart_inspect -- cgit v1.2.3 From 95e9b5fbfd87b81bf2d2b16a6df6d9ddbfdb686d Mon Sep 17 00:00:00 2001 From: John Donahue Date: Fri, 25 Nov 2011 09:06:14 -0800 Subject: Updating newline fix to maintain existing linebreaks and indentation and test for b/eol on inserts --- railties/test/generators/actions_test.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 917b196777..c1fd6a38f1 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -95,11 +95,13 @@ class ActionsTest < Rails::Generators::TestCase def test_gem_should_insert_on_separate_lines run_generator + File.open('Gemfile', 'a') {|f| f.write('# Some content...') } + action :gem, 'rspec' action :gem, 'rspec-rails' - assert_file 'Gemfile', /gem "rspec"$/ - assert_file 'Gemfile', /gem "rspec-rails"$/ + assert_file 'Gemfile', /^gem "rspec"$/ + assert_file 'Gemfile', /^gem "rspec-rails"$/ end def test_gem_group_should_wrap_gems_in_a_group @@ -112,8 +114,8 @@ class ActionsTest < Rails::Generators::TestCase action :gem_group, :test do gem 'fakeweb' end - - assert_file 'Gemfile', /\ngroup :development, :test do\n \ngem "rspec-rails"\nend\n\ngroup :test do\n \ngem "fakeweb"\nend/ + + assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/ end def test_environment_should_include_data_in_environment_initializer_block -- cgit v1.2.3 From 0a4035b12a6c59253cb60f9e3456513c6a6a9d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 19:29:39 +0000 Subject: Revert the serializers API as other alternatives are now also under discussion --- .../test/generators/scaffold_generator_test.rb | 9 ---- .../test/generators/serializer_generator_test.rb | 63 ---------------------- 2 files changed, 72 deletions(-) delete mode 100644 railties/test/generators/serializer_generator_test.rb (limited to 'railties/test') diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 2e8b03fbef..2db8090621 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -264,15 +264,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/assets/stylesheets/posts.css" end - def test_scaffold_also_generators_serializer - run_generator [ "posts", "name:string", "author:references", "--serializer" ] - assert_file "app/serializers/post_serializer.rb" do |serializer| - assert_match /class PostSerializer < ActiveModel::Serializer/, serializer - assert_match /^ attributes :name$/, serializer - assert_match /^ has_one :author$/, serializer - end - end - def test_scaffold_generator_outputs_error_message_on_missing_attribute_type run_generator ["post", "title", "body:text", "author"] diff --git a/railties/test/generators/serializer_generator_test.rb b/railties/test/generators/serializer_generator_test.rb deleted file mode 100644 index 2afaa65693..0000000000 --- a/railties/test/generators/serializer_generator_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/serializer/serializer_generator' - -class SerializerGeneratorTest < Rails::Generators::TestCase - include GeneratorsTestHelper - arguments %w(account name:string description:text business:references) - - def test_generates_a_serializer - run_generator - assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer/ - end - - def test_generates_a_namespaced_serializer - run_generator ["admin/account"] - assert_file "app/serializers/admin/account_serializer.rb", /class Admin::AccountSerializer < ActiveModel::Serializer/ - end - - def test_uses_application_serializer_if_one_exists - Object.const_set(:ApplicationSerializer, Class.new) - run_generator - assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ApplicationSerializer/ - ensure - Object.send :remove_const, :ApplicationSerializer - end - - def test_uses_namespace_application_serializer_if_one_exists - Object.const_set(:SerializerNamespace, Module.new) - SerializerNamespace.const_set(:ApplicationSerializer, Class.new) - Rails::Generators.namespace = SerializerNamespace - run_generator - assert_file "app/serializers/serializer_namespace/account_serializer.rb", - /module SerializerNamespace\n class AccountSerializer < ApplicationSerializer/ - ensure - Object.send :remove_const, :SerializerNamespace - Rails::Generators.namespace = nil - end - - def test_uses_given_parent - Object.const_set(:ApplicationSerializer, Class.new) - run_generator ["Account", "--parent=MySerializer"] - assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < MySerializer/ - ensure - Object.send :remove_const, :ApplicationSerializer - end - - def test_generates_attributes_and_associations - run_generator - assert_file "app/serializers/account_serializer.rb" do |serializer| - assert_match(/^ attributes :name, :description$/, serializer) - assert_match(/^ has_one :business$/, serializer) - end - end - - def test_with_no_attributes_does_not_add_extra_space - run_generator ["account"] - assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer\nend/ - end - - def test_invokes_default_test_framework - run_generator - assert_file "test/unit/account_serializer_test.rb", /class AccountSerializerTest < ActiveSupport::TestCase/ - end -end -- cgit v1.2.3 From 4e5eaae1faebe5e889a50a3c3cfade397f39863c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ku=C5=BAma?= Date: Sat, 26 Nov 2011 19:57:51 +0100 Subject: added tests, replaced classify with constantize - using classify here cuts the last 's' in ORM name --- railties/test/generators/orm_test.rb | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 railties/test/generators/orm_test.rb (limited to 'railties/test') diff --git a/railties/test/generators/orm_test.rb b/railties/test/generators/orm_test.rb new file mode 100644 index 0000000000..9dd3d3e0ec --- /dev/null +++ b/railties/test/generators/orm_test.rb @@ -0,0 +1,38 @@ +require "generators/generators_test_helper" +require "rails/generators/rails/scaffold_controller/scaffold_controller_generator" + +# Mock out two ORMs +module ORMWithGenerators + module Generators + class ActiveModel + def initialize(name) + end + end + end +end + +module ORMWithoutGenerators + # No generators +end + +class OrmTest < Rails::Generators::TestCase + include GeneratorsTestHelper + tests Rails::Generators::ScaffoldControllerGenerator + + def test_orm_class_returns_custom_generator_if_supported_custom_orm_set + g = generator ["Foo"], :orm => "ORMWithGenerators" + assert_equal ORMWithGenerators::Generators::ActiveModel, g.send(:orm_class) + end + + def test_orm_class_returns_rails_generator_if_unsupported_custom_orm_set + g = generator ["Foo"], :orm => "ORMWithoutGenerators" + assert_equal Rails::Generators::ActiveModel, g.send(:orm_class) + end + + def test_orm_instance_returns_orm_class_instance_with_name + g = generator ["Foo"] + orm_instance = g.send(:orm_instance) + assert g.send(:orm_class) === orm_instance + assert_equal "foo", orm_instance.name + end +end -- cgit v1.2.3 From 78ad94aaa7b70fee6c8f49de04f26d4ec14fa162 Mon Sep 17 00:00:00 2001 From: kennyj Date: Sun, 27 Nov 2011 20:25:05 +0900 Subject: avoid absolute path for the rails.png in index.html --- railties/test/generators/app_generator_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index a1bd2fbaa5..235c08e38e 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -55,6 +55,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "app/views/layouts/application.html.erb", /javascript_include_tag\s+"application"/ assert_file "app/assets/stylesheets/application.css" assert_file "config/application.rb", /config\.assets\.enabled = true/ + assert_file "public/index.html", /url\("assets\/rails.png"\);/ end def test_invalid_application_name_raises_an_error -- cgit v1.2.3 From fe7d4f09ef2296e45ab4a82c1556c63382856607 Mon Sep 17 00:00:00 2001 From: lest Date: Mon, 28 Nov 2011 19:25:37 +0300 Subject: put backtrace_cleaner to env --- railties/test/application/configuration_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index f37a024a0b..28ffff58ca 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -521,10 +521,11 @@ module ApplicationTests make_basic_app assert_respond_to app, :env_config - assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters - assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token - assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions - assert_equal app.env_config['action_dispatch.logger'], Rails.logger + assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters + assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token + assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions + assert_equal app.env_config['action_dispatch.logger'], Rails.logger + assert_equal app.env_config['action_dispatch.backtrace_cleaner'], Rails.backtrace_cleaner end end end -- cgit v1.2.3 From 4da879079e103346525523d5e687dfabb1120a77 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 29 Nov 2011 23:36:12 -0800 Subject: `run_test` method conflicts with newer minitest, so change the name --- railties/test/application/test_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb index 27a7959e84..a06facc04b 100644 --- a/railties/test/application/test_test.rb +++ b/railties/test/application/test_test.rb @@ -24,7 +24,7 @@ module ApplicationTests end RUBY - run_test 'unit/foo_test.rb' + run_test_file 'unit/foo_test.rb' end # Run just in Ruby < 1.9 @@ -40,7 +40,7 @@ module ApplicationTests end RUBY - run_test 'unit/backtrace_test.rb' + run_test_file 'unit/backtrace_test.rb' end end @@ -66,7 +66,7 @@ module ApplicationTests end RUBY - run_test 'integration/posts_test.rb' + run_test_file 'integration/posts_test.rb' end test "performance test" do @@ -91,11 +91,11 @@ module ApplicationTests end RUBY - run_test 'performance/posts_test.rb' + run_test_file 'performance/posts_test.rb' end private - def run_test(name) + def run_test_file(name) result = ruby '-Itest', "#{app_path}/test/#{name}" assert_equal 0, $?.to_i, result end -- cgit v1.2.3 From 13cab6ef50ab665e634f2834acbb0212300a3797 Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 30 Nov 2011 21:51:01 +0300 Subject: fix exception page when template contains utf-8 and parameters contain utf-8 --- .../application/middleware/show_exceptions_test.rb | 41 ++++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/show_exceptions_test.rb b/railties/test/application/middleware/show_exceptions_test.rb index e3f27f63c3..7dbadc6ce3 100644 --- a/railties/test/application/middleware/show_exceptions_test.rb +++ b/railties/test/application/middleware/show_exceptions_test.rb @@ -1,27 +1,23 @@ +# encoding: utf-8 require 'isolation/abstract_unit' +require 'rack/test' module ApplicationTests class ShowExceptionsTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + include Rack::Test::Methods def setup build_app boot_rails - FileUtils.rm_rf "#{app_path}/config/environments" end def teardown teardown_app end - def app - @app ||= Rails.application - end - test "unspecified route when set action_dispatch.show_exceptions to false" do - make_basic_app do |app| - app.config.action_dispatch.show_exceptions = false - end + app.config.action_dispatch.show_exceptions = false assert_raise(ActionController::RoutingError) do get '/foo' @@ -29,13 +25,36 @@ module ApplicationTests end test "unspecified route when set action_dispatch.show_exceptions to true" do - make_basic_app do |app| - app.config.action_dispatch.show_exceptions = true - end + app.config.action_dispatch.show_exceptions = true assert_nothing_raised(ActionController::RoutingError) do get '/foo' end end + + test "displays diagnostics message when exception raised in template that contains UTF-8" do + app.config.action_dispatch.show_exceptions = true + + controller :foo, <<-RUBY + class FooController < ActionController::Base + def index + end + end + RUBY + + app_file 'app/views/foo/index.html.erb', <<-ERB + <% raise 'boooom' %> + ✓ + ERB + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match ':controller(/:action)' + end + RUBY + + post '/foo', :utf8 => '✓' + assert_match(/boooom/, last_response.body) + end end end -- cgit v1.2.3 From 88237daae48c9867fca3b0e14e779d4f4cdd88d0 Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Thu, 17 Nov 2011 11:48:12 +0000 Subject: Leave default_asset_host_protocol unset When default_asset_host_protocol is left as nil, it will use absolute protocols when a request is present, and relative protocols otherwise (eg in asset generation) --- railties/test/application/assets_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index d4ffbe3d66..a22013f81c 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -451,6 +451,28 @@ module ApplicationTests assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists" end + test "asset urls should use the request's protocol by default" do + app_with_assets_in_view + add_to_config "config.asset_host = 'example.com'" + require "#{app_path}/config/environment" + class ::PostsController < ActionController::Base; end + + get '/posts', {}, {'HTTPS'=>'off'} + assert_match('src="http://example.com/assets/application.js', last_response.body) + get '/posts', {}, {'HTTPS'=>'on'} + assert_match('src="https://example.com/assets/application.js', last_response.body) + end + + test "asset urls should be protocol-relative if no request is in scope" do + app_file "app/assets/javascripts/image_loader.js.erb", 'var src="<%= image_path("rails.png") %>";' + add_to_config "config.assets.precompile = %w{image_loader.js}" + add_to_config "config.asset_host = 'example.com'" + precompile! + + assert_match 'src="//example.com/assets/rails.png"', File.read("#{app_path}/public/assets/image_loader.js") + end + + private def app_with_assets_in_view -- cgit v1.2.3 From b4359bc7234b61c9a4a104542fa77f63bb84d7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Dec 2011 19:16:19 +0100 Subject: Allow rescue responses to be configured through a railtie. --- .../application/middleware/show_exceptions_test.rb | 29 ++++++++++++++++++++++ railties/test/application/middleware_test.rb | 22 +--------------- 2 files changed, 30 insertions(+), 21 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/show_exceptions_test.rb b/railties/test/application/middleware/show_exceptions_test.rb index 7dbadc6ce3..f3cae6a11e 100644 --- a/railties/test/application/middleware/show_exceptions_test.rb +++ b/railties/test/application/middleware/show_exceptions_test.rb @@ -16,6 +16,35 @@ module ApplicationTests teardown_app end + test "show exceptions middleware filter backtrace before logging" do + my_middleware = Struct.new(:app) do + def call(env) + raise "Failure" + end + end + + app.config.middleware.use my_middleware + + stringio = StringIO.new + Rails.logger = Logger.new(stringio) + + get "/" + assert_no_match(/action_dispatch/, stringio.string) + end + + test "renders active record exceptions as 404" do + my_middleware = Struct.new(:app) do + def call(env) + raise ActiveRecord::RecordNotFound + end + end + + app.config.middleware.use my_middleware + + get "/" + assert_equal 404, last_response.status + end + test "unspecified route when set action_dispatch.show_exceptions to false" do app.config.action_dispatch.show_exceptions = false diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 4703a59326..dba79bfd96 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -104,7 +104,7 @@ module ApplicationTests assert !middleware.include?("ActionDispatch::Static") end - test "includes show exceptions even action_dispatch.show_exceptions is disabled" do + test "includes show exceptions even if action_dispatch.show_exceptions is disabled" do add_to_config "config.action_dispatch.show_exceptions = false" boot! assert middleware.include?("ActionDispatch::ShowExceptions") @@ -191,26 +191,6 @@ module ApplicationTests assert_equal nil, last_response.headers["Etag"] end - # Show exceptions middleware - test "show exceptions middleware filter backtrace before logging" do - my_middleware = Struct.new(:app) do - def call(env) - raise "Failure" - end - end - - make_basic_app do |app| - app.config.middleware.use my_middleware - end - - stringio = StringIO.new - Rails.logger = Logger.new(stringio) - - env = Rack::MockRequest.env_for("/") - Rails.application.call(env) - assert_no_match(/action_dispatch/, stringio.string) - end - private def boot! -- cgit v1.2.3 From 750bb5c865ac9234da91ec451eec7d9de55b8f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Dec 2011 20:46:18 +0100 Subject: Split ShowExceptions responsibilities in two middlewares. --- .../test/application/middleware/exceptions_test.rb | 89 ++++++++++++++++++++++ .../application/middleware/show_exceptions_test.rb | 89 ---------------------- railties/test/application/middleware_test.rb | 4 +- 3 files changed, 92 insertions(+), 90 deletions(-) create mode 100644 railties/test/application/middleware/exceptions_test.rb delete mode 100644 railties/test/application/middleware/show_exceptions_test.rb (limited to 'railties/test') diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb new file mode 100644 index 0000000000..0174352900 --- /dev/null +++ b/railties/test/application/middleware/exceptions_test.rb @@ -0,0 +1,89 @@ +# encoding: utf-8 +require 'isolation/abstract_unit' +require 'rack/test' + +module ApplicationTests + class MiddlewareExceptionsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + build_app + boot_rails + end + + def teardown + teardown_app + end + + test "show exceptions middleware filter backtrace before logging" do + my_middleware = Struct.new(:app) do + def call(env) + raise "Failure" + end + end + + app.config.middleware.use my_middleware + + stringio = StringIO.new + Rails.logger = Logger.new(stringio) + + get "/" + assert_no_match(/action_dispatch/, stringio.string) + end + + test "renders active record exceptions as 404" do + my_middleware = Struct.new(:app) do + def call(env) + raise ActiveRecord::RecordNotFound + end + end + + app.config.middleware.use my_middleware + + get "/" + assert_equal 404, last_response.status + end + + test "unspecified route when set action_dispatch.show_exceptions to false" do + app.config.action_dispatch.show_exceptions = false + + assert_raise(ActionController::RoutingError) do + get '/foo' + end + end + + test "unspecified route when set action_dispatch.show_exceptions to true" do + app.config.action_dispatch.show_exceptions = true + + assert_nothing_raised(ActionController::RoutingError) do + get '/foo' + end + end + + test "displays diagnostics message when exception raised in template that contains UTF-8" do + app.config.action_dispatch.show_exceptions = true + + controller :foo, <<-RUBY + class FooController < ActionController::Base + def index + end + end + RUBY + + app_file 'app/views/foo/index.html.erb', <<-ERB + <% raise 'boooom' %> + ✓ + ERB + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match ':controller(/:action)' + end + RUBY + + post '/foo', :utf8 => '✓' + assert_match(/boooom/, last_response.body) + end + end +end diff --git a/railties/test/application/middleware/show_exceptions_test.rb b/railties/test/application/middleware/show_exceptions_test.rb deleted file mode 100644 index f3cae6a11e..0000000000 --- a/railties/test/application/middleware/show_exceptions_test.rb +++ /dev/null @@ -1,89 +0,0 @@ -# encoding: utf-8 -require 'isolation/abstract_unit' -require 'rack/test' - -module ApplicationTests - class ShowExceptionsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - include Rack::Test::Methods - - def setup - build_app - boot_rails - end - - def teardown - teardown_app - end - - test "show exceptions middleware filter backtrace before logging" do - my_middleware = Struct.new(:app) do - def call(env) - raise "Failure" - end - end - - app.config.middleware.use my_middleware - - stringio = StringIO.new - Rails.logger = Logger.new(stringio) - - get "/" - assert_no_match(/action_dispatch/, stringio.string) - end - - test "renders active record exceptions as 404" do - my_middleware = Struct.new(:app) do - def call(env) - raise ActiveRecord::RecordNotFound - end - end - - app.config.middleware.use my_middleware - - get "/" - assert_equal 404, last_response.status - end - - test "unspecified route when set action_dispatch.show_exceptions to false" do - app.config.action_dispatch.show_exceptions = false - - assert_raise(ActionController::RoutingError) do - get '/foo' - end - end - - test "unspecified route when set action_dispatch.show_exceptions to true" do - app.config.action_dispatch.show_exceptions = true - - assert_nothing_raised(ActionController::RoutingError) do - get '/foo' - end - end - - test "displays diagnostics message when exception raised in template that contains UTF-8" do - app.config.action_dispatch.show_exceptions = true - - controller :foo, <<-RUBY - class FooController < ActionController::Base - def index - end - end - RUBY - - app_file 'app/views/foo/index.html.erb', <<-ERB - <% raise 'boooom' %> - ✓ - ERB - - app_file 'config/routes.rb', <<-RUBY - AppTemplate::Application.routes.draw do - match ':controller(/:action)' - end - RUBY - - post '/foo', :utf8 => '✓' - assert_match(/boooom/, last_response.body) - end - end -end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index dba79bfd96..578370cfca 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -33,6 +33,7 @@ module ApplicationTests "ActionDispatch::RequestId", "Rails::Rack::Logger", # must come after Rack::MethodOverride to properly log overridden methods "ActionDispatch::ShowExceptions", + "ActionDispatch::DebugExceptions", "ActionDispatch::RemoteIp", "Rack::Sendfile", "ActionDispatch::Reloader", @@ -104,10 +105,11 @@ module ApplicationTests assert !middleware.include?("ActionDispatch::Static") end - test "includes show exceptions even if action_dispatch.show_exceptions is disabled" do + test "includes exceptions middlewares even if action_dispatch.show_exceptions is disabled" do add_to_config "config.action_dispatch.show_exceptions = false" boot! assert middleware.include?("ActionDispatch::ShowExceptions") + assert middleware.include?("ActionDispatch::DebugExceptions") end test "removes ActionDispatch::Reloader if cache_classes is true" do -- cgit v1.2.3 From 0306f82e0c3cda3aad1b45eb0c3a359c254b62cc Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 2 Dec 2011 04:32:18 -0800 Subject: implements automatic EXPLAIN logging for slow queries --- railties/test/generators/app_generator_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 235c08e38e..41bb4d8b20 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -336,6 +336,15 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_generated_environments_file_for_auto_explain + run_generator [destination_root, "--skip-active-record"] + %w(development test production).each do |env| + assert_file "config/environments/#{env}.rb" do |file| + assert_no_match %r(auto_explain_threshold_in_seconds), file + end + end + end + protected def action(*args, &block) -- cgit v1.2.3 From c4f18683d9d486473d32f5861c765700e20a4af0 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 3 Dec 2011 15:46:24 +0530 Subject: Simplifying test in app/generator --- railties/test/generators/app_generator_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 41bb4d8b20..baa80419a6 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -329,8 +329,8 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generated_environments_file_for_sanitizer run_generator [destination_root, "--skip-active-record"] - ["config/environments/development.rb", "config/environments/test.rb"].each do |env_file| - assert_file env_file do |file| + %w(development test).each do |env| + assert_file "config/environments/#{env}.rb" do |file| assert_no_match(/config.active_record.mass_assignment_sanitizer = :strict/, file) end end @@ -338,7 +338,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generated_environments_file_for_auto_explain run_generator [destination_root, "--skip-active-record"] - %w(development test production).each do |env| + %w(development production).each do |env| assert_file "config/environments/#{env}.rb" do |file| assert_no_match %r(auto_explain_threshold_in_seconds), file end -- cgit v1.2.3 From 199353c658007727a428949ac11663175fb2c531 Mon Sep 17 00:00:00 2001 From: kennyj Date: Wed, 7 Dec 2011 21:11:08 +0900 Subject: Assign config.encoding to AD::Response.default_charset at the initialization time. --- railties/test/application/initializers/frameworks_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 446c85d65a..e6e2c525f5 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -136,6 +136,12 @@ module ApplicationTests assert_equal 2, ActionDispatch::Http::URL.tld_length end + test "assignment config.encoding to default_charset" do + add_to_config "config.encoding = 'Shift_JIS'" + require "#{app_path}/config/environment" + assert_equal 'Shift_JIS', ActionDispatch::Response.default_charset + end + # AS test "if there's no config.active_support.bare, all of ActiveSupport is required" do use_frameworks [] -- cgit v1.2.3 From 8f61df0bcd0e84f26c6c41b98eeb2f7bb8d5ca4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kazimierz=20Kie=C5=82kowicz?= Date: Wed, 7 Dec 2011 13:17:50 +0100 Subject: Add annotation to haml and slim template. --- railties/test/railties/rake_tasks_test.rb | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 railties/test/railties/rake_tasks_test.rb (limited to 'railties/test') diff --git a/railties/test/railties/rake_tasks_test.rb b/railties/test/railties/rake_tasks_test.rb new file mode 100644 index 0000000000..76d6ca8b5a --- /dev/null +++ b/railties/test/railties/rake_tasks_test.rb @@ -0,0 +1,42 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class RakeNotesTest < Test::Unit::TestCase + def setup + build_app + require "rails/all" + end + + def teardown + teardown_app + end + + test 'notes' do + app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>" + app_file "app/views/home/index.html.haml", "-# TODO: note in haml" + app_file "app/views/home/index.html.slim", "/ TODO: note in slim" + + boot_rails + require 'rake' + require 'rdoc/task' + require 'rake/testtask' + + Rails.application.load_tasks + + Dir.chdir(app_path) do + output = `bundle exec rake notes` + + assert_match /note in erb/, output + assert_match /note in haml/, output + assert_match /note in slim/, output + end + + end + + private + def boot_rails + super + require "#{app_path}/config/environment" + end + end +end -- cgit v1.2.3 From c45f744bb05698e72d540f158cae0ad1b0f2627f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kazimierz=20Kie=C5=82kowicz?= Date: Wed, 7 Dec 2011 17:31:31 +0100 Subject: Move rake notes test to railties/test/application/rake/notes_test.rb --- railties/test/application/rake/notes_test.rb | 45 ++++++++++++++++++++++++++++ railties/test/railties/rake_tasks_test.rb | 42 -------------------------- 2 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 railties/test/application/rake/notes_test.rb delete mode 100644 railties/test/railties/rake_tasks_test.rb (limited to 'railties/test') diff --git a/railties/test/application/rake/notes_test.rb b/railties/test/application/rake/notes_test.rb new file mode 100644 index 0000000000..659cbfec0f --- /dev/null +++ b/railties/test/application/rake/notes_test.rb @@ -0,0 +1,45 @@ +require "isolation/abstract_unit" + +module ApplicationTests + module RakeTests + class RakeNotesTest < Test::Unit::TestCase + def setup + build_app + require "rails/all" + end + + def teardown + teardown_app + end + + test 'notes' do + + app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>" + app_file "app/views/home/index.html.haml", "-# TODO: note in haml" + app_file "app/views/home/index.html.slim", "/ TODO: note in slim" + + boot_rails + require 'rake' + require 'rdoc/task' + require 'rake/testtask' + + Rails.application.load_tasks + + Dir.chdir(app_path) do + output = `bundle exec rake notes` + + assert_match /note in erb/, output + assert_match /note in haml/, output + assert_match /note in slim/, output + end + + end + + private + def boot_rails + super + require "#{app_path}/config/environment" + end + end + end +end diff --git a/railties/test/railties/rake_tasks_test.rb b/railties/test/railties/rake_tasks_test.rb deleted file mode 100644 index 76d6ca8b5a..0000000000 --- a/railties/test/railties/rake_tasks_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require "isolation/abstract_unit" - -module RailtiesTest - class RakeNotesTest < Test::Unit::TestCase - def setup - build_app - require "rails/all" - end - - def teardown - teardown_app - end - - test 'notes' do - app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>" - app_file "app/views/home/index.html.haml", "-# TODO: note in haml" - app_file "app/views/home/index.html.slim", "/ TODO: note in slim" - - boot_rails - require 'rake' - require 'rdoc/task' - require 'rake/testtask' - - Rails.application.load_tasks - - Dir.chdir(app_path) do - output = `bundle exec rake notes` - - assert_match /note in erb/, output - assert_match /note in haml/, output - assert_match /note in slim/, output - end - - end - - private - def boot_rails - super - require "#{app_path}/config/environment" - end - end -end -- cgit v1.2.3 From c6e6ce437cc370db9c395c0ffc852eee89482214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kazimierz=20Kie=C5=82kowicz?= Date: Wed, 7 Dec 2011 17:34:29 +0100 Subject: Moves migrations tests from railties/test/application/rake_test.rb to railties/test/application/rake/migrations_test.rb --- railties/test/application/rake/migrations_test.rb | 85 +++++++++++++++++++++++ railties/test/application/rake_test.rb | 68 ------------------ 2 files changed, 85 insertions(+), 68 deletions(-) create mode 100644 railties/test/application/rake/migrations_test.rb (limited to 'railties/test') diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb new file mode 100644 index 0000000000..4ec6f1b67c --- /dev/null +++ b/railties/test/application/rake/migrations_test.rb @@ -0,0 +1,85 @@ +require "isolation/abstract_unit" + +module ApplicationTests + module RakeTests + class RakeMigrationsTest < Test::Unit::TestCase + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + end + + def teardown + teardown_app + end + + test 'model and migration generator with change syntax' do + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + `rails generate migration add_email_to_users email:string` + end + + output = Dir.chdir(app_path){ `rake db:migrate` } + assert_match(/create_table\(:users\)/, output) + assert_match(/CreateUsers: migrated/, output) + assert_match(/add_column\(:users, :email, :string\)/, output) + assert_match(/AddEmailToUsers: migrated/, output) + + output = Dir.chdir(app_path){ `rake db:rollback STEP=2` } + assert_match(/drop_table\("users"\)/, output) + assert_match(/CreateUsers: reverted/, output) + assert_match(/remove_column\("users", :email\)/, output) + assert_match(/AddEmailToUsers: reverted/, output) + end + + test 'migration status when schema migrations table is not present' do + output = Dir.chdir(app_path){ `rake db:migrate:status` } + assert_equal "Schema migrations table does not exist yet.\n", output + end + + test 'test migration status' do + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + `rails generate migration add_email_to_users email:string` + end + + Dir.chdir(app_path) { `rake db:migrate`} + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/up\s+\d{14}\s+Add email to users/, output) + + Dir.chdir(app_path) { `rake db:rollback STEP=1` } + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/down\s+\d{14}\s+Add email to users/, output) + end + + test 'test migration status after rollback and redo' do + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + `rails generate migration add_email_to_users email:string` + end + + Dir.chdir(app_path) { `rake db:migrate`} + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/up\s+\d{14}\s+Add email to users/, output) + + Dir.chdir(app_path) { `rake db:rollback STEP=2` } + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/down\s+\d{14}\s+Create users/, output) + assert_match(/down\s+\d{14}\s+Add email to users/, output) + + Dir.chdir(app_path) { `rake db:migrate:redo` } + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/up\s+\d{14}\s+Add email to users/, output) + end + end + end +end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index c76bc3d526..4e406f23d2 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -108,74 +108,6 @@ module ApplicationTests assert_match "Sample log message", output end - def test_model_and_migration_generator_with_change_syntax - Dir.chdir(app_path) do - `rails generate model user username:string password:string` - `rails generate migration add_email_to_users email:string` - end - - output = Dir.chdir(app_path){ `rake db:migrate` } - assert_match(/create_table\(:users\)/, output) - assert_match(/CreateUsers: migrated/, output) - assert_match(/add_column\(:users, :email, :string\)/, output) - assert_match(/AddEmailToUsers: migrated/, output) - - output = Dir.chdir(app_path){ `rake db:rollback STEP=2` } - assert_match(/drop_table\("users"\)/, output) - assert_match(/CreateUsers: reverted/, output) - assert_match(/remove_column\("users", :email\)/, output) - assert_match(/AddEmailToUsers: reverted/, output) - end - - def test_migration_status_when_schema_migrations_table_is_not_present - output = Dir.chdir(app_path){ `rake db:migrate:status` } - assert_equal "Schema migrations table does not exist yet.\n", output - end - - def test_migration_status - Dir.chdir(app_path) do - `rails generate model user username:string password:string` - `rails generate migration add_email_to_users email:string` - end - - Dir.chdir(app_path) { `rake db:migrate`} - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/up\s+\d{14}\s+Add email to users/, output) - - Dir.chdir(app_path) { `rake db:rollback STEP=1` } - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/down\s+\d{14}\s+Add email to users/, output) - end - - def test_migration_status_after_rollback_and_redo - Dir.chdir(app_path) do - `rails generate model user username:string password:string` - `rails generate migration add_email_to_users email:string` - end - - Dir.chdir(app_path) { `rake db:migrate`} - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/up\s+\d{14}\s+Add email to users/, output) - - Dir.chdir(app_path) { `rake db:rollback STEP=2` } - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/down\s+\d{14}\s+Create users/, output) - assert_match(/down\s+\d{14}\s+Add email to users/, output) - - Dir.chdir(app_path) { `rake db:migrate:redo` } - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/up\s+\d{14}\s+Add email to users/, output) - end - def test_loading_specific_fixtures Dir.chdir(app_path) do `rails generate model user username:string password:string` -- cgit v1.2.3 From d4d2e8eb2e744e8a46f20a794b8923820fbacbe5 Mon Sep 17 00:00:00 2001 From: kennyj Date: Fri, 9 Dec 2011 01:27:58 +0900 Subject: Fix testcase an error on ruby 1.8.x. In Ruby 1.8.x, config.encoding sets $KCODE. Therefore, the possible values are UTF8, SJIS, or EUC. And, if we set SJIS, we'll has the error. Because some rails sources are written in utf-8 encoding. --- railties/test/application/initializers/frameworks_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index e6e2c525f5..cf6c4d8fc2 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -137,9 +137,10 @@ module ApplicationTests end test "assignment config.encoding to default_charset" do - add_to_config "config.encoding = 'Shift_JIS'" + charset = "ruby".respond_to?(:force_encoding) ? 'Shift_JIS' : 'UTF8' + add_to_config "config.encoding = '#{charset}'" require "#{app_path}/config/environment" - assert_equal 'Shift_JIS', ActionDispatch::Response.default_charset + assert_equal charset, ActionDispatch::Response.default_charset end # AS -- cgit v1.2.3 From b164ab75d65fa0c8a93c287835091bc704c226f1 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 03:32:37 +0100 Subject: Fix railties tests, identical migrations are not considered when copying --- railties/test/railties/shared_tests.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/test') diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 7653e52d26..abedadf9f9 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -56,6 +56,8 @@ module RailtiesTest app_file "db/migrate/1_create_sessions.rb", <<-RUBY class CreateSessions < ActiveRecord::Migration + def up + end end RUBY -- cgit v1.2.3 From ed0b1f6eed6d894f9a0f32a226d29337782ada3c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 11:45:19 +0100 Subject: Add suffix for migrations copied from engines --- railties/test/railties/shared_tests.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index abedadf9f9..a15dae2a0a 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -78,19 +78,19 @@ module RailtiesTest Dir.chdir(app_path) do output = `bundle exec rake bukkits:install:migrations` - assert File.exists?("#{app_path}/db/migrate/2_create_users.rb") - assert File.exists?("#{app_path}/db/migrate/3_add_last_name_to_users.rb") - assert_match(/Copied migration 2_create_users.rb from bukkits/, output) - assert_match(/Copied migration 3_add_last_name_to_users.rb from bukkits/, output) + assert File.exists?("#{app_path}/db/migrate/2_create_users.bukkits.rb") + assert File.exists?("#{app_path}/db/migrate/3_add_last_name_to_users.bukkits.rb") + assert_match(/Copied migration 2_create_users.bukkits.rb from bukkits/, output) + assert_match(/Copied migration 3_add_last_name_to_users.bukkits.rb from bukkits/, output) assert_match(/NOTE: Migration 3_create_sessions.rb from bukkits has been skipped/, output) assert_equal 3, Dir["#{app_path}/db/migrate/*.rb"].length output = `bundle exec rake railties:install:migrations`.split("\n") - assert File.exists?("#{app_path}/db/migrate/4_create_yaffles.rb") + assert File.exists?("#{app_path}/db/migrate/4_create_yaffles.acts_as_yaffle.rb") assert_no_match(/2_create_users/, output.join("\n")) - yaffle_migration_order = output.index(output.detect{|o| /Copied migration 4_create_yaffles.rb from acts_as_yaffle/ =~ o }) + yaffle_migration_order = output.index(output.detect{|o| /Copied migration 4_create_yaffles.acts_as_yaffle.rb from acts_as_yaffle/ =~ o }) bukkits_migration_order = output.index(output.detect{|o| /NOTE: Migration 3_create_sessions.rb from bukkits has been skipped/ =~ o }) assert_not_nil yaffle_migration_order, "Expected migration to be copied" assert_not_nil bukkits_migration_order, "Expected migration to be skipped" -- cgit v1.2.3 From 35a1744a45501fe79660ba11fbee35a7bf099bce Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 20:53:55 +0100 Subject: Allow to run migrations with given scope, with SCOPE= Scope in migrations can be defined by adding suffix in filename, like: 01_a_migration.blog.rb. Such migration have blog scope. Scope is automatically added while copying migrations from engine, so if you want to revert all of the migrations from given engine, you can just run db:migrate with SCOPE, like: rake db:migrate SCOPE=blog --- railties/test/application/rake/migrations_test.rb | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb index 4ec6f1b67c..3d3e01cdc0 100644 --- a/railties/test/application/rake/migrations_test.rb +++ b/railties/test/application/rake/migrations_test.rb @@ -12,6 +12,30 @@ module ApplicationTests def teardown teardown_app end + + test 'running migrations with given scope' do + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + end + app_file "db/migrate/01_a_migration.bukkits.rb", <<-MIGRATION + class AMigration < ActiveRecord::Migration + end + MIGRATION + + output = Dir.chdir(app_path) { `rake db:migrate SCOPE=bukkits` } + assert_no_match(/create_table\(:users\)/, output) + assert_no_match(/CreateUsers/, output) + assert_no_match(/add_column\(:users, :email, :string\)/, output) + + assert_match(/AMigration: migrated/, output) + + output = Dir.chdir(app_path) { `rake db:migrate SCOPE=bukkits VERSION=0` } + assert_no_match(/drop_table\(:users\)/, output) + assert_no_match(/CreateUsers/, output) + assert_no_match(/remove_column\(:users, :email\)/, output) + + assert_match(/AMigration: reverted/, output) + end test 'model and migration generator with change syntax' do Dir.chdir(app_path) do -- cgit v1.2.3 From 866d2dbd8786a29a61c3b11c1b052eede7b03ab1 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Dec 2011 21:19:49 +0100 Subject: Fix indentation --- railties/test/application/rake/migrations_test.rb | 134 +++++++++++----------- 1 file changed, 67 insertions(+), 67 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb index 3d3e01cdc0..fd8a30557e 100644 --- a/railties/test/application/rake/migrations_test.rb +++ b/railties/test/application/rake/migrations_test.rb @@ -36,74 +36,74 @@ module ApplicationTests assert_match(/AMigration: reverted/, output) end - + test 'model and migration generator with change syntax' do - Dir.chdir(app_path) do - `rails generate model user username:string password:string` - `rails generate migration add_email_to_users email:string` - end - - output = Dir.chdir(app_path){ `rake db:migrate` } - assert_match(/create_table\(:users\)/, output) - assert_match(/CreateUsers: migrated/, output) - assert_match(/add_column\(:users, :email, :string\)/, output) - assert_match(/AddEmailToUsers: migrated/, output) - - output = Dir.chdir(app_path){ `rake db:rollback STEP=2` } - assert_match(/drop_table\("users"\)/, output) - assert_match(/CreateUsers: reverted/, output) - assert_match(/remove_column\("users", :email\)/, output) - assert_match(/AddEmailToUsers: reverted/, output) - end - - test 'migration status when schema migrations table is not present' do - output = Dir.chdir(app_path){ `rake db:migrate:status` } - assert_equal "Schema migrations table does not exist yet.\n", output - end - - test 'test migration status' do - Dir.chdir(app_path) do - `rails generate model user username:string password:string` - `rails generate migration add_email_to_users email:string` - end - - Dir.chdir(app_path) { `rake db:migrate`} - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/up\s+\d{14}\s+Add email to users/, output) - - Dir.chdir(app_path) { `rake db:rollback STEP=1` } - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/down\s+\d{14}\s+Add email to users/, output) - end - - test 'test migration status after rollback and redo' do - Dir.chdir(app_path) do - `rails generate model user username:string password:string` - `rails generate migration add_email_to_users email:string` - end - - Dir.chdir(app_path) { `rake db:migrate`} - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/up\s+\d{14}\s+Add email to users/, output) - - Dir.chdir(app_path) { `rake db:rollback STEP=2` } - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/down\s+\d{14}\s+Create users/, output) - assert_match(/down\s+\d{14}\s+Add email to users/, output) - - Dir.chdir(app_path) { `rake db:migrate:redo` } - output = Dir.chdir(app_path) { `rake db:migrate:status` } - - assert_match(/up\s+\d{14}\s+Create users/, output) - assert_match(/up\s+\d{14}\s+Add email to users/, output) - end + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + `rails generate migration add_email_to_users email:string` + end + + output = Dir.chdir(app_path){ `rake db:migrate` } + assert_match(/create_table\(:users\)/, output) + assert_match(/CreateUsers: migrated/, output) + assert_match(/add_column\(:users, :email, :string\)/, output) + assert_match(/AddEmailToUsers: migrated/, output) + + output = Dir.chdir(app_path){ `rake db:rollback STEP=2` } + assert_match(/drop_table\("users"\)/, output) + assert_match(/CreateUsers: reverted/, output) + assert_match(/remove_column\("users", :email\)/, output) + assert_match(/AddEmailToUsers: reverted/, output) + end + + test 'migration status when schema migrations table is not present' do + output = Dir.chdir(app_path){ `rake db:migrate:status` } + assert_equal "Schema migrations table does not exist yet.\n", output + end + + test 'test migration status' do + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + `rails generate migration add_email_to_users email:string` + end + + Dir.chdir(app_path) { `rake db:migrate`} + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/up\s+\d{14}\s+Add email to users/, output) + + Dir.chdir(app_path) { `rake db:rollback STEP=1` } + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/down\s+\d{14}\s+Add email to users/, output) + end + + test 'test migration status after rollback and redo' do + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + `rails generate migration add_email_to_users email:string` + end + + Dir.chdir(app_path) { `rake db:migrate`} + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/up\s+\d{14}\s+Add email to users/, output) + + Dir.chdir(app_path) { `rake db:rollback STEP=2` } + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/down\s+\d{14}\s+Create users/, output) + assert_match(/down\s+\d{14}\s+Add email to users/, output) + + Dir.chdir(app_path) { `rake db:migrate:redo` } + output = Dir.chdir(app_path) { `rake db:migrate:status` } + + assert_match(/up\s+\d{14}\s+Create users/, output) + assert_match(/up\s+\d{14}\s+Add email to users/, output) + end end end end -- cgit v1.2.3 From 5c60b44837cd52855b0082c73f8e7af051ba0550 Mon Sep 17 00:00:00 2001 From: Steve Richert Date: Fri, 9 Dec 2011 16:49:29 -0500 Subject: Add the .rdoc extension to the README that Rails generates for a new application --- railties/test/generators/actions_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index c1fd6a38f1..ee288871de 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -114,7 +114,7 @@ class ActionsTest < Rails::Generators::TestCase action :gem_group, :test do gem 'fakeweb' end - + assert_file 'Gemfile', /\ngroup :development, :test do\n gem "rspec-rails"\nend\n\ngroup :test do\n gem "fakeweb"\nend/ end @@ -233,14 +233,14 @@ class ActionsTest < Rails::Generators::TestCase def test_readme run_generator Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root) - assert_match(/Welcome to Rails/, action(:readme, "README")) + assert_match(/Welcome to Rails/, action(:readme, "README.rdoc")) end def test_readme_with_quiet generator(default_arguments, :quiet => true) run_generator Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root) - assert_no_match(/Welcome to Rails/, action(:readme, "README")) + assert_no_match(/Welcome to Rails/, action(:readme, "README.rdoc")) end def test_log -- cgit v1.2.3 From 55afc7dc609b6b2b7f7ce37537c0de5e4db8ca6b Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Fri, 9 Dec 2011 21:38:10 -0500 Subject: Add test to verify that therubyrhino isn't included when JRuby isn't used --- railties/test/generators/app_generator_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index baa80419a6..a0475fa21d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -210,9 +210,13 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_inclusion_of_therubyrhino_under_jruby + run_generator([destination_root]) if defined?(JRUBY_VERSION) - run_generator([destination_root]) assert_file "Gemfile", /gem\s+["']therubyrhino["']$/ + else + assert_file "Gemfile" do |content| + assert_no_match(/gem\s+["']therubyrhino["']$/, content) + end end end -- cgit v1.2.3 From b12a17665abe37ab7ef116fc56519fdadf045dd6 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Fri, 9 Dec 2011 21:52:10 -0500 Subject: Skip assets groups if --skip-sprockets option is given --- railties/test/generators/app_generator_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index baa80419a6..0e2990affd 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -206,6 +206,11 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content) assert_no_match(/config\.assets\.enabled = true/, content) end + assert_file "Gemfile" do |content| + assert_no_match(/sass-rails/, content) + assert_no_match(/coffee-rails/, content) + assert_no_match(/uglifier/, content) + end assert_file "test/performance/browsing_test.rb" end -- cgit v1.2.3 From cde99812f1fcd521552db8f7cf4e183088c157db Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 11 Dec 2011 00:12:09 +0100 Subject: Ensure that files that compile to js/css are not compiled by default with `rake assets:precompile` This case was not tested and documentation was a bit confusing on that topic, so it was not obvious if current code works properly or not. --- railties/test/application/assets_test.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a22013f81c..392bef3fd1 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -72,7 +72,7 @@ module ApplicationTests end end - test "precompile application.js and application.css and all other files not ending with .js or .css by default" do + test "precompile application.js and application.css and all other non JS/CSS files" do app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/stylesheets/application.css", "body{}" @@ -82,8 +82,11 @@ module ApplicationTests app_file "app/assets/javascripts/something.min.js", "alert();" app_file "app/assets/stylesheets/something.min.css", "body{}" + app_file "app/assets/javascripts/something.else.js.erb", "alert();" + app_file "app/assets/stylesheets/something.else.css.erb", "body{}" + images_should_compile = ["a.png", "happyface.png", "happy_face.png", "happy.face.png", - "happy-face.png", "happy.happy_face.png", "happy_happy.face.png", + "happy-face.png", "happy.happy_face.png", "happy_happy.face.png", "happy.happy.face.png", "happy", "happy.face", "-happyface", "-happy.png", "-happy.face.png", "_happyface", "_happy.face.png", "_happy.png"] @@ -106,6 +109,9 @@ module ApplicationTests assert !File.exists?("#{app_path}/public/assets/something.min.js") assert !File.exists?("#{app_path}/public/assets/something.min.css") + + assert !File.exists?("#{app_path}/public/assets/something.else.js") + assert !File.exists?("#{app_path}/public/assets/something.else.css") end test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do -- cgit v1.2.3 From ea5a70a462b463d46b4ec558cbf3e8db685acaf0 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 11 Dec 2011 08:48:58 -0500 Subject: Skip assets options in environments files when --skip-sprockets is used --- railties/test/generators/app_generator_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 4c22e7a3ce..ef9f2b22a7 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -211,6 +211,13 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/coffee-rails/, content) assert_no_match(/uglifier/, content) end + assert_file "config/environments/development.rb" do |content| + assert_no_match(/config\.assets\.debug = true/, content) + end + assert_file "config/environments/production.rb" do |content| + assert_no_match(/config\.assets\.digest = true/, content) + assert_no_match(/config\.assets\.compress = true/, content) + end assert_file "test/performance/browsing_test.rb" end -- cgit v1.2.3 From 5266eb9f611a114663c48eec0680b7050181d3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Oko=C5=84ski?= Date: Mon, 12 Dec 2011 16:52:56 +0100 Subject: Default relative_url_root to ENV["RAILS_RELATIVE_URL_ROOT"]. Fixes #3365 --- railties/test/application/assets_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 392bef3fd1..a08ea77ff3 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -478,6 +478,15 @@ module ApplicationTests assert_match 'src="//example.com/assets/rails.png"', File.read("#{app_path}/public/assets/image_loader.js") end + test "asset paths should use RAILS_RELATIVE_URL_ROOT by default" do + ENV["RAILS_RELATIVE_URL_ROOT"] = "/sub/uri" + + app_file "app/assets/javascripts/app.js.erb", 'var src="<%= image_path("rails.png") %>";' + add_to_config "config.assets.precompile = %w{app.js}" + precompile! + + assert_match 'src="/sub/uri/assets/rails.png"', File.read("#{app_path}/public/assets/app.js") + end private -- cgit v1.2.3 From 04d5eae4e835ead8ef785de4eb442893426f4b29 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Mon, 12 Dec 2011 13:40:29 -0600 Subject: Add ActiveSupport::Cache::NullStore to expose caching interface without actually caching for development and test environments. --- railties/test/application/middleware/cache_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb index 050a2161ae..790c5b2d53 100644 --- a/railties/test/application/middleware/cache_test.rb +++ b/railties/test/application/middleware/cache_test.rb @@ -54,9 +54,9 @@ module ApplicationTests def test_cache_keeps_if_modified_since simple_controller expected = "Wed, 30 May 1984 19:43:31 GMT" - + get "/expires/keeps_if_modified_since", {}, "HTTP_IF_MODIFIED_SINCE" => expected - + assert_equal 200, last_response.status assert_equal expected, last_response.body, "cache should have kept If-Modified-Since" end -- cgit v1.2.3 From b04e2d86df388098c12d2067ac6997e11b9479ad Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 12 Dec 2011 13:46:05 -0800 Subject: strip whitespace errors from the generated Gemfile --- railties/test/generators/app_generator_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index ef9f2b22a7..30fbe74e83 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -124,6 +124,16 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "hats/config/environment.rb", /Hats::Application\.initialize!/ end + def test_gemfile_has_no_whitespace_errors + run_generator + absolute = File.expand_path("Gemfile", destination_root) + File.open(absolute, 'r') do |f| + f.each_line do |line| + assert_no_match /^[ \t]+$/, line + end + end + end + def test_config_database_is_added_by_default run_generator assert_file "config/database.yml", /sqlite3/ -- cgit v1.2.3 From fa1d9a884c0d5b70c97442e3360ac98ca5fa4340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 22:51:33 +0100 Subject: Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting `config.reload_classes_only_on_change` to false. Extensions like Active Record should add their respective files like db/schema.rb and db/structure.sql to `config.watchable_files` if they want their changes to affect classes reloading. Thanks to https://github.com/paneq/active_reload and Pastorino for the inspiration. <3 --- railties/test/application/console_test.rb | 3 ++- railties/test/application/loading_test.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 2073c780bf..6f9d8d57b1 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -61,7 +61,8 @@ class ConsoleTest < Test::Unit::TestCase load_environment assert User.new.respond_to?(:name) - assert !User.new.respond_to?(:age) + + sleep(1) app_file "app/models/user.rb", <<-MODEL class User diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 47c6fd5c6e..c4908915dc 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -66,6 +66,7 @@ class LoadingTest < Test::Unit::TestCase def test_descendants_are_cleaned_on_each_request_without_cache_classes add_to_config <<-RUBY config.cache_classes = false + config.reload_classes_only_on_change = false RUBY app_file "app/models/post.rb", <<-MODEL -- cgit v1.2.3 From cd3033eb627f408b71a7adf98c350e2c01115c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 09:19:58 +0100 Subject: Add config.file_watcher so developers can provide their own watchers (for instance, hooking on fsevents). --- railties/test/application/loading_test.rb | 82 +++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index c4908915dc..5fb04cb3b3 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -16,7 +16,7 @@ class LoadingTest < Test::Unit::TestCase @app ||= Rails.application end - def test_constants_in_app_are_autoloaded + test "constants in app are autoloaded" do app_file "app/models/post.rb", <<-MODEL class Post < ActiveRecord::Base validates_acceptance_of :title, :accept => "omg" @@ -33,7 +33,7 @@ class LoadingTest < Test::Unit::TestCase assert_equal 'omg', p.title end - def test_models_without_table_do_not_panic_on_scope_definitions_when_loaded + test "models without table do not panic on scope definitions when loaded" do app_file "app/models/user.rb", <<-MODEL class User < ActiveRecord::Base default_scope where(:published => true) @@ -63,7 +63,7 @@ class LoadingTest < Test::Unit::TestCase assert ::AppTemplate::Application.config.loaded end - def test_descendants_are_cleaned_on_each_request_without_cache_classes + test "descendants are cleaned on each request without cache classes" do add_to_config <<-RUBY config.cache_classes = false config.reload_classes_only_on_change = false @@ -99,6 +99,82 @@ class LoadingTest < Test::Unit::TestCase assert_raise(RuntimeError) { ::AppTemplate::Application.initialize! } end + test "reload constants on development" do + add_to_config <<-RUBY + config.cache_classes = false + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] } + end + RUBY + + app_file "app/models/user.rb", <<-MODEL + class User + def self.counter; 1; end + end + MODEL + + require 'rack/test' + extend Rack::Test::Methods + + require "#{rails_root}/config/environment" + sleep(1) + + get "/c" + assert_equal "1", last_response.body + + app_file "app/models/user.rb", <<-MODEL + class User + def self.counter; 2; end + end + MODEL + + get "/c" + assert_equal "2", last_response.body + end + + test "does not reload constants on development if custom file watcher always returns false" do + add_to_config <<-RUBY + config.cache_classes = false + config.file_watcher = Class.new do + def initialize(*); end + def updated?; false; end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match '/c', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [User.counter.to_s]] } + end + RUBY + + app_file "app/models/user.rb", <<-MODEL + class User + def self.counter; 1; end + end + MODEL + + require 'rack/test' + extend Rack::Test::Methods + + require "#{rails_root}/config/environment" + sleep(1) + + get "/c" + assert_equal "1", last_response.body + + app_file "app/models/user.rb", <<-MODEL + class User + def self.counter; 2; end + end + MODEL + + get "/c" + assert_equal "1", last_response.body + end + protected def setup_ar! -- cgit v1.2.3 From 80256abb39332dd49996b909d6f0413a15291a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 13 Dec 2011 11:23:21 +0100 Subject: FileUpdateChecker should be able to handle deleted files. --- railties/test/application/loading_test.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 5fb04cb3b3..9c77f6210a 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -175,6 +175,38 @@ class LoadingTest < Test::Unit::TestCase assert_equal "1", last_response.body end + test "added files also trigger reloading" do + add_to_config <<-RUBY + config.cache_classes = false + RUBY + + app_file 'config/routes.rb', <<-RUBY + $counter = 0 + AppTemplate::Application.routes.draw do + match '/c', :to => lambda { |env| User; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] } + end + RUBY + + app_file "app/models/user.rb", <<-MODEL + class User + $counter += 1 + end + MODEL + + require 'rack/test' + extend Rack::Test::Methods + + require "#{rails_root}/config/environment" + + get "/c" + assert_equal "1", last_response.body + + app_file "db/schema.rb", "" + + get "/c" + assert_equal "2", last_response.body + end + protected def setup_ar! -- cgit v1.2.3 From 283a08763495a6b3ce0b196259ee1666f2b08cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 18:48:10 +0100 Subject: Clean up the cache before the request in case we are running in the reload_classes_only_on_change schema. --- railties/test/application/console_test.rb | 2 - railties/test/application/loading_test.rb | 54 +++++++++++++++++++++-- railties/test/application/rake/migrations_test.rb | 2 +- 3 files changed, 52 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 6f9d8d57b1..fa2652a6d3 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -62,8 +62,6 @@ class ConsoleTest < Test::Unit::TestCase load_environment assert User.new.respond_to?(:name) - sleep(1) - app_file "app/models/user.rb", <<-MODEL class User attr_accessor :name, :age diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 9c77f6210a..c4c93cce22 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -120,7 +120,6 @@ class LoadingTest < Test::Unit::TestCase extend Rack::Test::Methods require "#{rails_root}/config/environment" - sleep(1) get "/c" assert_equal "1", last_response.body @@ -160,7 +159,6 @@ class LoadingTest < Test::Unit::TestCase extend Rack::Test::Methods require "#{rails_root}/config/environment" - sleep(1) get "/c" assert_equal "1", last_response.body @@ -175,7 +173,7 @@ class LoadingTest < Test::Unit::TestCase assert_equal "1", last_response.body end - test "added files also trigger reloading" do + test "added files (like db/schema.rb) also trigger reloading" do add_to_config <<-RUBY config.cache_classes = false RUBY @@ -207,6 +205,56 @@ class LoadingTest < Test::Unit::TestCase assert_equal "2", last_response.body end + test "columns migrations also trigger reloading" do + add_to_config <<-RUBY + config.cache_classes = false + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match '/title', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.title]] } + match '/body', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.body]] } + end + RUBY + + app_file "app/models/post.rb", <<-MODEL + class Post < ActiveRecord::Base + end + MODEL + + require 'rack/test' + extend Rack::Test::Methods + + app_file "db/migrate/1_create_posts.rb", <<-MIGRATION + class CreatePosts < ActiveRecord::Migration + def change + create_table :posts do |t| + t.string :title, :default => "TITLE" + end + end + end + MIGRATION + + Dir.chdir(app_path) { `rake db:migrate`} + require "#{rails_root}/config/environment" + + get "/title" + assert_equal "TITLE", last_response.body + + app_file "db/migrate/2_add_body_to_posts.rb", <<-MIGRATION + class AddBodyToPosts < ActiveRecord::Migration + def change + add_column :posts, :body, :text, :default => "BODY" + end + end + MIGRATION + + Dir.chdir(app_path) { `rake db:migrate` } + + get "/body" + assert_equal "BODY", last_response.body + end + protected def setup_ar! diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb index fd8a30557e..7982c42d8f 100644 --- a/railties/test/application/rake/migrations_test.rb +++ b/railties/test/application/rake/migrations_test.rb @@ -86,7 +86,7 @@ module ApplicationTests `rails generate migration add_email_to_users email:string` end - Dir.chdir(app_path) { `rake db:migrate`} + Dir.chdir(app_path) { `rake db:migrate` } output = Dir.chdir(app_path) { `rake db:migrate:status` } assert_match(/up\s+\d{14}\s+Create users/, output) -- cgit v1.2.3 From 26e7400cc5415dbce5e2c5d13da96ad8c25749e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 19:43:49 +0100 Subject: Fix diagnostics page for routing errors. --- railties/test/application/middleware/exceptions_test.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index 0174352900..d130d244c1 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -45,7 +45,7 @@ module ApplicationTests assert_equal 404, last_response.status end - test "unspecified route when set action_dispatch.show_exceptions to false" do + test "unspecified route when action_dispatch.show_exceptions is not set raises an exception" do app.config.action_dispatch.show_exceptions = false assert_raise(ActionController::RoutingError) do @@ -53,11 +53,22 @@ module ApplicationTests end end - test "unspecified route when set action_dispatch.show_exceptions to true" do + test "unspecified route when action_dispatch.show_exceptions is set shows 404" do app.config.action_dispatch.show_exceptions = true assert_nothing_raised(ActionController::RoutingError) do get '/foo' + assert_match "The page you were looking for doesn't exist.", last_response.body + end + end + + test "unspecified route when action_dispatch.show_exceptions and consider_all_requests_local are set shows diagnostics" do + app.config.action_dispatch.show_exceptions = true + app.config.consider_all_requests_local = true + + assert_nothing_raised(ActionController::RoutingError) do + get '/foo' + assert_match "No route matches", last_response.body end end -- cgit v1.2.3 From 02127e64061fc61868f085102277ac5b679e0f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:41:05 +0100 Subject: Allow a custom exceptions app to set. --- railties/test/application/middleware/exceptions_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index d130d244c1..912903adb7 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -45,6 +45,20 @@ module ApplicationTests assert_equal 404, last_response.status end + test "uses custom exceptions app" do + add_to_config <<-RUBY + config.exceptions_app = lambda do |env| + ["404", { "Content-Type" => "text/plain" }, ["YOU FAILED BRO"]] + end + RUBY + + app.config.action_dispatch.show_exceptions = true + + get "/foo" + assert_equal 404, last_response.status + assert_equal "YOU FAILED BRO", last_response.body + end + test "unspecified route when action_dispatch.show_exceptions is not set raises an exception" do app.config.action_dispatch.show_exceptions = false -- cgit v1.2.3 From 7dd1c751f90858cbdfaebeafed5fdf1ef400ae8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 09:45:14 +0100 Subject: Improve the specs on exceptions app. --- railties/test/application/middleware/exceptions_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index 912903adb7..6819e3e2e2 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -48,7 +48,7 @@ module ApplicationTests test "uses custom exceptions app" do add_to_config <<-RUBY config.exceptions_app = lambda do |env| - ["404", { "Content-Type" => "text/plain" }, ["YOU FAILED BRO"]] + [404, { "Content-Type" => "text/plain" }, ["YOU FAILED BRO"]] end RUBY -- cgit v1.2.3 From 654df86b7b022085785a64c431c45d8450d5e987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 10:38:17 +0100 Subject: Show detailed exceptions no longer returns true if the request is local in production. --- railties/test/application/middleware/exceptions_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index 6819e3e2e2..a9cde42be8 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -88,6 +88,7 @@ module ApplicationTests test "displays diagnostics message when exception raised in template that contains UTF-8" do app.config.action_dispatch.show_exceptions = true + app.config.consider_all_requests_local = true controller :foo, <<-RUBY class FooController < ActionController::Base -- cgit v1.2.3 From dbe28f3cb0c3957b2fb5847b2b205a5359481924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 11:43:29 +0100 Subject: Fix failing asset test. --- railties/test/application/assets_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a08ea77ff3..cc5695091b 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -219,7 +219,9 @@ module ApplicationTests app_file "app/assets/javascripts/app.js", "alert();" require "#{app_path}/config/environment" - class ::PostsController < ActionController::Base ; end + class ::PostsController < ActionController::Base + def show_detailed_exceptions?() true end + end get '/posts' assert_match(/AssetNotPrecompiledError/, last_response.body) -- cgit v1.2.3 From 4fe76f4f272571bb88aa54af1d7e6bcad413c6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Dec 2011 13:22:06 +0100 Subject: Wait a full second so we have time for changes to propagate --- railties/test/application/initializers/i18n_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb index 8c2c079fb8..305ae7eb0a 100644 --- a/railties/test/application/initializers/i18n_test.rb +++ b/railties/test/application/initializers/i18n_test.rb @@ -120,6 +120,9 @@ en: get "/i18n" assert_equal "1", last_response.body + # Wait a full second so we have time for changes to propagate + sleep(1) + app_file "config/locales/en.yml", <<-YAML en: foo: "2" -- cgit v1.2.3 From 5e68fed450f6e6c16f308bad0fc270777d1015f3 Mon Sep 17 00:00:00 2001 From: Kir Date: Tue, 13 Dec 2011 15:06:36 +0400 Subject: Rake tasks generator with test --- railties/test/generators/task_generator_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 railties/test/generators/task_generator_test.rb (limited to 'railties/test') diff --git a/railties/test/generators/task_generator_test.rb b/railties/test/generators/task_generator_test.rb new file mode 100644 index 0000000000..f810a21d1e --- /dev/null +++ b/railties/test/generators/task_generator_test.rb @@ -0,0 +1,12 @@ +require 'generators/generators_test_helper' +require 'rails/generators/rails/task/task_generator' + +class TaskGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + arguments %w(feeds foo bar) + + def test_controller_skeleton_is_created + run_generator + assert_file "lib/tasks/feeds.rake", /namespace :feeds/ + end +end -- cgit v1.2.3 From 1e50af9b6fa411791ac917ec5bc9689e547b2b10 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 18 Dec 2011 13:23:54 +0530 Subject: No need 'abstract_unit' here. It's already in 'generators_test_helper' --- railties/test/generators/app_generator_test.rb | 1 - railties/test/generators/plugin_new_generator_test.rb | 1 - 2 files changed, 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 30fbe74e83..f92ea5209f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/app/app_generator' require 'generators/shared_generator_tests.rb' diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 826eac904e..b62bd4b131 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -1,4 +1,3 @@ -require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/plugin_new/plugin_new_generator' require 'generators/shared_generator_tests.rb' -- cgit v1.2.3 From ff502d96019a84f25b292380ec6af1e464f17eba Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 18 Dec 2011 13:37:07 +0530 Subject: Warning removed in test --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f92ea5209f..c456347e5c 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -128,7 +128,7 @@ class AppGeneratorTest < Rails::Generators::TestCase absolute = File.expand_path("Gemfile", destination_root) File.open(absolute, 'r') do |f| f.each_line do |line| - assert_no_match /^[ \t]+$/, line + assert_no_match %r{/^[ \t]+$/}, line end end end -- cgit v1.2.3 From a2249eee760a84385dd5af8d9ee084123bc173e3 Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Sun, 18 Dec 2011 20:43:36 +0100 Subject: Rename STRUCTURE to DB_STRUCTURE, update dump task description and add simple testcase. --- railties/test/application/rake_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 4e406f23d2..d4d4e4e5ff 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -133,5 +133,13 @@ module ApplicationTests assert_match(/7 tests, 10 assertions, 0 failures, 0 errors/, content) end + + def test_rake_dump_structure_should_respect_db_structure_env_variable + Dir.chdir(app_path) do + `bundle exec rake db:migrate` # ensure we have a schema_migrations table to dump + `bundle exec rake db:structure:dump DB_STRUCTURE=db/my_structure.sql` + end + assert File.exists?(File.join(app_path, 'db', 'my_structure.sql')) + end end end -- cgit v1.2.3 From 572c3d517899524c2a7c4c84ad9646660168d4cd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Dec 2011 18:41:37 -0800 Subject: * BufferedLogger is deprecated. Use ActiveSupport::Logger, or the logger from Ruby stdlib. --- railties/test/abstract_unit.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 1c3f8a701a..400068d94c 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -5,7 +5,6 @@ require 'test/unit' require 'fileutils' require 'active_support' -require 'active_support/core_ext/logger' require 'action_controller' require 'rails/all' -- cgit v1.2.3 From 10304a228d2b31a52c3e2e0efd83190f4d1d5e28 Mon Sep 17 00:00:00 2001 From: Xu Pan Date: Tue, 20 Dec 2011 12:33:34 +0800 Subject: don't encode an UTF-8 encoded template --- railties/test/application/middleware/exceptions_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index a9cde42be8..aedc4fe648 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -99,7 +99,7 @@ module ApplicationTests app_file 'app/views/foo/index.html.erb', <<-ERB <% raise 'boooom' %> - ✓ + ✓測試テスト시험 ERB app_file 'config/routes.rb', <<-RUBY @@ -110,6 +110,7 @@ module ApplicationTests post '/foo', :utf8 => '✓' assert_match(/boooom/, last_response.body) + assert_match(/測試テスト시험/, last_response.body) end end end -- cgit v1.2.3 From 9cf38be008aff555b3aecc53a6f18800cea30a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 17:51:26 +0100 Subject: Get rid of --old-style-hash --- railties/test/generators/app_generator_test.rb | 13 +----------- railties/test/generators/mailer_generator_test.rb | 23 ++-------------------- .../scaffold_controller_generator_test.rb | 13 +----------- 3 files changed, 4 insertions(+), 45 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index c456347e5c..7ac222d84f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -337,18 +337,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_new_hash_style run_generator [destination_root] assert_file "config/initializers/session_store.rb" do |file| - if RUBY_VERSION < "1.9" - assert_match(/config.session_store :cookie_store, :key => '_.+_session'/, file) - else - assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file) - end - end - end - - def test_force_old_style_hash - run_generator [destination_root, "--old-style-hash"] - assert_file "config/initializers/session_store.rb" do |file| - assert_match(/config.session_store :cookie_store, :key => '_.+_session'/, file) + assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file) end end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 139d6b1421..63a97404ee 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -77,33 +77,14 @@ class MailerGeneratorTest < Rails::Generators::TestCase assert_file "app/mailers/notifier.rb" do |mailer| assert_instance_method :foo, mailer do |foo| - if RUBY_VERSION < "1.9" - assert_match(/mail :to => "to@example.org"/, foo) - else - assert_match(/mail to: "to@example.org"/, foo) - end + assert_match(/mail to: "to@example.org"/, foo) assert_match(/@greeting = "Hi"/, foo) end assert_instance_method :bar, mailer do |bar| - if RUBY_VERSION < "1.9" - assert_match(/mail :to => "to@example.org"/, bar) - else - assert_match(/mail to: "to@example.org"/, bar) - end + assert_match(/mail to: "to@example.org"/, bar) assert_match(/@greeting = "Hi"/, bar) end end end - - def test_force_old_style_hash - run_generator ["notifier", "foo", "--old-style-hash"] - assert_file "app/mailers/notifier.rb" do |mailer| - assert_match(/default :from => "from@example.com"/, mailer) - - assert_instance_method :foo, mailer do |foo| - assert_match(/mail :to => "to@example.org"/, foo) - end - end - end end diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 65b30b9fbd..1382133d7b 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -126,18 +126,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase def test_new_hash_style run_generator assert_file "app/controllers/users_controller.rb" do |content| - if RUBY_VERSION < "1.9" - assert_match(/\{ render :action => "new" \}/, content) - else - assert_match(/\{ render action: "new" \}/, content) - end - end - end - - def test_force_old_style_hash - run_generator ["User", "--old-style-hash"] - assert_file "app/controllers/users_controller.rb" do |content| - assert_match(/\{ render :action => "new" \}/, content) + assert_match(/\{ render action: "new" \}/, content) end end end -- cgit v1.2.3 From 2d5f5c32e6a172863e08a1eecea39b69b1d23d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 17:53:21 +0100 Subject: This test is rubbish. --- .../initializers/check_ruby_version_test.rb | 39 ---------------------- 1 file changed, 39 deletions(-) delete mode 100644 railties/test/application/initializers/check_ruby_version_test.rb (limited to 'railties/test') diff --git a/railties/test/application/initializers/check_ruby_version_test.rb b/railties/test/application/initializers/check_ruby_version_test.rb deleted file mode 100644 index df7e9696a9..0000000000 --- a/railties/test/application/initializers/check_ruby_version_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class CheckRubyVersionTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - end - - def teardown - teardown_app - end - - test "rails initializes with ruby 1.8.7 or later, except for 1.9.1" do - if RUBY_VERSION < '1.8.7' - assert_rails_does_not_boot - elsif RUBY_VERSION == '1.9.1' - assert_rails_does_not_boot - else - assert_rails_boots - end - end - - def assert_rails_boots - assert_nothing_raised "It appears that rails does not boot" do - require "rails/all" - end - end - - def assert_rails_does_not_boot - $stderr = File.open("/dev/null", "w") - assert_raises(SystemExit) do - require "rails/all" - end - end - end -end -- cgit v1.2.3 From 51095be1b08b1dd2a8a049f009bac6220fa7a68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Dec 2011 17:58:45 +0100 Subject: Get rid of more 1.8.x dead code --- railties/test/application/configuration_test.rb | 8 ++------ railties/test/generators/app_generator_test.rb | 11 ++--------- railties/test/generators/mailer_generator_test.rb | 6 +----- railties/test/generators/namespaced_generators_test.rb | 6 +----- railties/test/railties/generators_test.rb | 4 ---- 5 files changed, 6 insertions(+), 29 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 28ffff58ca..8f2e6e9ac0 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -189,12 +189,8 @@ module ApplicationTests end def assert_utf8 - if RUBY_VERSION < '1.9' - assert_equal "UTF8", $KCODE - else - assert_equal Encoding::UTF_8, Encoding.default_external - assert_equal Encoding::UTF_8, Encoding.default_internal - end + assert_equal Encoding::UTF_8, Encoding.default_external + assert_equal Encoding::UTF_8, Encoding.default_internal end test "skipping config.encoding still results in 'utf-8' as the default" do diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 7ac222d84f..a15943dfc6 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -285,17 +285,10 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_inclusion_of_ruby_debug + def test_inclusion_of_ruby_debug19 run_generator assert_file "Gemfile" do |contents| - assert_match(/gem 'ruby-debug'/, contents) if RUBY_VERSION < '1.9' - end - end - - def test_inclusion_of_ruby_debug19_if_ruby19 - run_generator - assert_file "Gemfile" do |contents| - assert_match(/gem 'ruby-debug19', :require => 'ruby-debug'/, contents) unless RUBY_VERSION < '1.9' + assert_match(/gem 'ruby-debug19', :require => 'ruby-debug'/, contents) end end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 63a97404ee..c501780e7f 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -10,11 +10,7 @@ class MailerGeneratorTest < Rails::Generators::TestCase run_generator assert_file "app/mailers/notifier.rb" do |mailer| assert_match(/class Notifier < ActionMailer::Base/, mailer) - if RUBY_VERSION < "1.9" - assert_match(/default :from => "from@example.com"/, mailer) - else - assert_match(/default from: "from@example.com"/, mailer) - end + assert_match(/default from: "from@example.com"/, mailer) end end diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index dd1e4bdac1..5c63b13dce 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -155,11 +155,7 @@ class NamespacedMailerGeneratorTest < NamespacedGeneratorTestCase assert_file "app/mailers/test_app/notifier.rb" do |mailer| assert_match(/module TestApp/, mailer) assert_match(/class Notifier < ActionMailer::Base/, mailer) - if RUBY_VERSION < "1.9" - assert_match(/default :from => "from@example.com"/, mailer) - else - assert_match(/default from: "from@example.com"/, mailer) - end + assert_match(/default from: "from@example.com"/, mailer) end end diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index f8540d69d9..6ebbabc0ff 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -46,10 +46,6 @@ module RailtiesTests gem 'rails', :path => '#{RAILS_FRAMEWORK_ROOT}' gem 'sqlite3' - - if RUBY_VERSION < '1.9' - gem "ruby-debug", ">= 0.10.3" - end GEMFILE end end -- cgit v1.2.3 From 482ec2ac3f518c91544a3b3e92765eef41b91419 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 20 Dec 2011 20:17:17 +0100 Subject: Add ORIGINAL_FULLPATH to env This behaves similarly to REQUEST_URI, but we need to implement it on our own because REQUEST_URI is not reliable. Note that since PATH_INFO does not contain information about trailing question mark, this is not 100% accurate, for example `/foo?` will result in `/foo` in ORIGINAL_FULLPATH --- .../application/build_original_fullpath_test.rb | 27 ++++++++++++++++++++++ railties/test/application/middleware_test.rb | 11 ++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 railties/test/application/build_original_fullpath_test.rb (limited to 'railties/test') diff --git a/railties/test/application/build_original_fullpath_test.rb b/railties/test/application/build_original_fullpath_test.rb new file mode 100644 index 0000000000..7a679ea04e --- /dev/null +++ b/railties/test/application/build_original_fullpath_test.rb @@ -0,0 +1,27 @@ +require "abstract_unit" + +module ApplicationTests + class BuildOriginalPathTest < Test::Unit::TestCase + def test_include_original_PATH_info_in_ORIGINAL_FULLPATH + env = { 'PATH_INFO' => '/foo/' } + assert_equal "/foo/", Rails.application.send(:build_original_fullpath, env) + end + + def test_include_SCRIPT_NAME + env = { + 'SCRIPT_NAME' => '/foo', + 'PATH_INFO' => '/bar' + } + + assert_equal "/foo/bar", Rails.application.send(:build_original_fullpath, env) + end + + def test_include_QUERY_STRING + env = { + 'PATH_INFO' => '/foo', + 'QUERY_STRING' => 'bar', + } + assert_equal "/foo?bar", Rails.application.send(:build_original_fullpath, env) + end + end +end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 578370cfca..9e02ef9c66 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -1,5 +1,6 @@ require 'isolation/abstract_unit' require 'stringio' +require 'rack/test' module ApplicationTests class MiddlewareTest < Test::Unit::TestCase @@ -75,7 +76,7 @@ module ApplicationTests add_to_config "config.force_ssl = true" add_to_config "config.ssl_options = { :host => 'example.com' }" boot! - + assert_equal AppTemplate::Application.middleware.first.args, [{:host => 'example.com'}] end @@ -193,6 +194,14 @@ module ApplicationTests assert_equal nil, last_response.headers["Etag"] end + test "ORIGINAL_FULLPATH is passed to env" do + boot! + env = ::Rack::MockRequest.env_for("/foo/?something") + Rails.application.call(env) + + assert_equal "/foo/?something", env["ORIGINAL_FULLPATH"] + end + private def boot! -- cgit v1.2.3 From 5a4b41443c09c1d1f5c996afe0838391b2e2c5f2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 21 Dec 2011 12:43:41 -0700 Subject: Move SubTestTask. Soften up tests. --- railties/test/application/rake_test.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index d4d4e4e5ff..1d90671e44 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -63,26 +63,23 @@ module ApplicationTests def test_rake_test_error_output Dir.chdir(app_path){ `rake db:migrate` } - app_file "config/database.yml", <<-RUBY - development: - RUBY - app_file "test/unit/one_unit_test.rb", <<-RUBY + raise 'unit' RUBY app_file "test/functional/one_functional_test.rb", <<-RUBY - raise RuntimeError + raise 'functional' RUBY app_file "test/integration/one_integration_test.rb", <<-RUBY - raise RuntimeError + raise 'integration' RUBY silence_stderr do - output = Dir.chdir(app_path){ `rake test` } - assert_match(/Errors running test:units! #&1` } + assert_match 'unit', output + assert_match 'functional', output + assert_match 'integration', output end end -- cgit v1.2.3 From d4a4fcbc936818e1925781caa3ba735df77866da Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 14:54:39 -0700 Subject: append puts the routes after the default, which causes a 404. instead use prepend --- railties/test/application/configuration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 8f2e6e9ac0..30748674cd 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -479,7 +479,7 @@ module ApplicationTests RUBY add_to_config <<-RUBY - routes.append do + routes.prepend do resources :posts end RUBY -- cgit v1.2.3 From 401b266f5fc1e6c5f13feb36122a1983989d8f58 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 15:03:43 -0700 Subject: just require things once --- railties/test/application/configuration_test.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 30748674cd..758b56d17d 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1,4 +1,5 @@ require "isolation/abstract_unit" +require 'rack/test' class ::MyMailInterceptor def self.delivering_email(email); email; end @@ -15,6 +16,7 @@ class ::MyOtherMailObserver < ::MyMailObserver; end module ApplicationTests class ConfigurationTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + include Rack::Test::Methods def new_app File.expand_path("#{app_path}/../new_app") @@ -181,8 +183,6 @@ module ApplicationTests assert !$prepared require "#{app_path}/config/environment" - require 'rack/test' - extend Rack::Test::Methods get "/" assert $prepared @@ -485,8 +485,6 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - require "rack/test" - extend Rack::Test::Methods post "/posts.json", '{ "title": "foo", "name": "bar" }', "CONTENT_TYPE" => "application/json" assert_equal '{"title"=>"foo"}', last_response.body -- cgit v1.2.3 From 2adc145264c5c30499d8837bf32536171aefca9a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 22 Dec 2011 10:55:38 -0700 Subject: Depend on 4.0.0.beta gems. Use https for github urls. --- railties/test/generators/shared_generator_tests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 1534f0d828..14a20eddb8 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -125,7 +125,7 @@ module SharedGeneratorTests def test_edge_option generator([destination_root], :edge => true).expects(:bundle_command).with('install').once quietly { generator.invoke_all } - assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$} + assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("https://github.com/rails/rails.git")}["']$} end def test_skip_gemfile -- cgit v1.2.3 From 5f3b9dec0a03055824fa8187ef260e74d75a75eb Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Fri, 23 Dec 2011 19:56:49 +0300 Subject: remove Rails application fallback from AD::IntegrationTest set AD::IntegrationTest.app in railtie initializer --- railties/test/application/configuration_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 758b56d17d..0d64a136f8 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -282,6 +282,11 @@ module ApplicationTests assert_equal res, last_response.body # value should be unchanged end + test "sets ActionDispatch.test_app" do + make_basic_app + assert_equal Rails.application, ActionDispatch.test_app + end + test "sets all Active Record models to whitelist all attributes by default" do add_to_config <<-RUBY config.active_record.whitelist_attributes = true -- cgit v1.2.3 From 7a47f362c8246c20437f49111e5dcc0781d6d024 Mon Sep 17 00:00:00 2001 From: Dmitrii Samoilov Date: Wed, 17 Aug 2011 12:16:04 +0300 Subject: added ability to specify from cli when generating a model/migration whether particular property should be an index like this 'rails g model person name:string:index profile:string' --- .../test/generators/generated_attribute_test.rb | 2 +- .../test/generators/migration_generator_test.rb | 62 ++++++++++++++++++++ railties/test/generators/model_generator_test.rb | 68 ++++++++++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index a85829085c..ea6c6e4e2c 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -69,7 +69,7 @@ class GeneratedAttributeTest < Rails::Generators::TestCase end def test_default_value_for_type - att = Rails::Generators::GeneratedAttribute.new("type", "string") + att = Rails::Generators::GeneratedAttribute.new("type:string") assert_equal("", att.default) end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 337257df7d..6b6c9dee7c 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -58,6 +58,68 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_add_migration_with_attributes_and_indices + migration = "add_title_with_index_and_body_to_posts" + run_generator [migration, "title:string:index", "body:text", "user_id:integer:unique"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |up| + assert_match(/add_column :posts, :title, :string/, up) + assert_match(/add_column :posts, :body, :text/, up) + assert_match(/add_column :posts, :user_id, :integer/, up) + end + assert_match(/add_index :posts, :title/, content) + assert_match(/add_index :posts, :user_id, :unique => true/, content) + end + end + + def test_add_migration_with_attributes_and_wrong_index_declaration + migration = "add_title_and_content_to_books" + run_generator [migration, "title:string:inex", "content:text", "user_id:integer:unik"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |up| + assert_match(/add_column :books, :title, :string/, up) + assert_match(/add_column :books, :content, :text/, up) + assert_match(/add_column :books, :user_id, :integer/, up) + end + assert_not_match(/add_index :books, :title/, content) + assert_not_match(/add_index :books, :user_id/, content) + end + end + + def test_add_migration_with_attributes_without_type_and_index + migration = "add_title_with_index_and_body_to_posts" + run_generator [migration, "title:index", "body:text", "user_uuid:uniq"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |up| + assert_match(/add_column :posts, :title, :string/, up) + assert_match(/add_column :posts, :body, :text/, up) + assert_match(/add_column :posts, :user_uuid, :string/, up) + end + assert_match(/add_index :posts, :title/, content) + assert_match(/add_index :posts, :user_uuid, :unique => true/, content) + end + end + + def test_add_migration_with_attributes_index_declaration_and_attribute_options + migration = "add_title_and_content_to_books" + run_generator [migration, "title:string{40}:index", "content:string{255}", "price:decimal{5,2}:index", "discount:decimal{3,2}:uniq"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |up| + assert_match(/add_column :books, :title, :string, :limit=>40/, up) + assert_match(/add_column :books, :content, :string, :limit=>255/, up) + assert_match(/add_column :books, :price, :decimal, :precision=>5, :scale=>2/, up) + assert_match(/add_column :books, :discount, :decimal, :precision=>3, :scale=>2/, up) + end + assert_match(/add_index :books, :title/, content) + assert_match(/add_index :books, :price/, content) + assert_match(/add_index :books, :discount, :unique => true/, content) + end + end + def test_should_create_empty_migrations_if_name_not_start_with_add_or_remove migration = "create_books" run_generator [migration, "title:string", "content:text"] diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 1b0cb425c6..7a8cf1d8a7 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -113,6 +113,74 @@ class ModelGeneratorTest < Rails::Generators::TestCase end end + def test_migration_with_attributes_and_with_index + run_generator ["product", "name:string:index", "supplier_id:integer:index", "user_id:integer:uniq", "order_id:unique"] + + assert_migration "db/migrate/create_products.rb" do |m| + assert_method :change, m do |up| + assert_match(/create_table :products/, up) + assert_match(/t\.string :name/, up) + assert_match(/t\.integer :supplier_id/, up) + assert_match(/t\.integer :user_id/, up) + assert_match(/t\.string :order_id/, up) + + assert_match(/add_index :products, :name/, up) + assert_match(/add_index :products, :supplier_id/, up) + assert_match(/add_index :products, :user_id, :unique => true/, up) + assert_match(/add_index :products, :order_id, :unique => true/, up) + end + end + end + + def test_migration_with_attributes_and_with_wrong_index_declaration + run_generator ["product", "name:string", "supplier_id:integer:inex", "user_id:integer:unqu"] + + assert_migration "db/migrate/create_products.rb" do |m| + assert_method :change, m do |up| + assert_match(/create_table :products/, up) + assert_match(/t\.string :name/, up) + assert_match(/t\.integer :supplier_id/, up) + assert_match(/t\.integer :user_id/, up) + + assert_not_match(/add_index :products, :name/, up) + assert_not_match(/add_index :products, :supplier_id/, up) + assert_not_match(/add_index :products, :user_id/, up) + end + end + end + + def test_migration_with_missing_attribute_type_and_with_index + run_generator ["product", "name:index", "supplier_id:integer:index", "year:integer"] + + assert_migration "db/migrate/create_products.rb" do |m| + assert_method :change, m do |up| + assert_match(/create_table :products/, up) + assert_match(/t\.string :name/, up) + assert_match(/t\.integer :supplier_id/, up) + + assert_match(/add_index :products, :name/, up) + assert_match(/add_index :products, :supplier_id/, up) + assert_not_match(/add_index :products, :year/, up) + end + end + end + + def test_add_migration_with_attributes_index_declaration_and_attribute_options + run_generator ["product", "title:string{40}:index", "content:string{255}", "price:decimal{5,2}:index", "discount:decimal{5,2}:uniq"] + + assert_migration "db/migrate/create_products.rb" do |content| + assert_method :change, content do |up| + assert_match(/create_table :products/, up) + assert_match(/t.string :title, :limit=>40/, up) + assert_match(/t.string :content, :limit=>255/, up) + assert_match(/t.decimal :price, :precision=>5, :scale=>2/, up) + end + assert_match(/add_index :products, :title/, content) + assert_match(/add_index :products, :price/, content) + assert_match(/add_index :products, :discount, :unique => true/, content) + end + end + def test_migration_without_timestamps ActiveRecord::Base.timestamped_migrations = false run_generator ["account"] -- cgit v1.2.3 From b4e97ea2d961c7ed99dcfa48044f4922378ff9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 10:38:19 +0100 Subject: Tidy up migration types. --- railties/test/generators/generated_attribute_test.rb | 7 ++++++- railties/test/generators/migration_generator_test.rb | 2 +- railties/test/generators/model_generator_test.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index ea6c6e4e2c..6e3fc84781 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -69,7 +69,7 @@ class GeneratedAttributeTest < Rails::Generators::TestCase end def test_default_value_for_type - att = Rails::Generators::GeneratedAttribute.new("type:string") + att = Rails::Generators::GeneratedAttribute.parse("type:string") assert_equal("", att.default) end @@ -122,4 +122,9 @@ class GeneratedAttributeTest < Rails::Generators::TestCase assert_equal :string, create_generated_attribute(nil, 'title').type assert_equal :string, create_generated_attribute("", 'title').type end + + def test_handles_index_names_for_references + assert_equal "post", create_generated_attribute('string', 'post').index_name + assert_equal "post_id", create_generated_attribute('references', 'post').index_name + end end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 6b6c9dee7c..9da1b53c96 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -60,7 +60,7 @@ class MigrationGeneratorTest < Rails::Generators::TestCase def test_add_migration_with_attributes_and_indices migration = "add_title_with_index_and_body_to_posts" - run_generator [migration, "title:string:index", "body:text", "user_id:integer:unique"] + run_generator [migration, "title:string:index", "body:text", "user_id:integer:uniq"] assert_migration "db/migrate/#{migration}.rb" do |content| assert_method :change, content do |up| diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 7a8cf1d8a7..c063d4d687 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -114,7 +114,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase end def test_migration_with_attributes_and_with_index - run_generator ["product", "name:string:index", "supplier_id:integer:index", "user_id:integer:uniq", "order_id:unique"] + run_generator ["product", "name:string:index", "supplier_id:integer:index", "user_id:integer:uniq", "order_id:uniq"] assert_migration "db/migrate/create_products.rb" do |m| assert_method :change, m do |up| -- cgit v1.2.3 From 7a2a661b834ec744d3bfb166f1afd546312b739e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 17:04:32 +0100 Subject: assert_not_match -> assert_no_match. --- railties/test/generators/migration_generator_test.rb | 4 ++-- railties/test/generators/model_generator_test.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 9da1b53c96..d81fc59fbf 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -83,8 +83,8 @@ class MigrationGeneratorTest < Rails::Generators::TestCase assert_match(/add_column :books, :content, :text/, up) assert_match(/add_column :books, :user_id, :integer/, up) end - assert_not_match(/add_index :books, :title/, content) - assert_not_match(/add_index :books, :user_id/, content) + assert_no_match(/add_index :books, :title/, content) + assert_no_match(/add_index :books, :user_id/, content) end end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index c063d4d687..ffb3d2ceba 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -142,9 +142,9 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_match(/t\.integer :supplier_id/, up) assert_match(/t\.integer :user_id/, up) - assert_not_match(/add_index :products, :name/, up) - assert_not_match(/add_index :products, :supplier_id/, up) - assert_not_match(/add_index :products, :user_id/, up) + assert_no_match(/add_index :products, :name/, up) + assert_no_match(/add_index :products, :supplier_id/, up) + assert_no_match(/add_index :products, :user_id/, up) end end end @@ -160,7 +160,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_match(/add_index :products, :name/, up) assert_match(/add_index :products, :supplier_id/, up) - assert_not_match(/add_index :products, :year/, up) + assert_no_match(/add_index :products, :year/, up) end end end -- cgit v1.2.3 From 7c9bcbb5e486a5d5e35d38c5fbcbea6af88fc23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Dec 2011 22:06:25 +0100 Subject: Use 1.9 hash syntax instead. --- railties/test/generators/migration_generator_test.rb | 14 +++++++------- railties/test/generators/model_generator_test.rb | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index d81fc59fbf..68fbd58061 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -69,7 +69,7 @@ class MigrationGeneratorTest < Rails::Generators::TestCase assert_match(/add_column :posts, :user_id, :integer/, up) end assert_match(/add_index :posts, :title/, content) - assert_match(/add_index :posts, :user_id, :unique => true/, content) + assert_match(/add_index :posts, :user_id, unique: true/, content) end end @@ -99,7 +99,7 @@ class MigrationGeneratorTest < Rails::Generators::TestCase assert_match(/add_column :posts, :user_uuid, :string/, up) end assert_match(/add_index :posts, :title/, content) - assert_match(/add_index :posts, :user_uuid, :unique => true/, content) + assert_match(/add_index :posts, :user_uuid, unique: true/, content) end end @@ -109,14 +109,14 @@ class MigrationGeneratorTest < Rails::Generators::TestCase assert_migration "db/migrate/#{migration}.rb" do |content| assert_method :change, content do |up| - assert_match(/add_column :books, :title, :string, :limit=>40/, up) - assert_match(/add_column :books, :content, :string, :limit=>255/, up) - assert_match(/add_column :books, :price, :decimal, :precision=>5, :scale=>2/, up) - assert_match(/add_column :books, :discount, :decimal, :precision=>3, :scale=>2/, up) + assert_match(/add_column :books, :title, :string, limit: 40/, up) + assert_match(/add_column :books, :content, :string, limit: 255/, up) + assert_match(/add_column :books, :price, :decimal, precision: 5, scale: 2/, up) + assert_match(/add_column :books, :discount, :decimal, precision: 3, scale: 2/, up) end assert_match(/add_index :books, :title/, content) assert_match(/add_index :books, :price/, content) - assert_match(/add_index :books, :discount, :unique => true/, content) + assert_match(/add_index :books, :discount, unique: true/, content) end end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index ffb3d2ceba..156fa86eee 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -126,8 +126,8 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_match(/add_index :products, :name/, up) assert_match(/add_index :products, :supplier_id/, up) - assert_match(/add_index :products, :user_id, :unique => true/, up) - assert_match(/add_index :products, :order_id, :unique => true/, up) + assert_match(/add_index :products, :user_id, unique: true/, up) + assert_match(/add_index :products, :order_id, unique: true/, up) end end end @@ -171,13 +171,13 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_migration "db/migrate/create_products.rb" do |content| assert_method :change, content do |up| assert_match(/create_table :products/, up) - assert_match(/t.string :title, :limit=>40/, up) - assert_match(/t.string :content, :limit=>255/, up) - assert_match(/t.decimal :price, :precision=>5, :scale=>2/, up) + assert_match(/t.string :title, limit: 40/, up) + assert_match(/t.string :content, limit: 255/, up) + assert_match(/t.decimal :price, precision: 5, scale: 2/, up) end assert_match(/add_index :products, :title/, content) assert_match(/add_index :products, :price/, content) - assert_match(/add_index :products, :discount, :unique => true/, content) + assert_match(/add_index :products, :discount, unique: true/, content) end end -- cgit v1.2.3 From 1e9e88fcd335c7d5a99159d592c3e1b605510a16 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Sun, 25 Dec 2011 14:34:58 +0300 Subject: remove checks for encodings availability --- railties/test/application/initializers/frameworks_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index cf6c4d8fc2..a0417360a1 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -137,7 +137,7 @@ module ApplicationTests end test "assignment config.encoding to default_charset" do - charset = "ruby".respond_to?(:force_encoding) ? 'Shift_JIS' : 'UTF8' + charset = 'Shift_JIS' add_to_config "config.encoding = '#{charset}'" require "#{app_path}/config/environment" assert_equal charset, ActionDispatch::Response.default_charset -- cgit v1.2.3 From a1a5c40dad32b69a013a15787e95f4c63f23546f Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 26 Dec 2011 01:51:05 +0530 Subject: Test::Unit::Util::BacktraceFilter not available in ruby19 test/unit --- railties/test/application/test_test.rb | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb index a06facc04b..aa55a3cf1e 100644 --- a/railties/test/application/test_test.rb +++ b/railties/test/application/test_test.rb @@ -27,23 +27,6 @@ module ApplicationTests run_test_file 'unit/foo_test.rb' end - # Run just in Ruby < 1.9 - if defined?(Test::Unit::Util::BacktraceFilter) - test "adds backtrace cleaner" do - app_file 'test/unit/backtrace_test.rb', <<-RUBY - require 'test_helper' - - class FooTest < ActiveSupport::TestCase - def test_truth - assert Test::Unit::Util::BacktraceFilter.ancestors.include?(Rails::BacktraceFilterForTestUnit) - end - end - RUBY - - run_test_file 'unit/backtrace_test.rb' - end - end - test "integration test" do controller 'posts', <<-RUBY class PostsController < ActionController::Base -- cgit v1.2.3 From 28cd098d99c52486aecb72aab39105d8abcd52ad Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 26 Dec 2011 11:31:22 +0100 Subject: Correctly display rack apps with dynamic constraints in RoutesInspector If you used dynamic constraint like that: scope :constraint => MyConstraint.new do mount RackApp => "/foo" end routes were not displayed correctly when using `rake routes`. This commit fixes it. If you want nice display of dynamic constraints in `rake routes` output, please just override to_s method in your constraint's class. --- railties/test/application/route_inspect_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb index 2ad5ee6c4c..6503251b9f 100644 --- a/railties/test/application/route_inspect_test.rb +++ b/railties/test/application/route_inspect_test.rb @@ -127,5 +127,22 @@ module ApplicationTests output = @inspector.format @set.routes assert_equal [" /foo/:id(.:format) #{RackApp.name} {:id=>/[A-Z]\\d{5}/}"], output end + + def test_rake_routes_shows_route_with_rack_app_nested_with_dynamic_constraints + constraint = Class.new do + def to_s + "( my custom constraint )" + end + end + + @set.draw do + scope :constraint => constraint.new do + mount RackApp => '/foo' + end + end + + output = @inspector.format @set.routes + assert_equal [" /foo #{RackApp.name} {:constraint=>( my custom constraint )}"], output + end end end -- cgit v1.2.3