acts_as_votable 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,37 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acts_as_votable (0.4.0)
4
+ acts_as_votable (0.5.0)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- actionmailer (3.2.8)
11
- actionpack (= 3.2.8)
10
+ actionmailer (3.2.11)
11
+ actionpack (= 3.2.11)
12
12
  mail (~> 2.4.4)
13
- actionpack (3.2.8)
14
- activemodel (= 3.2.8)
15
- activesupport (= 3.2.8)
13
+ actionpack (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
16
  builder (~> 3.0.0)
17
17
  erubis (~> 2.7.0)
18
18
  journey (~> 1.0.4)
19
19
  rack (~> 1.4.0)
20
20
  rack-cache (~> 1.2)
21
21
  rack-test (~> 0.6.1)
22
- sprockets (~> 2.1.3)
23
- activemodel (3.2.8)
24
- activesupport (= 3.2.8)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.11)
24
+ activesupport (= 3.2.11)
25
25
  builder (~> 3.0.0)
26
- activerecord (3.2.8)
27
- activemodel (= 3.2.8)
28
- activesupport (= 3.2.8)
26
+ activerecord (3.2.11)
27
+ activemodel (= 3.2.11)
28
+ activesupport (= 3.2.11)
29
29
  arel (~> 3.0.2)
30
30
  tzinfo (~> 0.3.29)
31
- activeresource (3.2.8)
32
- activemodel (= 3.2.8)
33
- activesupport (= 3.2.8)
34
- activesupport (3.2.8)
31
+ activeresource (3.2.11)
32
+ activemodel (= 3.2.11)
33
+ activesupport (= 3.2.11)
34
+ activesupport (3.2.11)
35
35
  i18n (~> 0.6)
36
36
  multi_json (~> 1.0)
37
37
  arel (3.0.2)
@@ -41,37 +41,37 @@ GEM
41
41
  hike (1.2.1)
42
42
  i18n (0.6.1)
43
43
  journey (1.0.4)
44
- json (1.7.5)
44
+ json (1.7.6)
45
45
  mail (2.4.4)
46
46
  i18n (>= 0.4.0)
47
47
  mime-types (~> 1.16)
48
48
  treetop (~> 1.4.8)
49
49
  mime-types (1.19)
50
- multi_json (1.3.7)
50
+ multi_json (1.5.0)
51
51
  polyglot (0.3.3)
52
- rack (1.4.1)
52
+ rack (1.4.4)
53
53
  rack-cache (1.2)
54
54
  rack (>= 0.4)
55
55
  rack-ssl (1.3.2)
56
56
  rack
57
57
  rack-test (0.6.2)
58
58
  rack (>= 1.0)
59
- rails (3.2.8)
60
- actionmailer (= 3.2.8)
61
- actionpack (= 3.2.8)
62
- activerecord (= 3.2.8)
63
- activeresource (= 3.2.8)
64
- activesupport (= 3.2.8)
59
+ rails (3.2.11)
60
+ actionmailer (= 3.2.11)
61
+ actionpack (= 3.2.11)
62
+ activerecord (= 3.2.11)
63
+ activeresource (= 3.2.11)
64
+ activesupport (= 3.2.11)
65
65
  bundler (~> 1.0)
66
- railties (= 3.2.8)
67
- railties (3.2.8)
68
- actionpack (= 3.2.8)
69
- activesupport (= 3.2.8)
66
+ railties (= 3.2.11)
67
+ railties (3.2.11)
68
+ actionpack (= 3.2.11)
69
+ activesupport (= 3.2.11)
70
70
  rack-ssl (~> 1.3.2)
71
71
  rake (>= 0.8.7)
72
72
  rdoc (~> 3.4)
73
73
  thor (>= 0.14.6, < 2.0)
74
- rake (0.9.2.2)
74
+ rake (10.0.3)
75
75
  rdoc (3.12)
76
76
  json (~> 1.4)
77
77
  rspec (2.9.0)
@@ -82,8 +82,9 @@ GEM
82
82
  rspec-expectations (2.9.1)
