diff options
27 files changed, 124 insertions, 59 deletions
diff --git a/actionmailer/MIT-LICENSE b/actionmailer/MIT-LICENSE index a345a2419d..7ad1051066 100644 --- a/actionmailer/MIT-LICENSE +++ b/actionmailer/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010 David Heinemeier Hansson +Copyright (c) 2004-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 02a9916703..b9e682b711 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2010 David Heinemeier Hansson +# Copyright (c) 2004-2011 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/actionpack/MIT-LICENSE b/actionpack/MIT-LICENSE index a345a2419d..7ad1051066 100644 --- a/actionpack/MIT-LICENSE +++ b/actionpack/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010 David Heinemeier Hansson +Copyright (c) 2004-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index b89e03bfb6..1cd93a188c 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -66,7 +66,7 @@ module ActionController #:nodoc: # * <tt>:only/:except</tt> - Passed to the <tt>before_filter</tt> call. Set which actions are verified. def protect_from_forgery(options = {}) self.request_forgery_protection_token ||= :authenticity_token - before_filter :verify_authenticity_token, options + prepend_before_filter :verify_authenticity_token, options end end diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index 50d0d191c1..49971fc9f8 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2010 David Heinemeier Hansson +# Copyright (c) 2004-2011 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/actionpack/lib/action_pack.rb b/actionpack/lib/action_pack.rb index 1a1497385a..914b13dbfb 100644 --- a/actionpack/lib/action_pack.rb +++ b/actionpack/lib/action_pack.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2010 David Heinemeier Hansson +# Copyright (c) 2004-2011 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index dada64a86f..60665387b6 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2010 David Heinemeier Hansson +# Copyright (c) 2004-2011 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/activemodel/MIT-LICENSE b/activemodel/MIT-LICENSE index a345a2419d..7ad1051066 100644 --- a/activemodel/MIT-LICENSE +++ b/activemodel/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010 David Heinemeier Hansson +Copyright (c) 2004-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index dd6ee058cc..d0e2a6f39c 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2010 David Heinemeier Hansson +# Copyright (c) 2004-2011 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/activerecord/MIT-LICENSE b/activerecord/MIT-LICENSE index 86bcb23b7c..c73d1af096 100644 --- a/activerecord/MIT-LICENSE +++ b/activerecord/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010 David Heinemeier Hansson +Copyright (c) 2004-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 8379f6a66f..0777f85869 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2010 David Heinemeier Hansson +# Copyright (c) 2004-2011 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 0f421560f0..d291632260 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -102,10 +102,9 @@ module ActiveRecord def scope(name, scope_options = {}) name = name.to_sym valid_scope_name?(name) - extension = Module.new(&Proc.new) if block_given? - scopes[name] = lambda do |*args| + scope_proc = lambda do |*args| options = scope_options.respond_to?(:call) ? scope_options.call(*args) : scope_options relation = if options.is_a?(Hash) @@ -119,6 +118,8 @@ module ActiveRecord extension ? relation.extending(extension) : relation end + self.scopes = self.scopes.merge name => scope_proc + singleton_class.send(:redefine_method, name, &scopes[name]) end diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb index 8b011ad9af..0893d7e337 100644 --- a/activerecord/lib/active_record/observer.rb +++ b/activerecord/lib/active_record/observer.rb @@ -104,10 +104,17 @@ module ActiveRecord def define_callbacks(klass) observer = self + observer_name = observer.class.name.underscore.gsub('/', '__') ActiveRecord::Callbacks::CALLBACKS.each do |callback| next unless respond_to?(callback) - klass.send(callback){|record| observer.send(callback, record)} + callback_meth = :"_notify_#{observer_name}_for_#{callback}" + unless klass.respond_to?(callback_meth) + klass.send(:define_method, callback_meth) do + observer.send(callback, self) + end + klass.send(callback, callback_meth) + end end end end diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index c6cd8891e3..3c7533ea48 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -67,15 +67,10 @@ module ActiveRecord end def respond_to?(method, include_private = false) - return true if arel.respond_to?(method, include_private) || Array.method_defined?(method) || @klass.respond_to?(method, include_private) - - if match = DynamicFinderMatch.match(method) - return true if @klass.send(:all_attributes_exists?, match.attribute_names) - elsif match = DynamicScopeMatch.match(method) - return true if @klass.send(:all_attributes_exists?, match.attribute_names) - else + arel.respond_to?(method, include_private) || + Array.method_defined?(method) || + @klass.respond_to?(method, include_private) || super - end end def to_a diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index b9d9d89220..8f55b7ebe6 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -965,7 +965,10 @@ class TestAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCase values = [@pirate.reload.catchphrase, @pirate.ship.name, *@pirate.ship.parts.map(&:name)] # Oracle saves empty string as NULL if current_adapter?(:OracleAdapter) - assert_equal [nil, nil, nil, nil], values + expected = ActiveRecord::IdentityMap.enabled? ? + [nil, nil, '', ''] : + [nil, nil, nil, nil] + assert_equal expected, values else assert_equal ['', '', '', ''], values end @@ -1060,7 +1063,8 @@ class TestAutosaveAssociationOnABelongsToAssociation < ActiveRecord::TestCase @ship.save(:validate => false) # Oracle saves empty string as NULL if current_adapter?(:OracleAdapter) - assert_equal [nil, nil], [@ship.reload.name, @ship.pirate.catchphrase] + expected = ActiveRecord::IdentityMap.enabled? ? [nil, ''] : [nil, nil] + assert_equal expected, [@ship.reload.name, @ship.pirate.catchphrase] else assert_equal ['', ''], [@ship.reload.name, @ship.pirate.catchphrase] end diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 0558deb71b..6cd8494c9e 100644 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -7,6 +7,16 @@ require 'models/comment' class SpecialDeveloper < Developer; end +class DeveloperObserver < ActiveRecord::Observer + def calls + @calls ||= [] + end + + def before_save(developer) + calls << developer + end +end + class SalaryChecker < ActiveRecord::Observer observe :special_developer attr_accessor :last_saved @@ -196,4 +206,14 @@ class LifecycleTest < ActiveRecord::TestCase assert_equal developer, SalaryChecker.instance.last_saved end + def test_observer_is_called_once + observer = DeveloperObserver.instance # activate + observer.calls.clear + + developer = Developer.create! :name => 'Ancestor', :salary => 100000 + special_developer = SpecialDeveloper.create! :name => 'Descendent', :salary => 100000 + + assert_equal [developer, special_developer], observer.calls + end + end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index d05b0ff947..fb050c3e52 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -64,6 +64,10 @@ class NamedScopeTest < ActiveRecord::TestCase assert Reply.scopes.include?(:base) assert_equal Reply.find(:all), Reply.base end + + def test_classes_dont_inherit_subclasses_scopes + assert !ActiveRecord::Base.scopes.include?(:base) + end def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified assert !Topic.find(:all, :conditions => {:approved => true}).empty? diff --git a/activeresource/MIT-LICENSE b/activeresource/MIT-LICENSE index 1bf965ff1e..216b6e5ba0 100644 --- a/activeresource/MIT-LICENSE +++ b/activeresource/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2006-2010 David Heinemeier Hansson +Copyright (c) 2006-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/activesupport/MIT-LICENSE b/activesupport/MIT-LICENSE index cd928b856d..5e8b7a9450 100644 --- a/activesupport/MIT-LICENSE +++ b/activesupport/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2005-2010 David Heinemeier Hansson +Copyright (c) 2005-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 97c0ef14db..8d1b1c02c6 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -115,11 +115,9 @@ class BufferedLoggerTest < Test::Unit::TestCase def test_should_create_the_log_directory_if_it_doesnt_exist tmp_directory = File.join(File.dirname(__FILE__), "tmp") log_file = File.join(tmp_directory, "development.log") - assert !File.exist?(tmp_directory) + FileUtils.rm_rf(tmp_directory) @logger = Logger.new(log_file) assert File.exist?(tmp_directory) - ensure - FileUtils.rm_rf(tmp_directory) end def test_logger_should_maintain_separate_buffers_for_each_thread diff --git a/activesupport/test/file_watcher_test.rb b/activesupport/test/file_watcher_test.rb index 027453f86a..7b4d4be24f 100644 --- a/activesupport/test/file_watcher_test.rb +++ b/activesupport/test/file_watcher_test.rb @@ -80,27 +80,10 @@ end module FSSM::Backends class Polling - def initialize(options={}) - @handlers = [] - @latency = options[:latency] || 0.1 - end - - def add_handler(handler, preload=true) - handler.refresh(nil, true) if preload - @handlers << handler - end - - def run - begin - loop do - start = Time.now.to_f - @handlers.each { |handler| handler.refresh } - nap_time = @latency - (Time.now.to_f - start) - sleep nap_time if nap_time > 0 - end - rescue Interrupt - end + def initialize_with_low_latency(options={}) + initialize_without_low_latency(options.merge(:latency => 0.1)) end + alias_method_chain :initialize, :low_latency end end @@ -110,10 +93,10 @@ class FSSMFileWatcherTest < ActiveSupport::TestCase super monitor = FSSM::Monitor.new - monitor.path(path, '**/*') do |monitor| - monitor.update { |base, relative| trigger relative => :changed } - monitor.delete { |base, relative| trigger relative => :deleted } - monitor.create { |base, relative| trigger relative => :created } + monitor.path(path, '**/*') do |p| + p.update { |base, relative| trigger relative => :changed } + p.delete { |base, relative| trigger relative => :deleted } + p.create { |base, relative| trigger relative => :created } end @thread = Thread.new do diff --git a/railties/MIT-LICENSE b/railties/MIT-LICENSE index 86bcb23b7c..c73d1af096 100644 --- a/railties/MIT-LICENSE +++ b/railties/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010 David Heinemeier Hansson +Copyright (c) 2004-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9cb3a0f008..94819820bc 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -122,7 +122,8 @@ module Rails @env_config ||= super.merge({ "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.secret_token" => config.secret_token, - "action_dispatch.asset_path" => nil + "action_dispatch.asset_path" => nil, + "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions }) end @@ -156,7 +157,7 @@ module Rails middleware.use ::Rack::Lock unless config.allow_concurrency middleware.use ::Rack::Runtime middleware.use ::Rails::Rack::Logger - middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local if config.action_dispatch.show_exceptions + middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header middleware.use ::ActionDispatch::Reloader unless config.cache_classes diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 4f4b7beec4..044fd2a278 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -318,5 +318,20 @@ module ApplicationTests assert ActionView::Resolver.caching? end + + test "config.action_dispatch.show_exceptions is sent in env" do + make_basic_app do |app| + app.config.action_dispatch.show_exceptions = true + end + + class ::OmgController < ActionController::Base + def index + render :text => env["action_dispatch.show_exceptions"] + end + end + + get "/" + assert_equal 'true', 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 new file mode 100644 index 0000000000..5487e41e0a --- /dev/null +++ b/railties/test/application/middleware/show_exceptions_test.rb @@ -0,0 +1,37 @@ +require 'isolation/abstract_unit' + +module ApplicationTests + class ShowExceptionsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + 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 + + assert_raise(ActionController::RoutingError) do + get '/foo' + end + 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 + + assert_nothing_raised(ActionController::RoutingError) do + get '/foo' + end + end + end +end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 44dd0bc8e4..b314832685 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -78,10 +78,10 @@ module ApplicationTests assert !middleware.include?("ActionDispatch::Static") end - test "removes show exceptions if action_dispatch.show_exceptions is disabled" do + test "includes show exceptions even 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::ShowExceptions") end test "removes ActionDispatch::Reloader if cache_classes is true" do diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 46a6da3568..1b9a8fd8a7 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -34,6 +34,6 @@ module GeneratorsTestHelper routes = File.expand_path("../../../lib/rails/generators/rails/app/templates/config/routes.rb", __FILE__) destination = File.join(destination_root, "config") FileUtils.mkdir_p(destination) - FileUtils.cp File.expand_path(routes), destination + FileUtils.cp routes, destination end end |