mongoid_rateable 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -15,6 +15,8 @@ Include the module in models where you want it:
15
15
  class Post
16
16
  include Mongoid::Document
17
17
  include Mongoid::Rateable
18
+
19
+ RATING_RANGE = (1..5) # Optional (if you need restriction)
18
20
  ...
19
21
  end
20
22
 
data/TODO CHANGED
@@ -1,5 +1,7 @@
1
- add min/max rating
2
1
  improve speed (http://cookbook.mongodb.org/patterns/votes/)
3
2
  rate embedded (indexes?!)
4
3
  add random values to specs
5
- add task for rating update
4
+ add task for rating update
5
+ add bayesian_rating ( https://github.com/mepatterson/acts_as_mongo_rateable )
6
+ add scope for most_rated
7
+ add weight to rating
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -24,6 +24,7 @@ module Mongoid
24
24
  module InstanceMethods
25
25
 
26
26
  def rate(mark, rater)
27
+ validate_rating!(mark)
27
28
  unrate_without_rating_update(rater)
28
29
  self.rates += mark.to_i
29
30
  self.rating_marks.new(:rater_id => rater.id, :mark => mark, :rater_class => rater.class.to_s)
@@ -66,7 +67,13 @@ module Mongoid
66
67
  rating_marks.size
67
68
  end
68
69
 
69
- private
70
+ protected
71
+
72
+ def validate_rating!(value)
73
+ if (defined? self.class::RATING_RANGE) and (range = self.class::RATING_RANGE) and !range.include?(value.to_i)
74
+ raise ArgumentError, "Rating not in range #{range}. Rating provided was #{value}."
75
+ end
76
+ end
70
77
 
71
78
  def unrate_without_rating_update(rater)
72
79
  rmark = self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).first
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_rateable}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Peter Savichev (proton)"]
12
- s.date = %q{2011-07-29}
11
+ s.authors = [%q{Peter Savichev (proton)}]
12
+ s.date = %q{2011-08-07}
13
13
  s.description = %q{Provides fields and methods for the manipulation of rates on Mongoid documents.}
14
14
  s.email = %q{psavichev@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -31,15 +31,16 @@ Gem::Specification.new do |s|
31
31
  "lib/mongoid_rateable/rateable.rb",
32
32
  "lib/mongoid_rateable/rating.rb",
33
33
  "mongoid_rateable.gemspec",
34
+ "spec/models/article.rb",
34
35
  "spec/models/post.rb",
35
36
  "spec/models/user.rb",
36
37
  "spec/rateable_spec.rb",
37
38
  "spec/spec_helper.rb"
38
39
  ]
39
40
  s.homepage = %q{http://github.com/proton/mongoid_rateable}
40
- s.licenses = ["MIT"]
41
- s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.6.2}
41
+ s.licenses = [%q{MIT}]
42
+ s.require_paths = [%q{lib}]
43
+ s.rubygems_version = %q{1.8.6}
43
44
  s.summary = %q{Rating functionality for Mongoid documents}
44
45
 
45
46
  if s.respond_to? :specification_version then
@@ -0,0 +1,9 @@
1
+ class Article
2
+ include Mongoid::Document
3
+ include Mongoid::Rateable
4
+
5
+ RATING_RANGE = (1..5)
6
+
7
+ field :name
8
+
9
+ end
@@ -7,6 +7,7 @@ describe Post do
7
7
  @alice = User.create :name => "Alice"
8
8
  @sally = User.create :name => "Sally"
9
9
  @post = Post.create :name => "Announcement"
10
+ @article = Article.create :name => "Article"
10
11
  end
11
12
 
12
13
  it "should have Mongoid::Rateable module" do
@@ -51,6 +52,14 @@ describe Post do
51
52
  @post.rates.should eql 5
52
53
  end
53
54
 
55
+ it "should not raise exception if rate_value in RATING_RANGE" do
56
+ lambda { @article.rate 1, @sally }.should_not raise_error
57
+ end
58
+
59
+ it "should raise exception if rate_value not in RATING_RANGE" do
60
+ lambda { @article.rate 7, @sally }.should raise_error(ArgumentError)
61
+ end
62
+
54
63
  #TODO: Rewrite for random values
