mongoid_rating 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c46a533fed5f93903eea6cb5af5d45ad034fd14c
4
- data.tar.gz: 0ebcd0ae9aea25aca80ad0d9712035cc7dc593bb
3
+ metadata.gz: 6ec9fb8ca4177c886bbda6efaf5897092d801602
4
+ data.tar.gz: b0e778371a7ea4f73107a25cc89d306e57a75c5a
5
5
  SHA512:
6
- metadata.gz: 1e0a902185c5a8115b8f879bcf5bac2f10b3a08d3a3bfd4b127fce5e4db402d9398a67974d0c5dfe366cfdd299e0f96a23a3f18bc0667142aa44603b19c09bf7
7
- data.tar.gz: ee70c1b36395f47eec03e008c8252a7a291289f8622f292b422c102833a4aeef46f54ff247e6f2862478f9b4e0b9c04125cd6a672f8f1a61887557a4bb41bcec
6
+ metadata.gz: 89e37367dbfbaea78ded2230d87aadcdd19d27bd39590c3d5363eec8edd6c6bca17af9b775e5c0d980ca07b84a48665d06ab336aaf3f3a5db8f8d4c88e971c50
7
+ data.tar.gz: bcd2897fa39a48e7bef7670e75449f0d29d0a0e3529c0dcb63babf5455fdb3fe7f3eddd990c5172a1f6533f99800221abcb36f98b55f51fc66a43e1c72655245
@@ -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
- value = value.to_i unless #{options[:float]}
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
@@ -1,3 +1,3 @@
1
1
  module MongoidRating
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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.5]
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
 
@@ -1,7 +1,7 @@
1
1
  class Comment
2
2
  include Mongoid::Document
3
3
 
4
- rateable :rate, eval: false
4
+ rateable :rate, float: false
5
5
 
6
6
  embedded_in :post
7
7
 
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.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-07 00:00:00.000000000 Z
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid