mongoid_rateable 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Mongoid::Rateable
2
2
 
3
- Adding simple rating functionality for Mongoid models
3
+ Provides fields and methods for the *rating* manipulation on Mongoid documents
4
4
 
5
5
  == Installation
6
6
 
@@ -85,6 +85,11 @@ You can get posts with some rating:
85
85
  Post.with_rating(0..10)
86
86
  Post.with_rating(-2..2)
87
87
 
88
+ You can get most rated and highest rated posts:
89
+
90
+ Post.highest_rated # 10 (or less) highest rated posts
91
+ Post.highest_rated(5) # 5 (or less) highest rated posts
92
+
88
93
  == Contributing to Mongoid::Rateable
89
94
 
90
95
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.homepage = "http://github.com/proton/mongoid_rateable"
21
21
  gem.license = "MIT"
22
22
  gem.summary = %q{Rating functionality for Mongoid documents}
23
- gem.description = %q{Provides fields and methods for the manipulation of rates on Mongoid documents.}
23
+ gem.description = %q{Provides fields and methods for the rating manipulation on Mongoid documents.}
24
24
  gem.email = "psavichev@gmail.com"
25
25
  gem.authors = ["Peter Savichev (proton)"]
26
26
  # dependencies defined in Gemfile
data/TODO CHANGED
@@ -3,5 +3,4 @@ rate embedded (indexes?!)
3
3
  add random values to specs
4
4
  add task for rating update
5
5
  add bayesian_rating ( https://github.com/mepatterson/acts_as_mongo_rateable )
6
- add scopes for most_rated/highest_rated
7
6
  add weight to rating
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -19,6 +19,7 @@ module Mongoid
19
19
  scope :rated, where(:rating.exists => true)
20
20
  scope :rated_by, ->(rater) { where("rating_marks.rater_id" => rater.id, "rating_marks.rater_class" => rater.class.to_s) }
21
21
  scope :with_rating, ->(range) { where(:rating.gte => range.begin, :rating.lte => range.end) }
22
+ scope :highest_rated, ->(limit=10) { order_by([:rating, :desc]).limit(limit) }
22
23
  end
23
24
 
24
25
  module InstanceMethods
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_rateable}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Peter Savichev (proton)}]
12
- s.date = %q{2011-08-07}
13
- s.description = %q{Provides fields and methods for the manipulation of rates on Mongoid documents.}
12
+ s.date = %q{2011-08-20}
13
+ s.description = %q{Provides fields and methods for the rating manipulation on Mongoid documents.}
14
14
  s.email = %q{psavichev@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -254,11 +254,11 @@ describe Post do
254
254
  describe "#scopes" do
255
255
  before (:each) do
256
256
  @post.delete
257
- @post1 = Post.create
258
- @post2 = Post.create
259
- @post3 = Post.create
260
- @post4 = Post.create
261
- @post5 = Post.create
257
+ @post1 = Post.create(:name => "Post 1")
258
+ @post2 = Post.create(:name => "Post 2")
259
+ @post3 = Post.create(:name => "Post 3")
260
+ @post4 = Post.create(:name => "Post 4")
261
+ @post5 = Post.create(:name => "Post 5")
262
262
  @post1.rate_and_save 5, @sally
263
263
  @post1.rate_and_save 3, @bob
264
264
  @post4.rate_and_save 1, @sally
@@ -306,5 +306,25 @@ describe Post do
306
306
  Post.with_rating(0..5).size.should eql 4
307
307
  end
308
308
  end
309
+
310
+ describe "#highest_rated" do
311
+ it "should return proper count of posts" do
312
+ #mongoid has problems with returning count of documents (https://github.com/mongoid/mongoid/issues/817)
313
+ posts_count = 0
314
+ Post.highest_rated(1).each {|x| posts_count+=1 }
315
+ posts_count.should eql 1
316
+ end
317
+
318
+ it "should return proper count of posts" do
319
+ #mongoid has problems with returning count of documents (https://github.com/mongoid/mongoid/issues/817)
320
+ posts_count = 0
321
+ Post.highest_rated(10).each {|x| posts_count+=1 }
322
+ posts_count.should eql 5
323
+ end
324
+
325
+ it "should return proper document" do
326
+ Post.highest_rated(1).first.name.should eql "Post 1"
327
+ end
328
+ end
309
329
  end
310
330
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_rateable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-07 00:00:00.000000000Z
12
+ date: 2011-08-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
16
- requirement: &84791020 !ruby/object:Gem::Requirement
16
+ requirement: &80263240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84791020
24
+ version_requirements: *80263240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &84790630 !ruby/object:Gem::Requirement
27
+ requirement: &80262940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *84790630
35
+ version_requirements: *80262940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &84790270 !ruby/object:Gem::Requirement
38
+ requirement: &80262640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *84790270
46
+ version_requirements: *80262640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &84789910 !ruby/object:Gem::Requirement
49
+ requirement: &80262310 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *84789910
57
+ version_requirements: *80262310
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &84789550 !ruby/object:Gem::Requirement
60
+ requirement: &80261990 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.4.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *84789550
68
+ version_requirements: *80261990
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &84789190 !ruby/object:Gem::Requirement
71
+ requirement: &80261710 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *84789190
79
+ version_requirements: *80261710
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &84788780 !ruby/object:Gem::Requirement
82
+ requirement: &80261420 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.0.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *84788780
90
+ version_requirements: *80261420
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: database_cleaner
93
- requirement: &84788430 !ruby/object:Gem::Requirement
93
+ requirement: &80261110 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,9 +98,8 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *84788430
102
- description: Provides fields and methods for the manipulation of rates on Mongoid
103
- documents.
101
+ version_requirements: *80261110
102
+ description: Provides fields and methods for the rating manipulation on Mongoid documents.
104
103
  email: psavichev@gmail.com
105
104
  executables: []
106
105
  extensions: []
@@ -142,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
141
  version: '0'
143
142
  segments:
144
143
  - 0
145
- hash: 70095789
144
+ hash: -505441169
146
145
  required_rubygems_version: !ruby/object:Gem::Requirement
147
146
  none: false
148
147
  requirements: