mongoid_rating 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongoid_rating/model.rb +8 -2
- data/lib/mongoid_rating/version.rb +1 -1
- data/spec/comment_spec.rb +12 -1
- data/spec/models/comment.rb +1 -1
- data/spec/post_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ec9fb8ca4177c886bbda6efaf5897092d801602
|
4
|
+
data.tar.gz: b0e778371a7ea4f73107a25cc89d306e57a75c5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89e37367dbfbaea78ded2230d87aadcdd19d27bd39590c3d5363eec8edd6c6bca17af9b775e5c0d980ca07b84a48665d06ab336aaf3f3a5db8f8d4c88e971c50
|
7
|
+
data.tar.gz: bcd2897fa39a48e7bef7670e75449f0d29d0a0e3529c0dcb63babf5455fdb3fe7f3eddd990c5172a1f6533f99800221abcb36f98b55f51fc66a43e1c72655245
|
data/lib/mongoid_rating/model.rb
CHANGED
@@ -12,8 +12,10 @@ module Mongoid
|
|
12
12
|
#
|
13
13
|
# Disable average completely
|
14
14
|
# rateable :design, range: -5..5, average: false
|
15
|
-
#
|
16
15
|
# rateable :quality, range: -5..5, average: true
|
16
|
+
#
|
17
|
+
# float: whether to allow non-integer rates (default true)
|
18
|
+
#
|
17
19
|
def rateable(field, options = {})
|
18
20
|
options = {
|
19
21
|
range: 1..5,
|
@@ -54,7 +56,11 @@ module Mongoid
|
|
54
56
|
}
|
55
57
|
|
56
58
|
def #{field}!(value, rater)
|
57
|
-
|
59
|
+
if #{options[:float]}
|
60
|
+
value = value.to_f
|
61
|
+
else
|
62
|
+
value = value.to_i
|
63
|
+
end
|
58
64
|
unless (#{options[:range]}).include?(value)
|
59
65
|
raise "bad vote value"
|
60
66
|
end
|
data/spec/comment_spec.rb
CHANGED
@@ -25,10 +25,21 @@ describe Comment do
|
|
25
25
|
it "should contain an array of rating marks" do
|
26
26
|
@comment1.rate_values.should be_an_instance_of Array
|
27
27
|
@comment1.rate_values.should eq []
|
28
|
+
|
28
29
|
@comment1.rate! 2, @bob
|
29
30
|
@comment1.rate_values.should eq [2]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'allows string rate' do
|
34
|
+
@comment1.rate! '3', @bob
|
35
|
+
@comment1.rate_values.should eq [3]
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'disallows float' do
|
30
39
|
@comment1.rate! 2.5, @bob
|
31
|
-
@comment1.rate_values.should eq [2
|
40
|
+
@comment1.rate_values.should eq [2]
|
41
|
+
@comment1.rate! '2.7', @bob
|
42
|
+
@comment1.rate_values.should eq [2]
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
data/spec/models/comment.rb
CHANGED
data/spec/post_spec.rb
CHANGED
@@ -52,6 +52,16 @@ describe Post do
|
|
52
52
|
it { expect { @post.rate 17, @sally }.to raise_error() }
|
53
53
|
it { expect { @post.rate -17, @sally }.to raise_error() }
|
54
54
|
end
|
55
|
+
|
56
|
+
it 'allows string rate' do
|
57
|
+
@post.rate! '5', @bob
|
58
|
+
@post.rate.should eql 5.0
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'allows string rate' do
|
62
|
+
@post.rate! '3.2', @bob
|
63
|
+
@post.rate.should eql 3.2
|
64
|
+
end
|
55
65
|
end
|
56
66
|
|
57
67
|
describe "#rated?" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_rating
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebtv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|