acts_as_votable 0.5.0 → 0.8.0

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.
@@ -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 => [
@@ -27,15 +27,13 @@ module ActsAsVotable
27
27
  :down_votes => [
28
28
  :false_votes, :downs, :downvotes, :dislikes, :negatives
29
29
  ],
30
- :unvote => [
31
- :unliked_by, :undisliked_by
30
+ :unvote_for => [
31
+ :unvote_up, :unvote_down, :unliked_by, :undisliked_by
32
32
  ]
33
33
  }
34
34
 
35
35
  base.class_eval do
36
-
37
- belongs_to :votable, :polymorphic => true
38
- has_many :votes, :class_name => "ActsAsVotable::Vote", :as => :votable do
36
+ has_many :votes, :class_name => 'ActsAsVotable::Vote', :as => :votable, :dependent => :destroy do
39
37
  def voters
40
38
  includes(:voter).map(&:voter)
41
39
  end
@@ -84,16 +82,18 @@ module ActsAsVotable
84
82
  :voter_type => options[:voter].class.name
85
83
  })
86
84
 
87
- if _votes_.count == 0
85
+ if _votes_.count == 0 or options[:duplicate]
88
86
  # this voter has never voted
89
87
  vote = ActsAsVotable::Vote.new(
90
88
  :votable => self,
91
89
  :voter => options[:voter],
92
90
  :vote_scope => options[:vote_scope]
93
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
94
94
  else
95
95
  # this voter is potentially changing his vote
96
- vote = _votes_.first
96
+ vote = _votes_.last
97
97
  end
98
98
 
99
99
  last_update = vote.updated_at
@@ -102,7 +102,7 @@ module ActsAsVotable
102
102
 
103
103
  if vote.save
104
104
  self.vote_registered = true if last_update != vote.updated_at
105
- update_cached_votes
105
+ update_cached_votes options[:vote_scope]
106
106
  return true
107
107
  else
108
108
  self.vote_registered = false
@@ -117,21 +117,52 @@ module ActsAsVotable
117
117
 
118
118
  return true if _votes_.size == 0
119
119
  _votes_.each(&:destroy)
120
- update_cached_votes
120
+ update_cached_votes args[:vote_scope]
121
121
  self.vote_registered = false if votes.count == 0
122
122
  return true
123
123
  end
124
124
 
125
125
  def vote_up voter, options={}
126
- 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]
127
127
  end
128
128
 
129
129
  def vote_down voter, options={}
130
- 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]
131
+ end
132
+
133
+ def unvote_for voter, options = {}
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
131
162
  end
132
163
 
133
164
  # caching
134
- def update_cached_votes
165
+ def update_cached_votes vote_scope = nil
135
166
 
136
167
  updates = {}
137
168
 
@@ -154,7 +185,40 @@ module ActsAsVotable
154
185
  )
155
186
  end
156
187
 
157
- self.update_attributes(updates, :without_protection => true) if updates.size > 0
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
+
217
+ if (::ActiveRecord::VERSION::MAJOR == 3) && (::ActiveRecord::VERSION::MINOR != 0)
218
+ self.update_attributes(updates, :without_protection => true) if updates.size > 0
219
+ else
220
+ self.update_attributes(updates) if updates.size > 0
221
+ end
158
222
 
159
223
  end
160
224
 
@@ -174,25 +238,34 @@ module ActsAsVotable
174
238
 
175
239
 
176
240
  # counting
177
- def count_votes_total skip_cache = false
178
- if !skip_cache && self.respond_to?(:cached_votes_total)
179
- 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)
180
251
  end
181
- find_votes.count
252
+ up_votes(:vote_scope => vote_scope).count
182
253
  end
183
254
 
184
- def count_votes_up skip_cache = false
185
- if !skip_cache && self.respond_to?(:cached_votes_up)
186
- return self.send(:cached_votes_up)
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)
187
258
  end
188
- up_votes.count
259
+ down_votes(:vote_scope => vote_scope).count
189
260
  end
190
261
 
191
- def count_votes_down skip_cache = false
192
- if !skip_cache && self.respond_to?(:cached_votes_down)
193
- return self.send(:cached_votes_down)
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)
194
265
  end
195
- down_votes.count
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
196
269
  end
197
270
 
198
271
  # voters
@@ -5,16 +5,18 @@ module ActsAsVotable
5
5
 