83
83
  diff-lcs (~> 1.1.3)
84
84
  rspec-mocks (2.9.0)
85
- sprockets (2.1.3)
85
+ sprockets (2.2.2)
86
86
  hike (~> 1.2)
87
+ multi_json (~> 1.0)
87
88
  rack (~> 1.0)
88
89
  tilt (~> 1.1, != 1.3.0)
89
90
  sqlite3 (1.3.5)
@@ -92,7 +93,7 @@ GEM
92
93
  treetop (1.4.12)
93
94
  polyglot
94
95
  polyglot (>= 0.3.1)
95
- tzinfo (0.3.34)
96
+ tzinfo (0.3.35)
96
97
 
97
98
  PLATFORMS
98
99
  ruby
data/README.markdown CHANGED
@@ -4,17 +4,18 @@ Acts As Votable is a Ruby Gem specifically written for Rails/ActiveRecord models
4
4
  The main goals of this gem are:
5
5
 
6
6
  - Allow any model to be voted on, like/dislike, upvote/downvote, etc.
7
+ - Allow any model to be voted under arbitrary scopes.
7
8
  - Allow any model to vote. In other words, votes do not have to come from a user,
8
9
  they can come from any model (such as a Group or Team).
9
10
  - Provide an easy to write/read syntax.
10
11
 
11
12
  ## Installation
12
13
 
13
- ### Rails 3
14
+ ### Rails 3+
14
15
 
15
16
  Just add the following to your Gemfile.
16
17
 
17
- gem 'acts_as_votable', '~> 0.4.0'
18
+ gem 'acts_as_votable', '~> 0.5.0'
18
19
 
19
20
  And follow that up with a ``bundle install``.
20
21
 
@@ -105,13 +106,42 @@ voter/votable
105
106
  You can also 'unvote' a model to remove a previous vote.
106
107
 
107
108
  @post.liked_by @user1
108
- @post.unlike_by @user1
109
+ @post.unliked_by @user1
109
110
 
110
111
  @post.disliked_by @user1
111
112
  @post.undisliked_by @user1
112
113
 
113
114
  Unvoting works for both positive and negative votes.
114
115
 
116
+ ### Examples with scopes
117
+
118
+ You can add an scope to your vote
119
+
120
+ # positive votes
121
+ @post.liked_by @user1, :vote_scope => 'rank'
122
+ @post.vote :voter => @user3, :vote_scope => 'rank'
123
+ @post.vote :voter => @user5, :vote => 'like', :vote_scope => 'rank'
124
+
125
+ # negative votes
126
+ @post.downvote_from @user2, :vote_scope => 'rank'
127
+ @post.vote :voter => @user2, :vote => 'bad', :vote_scope => 'rank'
128
+
129
+ # tally them up!
130
+ @post.find_votes(:vote_scope => 'rank').size # => 5
131
+ @post.likes(:vote_scope => 'rank').size # => 3
132
+ @post.upvotes(:vote_scope => 'rank').size # => 3
133
+ @post.dislikes(:vote_scope => 'rank').size # => 2
134
+ @post.downvotes(:vote_scope => 'rank').size # => 2
135
+
136
+ # votable model can be voted under different scopes
137
+ # by the same user
138
+ @post.vote :voter => @user1, :vote_scope => 'week'
139
+ @post.vote :voter => @user1, :vote_scope => 'month'
140
+
141
+ @post.votes.size # => 2
142
+ @post.find_votes(:vote_scope => 'week').size # => 1
143
+ @post.find_votes(:vote_scope => 'month').size # => 1
144
+
115
145
  ### The Voter
116
146
 
117
147
  You can have your voters ``acts_as_voter`` to provide some reserve functionality.
@@ -156,6 +186,8 @@ You can also check whether the voter has voted up or down.
156
186
  @user.voted_up_on? @comment3 # => false
157
187
  @user.voted_down_on? @comment3 # => false
158
188
 
