From a8b370f5c2fed87001e363d18ce60a47c1748885 Mon Sep 17 00:00:00 2001 From: Johannes Barre Date: Thu, 10 May 2012 13:47:50 +0200 Subject: Don't destroy readonly models --- activerecord/CHANGELOG.md | 5 +++++ activerecord/lib/active_record/persistence.rb | 1 + activerecord/test/cases/readonly_test.rb | 1 + 3 files changed, 7 insertions(+) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 198b054f99..11fd0e7047 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* It's not possible anymore to destroy a model marked as read only. + + *Johannes Barre* + + * Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects Record.from(subquery) diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 4a987c2343..a1bc39a32d 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -123,6 +123,7 @@ module ActiveRecord # Deletes the record in the database and freezes this instance to reflect # that no changes should be made (since they can't be persisted). def destroy + raise ReadOnlyRecord if readonly? destroy_associations destroy_row if persisted? @destroyed = true diff --git a/activerecord/test/cases/readonly_test.rb b/activerecord/test/cases/readonly_test.rb index 39b66b3399..df0399f548 100644 --- a/activerecord/test/cases/readonly_test.rb +++ b/activerecord/test/cases/readonly_test.rb @@ -23,6 +23,7 @@ class ReadOnlyTest < ActiveRecord::TestCase end assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save } assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save! } + assert_raise(ActiveRecord::ReadOnlyRecord) { dev.destroy } end -- cgit v1.2.3