6
6
  include Helpers::Words
7
7
 
8
- attr_accessible :votable_id, :votable_type,
9
- :voter_id, :voter_type,
10
- :votable, :voter,
11
- :vote_flag, :vote_scope
8
+ if ::ActiveRecord::VERSION::MAJOR < 4
9
+ attr_accessible :votable_id, :votable_type,
10
+ :voter_id, :voter_type,
11
+ :votable, :voter,
12
+ :vote_flag, :vote_scope
13
+ end
12
14
 
13
15
  belongs_to :votable, :polymorphic => true
14
16
  belongs_to :voter, :polymorphic => true
15
17
 
16
- scope :up, where(:vote_flag => true)
17
- scope :down, where(:vote_flag => false)
18
+ scope :up, lambda{ where(:vote_flag => true) }
19
+ scope :down, lambda{ where(:vote_flag => false) }
18
20
  scope :for_type, lambda{ |klass| where(:votable_type => klass) }
19
21
  scope :by_type, lambda{ |klass| where(:voter_type => klass) }
20
22
 
@@ -5,17 +5,20 @@ module ActsAsVotable
5
5
 
6
6
  # allow user to define these
7
7
  aliases = {
8
- :vote_up_for => [:likes, :upvotes, :up_votes],
9
- :vote_down_for => [:dislikes, :downvotes, :down_votes],
10
- :unvote_for => [:unlike, :undislike],
8
+ :vote_up_for => [:likes, :upvotes, :up_votes],
9
+ :vote_down_for => [:dislikes, :downvotes, :down_votes],
10
+ :unvote_for => [:unlike, :undislike],
11
+ :voted_on? => [:voted_for?],
11
12
  :voted_up_on? => [:voted_up_for?, :liked?],
12
- :voted_down_on? => [:voted_down_for?, :disliked?]
13
+ :voted_down_on? => [:voted_down_for?, :disliked?],
14
+ :voted_as_when_voting_on => [:voted_as_when_voted_on, :voted_as_when_voting_for, :voted_as_when_voted_for],
15
+ :find_up_voted_items => [:find_liked_items],
16
+ :find_down_voted_items => [:find_disliked_items]
13
17
  }
14
18
 
15
19
  base.class_eval do
16
20
 
17
- belongs_to :voter, :polymorphic => true
18
- has_many :votes, :class_name => "ActsAsVotable::Vote", :as => :voter do
21
+ has_many :votes, :class_name => 'ActsAsVotable::Vote', :as => :voter, :dependent => :destroy do
19
22
  def votables
20
23
  includes(:votable).map(&:votable)
21
24
  end
@@ -66,15 +69,13 @@ module ActsAsVotable
66
69
  :vote_scope => args[:vote_scope], :vote_flag => false)
67
70
  votes.size > 0
68
71
  end
69
- alias :voted_down_for? :voted_down_on?
70
72
 
71
73
  def voted_as_when_voting_on votable, args={}
72
- votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name,
73
- :vote_scope => args[:vote_scope])
74
- return nil if votes.size == 0
75
- return votes.first.vote_flag
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
76
78
  end
77
- alias :voted_as_when_voted_for :voted_as_when_voting_on
78
79
 
79
80
  def find_votes extra_conditions = {}
80
81
  votes.where(extra_conditions)
@@ -113,12 +114,10 @@ module ActsAsVotable
113
114
  def find_up_voted_items extra_conditions = {}
114
115
  find_voted_items extra_conditions.merge(:vote_flag => true)
115
116
  end
116
- alias_method :find_liked_items, :find_up_voted_items
117
117
 
118
118
  def find_down_voted_items extra_conditions = {}
119
119
  find_voted_items extra_conditions.merge(:vote_flag => false)
120
120
  end
121
- alias_method :find_disliked_items, :find_down_voted_items
122
121
 
123
122
  def get_voted klass, extra_conditions = {}
124
123
  klass.joins(:votes).merge find_votes(extra_conditions)
@@ -14,3 +14,8 @@ module ActsAsVotable
14
14
  end
15
15
 
16
16
  end
17
+
18
+ require 'acts_as_votable/extenders/controller'
19
+ ActiveSupport.on_load(:action_controller) do
20
+ include ActsAsVotable::Extenders::Controller
21
+ end
@@ -7,12 +7,16 @@ class ActsAsVotableMigration < ActiveRecord::Migration
7
7
 