189
+ Aliases for methods ``voted_up_on?`` and ``voted_down_on?`` are: ``voted_up_for?``, ``voted_down_for?``, ``liked?`` and ``disliked?``.
190
+
159
191
  Also, you can obtain a list of all the objects a user has voted for.
160
192
  This returns the actual objects instead of instances of the Vote model.
161
193
  All objects are eager loaded
@@ -213,15 +245,18 @@ to speed up @post we would use the following migration:
213
245
  class AddCachedVotesToPosts < ActiveRecord::Migration
214
246
  def self.up
215
247
  add_column :posts, :cached_votes_total, :integer, :default => 0
248
+ add_column :posts, :cached_votes_score, :integer, :default => 0
216
249
  add_column :posts, :cached_votes_up, :integer, :default => 0
217
250
  add_column :posts, :cached_votes_down, :integer, :default => 0
218
251
  add_index :posts, :cached_votes_total
252
+ add_index :posts, :cached_votes_score
219
253
  add_index :posts, :cached_votes_up
220
254
  add_index :posts, :cached_votes_down
221
255
  end
222
256
 
223
257
  def self.down
224
258
  remove_column :posts, :cached_votes_total
259
+ remove_column :posts, :cached_votes_score
225
260
  remove_column :posts, :cached_votes_up
226
261
  remove_column :posts, :cached_votes_down
227
262
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsVotable
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -68,6 +68,7 @@ module ActsAsVotable
68
68
 
69
69
  options = {
70
70
  :vote => true,
71
+ :vote_scope => nil
71
72
  }.merge(args)
72
73
 
73
74
  self.vote_registered = false
@@ -79,6 +80,7 @@ module ActsAsVotable
79
80
  # find the vote
80
81
  _votes_ = find_votes({
81
82
  :voter_id => options[:voter].id,
83
+ :vote_scope => options[:vote_scope],
82
84
  :voter_type => options[:voter].class.name
83
85
  })
84
86
 
@@ -86,7 +88,8 @@ module ActsAsVotable
86
88
  # this voter has never voted
87
89
  vote = ActsAsVotable::Vote.new(
88
90
  :votable => self,
89
- :voter => options[:voter]
91
+ :voter => options[:voter],
92
+ :vote_scope => options[:vote_scope]
90
93
  )
91
94
  else
92
95
  # this voter is potentially changing his vote
@@ -110,7 +113,7 @@ module ActsAsVotable
110
113
 
111
114
  def unvote args = {}
112
115
  return false if args[:voter].nil?
113
- _votes_ = find_votes(:voter_id => args[:voter].id, :voter_type => args[:voter].class.name)
116
+ _votes_ = find_votes(:voter_id => args[:voter].id, :vote_scope => args[:vote_scope], :voter_type => args[:voter].class.name)
114
117
 
115
118
  return true if _votes_.size == 0
116
119
  _votes_.each(&:destroy)
@@ -119,12 +122,12 @@ module ActsAsVotable
119
122
  return true
120
123
  end
121
124
 
122
- def vote_up voter
123
- self.vote :voter => voter, :vote => true
125
+ def vote_up voter, options={}
126
+ self.vote :voter => voter, :vote => true, :vote_scope => options[:vote_scope]
124
127
  end
125
128
 
126
- def vote_down voter
127
- self.vote :voter => voter, :vote => false
129
+ def vote_down voter, options={}
130
+ self.vote :voter => voter, :vote => false, :vote_scope => options[:vote_scope]
128
131
  end
129
132
 
130
133
  # caching
@@ -144,6 +147,13 @@ module ActsAsVotable
144
147
  updates[:cached_votes_down] = count_votes_down(true)
145
148
  end
146
149
 
150
+ if self.respond_to?(:cached_votes_score=)
151
+ updates[:cached_votes_score] = (
152
+ (updates[:cached_votes_up] || count_votes_up(true)) -
153
+ (updates[:cached_votes_down] || count_votes_down(true))
154
+ )
155
+ end
156
+
147
157
  self.update_attributes(updates, :without_protection => true) if updates.size > 0
148
158
 
149
159
  end
@@ -154,12 +164,12 @@ module ActsAsVotable
154
164
  votes.where(extra_conditions)
