提交 6ada771a 编写于 作者: A Aaron Patterson

Merge pull request #6250 from iGEL/dont_destroy_readonly_models

Don't allow to destroy readonly models
## 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)
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册