55
64
  describe "when using negative values" do
56
65
  it "should work properly for -1" do
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.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-29 00:00:00.000000000 +04:00
13
- default_executable:
12
+ date: 2011-08-07 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: bson_ext
17
- requirement: &72661120 !ruby/object:Gem::Requirement
16
+ requirement: &85244380 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *72661120
24
+ version_requirements: *85244380
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: mongoid
28
- requirement: &72660860 !ruby/object:Gem::Requirement
27
+ requirement: &85244030 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '0'
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *72660860
35
+ version_requirements: *85244030
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: bundler
39
- requirement: &72660560 !ruby/object:Gem::Requirement
38
+ requirement: &85243670 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: 1.0.0
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *72660560
46
+ version_requirements: *85243670
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: jeweler
50
- requirement: &72660270 !ruby/object:Gem::Requirement
49
+ requirement: &85243290 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ~>
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: 1.6.2
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *72660270
57
+ version_requirements: *85243290
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: simplecov
61
- requirement: &72659980 !ruby/object:Gem::Requirement
60
+ requirement: &85242910 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ! '>='
@@ -66,10 +65,10 @@ dependencies:
66
65
  version: 0.4.0
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *72659980
68
+ version_requirements: *85242910
70
69
  - !ruby/object:Gem::Dependency
71
70
  name: rdoc
72
- requirement: &72659680 !ruby/object:Gem::Requirement
71
+ requirement: &85242560 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ! '>='
@@ -77,10 +76,10 @@ dependencies:
77
76
  version: '0'
78
77
  type: :development
79
78
  prerelease: false
80
- version_requirements: *72659680
79
+ version_requirements: *85242560
81
80
  - !ruby/object:Gem::Dependency
82
81
  name: rspec
83
- requirement: &72659390 !ruby/object:Gem::Requirement
82
+ requirement: &85242210 !ruby/object:Gem::Requirement
84
83
  none: false
85
84
  requirements:
86
85
  - - ! '>='
@@ -88,10 +87,10 @@ dependencies:
88
87
  version: 2.0.0
89
88
  type: :development
90
89
  prerelease: false
91
- version_requirements: *72659390
90
+ version_requirements: *85242210
92
91
  - !ruby/object:Gem::Dependency
93
92
  name: database_cleaner
94
- requirement: &72659130 !ruby/object:Gem::Requirement
93
+ requirement: &85241850 !ruby/object:Gem::Requirement
95
94
  none: false
96
95
  requirements:
97
96
  - - ! '>='
@@ -99,7 +98,7 @@ dependencies:
99
98
  version: '0'
100
99
  type: :development
101
100
  prerelease: false
102
- version_requirements: *72659130
101
+ version_requirements: *85241850
103
102
  description: Provides fields and methods for the manipulation of rates on Mongoid
104
103
  documents.
105
104
  email: psavichev@gmail.com
@@ -123,11 +122,11 @@ files:
123
122
  - lib/mongoid_rateable/rateable.rb
124
123
  - lib/mongoid_rateable/rating.rb
125
124
  - mongoid_rateable.gemspec
125
+ - spec/models/article.rb
126
126
  - spec/models/post.rb
127
127
  - spec/models/user.rb
128
128
  - spec/rateable_spec.rb
129
129
  - spec/spec_helper.rb
130
- has_rdoc: true
131
130
  homepage: http://github.com/proton/mongoid_rateable
132
131
  licenses:
133
132
  - MIT
@@ -143,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
142
  version: '0'
144
143
  segments:
145
144
  - 0
146
- hash: -695841681
145
+ hash: -60597165
147
146
  required_rubygems_version: !ruby/object:Gem::Requirement
148
147
  none: false
149
148
  requirements:
@@ -152,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
151
  version: '0'
153
152
  requirements: []
154
153
  rubyforge_project:
155
- rubygems_version: 1.6.2
154
+ rubygems_version: 1.8.6
156
155
  signing_key:
157
156
  specification_version: 3
158
157
  summary: Rating functionality for Mongoid documents