rs_voteable_mongo 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16f0b36eb31c9f148c7c0fb664c397bd76d0097f
4
- data.tar.gz: f5310c7ed2e97305c75cd80cfddaa0f90a4b881d
3
+ metadata.gz: 34491e2d1eb65a7076a9e623cc7460e32e76e987
4
+ data.tar.gz: 745aada7e71482e5c1b97a55d71828113f4c7647
5
5
  SHA512:
6
- metadata.gz: aaa8aa38e87235a027e99c7104bb51f4046d39c3037071e579e5f77e40ff600896661f6c0d935374961a3785b85ea31201fbf0c724338eabce3e6fe7b81bdb36
7
- data.tar.gz: cffc66072f9bd227a974f94397c71bd12367f816f237c39a3910455b0d5ccbafd7b84ef36dfb050d079318ed402d98f0fc1d071c2bd92801f83f33e1a4679907
6
+ metadata.gz: efbf594bffa6301f41535aee2bc732ef0ebcda5fa5201f7effed4dd5cb28d2a9eb7779ab5a9183e59969009c8d9f262dd1cbb1b4860f5540d080632a14d1e9e4
7
+ data.tar.gz: 4bd403bbb80c1590b987ee304b1bcf6db8f5226be640b8369216aa53d0d14f850659bcd99278b9d77bf47c7594a44de0a71673f3f376da54c61d907152ca5fce
data/.travis.yml CHANGED
@@ -7,16 +7,9 @@ language: ruby
7
7
  rvm:
8
8
  - 1.9.3
9
9
  - 2.0.0
10
+ - 2.1.0
10
11
  - jruby-19mode
11
- - rbx-19mode
12
12
 
13
13
  gemfile:
14
- - Gemfile
15
- - gemfiles/mongoid-3.0.gemfile
16
14
  - gemfiles/mongoid-3.1.gemfile
17
15
  - gemfiles/mongoid-4.0.gemfile
18
-
19
- matrix:
20
- exclude:
21
- - rvm: rbx-19mode
22
- gemfile: gemfiles/mongoid-4.0.gemfile
data/CHANGELOG.rdoc CHANGED
@@ -1,93 +1,9 @@
1
+ == rs-1.1.0
2
+ * fixes for mongoid 5
3
+
1
4
  == rs-1.0.0
2
5
  * Forked gem
3
6
  * drop mongomapper
4
7
  * Support mongoid 3 and 4
5
8
  * Add Travis-ci
6
9
 
