acts_as_votable 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +34 -0
- data/lib/acts_as_votable/version.rb +1 -1
- data/lib/acts_as_votable/votable.rb +92 -25
- data/lib/acts_as_votable/voter.rb +5 -5
- data/lib/generators/acts_as_votable/migration/templates/active_record/migration.rb +1 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/votable_spec.rb +137 -0
- metadata +3 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbab821eaed3208a063e8bcd39f67a4e28fb79b0
|
4
|
+
data.tar.gz: d788852ccc01167a02a0b5a8d09b76d4cb13b212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8323034cb58bd685120c2ef882ffe06f0a94c5c7d503207d83e4bcac52d9d8e83d8aedd3d04c230225ca1a6f2816a6e2a298271032afb65584cac79df2a02f1
|
7
|
+
data.tar.gz: 252fe90880661cefb906365409fd77da3853cafb3ca71633187ffe64ecdf17dee9abfa8ba06ac6f70841cfd7b402dcb700cc7beec87eb9d3492360fba5de31fd
|
data/README.markdown
CHANGED
@@ -158,6 +158,27 @@ You can add an scope to your vote
|
|
158
158
|
@post.find_votes(:vote_scope => 'week').size # => 1
|
159
159
|
@post.find_votes(:vote_scope => 'month').size # => 1
|
160
160
|
```
|
161
|
+
### Adding weights to your votes
|
162
|
+
|
163
|
+
You can add weight to your vote. The default value is 1.
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
# positive votes
|
167
|
+
@post.liked_by @user1, :vote_weight => 1
|
168
|
+
@post.vote :voter => @user3, :vote_weight => 2
|
169
|
+
@post.vote :voter => @user5, :vote => 'like', :vote_scope => 'rank', :vote_weight => 3
|
170
|
+
|
171
|
+
# negative votes
|
172
|
+
@post.downvote_from @user2, :vote_scope => 'rank', :vote_weight => 1
|
173
|
+
@post.vote :voter => @user2, :vote => 'bad', :vote_scope => 'rank', :vote_weight => 3
|
174
|
+
|
175
|
+
# tally them up!
|
176
|
+
@post.find_votes(:vote_scope => 'rank').sum(:vote_weight) # => 6
|
177
|
+
@post.likes(:vote_scope => 'rank').sum(:vote_weight) # => 6
|
178
|
+
@post.upvotes(:vote_scope => 'rank').sum(:vote_weight) # => 6
|
179
|
+
@post.dislikes(:vote_scope => 'rank').sum(:vote_weight) # => 4
|
180
|
+
@post.downvotes(:vote_scope => 'rank').sum(:vote_weight) # => 4
|
181
|
+
```
|
161
182
|
|
162
183
|
### The Voter
|
163
184
|
|
@@ -267,6 +288,13 @@ after voting. For example:
|
|
267
288
|
@hat.negatives.size # => 1
|
268
289
|
```
|
269
290
|
|
291
|
+
To permit duplicates entries of a same voter, use option duplicate. Also notice that this
|
292
|
+
will limit some other methods that didn't deal with multiples votes, in this case, the last vote will be considered.
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
@hat.vote voter: @user, :duplicate => true
|
296
|
+
```
|
297
|
+
|
270
298
|
## Caching
|
271
299
|
|
272
300
|
To speed up perform you can add cache columns to your votable model's table. These
|
@@ -280,10 +308,15 @@ class AddCachedVotesToPosts < ActiveRecord::Migration
|
|
280
308
|
add_column :posts, :cached_votes_score, :integer, :default => 0
|
281
309
|
add_column :posts, :cached_votes_up, :integer, :default => 0
|
282
310
|
add_column :posts, :cached_votes_down, :integer, :default => 0
|
311
|
+
add_column :posts, :cached_weighted_score, :integer, :default => 0
|
283
312
|
add_index :posts, :cached_votes_total
|
284
313
|
add_index :posts, :cached_votes_score
|
285
314
|
add_index :posts, :cached_votes_up
|
286
315
|
add_index :posts, :cached_votes_down
|
316
|
+
add_index :posts, :cached_weighted_score
|
317
|
+
|
318
|
+
# Uncomment this line to force caching of existing votes
|
319
|
+
# Post.find_each(&:update_cached_votes)
|
287
320
|
end
|
288
321
|
|
289
322
|
def self.down
|
@@ -291,6 +324,7 @@ class AddCachedVotesToPosts < ActiveRecord::Migration
|
|
291
324
|
remove_column :posts, :cached_votes_score
|
292
325
|
remove_column :posts, :cached_votes_up
|
293
326
|
remove_column :posts, :cached_votes_down
|
327
|
+
remove_column :posts, :cached_weighted_score
|
294
328
|
end
|
295
329
|
end
|
296
330
|
```
|
@@ -6,13 +6,13 @@ module ActsAsVotable
|
|
6
6
|
include Helpers::Words
|
7
7
|
|
8
8
|
def self.included base
|
9
|
-
|
10
|
-
# allow the user to define these himself
|
9
|
+
|
10
|
+
# allow the user to define these himself
|
11
11
|
aliases = {
|
12
12
|
|
13
13
|
:vote_up => [
|
14
|
-
:up_by, :upvote_by, :like_by, :liked_by, :vote_by,
|
15
|
-
:up_from, :upvote_from, :upvote_by, :like_from, :liked_from, :vote_from
|
14
|
+
:up_by, :upvote_by, :like_by, :liked_by, :vote_by,
|
15
|
+
:up_from, :upvote_from, :upvote_by, :like_from, :liked_from, :vote_from
|
16
16
|
],
|
17
17
|
|
18
18
|
:vote_down => [
|
@@ -33,7 +33,7 @@ module ActsAsVotable
|
|
33
33
|
}
|
34
34
|
|
35
35
|
base.class_eval do
|
36
|
-
has_many :votes, :class_name =>
|
36
|
+
has_many :votes, :class_name => 'ActsAsVotable::Vote', :as => :votable, :dependent => :destroy do
|
37
37
|
def voters
|
38
38
|
includes(:voter).map(&:voter)
|
39
39
|
end
|
@@ -82,16 +82,18 @@ module ActsAsVotable
|
|
82
82
|
:voter_type => options[:voter].class.name
|
83
83
|
})
|
84
84
|
|
85
|
-
if _votes_.count == 0
|
85
|
+
if _votes_.count == 0 or options[:duplicate]
|
86
86
|
# this voter has never voted
|
87
87
|
vote = ActsAsVotable::Vote.new(
|
88
88
|
:votable => self,
|
89
89
|
:voter => options[:voter],
|
90
90
|
:vote_scope => options[:vote_scope]
|
91
91
|
)
|
92
|
+
#Allowing for a vote_weight to be associated with every vote. Could change with every voter object
|
93
|
+
vote.vote_weight = options.fetch(:vote_weight, 1).to_i
|
92
94
|
else
|
93
95
|
# this voter is potentially changing his vote
|
94
|
-
vote = _votes_.
|
96
|
+
vote = _votes_.last
|
95
97
|
end
|
96
98
|
|
97
99
|
last_update = vote.updated_at
|
@@ -100,7 +102,7 @@ module ActsAsVotable
|
|
100
102
|
|
101
103
|
if vote.save
|
102
104
|
self.vote_registered = true if last_update != vote.updated_at
|
103
|
-
update_cached_votes
|
105
|
+
update_cached_votes options[:vote_scope]
|
104
106
|
return true
|
105
107
|
else
|
106
108
|
self.vote_registered = false
|
@@ -115,25 +117,52 @@ module ActsAsVotable
|
|
115
117
|
|
116
118
|
return true if _votes_.size == 0
|
117
119
|
_votes_.each(&:destroy)
|
118
|
-
update_cached_votes
|
120
|
+
update_cached_votes args[:vote_scope]
|
119
121
|
self.vote_registered = false if votes.count == 0
|
120
122
|
return true
|
121
123
|
end
|
122
124
|
|
123
125
|
def vote_up voter, options={}
|
124
|
-
self.vote :voter => voter, :vote => true, :vote_scope => options[:vote_scope]
|
126
|
+
self.vote :voter => voter, :vote => true, :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight]
|
125
127
|
end
|
126
128
|
|
127
129
|
def vote_down voter, options={}
|
128
|
-
self.vote :voter => voter, :vote => false, :vote_scope => options[:vote_scope]
|
130
|
+
self.vote :voter => voter, :vote => false, :vote_scope => options[:vote_scope], :vote_weight => options[:vote_weight]
|
129
131
|
end
|
130
132
|
|
131
133
|
def unvote_for voter, options = {}
|
132
|
-
self.unvote :voter => voter, :vote_scope => options[:vote_scope]
|
134
|
+
self.unvote :voter => voter, :vote_scope => options[:vote_scope] #Does not need vote_weight since the votes are anyway getting destroyed
|
135
|
+
end
|
136
|
+
|
137
|
+
def scope_cache_field field, vote_scope
|
138
|
+
return field if vote_scope.nil?
|
139
|
+
|
140
|
+
case field
|
141
|
+
when :cached_votes_total=
|
142
|
+
"cached_scoped_#{vote_scope}_votes_total="
|
143
|
+
when :cached_votes_total
|
144
|
+
"cached_scoped_#{vote_scope}_votes_total"
|
145
|
+
when :cached_votes_up=
|
146
|
+
"cached_scoped_#{vote_scope}_votes_up="
|
147
|
+
when :cached_votes_up
|
148
|
+
"cached_scoped_#{vote_scope}_votes_up"
|
149
|
+
when :cached_votes_down=
|
150
|
+
"cached_scoped_#{vote_scope}_votes_down="
|
151
|
+
when :cached_votes_down
|
152
|
+
"cached_scoped_#{vote_scope}_votes_down"
|
153
|
+
when :cached_votes_score=
|
154
|
+
"cached_scoped_#{vote_scope}_votes_score="
|
155
|
+
when :cached_votes_score
|
156
|
+
"cached_scoped_#{vote_scope}_votes_score"
|
157
|
+
when :cached_weighted_scope
|
158
|
+
"cached_weighted_#{vote_scope}_score"
|
159
|
+
when :cached_weighted_score=
|
160
|
+
"cached_weighted_#{vote_scope}_score="
|
161
|
+
end
|
133
162
|
end
|
134
163
|
|
135
164
|
# caching
|
136
|
-
def update_cached_votes
|
165
|
+
def update_cached_votes vote_scope = nil
|
137
166
|
|
138
167
|
updates = {}
|
139
168
|
|
@@ -156,6 +185,35 @@ module ActsAsVotable
|
|
156
185
|
)
|
157
186
|
end
|
158
187
|
|
188
|
+
if self.respond_to?(:cached_weighted_score=)
|
189
|
+
updates[:cached_weighted_score] = weighted_score(true)
|
190
|
+
end
|
191
|
+
|
192
|
+
if vote_scope
|
193
|
+
if self.respond_to?(scope_cache_field :cached_votes_total=, vote_scope)
|
194
|
+
updates[scope_cache_field :cached_votes_total, vote_scope] = count_votes_total(true, vote_scope)
|
195
|
+
end
|
196
|
+
|
197
|
+
if self.respond_to?(scope_cache_field :cached_votes_up=, vote_scope)
|
198
|
+
updates[scope_cache_field :cached_votes_up, vote_scope] = count_votes_up(true, vote_scope)
|
199
|
+
end
|
200
|
+
|
201
|
+
if self.respond_to?(scope_cache_field :cached_votes_down=, vote_scope)
|
202
|
+
updates[scope_cache_field :cached_votes_down, vote_scope] = count_votes_down(true, vote_scope)
|
203
|
+
end
|
204
|
+
|
205
|
+
if self.respond_to?(scope_cache_field :cached_weighted_score=, vote_scope)
|
206
|
+
updates[scope_cache_field :cached_weighted_score, vote_scope] = weighted_score(true, vote_scope)
|
207
|
+
end
|
208
|
+
|
209
|
+
if self.respond_to?(scope_cache_field :cached_votes_score=, vote_scope)
|
210
|
+
updates[scope_cache_field :cached_votes_score, vote_scope] = (
|
211
|
+
(updates[scope_cache_field :cached_votes_up, vote_scope] || count_votes_up(true, vote_scope)) -
|
212
|
+
(updates[scope_cache_field :cached_votes_down, vote_scope] || count_votes_down(true, vote_scope))
|
213
|
+
)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
159
217
|
if (::ActiveRecord::VERSION::MAJOR == 3) && (::ActiveRecord::VERSION::MINOR != 0)
|
160
218
|
self.update_attributes(updates, :without_protection => true) if updates.size > 0
|
161
219
|
else
|
@@ -180,25 +238,34 @@ module ActsAsVotable
|
|
180
238
|
|
181
239
|
|
182
240
|
# counting
|
183
|
-
def count_votes_total skip_cache = false
|
184
|
-
if !skip_cache && self.respond_to?(:cached_votes_total)
|
185
|
-
return self.send(:cached_votes_total)
|
241
|
+
def count_votes_total skip_cache = false, vote_scope = nil
|
242
|
+
if !skip_cache && self.respond_to?(scope_cache_field :cached_votes_total, vote_scope)
|
243
|
+
return self.send(scope_cache_field :cached_votes_total, vote_scope)
|
244
|
+
end
|
245
|
+
find_votes(:vote_scope => vote_scope).count
|
246
|
+
end
|
247
|
+
|
248
|
+
def count_votes_up skip_cache = false, vote_scope = nil
|
249
|
+
if !skip_cache && self.respond_to?(scope_cache_field :cached_votes_up, vote_scope)
|
250
|
+
return self.send(scope_cache_field :cached_votes_up, vote_scope)
|
186
251
|
end
|
187
|
-
|
252
|
+
up_votes(:vote_scope => vote_scope).count
|
188
253
|
end
|
189
254
|
|
190
|
-
def
|
191
|
-
if !skip_cache && self.respond_to?(:
|
192
|
-
return self.send(:
|
255
|
+
def count_votes_down skip_cache = false, vote_scope = nil
|
256
|
+
if !skip_cache && self.respond_to?(scope_cache_field :cached_votes_down, vote_scope)
|
257
|
+
return self.send(scope_cache_field :cached_votes_down, vote_scope)
|
193
258
|
end
|
194
|
-
|
259
|
+
down_votes(:vote_scope => vote_scope).count
|
195
260
|
end
|
196
261
|
|
197
|
-
def
|
198
|
-
if !skip_cache && self.respond_to?(:
|
199
|
-
return self.send(:
|
262
|
+
def weighted_score skip_cache = false, vote_scope = nil
|
263
|
+
if !skip_cache && self.respond_to?(scope_cache_field :cached_weighted_score, vote_scope)
|
264
|
+
return self.send(scope_cache_field :cached_weighted_score, vote_scope)
|
200
265
|
end
|
201
|
-
|
266
|
+
ups = up_votes(:vote_scope => vote_scope).sum(:vote_weight)
|
267
|
+
downs = down_votes(:vote_scope => vote_scope).sum(:vote_weight)
|
268
|
+
ups - downs
|
202
269
|
end
|
203
270
|
|
204
271
|
# voters
|
@@ -18,7 +18,7 @@ module ActsAsVotable
|
|
18
18
|
|
19
19
|
base.class_eval do
|
20
20
|
|
21
|
-
has_many :votes, :class_name =>
|
21
|
+
has_many :votes, :class_name => 'ActsAsVotable::Vote', :as => :voter, :dependent => :destroy do
|
22
22
|
def votables
|
23
23
|
includes(:votable).map(&:votable)
|
24
24
|
end
|
@@ -71,10 +71,10 @@ module ActsAsVotable
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def voted_as_when_voting_on votable, args={}
|
74
|
-
|
75
|
-
:vote_scope => args[:vote_scope])
|
76
|
-
return nil
|
77
|
-
return
|
74
|
+
vote = find_votes(:votable_id => votable.id, :votable_type => votable.class.name,
|
75
|
+
:vote_scope => args[:vote_scope]).select(:vote_flag).last
|
76
|
+
return nil unless vote
|
77
|
+
return vote.vote_flag
|
78
78
|
end
|
79
79
|
|
80
80
|
def find_votes extra_conditions = {}
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
11
11
|
|
12
12
|
t.boolean :vote_flag
|
13
13
|
t.string :vote_scope
|
14
|
+
t.integer :vote_weight
|
14
15
|
|
15
16
|
t.timestamps
|
16
17
|
end
|
@@ -52,6 +53,13 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
52
53
|
t.integer :cached_votes_score
|
53
54
|
t.integer :cached_votes_up
|
54
55
|
t.integer :cached_votes_down
|
56
|
+
t.integer :cached_weighted_score
|
57
|
+
|
58
|
+
t.integer :cached_scoped_test_votes_total
|
59
|
+
t.integer :cached_scoped_test_votes_score
|
60
|
+
t.integer :cached_scoped_test_votes_up
|
61
|
+
t.integer :cached_scoped_test_votes_down
|
62
|
+
t.integer :cached_scoped_weighted_score
|
55
63
|
end
|
56
64
|
|
57
65
|
end
|
data/spec/votable_spec.rb
CHANGED
@@ -44,6 +44,12 @@ describe ActsAsVotable::Votable do
|
|
44
44
|
@votable.votes.size.should == 1
|
45
45
|
end
|
46
46
|
|
47
|
+
it "should have two votes when voted on twice by the same person with duplicate paramenter" do
|
48
|
+
@votable.vote :voter => @voter, :vote => 'yes'
|
49
|
+
@votable.vote :voter => @voter, :vote => 'no', :duplicate => true
|
50
|
+
@votable.votes.size.should == 2
|
51
|
+
end
|
52
|
+
|
47
53
|
it "should have one scoped vote when voting under an scope" do
|
48
54
|
@votable.vote :voter => @voter, :vote => 'yes', :vote_scope => 'rank'
|
49
55
|
@votable.find_votes(:vote_scope => 'rank').size.should == 1
|
@@ -219,6 +225,30 @@ describe ActsAsVotable::Votable do
|
|
219
225
|
@votable_cache.cached_votes_score.should == 0
|
220
226
|
end
|
221
227
|
|
228
|
+
it "should update cached weighted score if there is a weighted score column" do
|
229
|
+
@votable_cache.cached_weighted_score = 50
|
230
|
+
@votable_cache.vote :voter => @voter
|
231
|
+
@votable_cache.cached_weighted_score.should == 1
|
232
|
+
@votable_cache.vote :voter => @voter2, :vote => 'false'
|
233
|
+
@votable_cache.cached_weighted_score.should == 0
|
234
|
+
@votable_cache.vote :voter => @voter, :vote => 'false'
|
235
|
+
@votable_cache.cached_weighted_score.should == -2
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should update cached weighted score votes when a vote up is removed" do
|
239
|
+
@votable_cache.vote :voter => @voter, :vote => 'true', :vote_weight => 3
|
240
|
+
@votable_cache.cached_weighted_score.should == 3
|
241
|
+
@votable_cache.unvote :voter => @voter
|
242
|
+
@votable_cache.cached_weighted_score.should == 0
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should update cached weighted score votes when a vote down is removed" do
|
246
|
+
@votable_cache.vote :voter => @voter, :vote => 'false', :vote_weight => 4
|
247
|
+
@votable_cache.cached_weighted_score.should == -4
|
248
|
+
@votable_cache.unvote :voter => @voter
|
249
|
+
@votable_cache.cached_weighted_score.should == 0
|
250
|
+
end
|
251
|
+
|
222
252
|
it "should update cached up votes if there is an up vote column" do
|
223
253
|
@votable_cache.cached_votes_up = 50
|
224
254
|
@votable_cache.vote :voter => @voter
|
@@ -262,6 +292,113 @@ describe ActsAsVotable::Votable do
|
|
262
292
|
@votable_cache.count_votes_down.should == 50
|
263
293
|
end
|
264
294
|
|
295
|
+
it "should select from cached weighted score if there is a weighted score column" do
|
296
|
+
@votable_cache.vote :voter => @voter, :vote => 'false'
|
297
|
+
@votable_cache.cached_weighted_score = 50
|
298
|
+
@votable_cache.weighted_score.should == 50
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
describe "with scoped cached votes" do
|
304
|
+
|
305
|
+
before(:each) do
|
306
|
+
clean_database
|
307
|
+
@voter = Voter.new(:name => 'i can vote!')
|
308
|
+
@voter.save
|
309
|
+
|
310
|
+
@votable = Votable.new(:name => 'a voting model without a cache')
|
311
|
+
@votable.save
|
312
|
+
|
313
|
+
@votable_cache = VotableCache.new(:name => 'voting model with cache')
|
314
|
+
@votable_cache.save
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should update cached total votes if there is a total column" do
|
318
|
+
@votable_cache.cached_scoped_test_votes_total = 50
|
319
|
+
@votable_cache.vote :voter => @voter, :vote_scope => "test"
|
320
|
+
@votable_cache.cached_scoped_test_votes_total.should == 1
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should update cached total votes when a vote up is removed" do
|
324
|
+
@votable_cache.vote :voter => @voter, :vote => 'true', :vote_scope => "test"
|
325
|
+
@votable_cache.unvote :voter => @voter, :vote_scope => "test"
|
326
|
+
@votable_cache.cached_scoped_test_votes_total.should == 0
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should update cached total votes when a vote down is removed" do
|
330
|
+
@votable_cache.vote :voter => @voter, :vote => 'false', :vote_scope => "test"
|
331
|
+
@votable_cache.unvote :voter => @voter, :vote_scope => "test"
|
332
|
+
@votable_cache.cached_scoped_test_votes_total.should == 0
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should update cached score votes if there is a score column" do
|
336
|
+
@votable_cache.cached_scoped_test_votes_score = 50
|
337
|
+
@votable_cache.vote :voter => @voter, :vote_scope => "test"
|
338
|
+
@votable_cache.cached_scoped_test_votes_score.should == 1
|
339
|
+
@votable_cache.vote :voter => @voter2, :vote => 'false', :vote_scope => "test"
|
340
|
+
@votable_cache.cached_scoped_test_votes_score.should == 0
|
341
|
+
@votable_cache.vote :voter => @voter, :vote => 'false', :vote_scope => "test"
|
342
|
+
@votable_cache.cached_scoped_test_votes_score.should == -2
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should update cached score votes when a vote up is removed" do
|
346
|
+
@votable_cache.vote :voter => @voter, :vote => 'true', :vote_scope => "test"
|
347
|
+
@votable_cache.cached_scoped_test_votes_score.should == 1
|
348
|
+
@votable_cache.unvote :voter => @voter, :vote_scope => "test"
|
349
|
+
@votable_cache.cached_scoped_test_votes_score.should == 0
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should update cached score votes when a vote down is removed" do
|
353
|
+
@votable_cache.vote :voter => @voter, :vote => 'false', :vote_scope => "test"
|
354
|
+
@votable_cache.cached_scoped_test_votes_score.should == -1
|
355
|
+
@votable_cache.unvote :voter => @voter, :vote_scope => "test"
|
356
|
+
@votable_cache.cached_scoped_test_votes_score.should == 0
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should update cached up votes if there is an up vote column" do
|
360
|
+
@votable_cache.cached_scoped_test_votes_up = 50
|
361
|
+
@votable_cache.vote :voter => @voter, :vote_scope => "test"
|
362
|
+
@votable_cache.vote :voter => @voter, :vote_scope => "test"
|
363
|
+
@votable_cache.cached_scoped_test_votes_up.should == 1
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should update cached down votes if there is a down vote column" do
|
367
|
+
@votable_cache.cached_scoped_test_votes_down = 50
|
368
|
+
@votable_cache.vote :voter => @voter, :vote => 'false', :vote_scope => "test"
|
369
|
+
@votable_cache.cached_scoped_test_votes_down.should == 1
|
370
|
+
end
|
371
|
+
|
372
|
+
it "should update cached up votes when a vote up is removed" do
|
373
|
+
@votable_cache.vote :voter => @voter, :vote => 'true', :vote_scope => "test"
|
374
|
+
@votable_cache.unvote :voter => @voter, :vote_scope => "test"
|
375
|
+
@votable_cache.cached_scoped_test_votes_up.should == 0
|
376
|
+
end
|
377
|
+
|
378
|
+
it "should update cached down votes when a vote down is removed" do
|
379
|
+
@votable_cache.vote :voter => @voter, :vote => 'false', :vote_scope => "test"
|
380
|
+
@votable_cache.unvote :voter => @voter, :vote_scope => "test"
|
381
|
+
@votable_cache.cached_scoped_test_votes_down.should == 0
|
382
|
+
end
|
383
|
+
|
384
|
+
it "should select from cached total votes if there a total column" do
|
385
|
+
@votable_cache.vote :voter => @voter, :vote_scope => "test"
|
386
|
+
@votable_cache.cached_scoped_test_votes_total = 50
|
387
|
+
@votable_cache.count_votes_total(false, "test").should == 50
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should select from cached up votes if there is an up vote column" do
|
391
|
+
@votable_cache.vote :voter => @voter, :vote_scope => "test"
|
392
|
+
@votable_cache.cached_scoped_test_votes_up = 50
|
393
|
+
@votable_cache.count_votes_up(false, "test").should == 50
|
394
|
+
end
|
395
|
+
|
396
|
+
it "should select from cached down votes if there is a down vote column" do
|
397
|
+
@votable_cache.vote :voter => @voter, :vote => 'false', :vote_scope => "test"
|
398
|
+
@votable_cache.cached_scoped_test_votes_down = 50
|
399
|
+
@votable_cache.count_votes_down(false, "test").should == 50
|
400
|
+
end
|
401
|
+
|
265
402
|
end
|
266
403
|
|
267
404
|
describe "sti models" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_votable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -89,8 +89,4 @@ rubygems_version: 2.0.3
|
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: Rails gem to allowing records to be votable
|
92
|
-
test_files:
|
93
|
-
- spec/spec_helper.rb
|
94
|
-
- spec/votable_spec.rb
|
95
|
-
- spec/voter_spec.rb
|
96
|
-
- spec/words_spec.rb
|
92
|
+
test_files: []
|