155
165
  end
156
166
 
157
- def up_votes
158
- find_votes(:vote_flag => true)
167
+ def up_votes options={}
168
+ find_votes(:vote_flag => true, :vote_scope => options[:vote_scope])
159
169
  end
160
170
 
161
- def down_votes
162
- find_votes(:vote_flag => false)
171
+ def down_votes options={}
172
+ find_votes(:vote_flag => false, :vote_scope => options[:vote_scope])
163
173
  end
164
174
 
165
175
 
@@ -8,7 +8,7 @@ module ActsAsVotable
8
8
  attr_accessible :votable_id, :votable_type,
9
9
  :voter_id, :voter_type,
10
10
  :votable, :voter,
11
- :vote_flag
11
+ :vote_flag, :vote_scope
12
12
 
13
13
  belongs_to :votable, :polymorphic => true
14
14
  belongs_to :voter, :polymorphic => true
@@ -7,7 +7,9 @@ module ActsAsVotable
7
7
  aliases = {
8
8
  :vote_up_for => [:likes, :upvotes, :up_votes],
9
9
  :vote_down_for => [:dislikes, :downvotes, :down_votes],
10
- :unvote_for => [:unlike, :undislike]
10
+ :unvote_for => [:unlike, :undislike],
11
+ :voted_up_on? => [:voted_up_for?, :liked?],
12
+ :voted_down_on? => [:voted_down_for?, :disliked?]
11
13
  }
12
14
 
13
15
  base.class_eval do
@@ -34,12 +36,12 @@ module ActsAsVotable
34
36
  args[:votable].vote args.merge({:voter => self})
35
37
  end
36
38
 
37
- def vote_up_for model=nil
38
- vote :votable => model, :vote => true
39
+ def vote_up_for model=nil, args={}
40
+ vote :votable => model, :vote_scope => args[:vote_scope], :vote => true
39
41
  end
40
42
 
41
- def vote_down_for model
42
- vote :votable => model, :vote => false
43
+ def vote_down_for model=nil, args={}
44
+ vote :votable => model, :vote_scope => args[:vote_scope], :vote => false
43
45
  end
44
46
 
45
47
  def unvote_for model
@@ -47,26 +49,28 @@ module ActsAsVotable
47
49
  end
48
50
 
49
51
  # results
50
- def voted_on? votable
51
- votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name)
52
+ def voted_on? votable, args={}
53
+ votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name,
54
+ :vote_scope => args[:vote_scope])
52
55
  votes.size > 0
53
56
  end
54
- alias :voted_for? :voted_on?
55
57
 
56
- def voted_up_on? votable
57
- votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name, :vote_flag => true)
58
+ def voted_up_on? votable, args={}
59
+ votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name,
60
+ :vote_scope => args[:vote_scope], :vote_flag => true)
58
61
  votes.size > 0
59
62
  end
60
- alias :voted_up_for? :voted_up_on?
61
63
 
62
- def voted_down_on? votable
63
- votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name, :vote_flag => false)
64
+ def voted_down_on? votable, args={}
65
+ votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name,
66
+ :vote_scope => args[:vote_scope], :vote_flag => false)
64
67
  votes.size > 0
65
68
  end
66
69
  alias :voted_down_for? :voted_down_on?
67
70
 
68
- def voted_as_when_voting_on votable
69
- votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name)
71
+ 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])
70
74
  return nil if votes.size == 0
71
75
  return votes.first.vote_flag
72
76
  end
@@ -76,24 +80,24 @@ module ActsAsVotable
76
80
  votes.where(extra_conditions)
77
81
  end
78
82
 
79
- def find_up_votes
80
- find_votes :vote_flag => true
83
+ def find_up_votes args={}
84
+ find_votes :vote_flag => true, :vote_scope => args[:vote_scope]
81
85
  end
82
86
 
83
- def find_down_votes
84
- find_votes :vote_flag => false
87
+ def find_down_votes args={}
88
+ find_votes :vote_flag => false, :vote_scope => args[:vote_scope]
85
89
  end
