Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't destroy readonly models

  • Loading branch information...
commit a8b370f5c2fed87001e363d18ce60a47c1748885 1 parent 85ac143
Johannes Barre iGEL authored
5 activerecord/CHANGELOG.md
View
@@ -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)
1  activerecord/lib/active_record/persistence.rb
View
@@ -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
1  activerecord/test/cases/readonly_test.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.