8
8
  t.boolean :vote_flag
9
9
  t.string :vote_scope
10
+ t.integer :vote_weight
10
11
 
11
12
  t.timestamps
12
13
  end
13
14
 
14
- add_index :votes, [:votable_id, :votable_type]
15
- add_index :votes, [:voter_id, :voter_type]
15
+ if ActiveRecord::VERSION::MAJOR < 4
16
+ add_index :votes, [:votable_id, :votable_type]
17
+ add_index :votes, [:voter_id, :voter_type]
18
+ end
19
+
16
20
  add_index :votes, [:voter_id, :voter_type, :vote_scope]
17
21
  add_index :votes, [:votable_id, :votable_type, :vote_scope]
18
22
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'sqlite3'
2
3
  require 'acts_as_votable'
3
4
 
4
5
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
@@ -10,6 +11,7 @@ ActiveRecord::Schema.define(:version => 1) do
10
11
 
11
12
  t.boolean :vote_flag
12
13
  t.string :vote_scope
14
+ t.integer :vote_weight
13
15
 
14
16
  t.timestamps
15
17
  end
@@ -51,6 +53,13 @@ ActiveRecord::Schema.define(:version => 1) do
51
53
  t.integer :cached_votes_score
52
54
  t.integer :cached_votes_up
53
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
54
63
  end
55
64
 
56
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
@@ -116,6 +122,12 @@ describe ActsAsVotable::Votable do
116
122
  @votable.voted_on_by?(@voter).should be true
117
123
  end
118
124
 
125
+ it "should be able to unvote a voter" do
126
+ @votable.liked_by(@voter)
127
+ @votable.unliked_by(@voter)
128
+ @votable.voted_on_by?(@voter).should be false
129
+ end
130
+
119
131
  it "should unvote a positive vote" do
120
132
  @votable.vote :voter => @voter
121
133
  @votable.unvote :voter => @voter
@@ -213,6 +225,30 @@ describe ActsAsVotable::Votable do
213
225
  @votable_cache.cached_votes_score.should == 0
214
226
  end
215
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
+
216
252
  it "should update cached up votes if there is an up vote column" do
217
253
  @votable_cache.cached_votes_up = 50
218
254
  @votable_cache.vote :voter => @voter
@@ -256,6 +292,113 @@ describe ActsAsVotable::Votable do
256
292
  @votable_cache.count_votes_down.should == 50
257
293
  end
258
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
+
259
402
  end
260
403
 
261
404
  describe "sti models" do
data/spec/voter_spec.rb CHANGED
@@ -35,6 +35,7 @@ describe ActsAsVotable::Voter do
35
35
  it "should be voted on after a voter has voted" do
36
36
  @votable.vote :voter => @voter
37
37
  @voter.voted_on?(@votable).should be true
38
+ @voter.voted_for?(@votable).should be true
38
39
  end
39
40
 
40
41
  it "should not be voted on if a voter has not voted" do
@@ -53,6 +54,7 @@ describe ActsAsVotable::Voter do
53
54
 
54
55
  it "should be voted as true when a voter has voted true" do
55
56
  @votable.vote :voter => @voter
57
+ @voter.voted_as_when_voted_on(@votable).should be true
56
58
  @voter.voted_as_when_voted_for(@votable).should be true
57
59
  end
58
60
 
@@ -206,6 +208,8 @@ describe ActsAsVotable::Voter do
206
208
  @votable2.vote :voter => @voter2
207
209
  @voter.find_up_voted_items.should include @votable
208
210
  @voter.find_up_voted_items.size.should == 1
211
+ @voter.find_liked_items.should include @votable
212
+ @voter.find_liked_items.size.should == 1
209
213
  end
210
214
 
211
215
  it 'returns objects that a user has upvoted for, using scope' do
@@ -242,6 +246,8 @@ describe ActsAsVotable::Voter do
242
246
  @votable2.vote_down @voter2
243
247
  @voter.find_down_voted_items.should include @votable
244
248
  @voter.find_down_voted_items.size.should == 1
249
+ @voter.find_disliked_items.should include @votable
250
+ @voter.find_disliked_items.size.should == 1
245
251
  end
246
252
 
247
253
  it 'returns objects that a user has downvoted for, using scope' do