aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/configuration_test.rb12
-rw-r--r--railties/test/application/middleware_test.rb4
-rw-r--r--railties/test/application/routing_test.rb28
-rw-r--r--railties/test/fixtures/lib/generators/model_generator.rb1
-rw-r--r--railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb (renamed from railties/test/fixtures/lib/generators/foobar/foobar_generator.rb)0
-rw-r--r--railties/test/generators/plugin_generator_test.rb2
-rw-r--r--railties/test/generators_test.rb15
-rw-r--r--railties/test/plugins/framework_extension_test.rb16
-rw-r--r--railties/test/subscriber_test.rb41
9 files changed, 90 insertions, 29 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 79dfacdcdb..6968e87986 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -122,5 +122,17 @@ module ApplicationTests
require "#{app_path}/config/environment"
end
end
+
+ test "filter_parameters should be able to set via config.filter_parameters" do
+ add_to_config <<-RUBY
+ config.filter_parameters += [ :foo, 'bar', lambda { |key, value|
+ value = value.reverse if key =~ /baz/
+ }]
+ RUBY
+
+ assert_nothing_raised do
+ require "#{app_path}/config/application"
+ end
+ end
end
end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 1c5cc62ecd..31696598ce 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -17,8 +17,8 @@ module ApplicationTests
"ActionDispatch::Static",
"Rack::Lock",
"Rack::Runtime",
+ "Rails::Rack::Logger",
"ActionDispatch::ShowExceptions",
- "ActionDispatch::Notifications",
"ActionDispatch::Callbacks",
"ActionDispatch::Cookies",
"ActionDispatch::Session::CookieStore",
@@ -76,7 +76,7 @@ module ApplicationTests
end
def middleware
- AppTemplate::Application.instance.middleware.active.map(&:klass).map(&:name)
+ AppTemplate::Application.middleware.active.map(&:klass).map(&:name)
end
end
end
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index 725dd06929..50cb9e3acc 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -176,5 +176,33 @@ module ApplicationTests
get '/foo'
assert_equal 'baz', last_response.body
end
+
+ test 'resource routing with irrigular inflection' do
+ app_file 'config/initializers/inflection.rb', <<-RUBY
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.irregular 'yazi', 'yazilar'
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ resources :yazilar
+ end
+ RUBY
+
+ controller 'yazilar', <<-RUBY
+ class YazilarController < ActionController::Base
+ def index
+ render :text => 'yazilar#index'
+ end
+ end
+ RUBY
+
+ get '/yazilars'
+ assert_equal 404, last_response.status
+
+ get '/yazilar'
+ assert_equal 200, last_response.status
+ end
end
end
diff --git a/railties/test/fixtures/lib/generators/model_generator.rb b/railties/test/fixtures/lib/generators/model_generator.rb
new file mode 100644
index 0000000000..9098a8a354
--- /dev/null
+++ b/railties/test/fixtures/lib/generators/model_generator.rb
@@ -0,0 +1 @@
+raise "I should never be loaded" \ No newline at end of file
diff --git a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb b/railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb
index d1de8c56fa..d1de8c56fa 100644
--- a/railties/test/fixtures/lib/generators/foobar/foobar_generator.rb
+++ b/railties/test/fixtures/lib/rails_generators/foobar/foobar_generator.rb
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index 4bfe210efb..0a79e2cfb8 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -17,11 +17,11 @@ class PluginGeneratorTest < Rails::Generators::TestCase
vendor/plugins/plugin_fu/uninstall.rb
vendor/plugins/plugin_fu/lib
vendor/plugins/plugin_fu/lib/plugin_fu.rb
+ vendor/plugins/plugin_fu/Rakefile
).each{ |path| assert_file path }
%w(
vendor/plugins/plugin_fu/README
- vendor/plugins/plugin_fu/Rakefile
).each{ |path| assert_file path, /PluginFu/ }
%w(
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 60c81a813f..f37b684f73 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -16,6 +16,7 @@ class GeneratorsTest < Rails::Generators::TestCase
end
def test_simple_invoke
+ assert File.exists?(File.join(@path, 'generators', 'model_generator.rb'))
TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {})
Rails::Generators.invoke("test_unit:model", ["Account"])
end
@@ -30,6 +31,13 @@ class GeneratorsTest < Rails::Generators::TestCase
assert_match /Description:/, output
end
+ def test_should_give_higher_preference_to_rails_generators
+ assert File.exists?(File.join(@path, 'generators', 'model_generator.rb'))
+ Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {})
+ warnings = capture(:stderr){ Rails::Generators.invoke :model, ["Account"] }
+ assert warnings.empty?
+ end
+
def test_invoke_with_default_values
Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {})
Rails::Generators.invoke :model, ["Account"]
@@ -148,6 +156,13 @@ class GeneratorsTest < Rails::Generators::TestCase
Rails::Generators.subclasses.delete(klass)
end
+ def test_load_generators_from_railties
+ Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {})
+ Rails::Generators.send(:remove_instance_variable, :@generators_from_railties)
+ Rails.application.expects(:load_generators)
+ Rails::Generators.invoke("model", ["Account"])
+ end
+
def test_rails_root_templates
template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb")
diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/plugins/framework_extension_test.rb
index c920db77aa..d57fd4e635 100644
--- a/railties/test/plugins/framework_extension_test.rb
+++ b/railties/test/plugins/framework_extension_test.rb
@@ -30,6 +30,22 @@ module PluginsTest
AppTemplate::Application.load_tasks
assert $ran_block
end
+
+ test "generators block is executed when MyApp.load_generators is called" do
+ $ran_block = false
+
+ class MyTie < Rails::Railtie
+ generators do
+ $ran_block = true
+ end
+ end
+
+ require "#{app_path}/config/environment"
+
+ assert !$ran_block
+ AppTemplate::Application.load_generators
+ assert $ran_block
+ end
end
class ActiveRecordExtensionTest < Test::Unit::TestCase
diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb
index fa3f7bfabb..f6c895093f 100644
--- a/railties/test/subscriber_test.rb
+++ b/railties/test/subscriber_test.rb
@@ -18,9 +18,15 @@ class MySubscriber < Rails::Subscriber
def bar(event)
info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}"
end
+
+ def puke(event)
+ raise "puke"
+ end
end
-module SubscriberTest
+class SyncSubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::TestHelper
+
def setup
super
@subscriber = MySubscriber.new
@@ -90,41 +96,24 @@ module SubscriberTest
assert_equal 1, @logger.flush_count
end
- def test_flushes_loggers_when_action_dispatch_callback_is_received
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "action_dispatch.after_dispatch"
- wait
- assert_equal 1, @logger.flush_count
- end
-
def test_flushes_the_same_logger_just_once
Rails::Subscriber.add :my_subscriber, @subscriber
Rails::Subscriber.add :another, @subscriber
- instrument "action_dispatch.after_dispatch"
+ Rails::Subscriber.flush_all!
wait
assert_equal 1, @logger.flush_count
end
- def test_tails_logs_when_action_dispatch_callback_is_received
- log_tailer = mock()
- log_tailer.expects(:tail!)
- Rails::Subscriber.log_tailer = log_tailer
-
+ def test_logging_does_not_die_on_failures
Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "action_dispatch.after_dispatch"
+ instrument "my_subscriber.puke"
+ instrument "my_subscriber.some_event"
wait
- ensure
- Rails::Subscriber.log_tailer = nil
- end
- class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::SyncTestHelper
- include SubscriberTest
- end
+ assert_equal 1, @logger.logged(:info).size
+ assert_equal 'my_subscriber.some_event', @logger.logged(:info).last
- class AsyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include SubscriberTest
+ assert_equal 1, @logger.logged(:error).size
+ assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
end
-
end \ No newline at end of file