1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #6250 from iGEL/dont_destroy_readonly_models

Don't allow to destroy readonly models
This commit is contained in:
Aaron Patterson 2012-05-17 09:56:21 -07:00
commit 6ada771a08
3 changed files with 7 additions and 0 deletions

View file

@ -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 file

@ -123,6 +123,7 @@ module ActiveRecord
# 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 file

@ -23,6 +23,7 @@ class ReadOnlyTest < ActiveRecord::TestCase
end
assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save }
assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save! }
assert_raise(ActiveRecord::ReadOnlyRecord) { dev.destroy }
end