voteable_mongoid 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/mongoid/voteable.rb +6 -4
  2. metadata +3 -3
@@ -19,7 +19,7 @@ module Mongoid
19
19
  scope :best_voted, order_by(:votes_point.desc)
20
20
 
21
21
 
22
- def self.vote_point(klass, options = nil)
22
+ def self.vote_point(klass = self, options = nil)
23
23
  VOTE_POINT[self] ||= {}
24
24
  VOTE_POINT[self][klass] ||= options
25
25
  end
@@ -88,7 +88,9 @@ module Mongoid
88
88
  VOTE_POINT[self].each do |klass, value_point|
89
89
  next unless association = associations[klass.name.underscore]
90
90
  next unless foreign_key = options[association.options[:foreign_key].to_sym]
91
- klass.collection.update({ :_id => foreign_key }, {
91
+ foreign_key = BSON::ObjectID(foreign_key) if foreign_key.is_a?(String)
92
+
93
+ klass.collection.update({ :_id => foreign_key }, {
92
94
  '$inc' => options[:revote] ? {
93
95
  :votes_point => ( value == :up ?
94
96
  value_point[:up] - value_point[:down] :
@@ -110,8 +112,8 @@ module Mongoid
110
112
  options[foreign_key] = read_attribute(foreign_key)
111
113
  end
112
114
 
113
- options[:votee_id] ||= _id
114
- options[:revote] ||= !vote_value(options[:voter_id]).nil?
115
+ options[:votee_id] = _id
116
+ options[:revote] = !vote_value(options[:voter_id]).nil?
115
117
 
116
118
  self.class.vote(options)
117
119
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voteable_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Nguyen