diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 198b054f99816bac9adb3ab4d62f2eaa8d2a0b75..11fd0e7047c0ffbd5f2cb861af60d3662252c553 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 4a987c234374c6bb302e291c357f4094a178898c..a1bc39a32d1cc6af8626707d3f24e63c1c54969c 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -123,6 +123,7 @@ def delete # 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 39b66b3399ae4c4d0a396c3b5e236e14f9c06f0f..df0399f54867c4544b207d5e81a0c7803c757bf0 100644 --- a/activerecord/test/cases/readonly_test.rb +++ b/activerecord/test/cases/readonly_test.rb @@ -23,6 +23,7 @@ def test_cant_save_readonly_record end assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save } assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save! } + assert_raise(ActiveRecord::ReadOnlyRecord) { dev.destroy } end