86
90
 
87
91
  def find_votes_for_class klass, extra_conditions = {}
88
92
  find_votes extra_conditions.merge({:votable_type => klass.name})
89
93
  end
90
94
 
91
- def find_up_votes_for_class klass
92
- find_votes_for_class klass, :vote_flag => true
95
+ def find_up_votes_for_class klass, args={}
96
+ find_votes_for_class klass, :vote_flag => true, :vote_scope => args[:vote_scope]
93
97
  end
94
98
 
95
- def find_down_votes_for_class klass
96
- find_votes_for_class klass, :vote_flag => false
99
+ def find_down_votes_for_class klass, args={}
100
+ find_votes_for_class klass, :vote_flag => false, :vote_scope => args[:vote_scope]
97
101
  end
98
102
 
99
103
  # Including polymporphic relations for eager loading
@@ -6,15 +6,18 @@ class ActsAsVotableMigration < ActiveRecord::Migration
6
6
  t.references :voter, :polymorphic => true
7
7
 
8
8
  t.boolean :vote_flag
9
+ t.string :vote_scope
9
10
 
10
11
  t.timestamps
11
12
  end
12
13
 
13
14
  add_index :votes, [:votable_id, :votable_type]
14
15
  add_index :votes, [:voter_id, :voter_type]
16
+ add_index :votes, [:voter_id, :voter_type, :vote_scope]
17
+ add_index :votes, [:votable_id, :votable_type, :vote_scope]
15
18
  end
16
19
 
17
20
  def self.down
18
21
  drop_table :votes
19
22
  end
20
- end
23
+ end
data/spec/spec_helper.rb CHANGED
@@ -9,12 +9,15 @@ ActiveRecord::Schema.define(:version => 1) do
9
9
  t.references :voter, :polymorphic => true
10
10
 
11
11
  t.boolean :vote_flag
12
+ t.string :vote_scope
12
13
 
13
14
  t.timestamps
14
15
  end
15
16
 
16
17
  add_index :votes, [:votable_id, :votable_type]
17
18
  add_index :votes, [:voter_id, :voter_type]
19
+ add_index :votes, [:voter_id, :voter_type, :vote_scope]
20
+ add_index :votes, [:votable_id, :votable_type, :vote_scope]
18
21
 
19
22
  create_table :voters do |t|
20
23
  t.string :name
@@ -45,6 +48,7 @@ ActiveRecord::Schema.define(:version => 1) do
45
48
  create_table :votable_caches do |t|
46
49
  t.string :name
47
50
  t.integer :cached_votes_total
51
+ t.integer :cached_votes_score
48
52
  t.integer :cached_votes_up
49
53
  t.integer :cached_votes_down
50
54
  end
data/spec/votable_spec.rb CHANGED
@@ -44,6 +44,23 @@ describe ActsAsVotable::Votable do
44
44
  @votable.votes.size.should == 1
45
45
  end
46
46
 
47
+ it "should have one scoped vote when voting under an scope" do
48
+ @votable.vote :voter => @voter, :vote => 'yes', :vote_scope => 'rank'
49
+ @votable.find_votes(:vote_scope => 'rank').size.should == 1
50
+ end
51
+
52
+ it "should have one vote when voted on twice using scope by the same person" do
53
+ @votable.vote :voter => @voter, :vote => 'yes', :vote_scope => 'rank'
54
+ @votable.vote :voter => @voter, :vote => 'no', :vote_scope => 'rank'
55
+ @votable.find_votes(:vote_scope => 'rank').size.should == 1
56
+ end
57
+
58
+ it "should have two votes when voting on two different scopes by the same person" do
59
+ @votable.vote :voter => @voter, :vote => 'yes', :vote_scope => 'weekly_rank'
60
+ @votable.vote :voter => @voter, :vote => 'no', :vote_scope => 'monthly_rank'
61
+ @votable.votes.size.should == 2
62
+ end
63
+
47
64
  it "should be callable with vote_up" do
48
65
  @votable.vote_up @voter
