diff options
author | Eileen M. Uchitelle <eileencodes@gmail.com> | 2015-09-08 08:13:57 -0400 |
---|---|---|
committer | Eileen M. Uchitelle <eileencodes@gmail.com> | 2015-09-08 08:13:57 -0400 |
commit | 269050072d53bc34d779c4f807c444aacb08a61a (patch) | |
tree | 6133bb53d7f6b7e0d4bac19416e53241bb81b788 /activerecord/lib/active_record/errors.rb | |
parent | e0cdc7c29d1afae9f0d86fc392cd40a9cf18efcf (diff) | |
parent | 4ff626cac901b41f86646dab1939d2a95b2d26bd (diff) | |
download | rails-269050072d53bc34d779c4f807c444aacb08a61a.tar.gz rails-269050072d53bc34d779c4f807c444aacb08a61a.tar.bz2 rails-269050072d53bc34d779c4f807c444aacb08a61a.zip |
Merge pull request #21511 from rwz/ar-exceptions-no-args
Removes mandatory arguments from AR exceptions
Diffstat (limited to 'activerecord/lib/active_record/errors.rb')
-rw-r--r-- | activerecord/lib/active_record/errors.rb | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 718f04871d..6721fe144f 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -63,7 +63,7 @@ module ActiveRecord class RecordNotSaved < ActiveRecordError attr_reader :record - def initialize(message, record = nil) + def initialize(message = nil, record = nil) @record = record super(message) end @@ -80,7 +80,7 @@ module ActiveRecord class RecordNotDestroyed < ActiveRecordError attr_reader :record - def initialize(message, record = nil) + def initialize(message = nil, record = nil) @record = record super(message) end @@ -92,9 +92,9 @@ module ActiveRecord class StatementInvalid < ActiveRecordError attr_reader :original_exception - def initialize(message, original_exception = nil) - super(message) + def initialize(message = nil, original_exception = nil) @original_exception = original_exception + super(message) end end @@ -134,10 +134,14 @@ module ActiveRecord class StaleObjectError < ActiveRecordError attr_reader :record, :attempted_action - def initialize(record, attempted_action) - super("Attempted to #{attempted_action} a stale object: #{record.class.name}") - @record = record - @attempted_action = attempted_action + def initialize(record = nil, attempted_action = nil) + if record && attempted_action + @record = record + @attempted_action = attempted_action + super("Attempted to #{attempted_action} a stale object: #{record.class.name}.") + else + super("Stale object error.") + end end end @@ -196,7 +200,7 @@ module ActiveRecord class AttributeAssignmentError < ActiveRecordError attr_reader :exception, :attribute - def initialize(message, exception, attribute) + def initialize(message = nil, exception = nil, attribute = nil) super(message) @exception = exception @attribute = attribute @@ -209,7 +213,7 @@ module ActiveRecord class MultiparameterAssignmentErrors < ActiveRecordError attr_reader :errors - def initialize(errors) + def initialize(errors = nil) @errors = errors end end @@ -218,11 +222,15 @@ module ActiveRecord class UnknownPrimaryKey < ActiveRecordError attr_reader :model - def initialize(model, description = nil) - message = "Unknown primary key for table #{model.table_name} in model #{model}." - message += "\n#{description}" if description - super(message) - @model = model + def initialize(model = nil, description = nil) + if model + message = "Unknown primary key for table #{model.table_name} in model #{model}." + message += "\n#{description}" if description + @model = model + super(message) + else + super("Unknown primary key.") + end end end |