Skip to content

Commit

Permalink
Don't destroy readonly models
Browse files Browse the repository at this point in the history
  • Loading branch information
iGEL committed May 17, 2012
1 parent 85ac143 commit a8b370f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions activerecord/lib/active_record/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/cases/readonly_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit a8b370f

Please sign in to comment.