lib/voteable_mongo/voting.rb in voteable_mongo-0.9.2 vs lib/voteable_mongo/voting.rb in voteable_mongo-0.9.3
- old
+ new
@@ -51,12 +51,12 @@
private
def validate_and_normalize_vote_options(options)
options.symbolize_keys!
- options[:votee_id] = BSON::ObjectId(options[:votee_id]) if options[:votee_id].is_a?(String)
- options[:voter_id] = BSON::ObjectId(options[:voter_id]) if options[:voter_id].is_a?(String)
+ options[:votee_id] = Helpers.try_to_convert_string_to_object_id(options[:votee_id])
+ options[:voter_id] = Helpers.try_to_convert_string_to_object_id(options[:voter_id])
options[:value] &&= options[:value].to_sym
end
def new_vote_query_and_update(options)
if options[:value] == :up
@@ -150,10 +150,10 @@
def update_parent_votes(doc, options)
VOTEABLE[name].each do |class_name, voteable|
if metadata = voteable_relation(class_name)
- if parent_id = doc[voteable_foreign_key(metadata)]
+ if (parent_id = doc[voteable_foreign_key(metadata)]).present?
parent_ids = parent_id.is_a?(Array) ? parent_id : [ parent_id ]
class_name.constantize.collection.update(
{ '_id' => { '$in' => parent_ids } },
{ '$inc' => parent_inc_options(voteable, options) },
{ :multi => true }