From 5142d5411481c893f817c1431b0869be3745060f Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Thu, 27 Nov 2014 17:44:36 -0800 Subject: Fix a bug where AR::RecordNotSaved loses error messages Since 3e30c5d, it started ignoring the given error message. This commit changes the behavior of AR::RecordNotSaved#initialize so that it no longer loses the given error message. --- activerecord/lib/active_record/errors.rb | 4 ++-- activerecord/lib/active_record/persistence.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 14819aab54..fc28ab585f 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -54,9 +54,9 @@ module ActiveRecord class RecordNotSaved < ActiveRecordError attr_reader :record - def initialize(record) + def initialize(message, record = nil) @record = record - super() + super(message) end end diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 8d84a3acae..99e104598b 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -139,7 +139,7 @@ module ActiveRecord # Attributes marked as readonly are silently ignored if the record is # being updated. def save!(*) - create_or_update || raise(RecordNotSaved, self) + create_or_update || raise(RecordNotSaved.new(nil, self)) end # Deletes the record in the database and freezes this instance to -- cgit v1.2.3