49
66
  @votable.up_votes.first.voter.should == @voter
@@ -172,6 +189,30 @@ describe ActsAsVotable::Votable do
172
189
  @votable_cache.cached_votes_total.should == 0
173
190
  end
174
191
 
192
+ it "should update cached score votes if there is a score column" do
193
+ @votable_cache.cached_votes_score = 50
194
+ @votable_cache.vote :voter => @voter
195
+ @votable_cache.cached_votes_score.should == 1
196
+ @votable_cache.vote :voter => @voter2, :vote => 'false'
197
+ @votable_cache.cached_votes_score.should == 0
198
+ @votable_cache.vote :voter => @voter, :vote => 'false'
199
+ @votable_cache.cached_votes_score.should == -2
200
+ end
201
+
202
+ it "should update cached score votes when a vote up is removed" do
203
+ @votable_cache.vote :voter => @voter, :vote => 'true'
204
+ @votable_cache.cached_votes_score.should == 1
205
+ @votable_cache.unvote :voter => @voter
206
+ @votable_cache.cached_votes_score.should == 0
207
+ end
208
+
209
+ it "should update cached score votes when a vote down is removed" do
210
+ @votable_cache.vote :voter => @voter, :vote => 'false'
211
+ @votable_cache.cached_votes_score.should == -1
212
+ @votable_cache.unvote :voter => @voter
213
+ @votable_cache.cached_votes_score.should == 0
214
+ end
215
+
175
216
  it "should update cached up votes if there is an up vote column" do
176
217
  @votable_cache.cached_votes_up = 50
177
218
  @votable_cache.vote :voter => @voter
data/spec/voter_spec.rb CHANGED
@@ -41,20 +41,45 @@ describe ActsAsVotable::Voter do
41
41
  @voter.voted_on?(@votable).should be false
42
42
  end
43
43
 
44
+ it "should be voted on after a voter has voted under scope" do
45
+ @votable.vote :voter => @voter, :vote_scope => 'rank'
46
+ @voter.voted_on?(@votable, :vote_scope => 'rank').should be true
47
+ end
48
+
49
+ it "should not be voted on other scope after a voter has voted under one scope" do
50
+ @votable.vote :voter => @voter, :vote_scope => 'rank'
51
+ @voter.voted_on?(@votable).should be false
52
+ end
53
+
44
54
  it "should be voted as true when a voter has voted true" do
45
55
  @votable.vote :voter => @voter
46
56
  @voter.voted_as_when_voted_for(@votable).should be true
47
57
  end
48
58
 
59
+ it "should be voted as true when a voter has voted true under scope" do
60
+ @votable.vote :voter => @voter, :vote_scope => 'rank'
61
+ @voter.voted_as_when_voted_for(@votable, :vote_scope => 'rank').should be true
62
+ end
63
+
49
64
  it "should be voted as false when a voter has voted false" do
50
65
  @votable.vote :voter => @voter, :vote => false
51
66
  @voter.voted_as_when_voted_for(@votable).should be false
52
67
  end
53
68
 
69
+ it "should be voted as false when a voter has voted false under scope" do
70
+ @votable.vote :voter => @voter, :vote => false, :vote_scope => 'rank'
71
+ @voter.voted_as_when_voted_for(@votable, :vote_scope => 'rank').should be false
72
+ end
73
+
54
74
  it "should be voted as nil when a voter has never voted" do
55
75
  @voter.voted_as_when_voting_on(@votable).should be nil
56
76
  end
57
77
 
78
+ it "should be voted as nil when a voter has never voted under the scope" do
79
+ @votable.vote :voter => @voter, :vote => false, :vote_scope => 'rank'
80
+ @voter.voted_as_when_voting_on(@votable).should be nil
81
+ end
82
+
58
83
  it "should return true if voter has voted true" do
59
84
  @votable.vote :voter => @voter
60
85
  @voter.voted_up_on?(@votable).should be true
@@ -153,12 +178,26 @@ describe ActsAsVotable::Voter do
153
178
  @voter.find_voted_items.size.should == 1
