diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-10 22:00:55 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-10 22:00:55 +0200 |
commit | 63560660062d552d6bbebec007154f0c639bf865 (patch) | |
tree | 0ff7ee5c1a63815685e9640ca4a9ceafb7732178 /railties/test | |
parent | 59e89facc2264322bcab59c9a8622380b62d4d40 (diff) | |
parent | 61fc7a455099f179de88967f403f2038b9d3c821 (diff) | |
download | rails-63560660062d552d6bbebec007154f0c639bf865.tar.gz rails-63560660062d552d6bbebec007154f0c639bf865.tar.bz2 rails-63560660062d552d6bbebec007154f0c639bf865.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/generators_test.rb | 1 | ||||
-rw-r--r-- | railties/test/application/initializers/check_ruby_version_test.rb | 4 | ||||
-rw-r--r-- | railties/test/application/middleware_test.rb | 20 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 3 | ||||
-rw-r--r-- | railties/test/generators/generated_attribute_test.rb | 91 | ||||
-rw-r--r-- | railties/test/script_rails_loader_test.rb | 22 |
6 files changed, 128 insertions, 13 deletions
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 712c8bef36..cbf0decd07 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -64,6 +64,7 @@ module ApplicationTests # Initialize the application require "#{app_path}/config/environment" require "rails/generators" + Rails::Generators.configure! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] diff --git a/railties/test/application/initializers/check_ruby_version_test.rb b/railties/test/application/initializers/check_ruby_version_test.rb index 58782b2511..5b6196307d 100644 --- a/railties/test/application/initializers/check_ruby_version_test.rb +++ b/railties/test/application/initializers/check_ruby_version_test.rb @@ -9,9 +9,11 @@ module ApplicationTests boot_rails end - test "rails initializes with ruby 1.8.7 or later" do + 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 diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index aa75fed793..999f666a64 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -1,4 +1,5 @@ require 'isolation/abstract_unit' +require 'stringio' module ApplicationTests class MiddlewareTest < Test::Unit::TestCase @@ -163,6 +164,25 @@ module ApplicationTests assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "4.2.42.42,1.1.1.1") end + 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! diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8bd9dc9f39..ffc5636467 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -59,7 +59,6 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_application_controller_and_layout_files run_generator - assert_file "app/controllers/application_controller.rb", /layout 'application'/ assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag :all/ assert_no_file "public/stylesheets/application.css" end @@ -272,4 +271,4 @@ protected def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } end -end
\ No newline at end of file +end diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index dacb06fb13..de7e4de2a6 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -5,36 +5,107 @@ class GeneratedAttributeTest < Rails::Generators::TestCase include GeneratorsTestHelper def test_field_type_returns_text_field - %w(integer float decimal string).each do |name| - assert_field_type name, :text_field + %w(integer float decimal string).each do |attribute_type| + assert_field_type attribute_type, :text_field end end def test_field_type_returns_datetime_select - %w(datetime timestamp).each do |name| - assert_field_type name, :datetime_select + %w(datetime timestamp).each do |attribute_type| + assert_field_type attribute_type, :datetime_select end end def test_field_type_returns_time_select - assert_field_type 'time', :time_select + assert_field_type :time, :time_select end def test_field_type_returns_date_select - assert_field_type 'date', :date_select + assert_field_type :date, :date_select end def test_field_type_returns_text_area - assert_field_type 'text', :text_area + assert_field_type :text, :text_area end def test_field_type_returns_check_box - assert_field_type 'boolean', :check_box + assert_field_type :boolean, :check_box end def test_field_type_with_unknown_type_returns_text_field - %w(foo bar baz).each do |name| - assert_field_type name, :text_field + %w(foo bar baz).each do |attribute_type| + assert_field_type attribute_type, :text_field + end + end + + def test_default_value_is_integer + assert_field_default_value :integer, 1 + end + + def test_default_value_is_float + assert_field_default_value :float, 1.5 + end + + def test_default_value_is_decimal + assert_field_default_value :decimal, '9.99' + end + + def test_default_value_is_datetime + %w(datetime timestamp time).each do |attribute_type| + assert_field_default_value attribute_type, Time.now.to_s(:db) + end + end + + def test_default_value_is_date + assert_field_default_value :date, Date.today.to_s(:db) + end + + def test_default_value_is_string + assert_field_default_value :string, 'MyString' + end + + def test_default_value_is_text + assert_field_default_value :text, 'MyText' + end + + def test_default_value_is_boolean + assert_field_default_value :boolean, false + end + + def test_default_value_is_nil + %w(references belongs_to).each do |attribute_type| + assert_field_default_value attribute_type, nil + end + end + + def test_default_value_is_empty_string + %w(foo bar baz).each do |attribute_type| + assert_field_default_value attribute_type, '' + end + end + + def test_human_name + assert_equal( + 'Full name', + create_generated_attribute(:string, 'full_name').human_name + ) + end + + def test_reference_is_true + %w(references belongs_to).each do |attribute_type| + assert_equal( + true, + create_generated_attribute(attribute_type).reference? + ) + end + end + + def test_reference_is_false + %w(foo bar baz).each do |attribute_type| + assert_equal( + false, + create_generated_attribute(attribute_type).reference? + ) end end end diff --git a/railties/test/script_rails_loader_test.rb b/railties/test/script_rails_loader_test.rb new file mode 100644 index 0000000000..2a87e5cb58 --- /dev/null +++ b/railties/test/script_rails_loader_test.rb @@ -0,0 +1,22 @@ +require 'abstract_unit' +require 'rails/script_rails_loader' + +class ScriptRailsLoaderTest < ActiveSupport::TestCase + + test "is in a rails application if script/rails exists" do + File.stubs(:exists?).returns(true) + assert Rails::ScriptRailsLoader.in_rails_application? + end + + test "is in a rails application if parent directory has script/rails" do + File.stubs(:exists?).with("/foo/bar/script/rails").returns(false) + File.stubs(:exists?).with("/foo/script/rails").returns(true) + assert Rails::ScriptRailsLoader.in_rails_application_subdirectory?(Pathname.new("/foo/bar")) + end + + test "is not in a rails application if at the root directory and doesn't have script/rails" do + Pathname.any_instance.stubs(:root?).returns true + assert !Rails::ScriptRailsLoader.in_rails_application? + end + +end
\ No newline at end of file |