Skip to content
This repository
Browse code

Don't destroy readonly models

  • Loading branch information...
commit a8b370f5c2fed87001e363d18ce60a47c1748885 1 parent 85ac143
Johannes Barre authored May 10, 2012
5  activerecord/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,10 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  3
+*   It's not possible anymore to destroy a model marked as read only.
  4
+
  5
+    *Johannes Barre*
  6
+
  7
+
3 8
 *   Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects
4 9
 
5 10
       Record.from(subquery)
1  activerecord/lib/active_record/persistence.rb
@@ -123,6 +123,7 @@ def delete
123 123
     # Deletes the record in the database and freezes this instance to reflect
124 124
     # that no changes should be made (since they can't be persisted).
125 125
     def destroy
  126
+      raise ReadOnlyRecord if readonly?
126 127
       destroy_associations
127 128
       destroy_row if persisted?
128 129
       @destroyed = true
1  activerecord/test/cases/readonly_test.rb
@@ -23,6 +23,7 @@ def test_cant_save_readonly_record
23 23
     end
24 24
     assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save  }
25 25
     assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save! }
  26
+    assert_raise(ActiveRecord::ReadOnlyRecord) { dev.destroy }
26 27
   end
27 28
 
28 29
 

0 notes on commit a8b370f

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