Skip to content
Browse files

Merge pull request #6250 from iGEL/dont_destroy_readonly_models

Don't allow to destroy readonly models
  • Loading branch information...
2 parents a8f568e + a8b370f commit 6ada771a08196d8a5d790f8b4b2224aa8e1748b3 @tenderlove tenderlove committed May 17, 2012
View
5 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)
View
1 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
View
1 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

0 comments on commit 6ada771

Please sign in to comment.
Something went wrong with that request. Please try again.