redis_voteable 0.1.0 → 0.1.1
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.
- data/lib/redis_voteable/version.rb +1 -1
- data/lib/redis_voteable/voteable.rb +2 -2
- data/lib/redis_voteable/voter.rb +4 -4
- data/redis_voteable.gemspec +1 -1
- data/redis_voteable.sqlite3 +0 -0
- data/spec/lib/redis_voteable_spec.rb +44 -18
- data/spec/spec_helper.rb +2 -2
- metadata +16 -16
@@ -38,12 +38,12 @@ module RedisVoteable
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def up_percentage
|
41
|
-
return (up_votes.to_f * 100 / total_votes) unless
|
41
|
+
return (up_votes.to_f * 100 / total_votes) unless total_votes == 0
|
42
42
|
nil
|
43
43
|
end
|
44
44
|
|
45
45
|
def down_percentage
|
46
|
-
return (down_votes.to_f * 100 / total_votes) unless
|
46
|
+
return (down_votes.to_f * 100 / total_votes) unless total_votes == 0
|
47
47
|
nil
|
48
48
|
end
|
49
49
|
|
data/lib/redis_voteable/voter.rb
CHANGED
@@ -113,17 +113,17 @@ module RedisVoteable
|
|
113
113
|
end
|
114
114
|
|
115
115
|
# Return the total number of votes a voter has cast.
|
116
|
-
def
|
117
|
-
|
116
|
+
def total_votes()
|
117
|
+
up_votes + down_votes
|
118
118
|
end
|
119
119
|
|
120
120
|
# Returns the number of upvotes a voter has cast.
|
121
|
-
def
|
121
|
+
def up_votes()
|
122
122
|
redis.scard prefixed("#{class_key(self)}:#{UP_VOTES}")
|
123
123
|
end
|
124
124
|
|
125
125
|
# Returns the number of downvotes a voter has cast.
|
126
|
-
def
|
126
|
+
def down_votes()
|
127
127
|
redis.scard prefixed("#{class_key(self)}:#{DOWN_VOTES}")
|
128
128
|
end
|
129
129
|
|
data/redis_voteable.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# Dependencies
|
22
22
|
s.add_dependency "redis", "~> 2.2.0"
|
23
|
-
s.add_dependency "activesupport"
|
23
|
+
s.add_dependency "activesupport", ">= 3.0.0"
|
24
24
|
|
25
25
|
# For development only
|
26
26
|
s.add_development_dependency "activerecord", "~> 3.0.0"
|
data/redis_voteable.sqlite3
CHANGED
Binary file
|
@@ -37,9 +37,9 @@ describe "Redis Voteable" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "voter should have up vote votings" do
|
40
|
-
@voter.
|
40
|
+
@voter.up_votes == 0
|
41
41
|
@voter.up_vote(@voteable)
|
42
|
-
@voter.
|
42
|
+
@voter.up_votes == 1
|
43
43
|
@voter.votings[0].should == @voteable
|
44
44
|
end
|
45
45
|
|
@@ -52,12 +52,38 @@ describe "Redis Voteable" do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "voter should have down vote votings" do
|
55
|
-
@voter.
|
55
|
+
@voter.down_votes.should == 0
|
56
56
|
@voter.down_vote(@voteable)
|
57
|
-
@voter.
|
57
|
+
@voter.down_votes.should == 1
|
58
58
|
@voter.votings[0].should == @voteable
|
59
59
|
end
|
60
60
|
|
61
|
+
it "voteable should calculate correct percentages" do
|
62
|
+
@voter.up_vote(@voteable)
|
63
|
+
@voteable.up_percentage.should == 100.0
|
64
|
+
@voteable.down_percentage.should == 0.0
|
65
|
+
@voter2 = VoterModel.create(:name => "Voter 2")
|
66
|
+
@voter2.down_vote(@voteable)
|
67
|
+
@voteable.up_percentage.should == 50.0
|
68
|
+
@voteable.down_percentage.should == 50.0
|
69
|
+
end
|
70
|
+
|
71
|
+
it "voteable should calculate lower Wilson confidence bound" do
|
72
|
+
@voter2 = VoterModel.create(:name => "Voter 2")
|
73
|
+
@voter3 = VoterModel.create(:name => "Voter 3")
|
74
|
+
@voter4 = VoterModel.create(:name => "Voter 4")
|
75
|
+
@voter.up_vote(@voteable)
|
76
|
+
score1 = @voteable.confidence
|
77
|
+
@voter2.down_vote(@voteable)
|
78
|
+
score2 = @voteable.confidence
|
79
|
+
@voter3.down_vote(@voteable)
|
80
|
+
score3 = @voteable.confidence
|
81
|
+
@voter3.up_vote(@voteable)
|
82
|
+
score4 = @voteable.confidence
|
83
|
+
@voter4.up_vote(@voteable)
|
84
|
+
score5 = @voteable.confidence
|
85
|
+
end
|
86
|
+
|
61
87
|
describe "up vote" do
|
62
88
|
it "should increase up votes of voteable by one" do
|
63
89
|
@voteable.up_votes.should == 0
|
@@ -66,9 +92,9 @@ describe "Redis Voteable" do
|
|
66
92
|
end
|
67
93
|
|
68
94
|
it "should increase up votes of voter by one" do
|
69
|
-
@voter.
|
95
|
+
@voter.up_votes.should == 0
|
70
96
|
@voter.up_vote(@voteable)
|
71
|
-
@voter.
|
97
|
+
@voter.up_votes.should == 1
|
72
98
|
end
|
73
99
|
|
74
100
|
it "should only allow a voter to up vote a voteable once" do
|
@@ -93,15 +119,15 @@ describe "Redis Voteable" do
|
|
93
119
|
@voteable.up_votes.should == 0
|
94
120
|
@voteable.down_votes.should == 1
|
95
121
|
@voteable.tally.should == -1
|
96
|
-
@voter.
|
97
|
-
@voter.
|
122
|
+
@voter.up_votes.should == 0
|
123
|
+
@voter.down_votes.should == 1
|
98
124
|
|
99
125
|
@voter.up_vote(@voteable)
|
100
126
|
@voteable.up_votes.should == 1
|
101
127
|
@voteable.down_votes.should == 0
|
102
128
|
@voteable.tally.should == 1
|
103
|
-
@voter.
|
104
|
-
@voter.
|
129
|
+
@voter.up_votes.should == 1
|
130
|
+
@voter.down_votes.should == 0
|
105
131
|
end
|
106
132
|
|
107
133
|
it "should allow up votes from different voters" do
|
@@ -133,9 +159,9 @@ describe "Redis Voteable" do
|
|
133
159
|
end
|
134
160
|
|
135
161
|
it "should decrease down votes of voter by one" do
|
136
|
-
@voter.
|
162
|
+
@voter.down_votes.should == 0
|
137
163
|
@voter.down_vote(@voteable)
|
138
|
-
@voter.
|
164
|
+
@voter.down_votes.should == 1
|
139
165
|
end
|
140
166
|
|
141
167
|
it "should only allow a voter to down vote a voteable once" do
|
@@ -160,15 +186,15 @@ describe "Redis Voteable" do
|
|
160
186
|
@voteable.up_votes.should == 1
|
161
187
|
@voteable.down_votes.should == 0
|
162
188
|
@voteable.tally.should == 1
|
163
|
-
@voter.
|
164
|
-
@voter.
|
189
|
+
@voter.up_votes.should == 1
|
190
|
+
@voter.down_votes.should == 0
|
165
191
|
|
166
192
|
@voter.down_vote(@voteable)
|
167
193
|
@voteable.up_votes.should == 0
|
168
194
|
@voteable.down_votes.should == 1
|
169
195
|
@voteable.tally.should == -1
|
170
|
-
@voter.
|
171
|
-
@voter.
|
196
|
+
@voter.up_votes.should == 0
|
197
|
+
@voter.down_votes.should == 1
|
172
198
|
end
|
173
199
|
|
174
200
|
it "should allow down votes from different voters" do
|
@@ -196,10 +222,10 @@ describe "Redis Voteable" do
|
|
196
222
|
it "should decrease the up votes if up voted before" do
|
197
223
|
@voter.up_vote(@voteable)
|
198
224
|
@voteable.up_votes.should == 1
|
199
|
-
@voter.
|
225
|
+
@voter.up_votes.should == 1
|
200
226
|
@voter.clear_vote(@voteable)
|
201
227
|
@voteable.up_votes.should == 0
|
202
|
-
@voter.
|
228
|
+
@voter.up_votes.should == 0
|
203
229
|
end
|
204
230
|
|
205
231
|
it "should raise an error if voter didn't vote for the voteable" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_voteable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-30 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70115573519260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: 2.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70115573519260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70115573518580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70115573518580
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activerecord
|
38
|
-
requirement: &
|
38
|
+
requirement: &70115573517840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70115573517840
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3-ruby
|
49
|
-
requirement: &
|
49
|
+
requirement: &70115573510500 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.3.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70115573510500
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70115573509880 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70115573509880
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70115573508880 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 2.0.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70115573508880
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: database_cleaner
|
82
|
-
requirement: &
|
82
|
+
requirement: &70115573508360 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: 0.6.7
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70115573508360
|
91
91
|
description: ! 'A Redis-backed voting extension for Rails applications. '
|
92
92
|
email:
|
93
93
|
- cbrauchli@gmail.com
|