From 89d1c77dd012f087c091e0f23874c582ea4e3703 Mon Sep 17 00:00:00 2001 From: Tom Ward <tom@popdog.net> Date: Tue, 19 Aug 2008 13:19:41 +0100 Subject: Initializer to sort files before eager loading. [#859 state:resolved] Changed Rails::Initializer to sort files before eager loading them. This ensures that any files in a parent directory will be loaded before files in a subdirectory of the 'same' name. i.e. zoo.rb will be loaded before zoo/reptile_house.rb Signed-off-by: Pratik Naik <pratiknaik@gmail.com> --- railties/test/fixtures/eager/zoo.rb | 3 +++ railties/test/fixtures/eager/zoo/reptile_house.rb | 2 ++ railties/test/initializer_test.rb | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 railties/test/fixtures/eager/zoo.rb create mode 100644 railties/test/fixtures/eager/zoo/reptile_house.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/eager/zoo.rb b/railties/test/fixtures/eager/zoo.rb new file mode 100644 index 0000000000..8b10ef984b --- /dev/null +++ b/railties/test/fixtures/eager/zoo.rb @@ -0,0 +1,3 @@ +class Zoo + include ReptileHouse +end \ No newline at end of file diff --git a/railties/test/fixtures/eager/zoo/reptile_house.rb b/railties/test/fixtures/eager/zoo/reptile_house.rb new file mode 100644 index 0000000000..82bbafce79 --- /dev/null +++ b/railties/test/fixtures/eager/zoo/reptile_house.rb @@ -0,0 +1,2 @@ +module Zoo::ReptileHouse +end \ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 07303a510e..5147eeb482 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -30,6 +30,24 @@ class Initializer_load_environment_Test < Test::Unit::TestCase end +class Initializer_eager_loading_Test < Test::Unit::TestCase + def setup + @config = ConfigurationMock.new("") + @config.cache_classes = true + @config.load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")] + @config.eager_load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")] + @initializer = Rails::Initializer.new(@config) + @initializer.set_load_path + @initializer.set_autoload_paths + end + + def test_eager_loading_loads_parent_classes_before_children + assert_nothing_raised do + @initializer.load_application_classes + end + end +end + uses_mocha 'Initializer after_initialize' do class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase def setup -- cgit v1.2.3 From 9223a919111867e6b47b2627c30d8eb21e8ac7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= <tarmo@itech.ee> Date: Sat, 23 Aug 2008 20:58:44 +0300 Subject: Generate belongs_to associations automatically for 'references' types [#640 state:resolved] --- railties/test/generators/rails_model_generator_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/rails_model_generator_test.rb b/railties/test/generators/rails_model_generator_test.rb index 0bfc338566..67cd3aa26f 100644 --- a/railties/test/generators/rails_model_generator_test.rb +++ b/railties/test/generators/rails_model_generator_test.rb @@ -29,4 +29,12 @@ class RailsModelGeneratorTest < GeneratorTestCase assert_generated_column t, :created_at, :timestamp end end + + def test_model_with_reference_attributes_generates_belongs_to_associations + run_generator('model', %w(Product name:string supplier:references)) + + assert_generated_model_for :product do |body| + assert body =~ /^\s+belongs_to :supplier/, "#{body.inspect} should contain 'belongs_to :supplier'" + end + end end -- cgit v1.2.3 From b1f3c6e6ec08a40fc7153ee3ba78d51b466a58e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= <tarmo@itech.ee> Date: Sat, 23 Aug 2008 21:54:43 +0300 Subject: Generate belongs_to association when generating a model --- railties/test/generators/rails_model_generator_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/rails_model_generator_test.rb b/railties/test/generators/rails_model_generator_test.rb index 67cd3aa26f..aea2abafba 100644 --- a/railties/test/generators/rails_model_generator_test.rb +++ b/railties/test/generators/rails_model_generator_test.rb @@ -37,4 +37,12 @@ class RailsModelGeneratorTest < GeneratorTestCase assert body =~ /^\s+belongs_to :supplier/, "#{body.inspect} should contain 'belongs_to :supplier'" end end + + def test_model_with_belongs_to_attributes_generates_belongs_to_associations + run_generator('model', %w(Product name:string supplier:belongs_to)) + + assert_generated_model_for :product do |body| + assert body =~ /^\s+belongs_to :supplier/, "#{body.inspect} should contain 'belongs_to :supplier'" + end + end end -- cgit v1.2.3 From f9f1ab4e3ddeacadf2a7bce021d742f08f67905f Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion" <hongli@phusion.nl> Date: Thu, 10 Jul 2008 13:21:08 +0200 Subject: When an unexpected exception is caught, tell the administrator to read the log file for more information about the error. This should make things less confusing for developers who are new to Rails. Signed-off-by: Michael Koziarski <michael@koziarski.com> --- railties/test/error_page_test.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 railties/test/error_page_test.rb (limited to 'railties/test') diff --git a/railties/test/error_page_test.rb b/railties/test/error_page_test.rb new file mode 100644 index 0000000000..0e43700eb6 --- /dev/null +++ b/railties/test/error_page_test.rb @@ -0,0 +1,37 @@ +require 'abstract_unit' +require 'action_controller' +require 'action_controller/test_process' + +RAILS_ENV = "test" + +module Rails + def self.public_path + File.expand_path(File.join(File.dirname(__FILE__), "..", "html")) + end +end + +class ErrorPageController < ActionController::Base + def crash + raise StandardError, "crash!" + end +end + +ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' +end + +class ErrorPageControllerTest < Test::Unit::TestCase + def setup + @controller = ErrorPageController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + ActionController::Base.consider_all_requests_local = false + end + + def test_500_error_page_instructs_system_administrator_to_check_log_file + get :crash + expected_log_file = "#{RAILS_ENV}.log" + assert_not_nil @response.body.index(expected_log_file) + end +end -- cgit v1.2.3 From c111522d5b8cd108756240a0348d515d6acee46c Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion" <hongli@phusion.nl> Date: Tue, 26 Aug 2008 15:59:03 +0200 Subject: The 'rails' command was broken by the last commit. Fix that. Signed-off-by: Michael Koziarski <michael@koziarski.com> --- railties/test/error_page_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/error_page_test.rb b/railties/test/error_page_test.rb index 0e43700eb6..844f889aad 100644 --- a/railties/test/error_page_test.rb +++ b/railties/test/error_page_test.rb @@ -3,10 +3,12 @@ require 'action_controller' require 'action_controller/test_process' RAILS_ENV = "test" +CURRENT_DIR = File.expand_path(File.dirname(__FILE__)) +HTML_DIR = File.expand_path(File.join(CURRENT_DIR, "..", "html")) module Rails def self.public_path - File.expand_path(File.join(File.dirname(__FILE__), "..", "html")) + CURRENT_DIR end end @@ -30,6 +32,10 @@ class ErrorPageControllerTest < Test::Unit::TestCase end def test_500_error_page_instructs_system_administrator_to_check_log_file + template = ERB.new(File.read(File.join(HTML_DIR, "500.html"))) + File.open(File.join(CURRENT_DIR, "500.html"), "w") do |f| + f.write(template.result) + end get :crash expected_log_file = "#{RAILS_ENV}.log" assert_not_nil @response.body.index(expected_log_file) -- cgit v1.2.3 From b3411ff59eb1e1c31f98f58f117a2ffaaf0c3ff5 Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion" <hongli@phusion.nl> Date: Wed, 27 Aug 2008 12:42:08 +0200 Subject: Deprecate Rails::SecretKeyGenerator in favor of ActiveSupport::SecureRandom. SecureRandom has a few minor security enhancements and can be used as a drop-in replacement Signed-off-by: Michael Koziarski <michael@koziarski.com> [#913 state:committed] --- railties/test/secret_key_generation_test.rb | 8 -------- 1 file changed, 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/secret_key_generation_test.rb b/railties/test/secret_key_generation_test.rb index ea1b0dae31..2a04cff856 100644 --- a/railties/test/secret_key_generation_test.rb +++ b/railties/test/secret_key_generation_test.rb @@ -33,12 +33,4 @@ class SecretKeyGenerationTest < Test::Unit::TestCase def test_secret_key_generation assert @generator.generate_secret.length >= SECRET_KEY_MIN_LENGTH end - - Rails::SecretKeyGenerator::GENERATORS.each do |generator| - if Rails::SecretKeyGenerator.send("supports_#{generator}?") - define_method("test_secret_key_generation_with_#{generator}") do - assert @generator.send("generate_secret_with_#{generator}").length >= SECRET_KEY_MIN_LENGTH - end - end - end end -- cgit v1.2.3 From 8b6870cfae8d50a2ffd4f024d33d51aadaa6a6f7 Mon Sep 17 00:00:00 2001 From: Michael Koziarski <michael@koziarski.com> Date: Thu, 28 Aug 2008 12:47:18 +0200 Subject: Prevent deprecation warning in the tests --- railties/test/secret_key_generation_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/secret_key_generation_test.rb b/railties/test/secret_key_generation_test.rb index 2a04cff856..7269f98ce5 100644 --- a/railties/test/secret_key_generation_test.rb +++ b/railties/test/secret_key_generation_test.rb @@ -31,6 +31,8 @@ class SecretKeyGenerationTest < Test::Unit::TestCase end def test_secret_key_generation - assert @generator.generate_secret.length >= SECRET_KEY_MIN_LENGTH + assert_deprecated /ActiveSupport::SecureRandom\.hex\(64\)/ do + assert @generator.generate_secret.length >= SECRET_KEY_MIN_LENGTH + end end end -- cgit v1.2.3