aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/error_page_test.rb43
-rw-r--r--railties/test/fixtures/eager/zoo.rb3
-rw-r--r--railties/test/fixtures/eager/zoo/reptile_house.rb2
-rw-r--r--railties/test/gem_dependency_test.rb9
-rw-r--r--railties/test/generators/generator_test_helper.rb5
-rw-r--r--railties/test/generators/rails_model_generator_test.rb16
-rw-r--r--railties/test/initializer_test.rb39
7 files changed, 114 insertions, 3 deletions
diff --git a/railties/test/error_page_test.rb b/railties/test/error_page_test.rb
new file mode 100644
index 0000000000..844f889aad
--- /dev/null
+++ b/railties/test/error_page_test.rb
@@ -0,0 +1,43 @@
+require 'abstract_unit'
+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
+ CURRENT_DIR
+ 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
+ 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)
+ end
+end
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/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb
index b5946aa7b8..964ca50992 100644
--- a/railties/test/gem_dependency_test.rb
+++ b/railties/test/gem_dependency_test.rb
@@ -11,6 +11,7 @@ uses_mocha "Plugin Tests" do
@gem_with_source = Rails::GemDependency.new "hpricot", :source => "http://code.whytheluckystiff.net"
@gem_with_version = Rails::GemDependency.new "hpricot", :version => "= 0.6"
@gem_with_lib = Rails::GemDependency.new "aws-s3", :lib => "aws/s3"
+ @gem_without_load = Rails::GemDependency.new "hpricot", :lib => false
end
def test_configuration_adds_gem_dependency
@@ -62,5 +63,13 @@ uses_mocha "Plugin Tests" do
@gem_with_lib.add_load_paths
@gem_with_lib.load
end
+
+ def test_gem_without_lib_loading
+ @gem_without_load.expects(:gem).with(@gem_without_load.name)
+ @gem_without_load.expects(:require).with(@gem_without_load.lib).never
+ @gem_without_load.add_load_paths
+ @gem_without_load.load
+ end
+
end
end
diff --git a/railties/test/generators/generator_test_helper.rb b/railties/test/generators/generator_test_helper.rb
index 05dca3400e..0901b215e4 100644
--- a/railties/test/generators/generator_test_helper.rb
+++ b/railties/test/generators/generator_test_helper.rb
@@ -5,9 +5,10 @@ require 'fileutils'
module ActiveRecord
class Base
class << self
- attr_accessor :pluralize_table_names
+ attr_accessor :pluralize_table_names, :timestamped_migrations
end
self.pluralize_table_names = true
+ self.timestamped_migrations = true
end
module ConnectionAdapters
@@ -226,7 +227,7 @@ class GeneratorTestCase < Test::Unit::TestCase
end
end
- # Asserts that the given fixtures yaml file was generated.
+ # Asserts that the given fixtures YAML file was generated.
# It takes a fixture name without the <tt>.yml</tt> part.
# The parsed YAML tree is passed to a block.
def assert_generated_fixtures_for(name)
diff --git a/railties/test/generators/rails_model_generator_test.rb b/railties/test/generators/rails_model_generator_test.rb
index 0bfc338566..aea2abafba 100644
--- a/railties/test/generators/rails_model_generator_test.rb
+++ b/railties/test/generators/rails_model_generator_test.rb
@@ -29,4 +29,20 @@ 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
+
+ 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
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index dee7abe05f..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
@@ -136,8 +154,27 @@ uses_mocha 'framework paths' do
end
end
- protected
+ def test_action_mailer_load_paths_set_only_if_action_mailer_in_use
+ @config.frameworks = [:action_controller]
+ initializer = Rails::Initializer.new @config
+ initializer.send :require_frameworks
+ assert_nothing_raised NameError do
+ initializer.send :load_view_paths
+ end
+ end
+
+ def test_action_controller_load_paths_set_only_if_action_controller_in_use
+ @config.frameworks = []
+ initializer = Rails::Initializer.new @config
+ initializer.send :require_frameworks
+
+ assert_nothing_raised NameError do
+ initializer.send :load_view_paths
+ end
+ end
+
+ protected
def assert_framework_path(path)
assert @config.framework_paths.include?(path),
"<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>"