7
- == 0.9.3
8
- * Support mongoid ~> 2.0, mongo_mapper ~> 0.9
9
-
10
- == 0.9.2
11
- * Replace votee_type to votee_class
12
- * Bug fixes
13
-
14
- == 0.9.1
15
- * Update gem description
16
-
17
- == 0.9.0
18
- * Add MongoMapper support
19
- * Simplify voting algorithm
20
- * vote / revote / unvote always return voteable object (votee)
21
- * Tasks module bug fixes
22
-
23
- == 0.8.1
24
- * Fix gem release bug
25
-
26
- == 0.8.0
27
- * Rename to voteable_mongo to support other MongoDB Object-Document Mappers like MongoMapper
28
- * Minor fixes and refactoring
29
-
30
- == 0.7.4
31
- * Add Votee#up_voters(VoterClass), Votee#down_voters(VoterClass), Votee#voters(VoterClass)
32
- * Add Voter scopes: Voter.up_voted_for(votee), Voter.down_voted_for(votee), Voter.voted_for(votee)
33
- * Add voteable ..., :index => true options
34
- * Optimization on unvote and revote validations
35
- * Fix for :up & :down points are nil in rake tasks
36
-
37
- == 0.7.3
38
- * Add :return_votee => true option to vote function to warranty always return voteable object
39
- * Add Votee.voted?, Votee.up_voted?, Votee.down_voted?
40
- * Update parent for ManyToMany relationship
41
- * Refactor
42
-
43
- == 0.7.2
44
- * Use Collection#find_and_modify to retrieve updated votes data and parent_ids (don't need an extra query to get parent_ids)
45
-
46
- == 0.7.1
47
- * Add votee#voted_by?(voter or voter_id)
48
- * Better doc
49
- * Refactor & cleanup source code
50
-
51
- == 0.7.0
52
- * Use readable field names (up, down, up_count, down_count, count, point) instead of very short field names (u, d, uc, dc, c, p)
53
-
54
- == 0.6.4
55
- * Drop Voter#votees, Voter#up_votees, Voter#down_votees in favor of Votee#voted_by(voter), Votee#up_voted_by(voter), Votee#down_voted_by(voter) scopes
56
-
57
- == 0.6.3
58
- * Add rake db:mongoid:voteable:migrate_old_votes to migrate vote data created by version < 0.6.0 to new vote data storage
59
-
60
- == 0.6.2
61
- * Fix bug: use before_create instead of after_after_initialize
62
-
63
- == 0.6.1
64
- * Set counters and point to 0 for uninitialized voteable objects in order sort and query
65
-
66
- == 0.6.0
67
- * Minimize vote data store (using short field names votes.u, votes.d, votes.c ...)
68
- * Add Voter#up_votees, Voter#down_votees
69
- * Remove index and scope from statistic module. User have to add indexes and scopes manually (see https://github.com/vinova/simple_qa/blob/master/app/models/question.rb)
70
- * Bug fixes
71
-
72
- == 0.5.0
73
- * Rename vote_point to voteable
74
-
75
- == 0.4.5
76
- * Can use rake db:mongoid:voteable:remake_stats in Rails apps
77
- * Use mongoid 2.0.0
78
-
79
- == 0.4.4
80
- * Add up_votes_count, down_votes_count
81
- * Re-generate vote statistic data (counters and point)
82
-
83
- == 0.4.3
84
- * Wrap vote data in voteable namespace (voteable.up_voters_id, voteable.down_voters_ids, voteable.votes_count ...)
85
-
86
- == 0.4.2
87
- * Bug fixes
88
-
89
- == 0.4.0
90
- * Can unvote
91
-
92
- == 0.3.5
93
- * Use mongoid 2.0.0.rc
@@ -3,11 +3,7 @@ module Mongo
3
3
  module Helpers
4
4
 
5
5
  def self.try_to_convert_string_to_object_id(x)
6
- if defined?(Moped::BSON)
7
- x.is_a?(String) && Moped::BSON::ObjectId.legal?(x) ? Moped::BSON::ObjectId.from_string(x) : x
8
- else
9
- x.is_a?(String) && BSON::ObjectId.legal?(x) ? BSON::ObjectId.from_string(x) : x
10
- end
6
+ x.is_a?(String) && BSON::ObjectId.legal?(x) ? BSON::ObjectId.from_string(x) : x
11
7
  end
12
8
 
13
9
  def self.get_mongo_id(x)
@@ -9,7 +9,7 @@ module Mongo
9
9
  klass = class_name.constantize
10
10
  klass_voteable = voteable[class_name]
11
11
  puts "Init stats for #{class_name}" if log
12
- klass.with(safe: true).where(votes: nil).update_all({ '$set' => {votes: DEFAULT_VOTES} })
12
+ klass.where(votes: nil).set(votes: DEFAULT_VOTES)
13
13
  end
14
14
  end
15
15
 
@@ -46,7 +46,7 @@ module Mongo
46
46
  up_count = up_voter_ids.size
47
47
  down_count = down_voter_ids.size
48
48
 
49
- klass.with(safe: true).where(_id: doc.id).update_all(
49
+ klass.collection.find({_id: doc.id}).update_many(
50
50
  '$set' => {
51
51
  'votes' => {
52
52
  'up' => up_voter_ids,
@@ -137,7 +137,7 @@ module Mongo
137
137
 
138
138
  parent_ids = parent_id.is_a?(Array) ? parent_id : [ parent_id ]
139
139
 
140
- parent_class.with(safe: true).where(:_id.in => parent_ids).update_all({ '$inc' => inc_options })
140
+ parent_class.collection.find({'_id' => {'$in' => parent_ids}}).update_many({ '$inc' => inc_options })
141
141
  end
142
142
  end
143
143
 
@@ -1,3 +1,3 @@
1
1
  module VoteableMongo
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -29,10 +29,7 @@ module Mongo
29
29
 
30
30
  # http://www.mongodb.org/display/DOCS/findAndModify+Command
31
31
  begin
32
- doc = where(query).find_and_modify(
33
- update,
34
- :new => true
35
- )
32
+ doc = where(query).find_one_and_update(update, {return_document: :after})
36
33
  rescue Moped::Errors::OperationFailure
37
34
  doc = nil
38
35
  end
@@ -155,7 +152,7 @@ module Mongo
155
152
 
156
153
  if (parent_id = doc[voteable_foreign_key(metadata)]).present?
157
154
  parent_ids = parent_id.is_a?(Array) ? parent_id : [ parent_id ]
158
- class_name.constantize.collection.find({'_id' => {'$in' => parent_ids}}).update_all(
155
+ class_name.constantize.collection.find({'_id' => {'$in' => parent_ids}}).update_many(
159
156
  { '$inc' => parent_inc_options(voteable, options) },
160
157
  )
161
158
  end
@@ -16,8 +16,9 @@ describe Mongo::Voteable do
16
16
  [ {'votes.up' => 1, '_id' => 1},
17
17
  {'votes.down' => 1, '_id' => 1},
18
18
  ].each { |index_key|
19
- klass.collection.indexes[index_key].should_not be_nil
20
- klass.collection.indexes[index_key]['unique'].should be_true
19
+
20
+ klass.collection.indexes.select { |i| i['key'] == index_key }.first.should_not be_nil
21
+ klass.collection.indexes.select { |i| i['key'] == index_key }.first['unique'].should be_true
21
22
  }
22
23
 
23
24
  [ {'votes.count' => -1},
@@ -25,7 +26,7 @@ describe Mongo::Voteable do
25
26
  {'votes.down_count' => -1},
26
27
  {'votes.point' => -1},
27
28
  ].each { |index_key|
28
- klass.collection.indexes[index_key].should_not be_nil
29
+ klass.collection.indexes.select { |i| i['key'] == index_key }.should_not be_nil
29
30
  }
30
31
  end
31
32
  end
@@ -49,7 +50,7 @@ describe Mongo::Voteable do
49
50
  end
50
51
 
51
52
  it "vote for unexisting post" do
52
- object_id = defined?(Moped::BSON) ? Moped::BSON::ObjectId : BSON::ObjectId
53
+ object_id = BSON::ObjectId
53
54
  @user1.vote(:votee_class => Post, :votee_id => object_id.new, :value => :up).should == false
54
55
  end
55
56
 
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_dependency "mongoid", [">= 3.0", "< 5.0"]
21
+ s.add_dependency "mongoid", '~> 5.0'
22
22
  s.add_development_dependency 'rspec', '~> 2.14.1'
23
- s.add_development_dependency "bundler", "~> 1.3"
23
+ s.add_development_dependency "bundler"
24
24
  s.add_development_dependency "rake"
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rs_voteable_mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RocketScience
@@ -9,68 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-03 00:00:00.000000000 Z
12
+ date: 2016-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
19
- - !ruby/object:Gem::Version
20
- version: '3.0'
21
- - - <
18
+ - - "~>"
22
19
  - !ruby/object:Gem::Version
23
20
  version: '5.0'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - '>='
29
- - !ruby/object:Gem::Version
30
- version: '3.0'
31
- - - <
25
+ - - "~>"
32
26
  - !ruby/object:Gem::Version
33
27
  version: '5.0'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: rspec
36
30
  requirement: !ruby/object:Gem::Requirement
37
31
  requirements:
38
- - - ~>
32
+ - - "~>"
39
33
  - !ruby/object:Gem::Version
40
34
  version: 2.14.1
41
35
  type: :development
42
36
  prerelease: false
43
37
  version_requirements: !ruby/object:Gem::Requirement
44
38
  requirements:
45
- - - ~>
39
+ - - "~>"
46
40
  - !ruby/object:Gem::Version
47
41
  version: 2.14.1
48
42
  - !ruby/object:Gem::Dependency
49
43
  name: bundler
50
44
  requirement: !ruby/object:Gem::Requirement
51
45
  requirements:
52
- - - ~>
46
+ - - ">="
53
47
  - !ruby/object:Gem::Version
54
- version: '1.3'
48
+ version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
52
  requirements:
59
- - - ~>
53
+ - - ">="
60
54
  - !ruby/object:Gem::Version
61
- version: '1.3'
55
+ version: '0'
62
56
  - !ruby/object:Gem::Dependency
63
57
  name: rake
64
58
  requirement: !ruby/object:Gem::Requirement
65
59
  requirements:
66
- - - '>='
60
+ - - ">="
67
61
  - !ruby/object:Gem::Version
68
62
  version: '0'
69
63
  type: :development
70
64
  prerelease: false
71
65
  version_requirements: !ruby/object:Gem::Requirement
72
66
  requirements:
73
- - - '>='
67
+ - - ">="
74
68
  - !ruby/object:Gem::Version
75
69
  version: '0'
76
70
  description: Add up / down voting ability to Mongoid documents. Optimized for speed
@@ -82,10 +76,10 @@ executables: []
82
76
  extensions: []
83
77
  extra_rdoc_files: []
84
78
  files:
85
- - .gitignore
86
- - .ruby-gemset
87
- - .ruby-version
88
- - .travis.yml
79
+ - ".gitignore"
80
+ - ".ruby-gemset"
81
+ - ".ruby-version"
82
+ - ".travis.yml"
89
83
  - CHANGELOG.rdoc
90
84
  - Gemfile
91
85
  - README.rdoc
@@ -125,17 +119,17 @@ require_paths:
125
119
  - lib
126
120
  required_ruby_version: !ruby/object:Gem::Requirement
127
121
  requirements:
128
- - - '>='
122
+ - - ">="
129
123
  - !ruby/object:Gem::Version
130
124
  version: '0'
131
125
  required_rubygems_version: !ruby/object:Gem::Requirement
132
126
  requirements:
133
- - - '>='
127
+ - - ">="
134
128
  - !ruby/object:Gem::Version
135
129
  version: '0'
136
130
  requirements: []
137
131
  rubyforge_project:
138
- rubygems_version: 2.0.6
132
+ rubygems_version: 2.5.1
139
133
  signing_key:
140
134
  specification_version: 4
141
135
  summary: Add up / down voting ability to Mongoid documents