From f1b4cacbae71585be3f5dcb4c1bdd7c78ef3d590 Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 21 Dec 2011 19:07:00 +0300 Subject: [PATCH 01/14] remove Enumerable#each_with_object from core_ext as it is present in ruby 1.9 --- .../lib/active_support/core_ext/enumerable.rb | 21 --------------- activesupport/lib/active_support/ruby/shim.rb | 4 +-- .../test/core_ext/enumerable_test.rb | 11 +------- .../active_support_core_extensions.textile | 26 ------------------- 4 files changed, 3 insertions(+), 59 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index ccd0e9692d599..3f13468e4d93a 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -33,27 +33,6 @@ def pluck(method) collect { |element| element.send(method) } end - # Iterates over a collection, passing the current element *and* the - # +memo+ to the block. Handy for building up hashes or - # reducing collections down to one object. Examples: - # - # %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } - # # => {'foo' => 'FOO', 'bar' => 'BAR'} - # - # *Note* that you can't use immutable objects like numbers, true or false as - # the memo. You would think the following returns 120, but since the memo is - # never changed, it does not. - # - # (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1 - # - def each_with_object(memo) - return to_enum :each_with_object, memo unless block_given? - each do |element| - yield element, memo - end - memo - end unless [].respond_to?(:each_with_object) - # Convert an enumerable to a hash. Examples: # # people.index_by(&:login) diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb index 608b3fe4b9b9b..fc37ab84a3d08 100644 --- a/activesupport/lib/active_support/ruby/shim.rb +++ b/activesupport/lib/active_support/ruby/shim.rb @@ -3,7 +3,7 @@ # # Date next_year, next_month # DateTime to_date, to_datetime, xmlschema -# Enumerable group_by, each_with_object, none? +# Enumerable group_by, none? # Process Process.daemon # REXML security fix # String ord @@ -19,4 +19,4 @@ require 'active_support/core_ext/rexml' require 'active_support/core_ext/time/conversions' require 'active_support/core_ext/file/path' -require 'active_support/core_ext/module/method_names' \ No newline at end of file +require 'active_support/core_ext/module/method_names' diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 7ce7c4d52d462..7c2aec3462d00 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -86,15 +86,6 @@ def test_range_sums assert_equal 'abc', ('a'..'c').sum end - def test_each_with_object - enum = GenericEnumerable.new(%w(foo bar)) - result = enum.each_with_object({}) { |str, hsh| hsh[str] = str.upcase } - assert_equal({'foo' => 'FOO', 'bar' => 'BAR'}, result) - assert_equal Enumerator, enum.each_with_object({}).class - result2 = enum.each_with_object({}).each{|str, hsh| hsh[str] = str.upcase} - assert_equal result, result2 - end - def test_index_by payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10) ]) assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) }, @@ -133,4 +124,4 @@ def test_pluck_single_method assert_equal [ "David", "Jamie" ], people.pluck(:name) end -end \ No newline at end of file +end diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index a5f9cd483b431..ee4565fdfeecd 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2038,32 +2038,6 @@ people.pluck(:name) # => [ "David Heinemeier Hansson", "Jamie Heinemeier Hansson NOTE: Defined in +active_support/core_ext/enumerable.rb+. -h4. +each_with_object+ - -The +inject+ method offers iteration with an accumulator: - - -[2, 3, 4].inject(1) {|product, i| product*i } # => 24 - - -The block is expected to return the value for the accumulator in the next iteration, and this makes building mutable objects a bit cumbersome: - - -[1, 2].inject({}) {|h, i| h[i] = i**2; h} # => {1 => 1, 2 => 4} - - -See that spurious "+; h+"? - -Active Support backports +each_with_object+ from Ruby 1.9, which addresses that use case. It iterates over the collection, passes the accumulator, and returns the accumulator when done. You normally modify the accumulator in place. The example above would be written this way: - - -[1, 2].each_with_object({}) {|i, h| h[i] = i**2} # => {1 => 1, 2 => 4} - - -WARNING. Note that the item of the collection and the accumulator come in different order in +inject+ and +each_with_object+. - -NOTE: Defined in +active_support/core_ext/enumerable.rb+. - h4. +index_by+ The method +index_by+ generates a hash with the elements of an enumerable indexed by some key. From 9fbaf9f0777485b32ae12d0cc261695b9bb26eea Mon Sep 17 00:00:00 2001 From: Lucas Mazza Date: Wed, 21 Dec 2011 17:31:53 -0200 Subject: [PATCH 02/14] raises an ArgumentError if no valid options are given to TemplateRenderer#determine_template --- .../lib/action_view/renderer/template_renderer.rb | 2 ++ actionpack/test/template/render_test.rb | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb index 3e3a44b4326db..06148ccc9822f 100644 --- a/actionpack/lib/action_view/renderer/template_renderer.rb +++ b/actionpack/lib/action_view/renderer/template_renderer.rb @@ -25,6 +25,8 @@ def determine_template(options) #:nodoc: elsif options.key?(:template) options[:template].respond_to?(:render) ? options[:template] : find_template(options[:template], options[:prefixes], false, keys, @details) + else + raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file or :text option." end end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 2ba86306f4488..761bcf61f229c 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -20,6 +20,13 @@ def setup_view(paths) assert_equal ORIGINAL_LOCALES, I18n.available_locales.map {|l| l.to_s }.sort end + def test_render_without_options + @view.render() + flunk "Render did not raise ArgumentError" + rescue ArgumentError => e + assert_match "You invoked render but did not give any of :partial, :template, :inline, :file or :text option.", e.message + end + def test_render_file assert_equal "Hello world!", @view.render(:file => "test/hello_world") end @@ -43,21 +50,21 @@ def test_render_template_with_format assert_match "

