diff options
-rw-r--r-- | actionpack/lib/abstract_controller/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/journey/router.rb | 3 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 5 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/helper_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 24 | ||||
-rw-r--r-- | guides/source/association_basics.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/reporter.rb | 12 | ||||
-rw-r--r-- | railties/test/test_unit/reporter_test.rb | 1 |
9 files changed, 37 insertions, 22 deletions
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index c95b9a4097..96d701dba5 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -88,7 +88,7 @@ module AbstractController # Returns the full controller name, underscored, without the ending Controller. # # class MyApp::MyPostsController < AbstractController::Base - # end + # # end # # MyApp::MyPostsController.controller_path # => "my_app/my_posts" diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index cc4bd6105d..b84aad8eb6 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -121,7 +121,8 @@ module ActionDispatch end def match_head_routes(routes, req) - head_routes = match_routes(routes, req) + verb_specific_routes = routes.reject { |route| route.verb == // } + head_routes = match_routes(verb_specific_routes, req) if head_routes.empty? begin diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 77f86b7a62..26b8636c2f 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3567,12 +3567,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest mount lambda { |env| [200, {}, [env['REQUEST_METHOD']]] }, at: '/' end - # TODO: HEAD request should match `get /home` rather than the + # HEAD request should match `get /home` rather than the # lower-precedence Rack app mounted at `/`. head '/home' assert_response :ok - #assert_equal 'test#index', @response.body - assert_equal 'HEAD', @response.body + assert_equal 'test#index', @response.body # But the Rack app can still respond to its own HEAD requests. head '/foobar' diff --git a/activemodel/lib/active_model/validations/helper_methods.rb b/activemodel/lib/active_model/validations/helper_methods.rb index 5a22b699d8..2176115334 100644 --- a/activemodel/lib/active_model/validations/helper_methods.rb +++ b/activemodel/lib/active_model/validations/helper_methods.rb @@ -1,6 +1,6 @@ module ActiveModel module Validations - module HelperMethods + module HelperMethods # :nodoc: private def _merge_attributes(attr_names) options = attr_names.extract_options!.symbolize_keys diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 0ec3902eac..95dd85a387 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,7 +1,7 @@ -* Correctly thrown `ActiveRecord::AssociationTypeMismatch` when assigning - a wrong value to a namespaced association. +* Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning + a wrong type to a namespaced association. - Fixes #20545 + Fixes #20545. *Diego Carrion* diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 7726829be4..4a72ec5054 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -153,20 +153,28 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_raise(ActiveRecord::AssociationTypeMismatch) { Account.find(1).firm = Project.find(1) } end - def test_type_mismatch_with_namespaced_class - assert_nil defined?(Region), "This test should be done with a only namespaced class" - ActiveRecord::Base.connection.create_table(:admin_regions) { |t| t.string :name } - ActiveRecord::Base.connection.add_column :admin_users, :region_id, :integer + def test_raises_type_mismatch_with_namespaced_class + assert_nil defined?(Region), "This test requires that there is no top-level Region class" + + ActiveRecord::Base.connection.instance_eval do + create_table(:admin_regions) { |t| t.string :name } + add_column :admin_users, :region_id, :integer + end Admin.const_set "RegionalUser", Class.new(Admin::User) { belongs_to(:region) } Admin.const_set "Region", Class.new(ActiveRecord::Base) - e = assert_raise(ActiveRecord::AssociationTypeMismatch) { Admin::RegionalUser.new(region: 'wrong value') } + + e = assert_raise(ActiveRecord::AssociationTypeMismatch) { + Admin::RegionalUser.new(region: 'wrong value') + } assert_match(/^Region\([^)]+\) expected, got String\([^)]+\)$/, e.message) ensure Admin.send :remove_const, "Region" if Admin.const_defined?("Region") Admin.send :remove_const, "RegionalUser" if Admin.const_defined?("RegionalUser") - connection = ActiveRecord::Base.connection - connection.remove_column :admin_users, :region_id if connection.column_exists?(:admin_users, :region_id) - connection.drop_table :admin_regions if connection.table_exists?(:admin_regions) + + ActiveRecord::Base.connection.instance_eval do + remove_column :admin_users, :region_id if column_exists?(:admin_users, :region_id) + drop_table :admin_regions, if_exists: true + end end def test_natural_assignment diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 05dd0d2a04..5c96a53d09 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -2344,13 +2344,13 @@ associations, public methods, etc. Creating a car will save it in the `vehicles` table with "Car" as the `type` field: ```ruby -Car.create color: 'Red', price: 10000 +Car.create(color: 'Red', price: 10000) ``` will generate the following SQL: ```sql -INSERT INTO "vehicles" ("type", "color", "price") VALUES ("Car", "Red", 10000) +INSERT INTO "vehicles" ("type", "color", "price") VALUES ('Car', 'Red', 10000) ``` Querying car records will just search for vehicles that are cars: diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb index faf551f381..09b8675cf8 100644 --- a/railties/lib/rails/test_unit/reporter.rb +++ b/railties/lib/rails/test_unit/reporter.rb @@ -7,7 +7,7 @@ module Rails self.executable = "bin/rails test" def report - return if results.empty? + return if filtered_results.empty? io.puts io.puts "Failed tests:" io.puts @@ -15,14 +15,20 @@ module Rails end def aggregated_results # :nodoc: - filtered_results = results.dup - filtered_results.reject!(&:skipped?) unless options[:verbose] filtered_results.map do |result| location, line = result.method(result.name).source_location "#{self.executable} #{relative_path_for(location)}:#{line}" end.join "\n" end + def filtered_results + if options[:verbose] + results + else + results.reject(&:skipped?) + end + end + def relative_path_for(file) file.sub(/^#{Rails.root}\/?/, '') end diff --git a/railties/test/test_unit/reporter_test.rb b/railties/test/test_unit/reporter_test.rb index f9c7888bc6..3066ba82d6 100644 --- a/railties/test/test_unit/reporter_test.rb +++ b/railties/test/test_unit/reporter_test.rb @@ -32,6 +32,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase @reporter.record(passing_test) @reporter.record(skipped_test) @reporter.report + assert_no_match 'Failed tests:', @output.string assert_rerun_snippet_count 0 end |