From be913c3964069fa9ff7c8a615e06705e3a6ec435 Mon Sep 17 00:00:00 2001 From: Steve Jorgensen Date: Mon, 21 May 2012 09:50:29 -0700 Subject: [PATCH 1/4] Don't crash exception translation w/ nil result attribute. Exception.result is nil when attempting a query after PostgreSQL disconnect, resulting in new exception: NoMethodError: undefined method `error_field' for nil:NilClass --- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 8806693397b73..f01dcec7be2f0 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1144,7 +1144,7 @@ def postgresql_version UNIQUE_VIOLATION = "23505" def translate_exception(exception, message) - case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE) + case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE) when UNIQUE_VIOLATION RecordNotUnique.new(message, exception) when FOREIGN_KEY_VIOLATION From dc2bc388bc8c6c345337052bf0d60f5243d899d4 Mon Sep 17 00:00:00 2001 From: kennyj Date: Fri, 1 Mar 2013 01:55:20 +0900 Subject: [PATCH 2/4] Wrong exception is occured when raising no translatable exception Conflicts: activerecord/CHANGELOG.md --- activerecord/CHANGELOG.md | 8 ++++++++ .../connection_adapters/postgresql_adapter.rb | 2 ++ .../cases/adapters/postgresql/postgresql_adapter_test.rb | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e55367662bdd0..ebab222b8c81f 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,10 +1,18 @@ ## unreleased ## +* Fix a problem wrong exception is occured + when raising no translatable exception in PostgreSQL. + + *kennyj* + * 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 #9796. +* Support PostgreSQL specific column types when using `change_table`. + Fixes #9480. + *Juan M. Cuello + Dembskiy Alexander* * Reload the association target if it's stale. `@stale_state` should be nil diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index f01dcec7be2f0..cbbb195458c77 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1144,6 +1144,8 @@ def postgresql_version UNIQUE_VIOLATION = "23505" def translate_exception(exception, message) + return exception unless exception.respond_to?(:result) + case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE) when UNIQUE_VIOLATION RecordNotUnique.new(message, exception) diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 0de3786eb8415..6c345cd8ccfd1 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -188,6 +188,12 @@ def test_distinct_with_nulls assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"]) end + def test_raise_error_when_cannot_translate_exception + assert_raise TypeError do + @connection.send(:log, nil) { @connection.execute(nil) } + end + end + private def insert(ctx, data) binds = data.map { |name, value| From 7e8a74d40125be9d8afc8571ab7e28c67662c484 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 20 Mar 2013 12:09:55 -0300 Subject: [PATCH 3/4] Remove bad changelog entry from AR [ci skip] Introduced in dc2bc388bc8c6c345337052bf0d60f5243d899d4. --- activerecord/CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index ebab222b8c81f..c0e0bb1dbcd26 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -10,9 +10,6 @@ are used. Fixes #9796. -* Support PostgreSQL specific column types when using `change_table`. - Fixes #9480. - *Juan M. Cuello + Dembskiy Alexander* * Reload the association target if it's stale. `@stale_state` should be nil From 2c8f34995378e4a18711cf5f947e8465227d3748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 20 Mar 2013 18:14:41 -0300 Subject: [PATCH 4/4] Merge pull request #9802 from newsline/fix-broken-action-missing Fix missing action_missing Conflicts: actionpack/CHANGELOG.md Conflicts: actionpack/test/controller/base_test.rb Fixes #9799 --- actionpack/CHANGELOG.md | 5 +++++ .../lib/action_controller/metal/hide_actions.rb | 2 +- actionpack/test/controller/base_test.rb | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 8c7e3327f32ac..dc9555b9d1247 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,10 @@ ## unreleased ## +* Fixed `ActionController#action_missing` not being called. + Fixes #9799. + + *Janko Luin* + * `ActiveSupport::NumberHelper#number_to_human` returns the number unaltered when the units hash does not contain the needed key, e.g. when the number provided is less than the largest key proivided. diff --git a/actionpack/lib/action_controller/metal/hide_actions.rb b/actionpack/lib/action_controller/metal/hide_actions.rb index 109484d88c986..1ded16649101f 100644 --- a/actionpack/lib/action_controller/metal/hide_actions.rb +++ b/actionpack/lib/action_controller/metal/hide_actions.rb @@ -28,7 +28,7 @@ def hide_action(*args) end def visible_action?(action_name) - action_methods.include?(action_name) + not hidden_actions.include?(action_name) end # Overrides AbstractController::Base#action_methods to remove any methods diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index affa9a6add0f4..a652d8ffad481 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -86,6 +86,12 @@ def url_options class RecordIdentifierController < ActionController::Base end +class ActionMissingController < ActionController::Base + def action_missing(action) + render :text => "Response for #{action}" + end +end + class ControllerClassTests < ActiveSupport::TestCase def test_controller_path @@ -196,6 +202,12 @@ def test_get_on_hidden_should_fail assert_raise(AbstractController::ActionNotFound) { get :hidden_action } assert_raise(AbstractController::ActionNotFound) { get :another_hidden_action } end + + def test_action_missing_should_work + use_controller ActionMissingController + get :arbitrary_action + assert_equal "Response for arbitrary_action", @response.body + end end class UrlOptionsTest < ActionController::TestCase