Skip to content

Commit

Permalink
change api update_attributes -> update
Browse files Browse the repository at this point in the history
AR 4 has changed their api, as mongoid wants to be as compatible as possible
we need to update that api as well.
[fixes #2966]
  • Loading branch information
arthurnn committed Jul 3, 2013
1 parent 4e19b0f commit d588805
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 159 deletions.
2 changes: 1 addition & 1 deletion lib/mongoid/persistable/savable.rb
Expand Up @@ -22,7 +22,7 @@ def save(options = {})
if new_record?
!insert(options).new_record?
else
update(options)
update_document(options)
end
end

Expand Down
12 changes: 7 additions & 5 deletions lib/mongoid/persistable/updatable.rb
Expand Up @@ -20,7 +20,7 @@ module Updatable
# @return [ true, false ] True if succeeded, false if not.
#
# @since 1.0.0
def update(options = {})
def update_document(options = {})
prepare_update(options) do
updates, conflicts = init_atomic_updates
unless updates.empty?
Expand Down Expand Up @@ -66,23 +66,24 @@ def update_attribute(name, value)
# Update the document attributes in the database.
#
# @example Update the document's attributes
# document.update_attributes(:title => "Sir")
# document.update(:title => "Sir")
#
# @param [ Hash ] attributes The attributes to update.
#
# @return [ true, false ] True if validation passed, false if not.
#
# @since 1.0.0
def update_attributes(attributes = {})
def update(attributes = {})
assign_attributes(attributes)
save
end
alias :update_attributes :update

# Update the document attributes in the database and raise an error if
# validation failed.
#
# @example Update the document's attributes.
# document.update_attributes(:title => "Sir")
# document.update!(:title => "Sir")
#
# @param [ Hash ] attributes The attributes to update.
#
Expand All @@ -92,14 +93,15 @@ def update_attributes(attributes = {})
# @return [ true, false ] True if validation passed.
#
# @since 1.0.0
def update_attributes!(attributes = {})
def update!(attributes = {})
result = update_attributes(attributes)
unless result
fail_due_to_validation! unless errors.empty?
fail_due_to_callback!(:update_attributes!)
end
result
end
alias :update_attributes! :update!

private

Expand Down

0 comments on commit d588805

Please sign in to comment.