154
179
  end
155
180
 
181
+ it 'returns objects that a user has upvoted for, using scope' do
182
+ @votable.vote :voter => @voter, :vote_scope => 'rank'
183
+ @votable2.vote :voter => @voter2, :vote_scope => 'rank'
184
+ @voter.find_voted_items(:vote_scope => 'rank').should include @votable
185
+ @voter.find_voted_items(:vote_scope => 'rank').size.should == 1
186
+ end
187
+
156
188
  it 'returns objects that a user has downvoted for' do
157
189
  @votable.vote_down @voter
158
190
  @votable2.vote_down @voter2
159
191
  @voter.find_voted_items.should include @votable
160
192
  @voter.find_voted_items.size.should == 1
161
193
  end
194
+
195
+ it 'returns objects that a user has downvoted for, using scope' do
196
+ @votable.vote_down @voter, :vote_scope => 'rank'
197
+ @votable2.vote_down @voter2, :vote_scope => 'rank'
198
+ @voter.find_voted_items(:vote_scope => 'rank').should include @votable
199
+ @voter.find_voted_items(:vote_scope => 'rank').size.should == 1
200
+ end
162
201
  end
163
202
 
164
203
  describe '#find_up_voted_items' do
@@ -169,10 +208,22 @@ describe ActsAsVotable::Voter do
169
208
  @voter.find_up_voted_items.size.should == 1
170
209
  end
171
210
 
211
+ it 'returns objects that a user has upvoted for, using scope' do
212
+ @votable.vote :voter => @voter, :vote_scope => 'rank'
213
+ @votable2.vote :voter => @voter2, :vote_scope => 'rank'
214
+ @voter.find_up_voted_items(:vote_scope => 'rank').should include @votable
215
+ @voter.find_up_voted_items(:vote_scope => 'rank').size.should == 1
216
+ end
217
+
172
218
  it 'does not return objects that a user has downvoted for' do
173
219
  @votable.vote_down @voter
174
220
  @voter.find_up_voted_items.size.should == 0
175
221
  end
222
+
223
+ it 'does not return objects that a user has downvoted for, using scope' do
224
+ @votable.vote_down @voter, :vote_scope => 'rank'
225
+ @voter.find_up_voted_items(:vote_scope => 'rank').size.should == 0
226
+ end
176
227
  end
177
228
 
178
229
  describe '#find_down_voted_items' do
@@ -181,13 +232,26 @@ describe ActsAsVotable::Voter do
181
232
  @voter.find_down_voted_items.size.should == 0
182
233
  end
183
234
 
235
+ it 'does not return objects that a user has upvoted for, using scope' do
236
+ @votable.vote :voter => @voter, :vote_scope => 'rank'
237
+ @voter.find_down_voted_items(:vote_scope => 'rank').size.should == 0
238
+ end
239
+
184
240
  it 'returns objects that a user has downvoted for' do
185
241
  @votable.vote_down @voter
186
242
  @votable2.vote_down @voter2
187
243
  @voter.find_down_voted_items.should include @votable
188
244
  @voter.find_down_voted_items.size.should == 1
189
245
  end
190
- end
246
+
247
+ it 'returns objects that a user has downvoted for, using scope' do
248
+ @votable.vote_down @voter, :vote_scope => 'rank'
249
+ @votable2.vote_down @voter2, :vote_scope => 'rank'
250
+ @voter.find_down_voted_items(:vote_scope => 'rank').should include @votable
251
+ @voter.find_down_voted_items(:vote_scope => 'rank').size.should == 1
252
+ end
253
+
254
+ end
191
255
 
192
256
  describe '#get_voted' do
193
257
  subject { @voter.get_voted(@votable.class) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_votable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-04 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  segments:
102
102
  - 0
103
- hash: -2774267182574358565
103
+ hash: 3405338433430010114
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: -2774267182574358565
112
+ hash: 3405338433430010114
113
113
  requirements: []
114
114
  rubyforge_project: acts_as_votable
115
115
  rubygems_version: 1.8.24