No Comment

", @view.render(:template => "comments/empty", :formats => [:html]) assert_match "No Comment", @view.render(:template => "comments/empty", :formats => [:xml]) end - + def test_render_file_with_locale assert_equal "

Kein Kommentar

", @view.render(:file => "comments/empty", :locale => [:de]) assert_equal "

Kein Kommentar

", @view.render(:file => "comments/empty", :locale => :de) end - + def test_render_template_with_locale assert_equal "

Kein Kommentar

", @view.render(:template => "comments/empty", :locale => [:de]) end - + def test_render_file_with_handlers assert_equal "

No Comment

\n", @view.render(:file => "comments/empty", :handlers => [:builder]) assert_equal "

No Comment

\n", @view.render(:file => "comments/empty", :handlers => :builder) end - + def test_render_template_with_handlers assert_equal "

No Comment

\n", @view.render(:template => "comments/empty", :handlers => [:builder]) end From 5a4b41443c09c1d1f5c996afe0838391b2e2c5f2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 21 Dec 2011 12:43:41 -0700 Subject: [PATCH 03/14] Move SubTestTask. Soften up tests. --- railties/lib/rails/test_unit/sub_test_task.rb | 36 +++++++++++++++++ railties/lib/rails/test_unit/testing.rake | 39 +------------------ railties/test/application/rake_test.rb | 17 ++++---- 3 files changed, 44 insertions(+), 48 deletions(-) create mode 100644 railties/lib/rails/test_unit/sub_test_task.rb diff --git a/railties/lib/rails/test_unit/sub_test_task.rb b/railties/lib/rails/test_unit/sub_test_task.rb new file mode 100644 index 0000000000000..284c70050fb3a --- /dev/null +++ b/railties/lib/rails/test_unit/sub_test_task.rb @@ -0,0 +1,36 @@ +module Rails + # Don't abort when tests fail; move on the next test task. + # Silence the default description to cut down on `rake -T` noise. + class SubTestTask < Rake::TestTask + # Create the tasks defined by this task lib. + def define + lib_path = @libs.join(File::PATH_SEPARATOR) + task @name do + run_code = '' + RakeFileUtils.verbose(@verbose) do + run_code = + case @loader + when :direct + "-e 'ARGV.each{|f| load f}'" + when :testrb + "-S testrb #{fix}" + when :rake + rake_loader + end + @ruby_opts.unshift( "-I\"#{lib_path}\"" ) + @ruby_opts.unshift( "-w" ) if @warning + + begin + ruby @ruby_opts.join(" ") + + " \"#{run_code}\" " + + file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + + " #{option_list}" + rescue => error + warn "Error running #{name}: #{error.inspect}" + end + end + end + self + end + end +end diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 62c8de8d22324..a23d22d6074a5 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,43 +1,6 @@ require 'rbconfig' require 'rake/testtask' - -module Rails - # Don't abort when tests fail; move on the next test task. - # Silence the default description to cut down on `rake -T` noise. - class SubTestTask < Rake::TestTask - # Create the tasks defined by this task lib. - def define - lib_path = @libs.join(File::PATH_SEPARATOR) - task @name do - run_code = '' - RakeFileUtils.verbose(@verbose) do - run_code = - case @loader - when :direct - "-e 'ARGV.each{|f| load f}'" - when :testrb - "-S testrb #{fix}" - when :rake - rake_loader - end - @ruby_opts.unshift( "-I\"#{lib_path}\"" ) - @ruby_opts.unshift( "-w" ) if @warning - - begin - ruby @ruby_opts.join(" ") + - " \"#{run_code}\" " + - file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + - " #{option_list}" - rescue => error - warn "Error running #{@name}: #{error.inspect}" - end - end - end - self - end - end -end - +require 'rails/test_unit/sub_test_task' TEST_CHANGES_SINCE = Time.now - 600 diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index d4d4e4e5ff8f8..1d90671e443f3 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -63,26 +63,23 @@ def test_code_statistics_sanity def test_rake_test_error_output Dir.chdir(app_path){ `rake db:migrate` } - app_file "config/database.yml", <<-RUBY - development: - RUBY - app_file "test/unit/one_unit_test.rb", <<-RUBY + raise 'unit' RUBY app_file "test/functional/one_functional_test.rb", <<-RUBY - raise RuntimeError + raise 'functional' RUBY app_file "test/integration/one_integration_test.rb", <<-RUBY - raise RuntimeError + raise 'integration' RUBY silence_stderr do - output = Dir.chdir(app_path){ `rake test` } - assert_match(/Errors running test:units! #&1` } + assert_match 'unit', output + assert_match 'functional', output + assert_match 'integration', output end end From 1ad0a5363bcf44da9ed51e30c5c47a83c3516c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ku=C5=BAma?= Date: Wed, 21 Dec 2011 15:28:24 +0100 Subject: [PATCH 04/14] added failing tests for has_many, has_one and belongs_to associations with strict mass assignment sanitizer, fixed build_record to not merge creation_attributes, removed failing nested attributes tests (that feature was broken anyway) #4051 --- .../active_record/associations/association.rb | 7 +-- .../cases/mass_assignment_security_test.rb | 63 +++++++++++++++++++ .../test/cases/nested_attributes_test.rb | 5 -- activerecord/test/models/person.rb | 4 +- 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 861dda618aaa2..7887d59aad443 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -230,13 +230,8 @@ def association_class end def build_record(attributes, options) - attributes = (attributes || {}).reverse_merge(creation_attributes) - reflection.build_association(attributes, options) do |record| - record.assign_attributes( - create_scope.except(*record.changed), - :without_protection => true - ) + record.assign_attributes(create_scope.except(*record.changed), :without_protection => true) end end end diff --git a/activerecord/test/cases/mass_assignment_security_test.rb b/activerecord/test/cases/mass_assignment_security_test.rb index 9fff50edcbee9..8122857f52dba 100644 --- a/activerecord/test/cases/mass_assignment_security_test.rb +++ b/activerecord/test/cases/mass_assignment_security_test.rb @@ -50,6 +50,13 @@ def assert_all_attributes(person) assert_equal 'm', person.gender assert_equal 'rides a sweet bike', person.comments end + + def with_strict_sanitizer + ActiveRecord::Base.mass_assignment_sanitizer = :strict + yield + ensure + ActiveRecord::Base.mass_assignment_sanitizer = :logger + end end module MassAssignmentRelationTestHelpers @@ -323,6 +330,13 @@ def test_has_one_build_without_protection assert_all_attributes(best_friend) end + def test_has_one_build_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.build_best_friend(attributes_hash.except(:id, :comments)) + assert_equal @person.id, best_friend.best_friend_id + end + end + # create def test_has_one_create_with_attr_protected_attributes @@ -350,6 +364,13 @@ def test_has_one_create_without_protection assert_all_attributes(best_friend) end + def test_has_one_create_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.create_best_friend(attributes_hash.except(:id, :comments)) + assert_equal @person.id, best_friend.best_friend_id + end + end + # create! def test_has_one_create_with_bang_with_attr_protected_attributes @@ -377,6 +398,13 @@ def test_has_one_create_with_bang_without_protection assert_all_attributes(best_friend) end + def test_has_one_create_with_bang_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.create_best_friend!(attributes_hash.except(:id, :comments)) + assert_equal @person.id, best_friend.best_friend_id + end + end + end @@ -438,6 +466,13 @@ def test_belongs_to_create_without_protection assert_all_attributes(best_friend) end + def test_belongs_to_create_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.create_best_friend_of(attributes_hash.except(:id, :comments)) + assert_equal best_friend.id, @person.best_friend_of_id + end + end + # create! def test_belongs_to_create_with_bang_with_attr_protected_attributes @@ -465,6 +500,13 @@ def test_belongs_to_create_with_bang_without_protection assert_all_attributes(best_friend) end + def test_belongs_to_create_with_bang_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.create_best_friend_of!(attributes_hash.except(:id, :comments)) + assert_equal best_friend.id, @person.best_friend_of_id + end + end + end @@ -499,6 +541,13 @@ def test_has_many_build_without_protection assert_all_attributes(best_friend) end + def test_has_many_build_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.best_friends.build(attributes_hash.except(:id, :comments)) + assert_equal @person.id, best_friend.best_friend_id + end + end + # create def test_has_many_create_with_attr_protected_attributes @@ -526,6 +575,13 @@ def test_has_many_create_without_protection assert_all_attributes(best_friend) end + def test_has_many_create_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.best_friends.create(attributes_hash.except(:id, :comments)) + assert_equal @person.id, best_friend.best_friend_id + end + end + # create! def test_has_many_create_with_bang_with_attr_protected_attributes @@ -553,6 +609,13 @@ def test_has_many_create_with_bang_without_protection assert_all_attributes(best_friend) end + def test_has_many_create_with_bang_with_strict_sanitizer + with_strict_sanitizer do + best_friend = @person.best_friends.create!(attributes_hash.except(:id, :comments)) + assert_equal @person.id, best_friend.best_friend_id + end + end + end diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 2f28dd4767f91..2ae9cb4888357 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -617,11 +617,6 @@ def test_should_take_a_hash_with_composite_id_keys_and_assign_the_attributes_to_ assert_equal ['Grace OMalley', 'Privateers Greed'], [@child_1.name, @child_2.name] end - def test_should_take_a_hash_with_owner_attributes_and_assign_the_attributes_to_the_associated_model - @pirate.birds.create :name => 'bird', :pirate_attributes => {:id => @pirate.id.to_s, :catchphrase => 'Holla!'} - assert_equal 'Holla!', @pirate.reload.catchphrase - end - def test_should_raise_RecordNotFound_if_an_id_is_given_but_doesnt_return_a_record assert_raise_with_message ActiveRecord::RecordNotFound, "Couldn't find #{@child_1.class.name} with ID=1234567890 for Pirate with ID=#{@pirate.id}" do @pirate.attributes = { association_getter => [{ :id => 1234567890 }] } diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index 967a3625aa7e4..36eb08d02fb14 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -54,7 +54,7 @@ class LoosePerson < ActiveRecord::Base self.table_name = 'people' self.abstract_class = true - attr_protected :comments + attr_protected :comments, :best_friend_id, :best_friend_of_id attr_protected :as => :admin has_one :best_friend, :class_name => 'LoosePerson', :foreign_key => :best_friend_id @@ -81,4 +81,4 @@ class TightPerson < ActiveRecord::Base accepts_nested_attributes_for :best_friend, :best_friend_of, :best_friends end -class TightDescendant < TightPerson; end \ No newline at end of file +class TightDescendant < TightPerson; end From d6d774063da02f0654f9203c8bface943e889454 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 11:41:19 -0700 Subject: [PATCH 05/14] switch to git journey --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 76fd2a2f9669a..1284c6053124b 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem 'jquery-rails' if ENV['JOURNEY'] gem 'journey', :path => ENV['JOURNEY'] else - gem 'journey' + gem 'journey', :git => "git://github.com/rails/journey" end # This needs to be with require false to avoid From 44ff03bb2eb1eb2b088265389a2adc89936d7099 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 11:45:41 -0700 Subject: [PATCH 06/14] adding integration test for journey #7 --- actionpack/test/controller/routing_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index a60da65ae533e..a931222bbcbba 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -81,6 +81,28 @@ def setup @rs = ::ActionDispatch::Routing::RouteSet.new end + def test_regexp_precidence + @rs.draw do + match '/whois/:domain', :constraints => { + :domain => /\w+\.[\w\.]+/ }, + :to => lambda { |env| [200, {}, 'regexp'] } + + match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] } + end + + body = @rs.call({'PATH_INFO' => '/whois/example.org', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'www.example.org'})[2] + + assert_equal 'regexp', body + + body = @rs.call({'PATH_INFO' => '/whois/123', + 'REQUEST_METHOD' => 'GET', + 'HTTP_HOST' => 'clients.example.org'})[2] + + assert_equal 'id', body + end + def test_class_and_lambda_constraints subdomain = Class.new { def matches? request From 3afeb6b39b9e36e3edb3bf02d111b6c61e04a795 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 14:15:13 -0700 Subject: [PATCH 07/14] DeprecatedUnderscoreRead does not exist anymore --- activerecord/lib/active_record.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 2463f3951f698..77971973f6020 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -105,7 +105,6 @@ module AttributeMethods autoload :TimeZoneConversion autoload :Write autoload :Serialization - autoload :DeprecatedUnderscoreRead end end From e68b72dbc4d121e05f70cc56c7b4dfb7e314b8b9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 14:22:38 -0700 Subject: [PATCH 08/14] just use def setup --- actionpack/test/dispatch/routing_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 5325f81364184..d5c15866008f9 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2414,7 +2414,8 @@ def simple_app(resp) lambda { |e| [ 200, { 'Content-Type' => 'text/plain' }, [resp] ] } end - setup do + def setup + super s = self @app = ActionDispatch::Routing::RouteSet.new @app.append do From d4a4fcbc936818e1925781caa3ba735df77866da Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 14:54:39 -0700 Subject: [PATCH 09/14] append puts the routes after the default, which causes a 404. instead use prepend --- railties/test/application/configuration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 8f2e6e9ac0017..30748674cd851 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -479,7 +479,7 @@ def create RUBY add_to_config <<-RUBY - routes.append do + routes.prepend do resources :posts end RUBY From 401b266f5fc1e6c5f13feb36122a1983989d8f58 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 21 Dec 2011 15:03:43 -0700 Subject: [PATCH 10/14] just require things once --- railties/test/application/configuration_test.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 30748674cd851..758b56d17d236 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1,4 +1,5 @@ require "isolation/abstract_unit" +require 'rack/test' class ::MyMailInterceptor def self.delivering_email(email); email; end @@ -15,6 +16,7 @@ class ::MyOtherMailObserver < ::MyMailObserver; end module ApplicationTests class ConfigurationTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + include Rack::Test::Methods def new_app File.expand_path("#{app_path}/../new_app") @@ -181,8 +183,6 @@ def teardown assert !$prepared require "#{app_path}/config/environment" - require 'rack/test' - extend Rack::Test::Methods get "/" assert $prepared @@ -485,8 +485,6 @@ def create RUBY require "#{app_path}/config/environment" - require "rack/test" - extend Rack::Test::Methods post "/posts.json", '{ "title": "foo", "name": "bar" }', "CONTENT_TYPE" => "application/json" assert_equal '{"title"=>"foo"}', last_response.body From 7bfaa979e4e48dea68023e1aa67eabd160c3a7d3 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Thu, 22 Dec 2011 08:43:42 +0300 Subject: [PATCH 11/14] remove Proces.daemon from core_ext --- .../lib/active_support/core_ext/process.rb | 1 - .../active_support/core_ext/process/daemon.rb | 23 ------------------- activesupport/lib/active_support/ruby/shim.rb | 2 -- .../active_support_core_extensions.textile | 6 ----- 4 files changed, 32 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/process.rb delete mode 100644 activesupport/lib/active_support/core_ext/process/daemon.rb diff --git a/activesupport/lib/active_support/core_ext/process.rb b/activesupport/lib/active_support/core_ext/process.rb deleted file mode 100644 index 0b0bc6dc69cf5..0000000000000 --- a/activesupport/lib/active_support/core_ext/process.rb +++ /dev/null @@ -1 +0,0 @@ -require 'active_support/core_ext/process/daemon' diff --git a/activesupport/lib/active_support/core_ext/process/daemon.rb b/activesupport/lib/active_support/core_ext/process/daemon.rb deleted file mode 100644 index f5202ddee4114..0000000000000 --- a/activesupport/lib/active_support/core_ext/process/daemon.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Process - def self.daemon(nochdir = nil, noclose = nil) - exit if fork # Parent exits, child continues. - Process.setsid # Become session leader. - exit if fork # Zap session leader. See [1]. - - unless nochdir - Dir.chdir "/" # Release old working directory. - end - - File.umask 0000 # Ensure sensible umask. Adjust as needed. - - unless noclose - STDIN.reopen "/dev/null" # Free file descriptors and - STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. - STDERR.reopen '/dev/null', 'a' - end - - trap("TERM") { exit } - - return 0 - end unless respond_to?(:daemon) -end diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb index fc37ab84a3d08..fd59677d83518 100644 --- a/activesupport/lib/active_support/ruby/shim.rb +++ b/activesupport/lib/active_support/ruby/shim.rb @@ -4,7 +4,6 @@ # Date next_year, next_month # DateTime to_date, to_datetime, xmlschema # Enumerable group_by, none? -# Process Process.daemon # REXML security fix # String ord # Time to_date, to_time, to_datetime @@ -12,7 +11,6 @@ require 'active_support/core_ext/date/calculations' require 'active_support/core_ext/date_time/conversions' require 'active_support/core_ext/enumerable' -require 'active_support/core_ext/process/daemon' require 'active_support/core_ext/string/conversions' require 'active_support/core_ext/string/interpolation' require 'active_support/core_ext/string/encoding' diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 25d8f50a7bbfe..1b467e1efd2e1 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -3479,12 +3479,6 @@ Time.utc_time(1582, 10, 3) + 5.days # => Mon Oct 18 00:00:00 UTC 1582 -h3. Extensions to +Process+ - -h4. +daemon+ - -Ruby 1.9 provides +Process.daemon+, and Active Support defines it for previous versions. It accepts the same two arguments, whether it should chdir to the root directory (default, true), and whether it should inherit the standard file descriptors from the parent (default, false). - h3. Extensions to +File+ h4. +atomic_write+ From 4f6af26a886630c97865a2e5023a9560692e6aa4 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Tue, 20 Dec 2011 22:18:23 +0300 Subject: [PATCH 12/14] remove AS whiny nil extension and deprecate config.whiny_nils --- activesupport/lib/active_support/railtie.rb | 6 ----- activesupport/lib/active_support/whiny_nil.rb | 22 ------------------- activesupport/test/whiny_nil_test.rb | 11 ---------- .../lib/rails/application/configuration.rb | 7 +++++- .../config/environments/development.rb.tt | 3 --- .../templates/config/environments/test.rb.tt | 3 --- 6 files changed, 6 insertions(+), 46 deletions(-) delete mode 100644 activesupport/lib/active_support/whiny_nil.rb delete mode 100644 activesupport/test/whiny_nil_test.rb diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index 1638512af0a78..f696716cc8ec2 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -5,12 +5,6 @@ module ActiveSupport class Railtie < Rails::Railtie config.active_support = ActiveSupport::OrderedOptions.new - # Loads support for "whiny nil" (noisy warnings when methods are invoked - # on +nil+ values) if Configuration#whiny_nils is true. - initializer "active_support.initialize_whiny_nils" do |app| - require 'active_support/whiny_nil' if app.config.whiny_nils - end - initializer "active_support.deprecation_behavior" do |app| if deprecation = app.config.active_support.deprecation ActiveSupport::Deprecation.behavior = deprecation diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb deleted file mode 100644 index a0652336793ed..0000000000000 --- a/activesupport/lib/active_support/whiny_nil.rb +++ /dev/null @@ -1,22 +0,0 @@ -# Extensions to +nil+ which allow for more helpful error messages for people who -# are new to Rails. -# -# NilClass#id exists in Ruby 1.8 (though it is deprecated). Since +id+ is a fundamental -# method of Active Record models NilClass#id is redefined as well to raise a RuntimeError -# and warn the user. She probably wanted a model database identifier and the 4 -# returned by the original method could result in obscure bugs. -# -# The flag config.whiny_nils determines whether this feature is enabled. -# By default it is on in development and test modes, and it is off in production -# mode. -class NilClass - def self.add_whiner(klass) - ActiveSupport::Deprecation.warn "NilClass.add_whiner is deprecated and this functionality is " \ - "removed from Rails versions as it affects Ruby 1.9 performance.", caller - end - - # Raises a RuntimeError when you attempt to call +id+ on +nil+. - def id - raise RuntimeError, "Called id for nil, which would mistakenly be #{object_id} -- if you really wanted the id of nil, use object_id", caller - end -end diff --git a/activesupport/test/whiny_nil_test.rb b/activesupport/test/whiny_nil_test.rb deleted file mode 100644 index 8c1f1b2677724..0000000000000 --- a/activesupport/test/whiny_nil_test.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'abstract_unit' -require 'active_support/whiny_nil' - -class WhinyNilTest < Test::Unit::TestCase - def test_id - nil.id - rescue RuntimeError => nme - assert_no_match(/nil:NilClass/, nme.message) - assert_match(Regexp.new(nil.object_id.to_s), nme.message) - end -end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a782441a21ba0..d14cf737d9830 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -12,7 +12,7 @@ class Configuration < ::Rails::Engine::Configuration :force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks, :railties_order, :relative_url_root, :reload_plugins, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, - :time_zone, :reload_classes_only_on_change, :whiny_nils + :time_zone, :reload_classes_only_on_change attr_writer :log_level attr_reader :encoding @@ -145,6 +145,11 @@ def session_store(*args) @session_options = args.shift || {} end end + + def whiny_nils=(*) + ActiveSupport::Deprecation.warn "config.whiny_nils option " \ + "is deprecated and no longer works", caller + end end end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 9e53b6a70d99d..a1d41fd7dd6ed 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -6,9 +6,6 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 37a8b81dad23a..86016da189bba 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -11,9 +11,6 @@ config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false From fa5adfb1e884bf21a7071ade634a820e37ac4db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 22 Dec 2011 09:35:22 +0100 Subject: [PATCH 13/14] Update activesupport/lib/active_support.rb --- activesupport/lib/active_support.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 896d0e5f65206..9fdc7a3b83ddb 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -43,6 +43,7 @@ def load_all!; load_all_hooks.each { |hook| hook.call } end module ActiveSupport extend ActiveSupport::Autoload + autoload :Concern autoload :DescendantsTracker autoload :FileUpdateChecker autoload :LogSubscriber @@ -56,7 +57,6 @@ module ActiveSupport autoload :Benchmarkable autoload :Cache autoload :Callbacks - autoload :Concern autoload :Configurable autoload :Deprecation autoload :Gzip From 5662ea511225b34d3b533d03614c496c007215b0 Mon Sep 17 00:00:00 2001 From: "Juan M. Cuello" Date: Wed, 21 Dec 2011 17:00:25 -0300 Subject: [PATCH 14/14] Reset postgreSQL search path in db:test:clone_structure. This patch resets the postgres search path in the structure.sql after the structure is dumped in order to find schema_migrations table when multiples schemas are used. Fixes #945 --- activerecord/lib/active_record/railties/databases.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 199eee43596e0..482901f23f71d 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -387,6 +387,7 @@ db_namespace = namespace :db do end `pg_dump -i -s -x -O -f #{filename} #{search_path} #{abcs[Rails.env]['database']}` raise 'Error dumping database' if $?.exitstatus == 1 + File.open(filename, "a") { |f| f << "SET search_path TO #{ActiveRecord::Base.connection.schema_search_path};\n\n" } when /sqlite/ dbfile = abcs[Rails.env]['database'] `sqlite3 #{dbfile} .schema > #{filename}`