acts_as_votable 0.5.0 → 0.9.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.
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'sqlite3'
2
3
  require 'acts_as_votable'
3
4
 
5
+ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
6
+
4
7
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
5
8
 
6
9
  ActiveRecord::Schema.define(:version => 1) do
@@ -10,6 +13,7 @@ ActiveRecord::Schema.define(:version => 1) do
10
13
 
11
14
  t.boolean :vote_flag
12
15
  t.string :vote_scope
16
+ t.integer :vote_weight
13
17
 
14
18
  t.timestamps
15
19
  end
@@ -31,6 +35,10 @@ ActiveRecord::Schema.define(:version => 1) do
31
35
  t.string :name
32
36
  end
33
37
 
38
+ create_table :votable_voters do |t|
39
+ t.string :name
40
+ end
41
+
34
42
  create_table :sti_votables do |t|
35
43
  t.string :name
36
44
  t.string :type
@@ -51,6 +59,13 @@ ActiveRecord::Schema.define(:version => 1) do
51
59
  t.integer :cached_votes_score
52
60
  t.integer :cached_votes_up
53
61
  t.integer :cached_votes_down
62
+ t.integer :cached_weighted_score
63
+
64
+ t.integer :cached_scoped_test_votes_total
65
+ t.integer :cached_scoped_test_votes_score
66
+ t.integer :cached_scoped_test_votes_up
67
+ t.integer :cached_scoped_test_votes_down
68
+ t.integer :cached_scoped_weighted_score
54
69
  end
55
70
 
56
71
  end
@@ -69,6 +84,11 @@ class Votable < ActiveRecord::Base
69
84
  validates_presence_of :name
70
85
  end
71
86
 
87
+ class VotableVoter < ActiveRecord::Base
88
+ acts_as_votable
89
+ acts_as_voter
90
+ end
91
+
72
92
  class StiVotable < ActiveRecord::Base
73
93
  acts_as_votable
74
94
  end
data/spec/votable_spec.rb CHANGED
@@ -2,11 +2,6 @@ require 'acts_as_votable'
2
2
  require 'spec_helper'
3
3
 
4
4
  describe ActsAsVotable::Votable do
5
-
6
- before(:each) do
7
- clean_database
8
- end
9
-
10
5
  it "should not be votable" do
11
6
  NotVotable.should_not be_votable
12
7
  end
@@ -15,277 +10,11 @@ describe ActsAsVotable::Votable do
15
10
  Votable.should be_votable
16
11
  end
17
12
 
18
- describe "voting on a votable object" do
19
-
20
- before(:each) do
21
- clean_database
22
- @voter = Voter.new(:name => 'i can vote!')
23
- @voter.save
24
-
25
- @voter2 = Voter.new(:name => 'a new person')
26
- @voter2.save
27
-
28
- @votable = Votable.new(:name => 'a voting model')
29
- @votable.save
30
- end
31
-
32
- it "should return false when a vote with no voter is saved" do
33
- @votable.vote.should be false
34
- end
35
-
36
- it "should have one vote when saved" do
37
- @votable.vote :voter => @voter, :vote => 'yes'
38
- @votable.votes.size.should == 1
39
- end
40
-
41
- it "should have one vote when voted on twice by the same person" do
42
- @votable.vote :voter => @voter, :vote => 'yes'
43
- @votable.vote :voter => @voter, :vote => 'no'
44
- @votable.votes.size.should == 1
45
- end
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
-
64
- it "should be callable with vote_up" do
65
- @votable.vote_up @voter
66
- @votable.up_votes.first.voter.should == @voter
67
- end
68
-
69
- it "should be callable with vote_down" do
70
- @votable.vote_down @voter
71
- @votable.down_votes.first.voter.should == @voter
72
- end
73
-
74
- it "should have 2 votes when voted on once by two different people" do
75
- @votable.vote :voter => @voter
76
- @votable.vote :voter => @voter2
77
- @votable.votes.size.should == 2
78
- end
79
-
80
- it "should have one true vote" do
81
- @votable.vote :voter => @voter
82
- @votable.vote :voter => @voter2, :vote => 'dislike'
83
- @votable.up_votes.size.should == 1
84
- end
85
-
86
- it "should have 2 false votes" do
87
- @votable.vote :voter => @voter, :vote => 'no'
88
- @votable.vote :voter => @voter2, :vote => 'dislike'
89
- @votable.down_votes.size.should == 2
90
- end
91
-
92
- it "should have been voted on by voter2" do
93
- @votable.vote :voter => @voter2, :vote => true
94
- @votable.find_votes.first.voter.id.should be @voter2.id
95
- end
96
-
97
- it "should count the vote as registered if this is the voters first vote" do
98
- @votable.vote :voter => @voter
99
- @votable.vote_registered?.should be true
100
- end
101
-
102
- it "should not count the vote as being registered if that voter has already voted and the vote has not changed" do
103
- @votable.vote :voter => @voter, :vote => true
104
- @votable.vote :voter => @voter, :vote => 'yes'
105
- @votable.vote_registered?.should be false
106
- end
107
-
108
- it "should count the vote as registered if the voter has voted and the vote has changed" do
109
- @votable.vote :voter => @voter, :vote => true
110
- @votable.vote :voter => @voter, :vote => 'dislike'
111
- @votable.vote_registered?.should be true
112
- end
113
-
114
- it "should be voted on by voter" do
115
- @votable.vote :voter => @voter
116
- @votable.voted_on_by?(@voter).should be true
117
- end
118
-
119
- it "should unvote a positive vote" do
120
- @votable.vote :voter => @voter
121
- @votable.unvote :voter => @voter
122
- @votable.find_votes.count.should == 0
123
- end
124
-
125
- it "should set the votable to unregistered after unvoting" do
126
- @votable.vote :voter => @voter
127
- @votable.unvote :voter => @voter
128
- @votable.vote_registered?.should be false
129
- end
130
-
131
- it "should unvote a negative vote" do
132
- @votable.vote :voter => @voter, :vote => 'no'
133
- @votable.unvote :voter => @voter
134
- @votable.find_votes.count.should == 0
135
- end
136
-
137
- it "should unvote only the from a single voter" do
138
- @votable.vote :voter => @voter
139
- @votable.vote :voter => @voter2
140
- @votable.unvote :voter => @voter
141
- @votable.find_votes.count.should == 1
142
- end
143
-
144
- it "should be contained to instances" do
145
- votable2 = Votable.new(:name => '2nd votable')
146
- votable2.save
147
-
148
- @votable.vote :voter => @voter, :vote => false
149
- votable2.vote :voter => @voter, :vote => true
150
- votable2.vote :voter => @voter, :vote => true
151
-
152
- @votable.vote_registered?.should be true
153
- votable2.vote_registered?.should be false
154
- end
155
-
156
- describe "with cached votes" do
157
-
158
- before(:each) do
159
- clean_database
160
- @voter = Voter.new(:name => 'i can vote!')
161
- @voter.save
162
-
163
- @votable = Votable.new(:name => 'a voting model without a cache')
164
- @votable.save
165
-
166
- @votable_cache = VotableCache.new(:name => 'voting model with cache')
167
- @votable_cache.save
168
- end
169
-
170
- it "should not update cached votes if there are no columns" do
171
- @votable.vote :voter => @voter
172
- end
173
-
174
- it "should update cached total votes if there is a total column" do
175
- @votable_cache.cached_votes_total = 50
176
- @votable_cache.vote :voter => @voter
177
- @votable_cache.cached_votes_total.should == 1
178
- end
179
-
180
- it "should update cached total votes when a vote up is removed" do
181
- @votable_cache.vote :voter => @voter, :vote => 'true'
182
- @votable_cache.unvote :voter => @voter
183
- @votable_cache.cached_votes_total.should == 0
184
- end
185
-
186
- it "should update cached total votes when a vote down is removed" do
187
- @votable_cache.vote :voter => @voter, :vote => 'false'
188
- @votable_cache.unvote :voter => @voter
189
- @votable_cache.cached_votes_total.should == 0
190
- end
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
-
216
- it "should update cached up votes if there is an up vote column" do
217
- @votable_cache.cached_votes_up = 50
218
- @votable_cache.vote :voter => @voter
219
- @votable_cache.vote :voter => @voter
220
- @votable_cache.cached_votes_up.should == 1
221
- end
222
-
223
- it "should update cached down votes if there is a down vote column" do
224
- @votable_cache.cached_votes_down = 50
225
- @votable_cache.vote :voter => @voter, :vote => 'false'
226
- @votable_cache.cached_votes_down.should == 1
227
- end
228
-
229
- it "should update cached up votes when a vote up is removed" do
230
- @votable_cache.vote :voter => @voter, :vote => 'true'
231
- @votable_cache.unvote :voter => @voter
232
- @votable_cache.cached_votes_up.should == 0
233
- end
234
-
235
- it "should update cached down votes when a vote down is removed" do
236
- @votable_cache.vote :voter => @voter, :vote => 'false'
237
- @votable_cache.unvote :voter => @voter
238
- @votable_cache.cached_votes_down.should == 0
239
- end
240
-
241
- it "should select from cached total votes if there a total column" do
242
- @votable_cache.vote :voter => @voter
243
- @votable_cache.cached_votes_total = 50
244
- @votable_cache.count_votes_total.should == 50
245
- end
246
-
247
- it "should select from cached up votes if there is an up vote column" do
248
- @votable_cache.vote :voter => @voter
249
- @votable_cache.cached_votes_up = 50
250
- @votable_cache.count_votes_up.should == 50
251
- end
252
-
253
- it "should select from cached down votes if there is a down vote column" do
254
- @votable_cache.vote :voter => @voter, :vote => 'false'
255
- @votable_cache.cached_votes_down = 50
256
- @votable_cache.count_votes_down.should == 50
257
- end
258
-
259
- end
260
-
261
- describe "sti models" do
262
-
263
- before(:each) do
264
- clean_database
265
- @voter = Voter.create(:name => 'i can vote!')
266
- end
267
-
268
- it "should be able to vote on a votable child of a non votable sti model" do
269
- votable = VotableChildOfStiNotVotable.create(:name => 'sti child')
270
-
271
- votable.vote :voter => @voter, :vote => 'yes'
272
- votable.votes.size.should == 1
273
- end
274
-
275
- it "should not be able to vote on a parent non votable" do
276
- StiNotVotable.should_not be_votable
277
- end
278
-
279
- it "should be able to vote on a child when its parent is votable" do
280
- votable = ChildOfStiVotable.create(:name => 'sti child')
281
-
282
- votable.vote :voter => @voter, :vote => 'yes'
283
- votable.votes.size.should == 1
284
- end
285
-
286
- end
287
-
13
+ it_behaves_like "a votable_model" do
14
+ # TODO Replace with factories
15
+ let (:voter) { Voter.create(:name =>'i can vote!') }
16
+ let (:voter2) { Voter.create(:name => 'a new person') }
17
+ let (:votable) { Votable.create(:name =>'a voting model') }
18
+ let (:votable_cache) { VotableCache.create(:name => 'voting model with cache') }
288
19
  end
289
-
290
-
291
20
  end
@@ -0,0 +1,20 @@
1
+ require 'acts_as_votable'
2
+ require 'spec_helper'
3
+
4
+ describe VotableVoter do
5
+ it_behaves_like "a votable_model" do
6
+ # TODO Replace with factories
7
+ let (:voter) { VotableVoter.create(:name => 'i can vote!') }
8
+ let (:voter2) { VotableVoter.create(:name => 'a new person') }
9
+ let (:votable) { VotableVoter.create(:name => 'a voting model') }
10
+ let (:votable_cache) { VotableCache.create(:name => 'voting model with cache') }
11
+ end
12
+
13
+ it_behaves_like "a voter_model" do
14
+ # TODO Replace with factories
15
+ let (:voter) { VotableVoter.create(:name => 'i can vote!') }
16
+ let (:voter2) { VotableVoter.create(:name => 'a new person') }
17
+ let (:votable) { VotableVoter.create(:name => 'a voting model') }
18
+ let (:votable2) { VotableVoter.create(:name => 'a 2nd voting model') }
19
+ end
20
+ end
data/spec/voter_spec.rb CHANGED
@@ -3,10 +3,6 @@ require 'spec_helper'
3
3
 
4
4
  describe ActsAsVotable::Voter do
5
5
 
6
- before(:each) do
7
- clean_database
8
- end
9
-
10
6
  it "should not be a voter" do
11
7
  NotVotable.should_not be_votable
12
8
  end
@@ -15,290 +11,11 @@ describe ActsAsVotable::Voter do
15
11
  Votable.should be_votable
16
12
  end
17
13
 
18
- describe "voting by a voter" do
19
-
20
- before(:each) do
21
- clean_database
22
- @voter = Voter.new(:name => 'i can vote!')
23
- @voter.save
24
-
25
- @voter2 = Voter.new(:name => 'a new person')
26
- @voter2.save
27
-
28
- @votable = Votable.new(:name => 'a voting model')
29
- @votable.save
30
-
31
- @votable2 = Votable.new(:name => 'a 2nd voting model')
32
- @votable2.save
33
- end
34
-
35
- it "should be voted on after a voter has voted" do
36
- @votable.vote :voter => @voter
37
- @voter.voted_on?(@votable).should be true
38
- end
39
-
40
- it "should not be voted on if a voter has not voted" do
41
- @voter.voted_on?(@votable).should be false
42
- end
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
-
54
- it "should be voted as true when a voter has voted true" do
55
- @votable.vote :voter => @voter
56
- @voter.voted_as_when_voted_for(@votable).should be true
57
- end
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
-
64
- it "should be voted as false when a voter has voted false" do
65
- @votable.vote :voter => @voter, :vote => false
66
- @voter.voted_as_when_voted_for(@votable).should be false
67
- end
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
-
74
- it "should be voted as nil when a voter has never voted" do
75
- @voter.voted_as_when_voting_on(@votable).should be nil
76
- end
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
-
83
- it "should return true if voter has voted true" do
84
- @votable.vote :voter => @voter
85
- @voter.voted_up_on?(@votable).should be true
86
- end
87
-
88
- it "should return false if voter has not voted true" do
89
- @votable.vote :voter => @voter, :vote => false
90
- @voter.voted_up_on?(@votable).should be false
91
- end
92
-
93
- it "should return true if the voter has voted false" do
94
- @votable.vote :voter => @voter, :vote => false
95
- @voter.voted_down_on?(@votable).should be true
96
- end
97
-
98
- it "should return false if the voter has not voted false" do
99
- @votable.vote :voter => @voter, :vote => true
100
- @voter.voted_down_on?(@votable).should be false
101
- end
102
-
103
- it "should provide reserve functionality, voter can vote on votable" do
104
- @voter.vote :votable => @votable, :vote => 'bad'
105
- @voter.voted_as_when_voting_on(@votable).should be false
106
- end
107
-
108
- it "should allow the voter to vote up a model" do
109
- @voter.vote_up_for @votable
110
- @votable.up_votes.first.voter.should == @voter
111
- @votable.votes.up.first.voter.should == @voter
112
- end
113
-
114
- it "should allow the voter to vote down a model" do
115
- @voter.vote_down_for @votable
116
- @votable.down_votes.first.voter.should == @voter
117
- @votable.votes.down.first.voter.should == @voter
118
- end
119
-
120
- it "should allow the voter to unvote a model" do
121
- @voter.vote_up_for @votable
122
- @voter.unvote_for @votable
123
- @votable.find_votes.size.should == 0
124
- @votable.votes.count.should == 0
125
- end
126
-
127
- it "should get all of the voters votes" do
128
- @voter.vote_up_for @votable
129
- @voter.find_votes.size.should == 1
130
- @voter.votes.up.count.should == 1
131
- end
132
-
133
- it "should get all of the voters up votes" do
134
- @voter.vote_up_for @votable
135
- @voter.find_up_votes.size.should == 1
136
- @voter.votes.up.count.should == 1
137
- end
138
-
139
- it "should get all of the voters down votes" do
140
- @voter.vote_down_for @votable
141
- @voter.find_down_votes.size.should == 1
142
- @voter.votes.down.count.should == 1
143
- end
144
-
145
- it "should get all of the votes votes for a class" do
146
- @votable.vote :voter => @voter
147
- @votable2.vote :voter => @voter, :vote => false
148
- @voter.find_votes_for_class(Votable).size.should == 2
149
- @voter.votes.for_type(Votable).count.should == 2
150
- end
151
-
152
- it "should get all of the voters up votes for a class" do
153
- @votable.vote :voter => @voter
154
- @votable2.vote :voter => @voter, :vote => false
155
- @voter.find_up_votes_for_class(Votable).size.should == 1
156
- @voter.votes.up.for_type(Votable).count.should == 1
157
- end
158
-
159
- it "should get all of the voters down votes for a class" do
160
- @votable.vote :voter => @voter
161
- @votable2.vote :voter => @voter, :vote => false
162
- @voter.find_down_votes_for_class(Votable).size.should == 1
163
- @voter.votes.down.for_type(Votable).count.should == 1
164
- end
165
-
166
- it "should be contained to instances" do
167
- @voter.vote :votable => @votable, :vote => false
168
- @voter2.vote :votable => @votable
169
-
170
- @voter.voted_as_when_voting_on(@votable).should be false
171
- end
172
-
173
- describe '#find_voted_items' do
174
- it 'returns objects that a user has upvoted for' do
175
- @votable.vote :voter => @voter
176
- @votable2.vote :voter => @voter2
177
- @voter.find_voted_items.should include @votable
178
- @voter.find_voted_items.size.should == 1
179
- end
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
-
188
- it 'returns objects that a user has downvoted for' do
189
- @votable.vote_down @voter
190
- @votable2.vote_down @voter2
191
- @voter.find_voted_items.should include @votable
192
- @voter.find_voted_items.size.should == 1
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
201
- end
202
-
203
- describe '#find_up_voted_items' do
204
- it 'returns objects that a user has upvoted for' do
205
- @votable.vote :voter => @voter
206
- @votable2.vote :voter => @voter2
207
- @voter.find_up_voted_items.should include @votable
208
- @voter.find_up_voted_items.size.should == 1
209
- end
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
-
218
- it 'does not return objects that a user has downvoted for' do
219
- @votable.vote_down @voter
220
- @voter.find_up_voted_items.size.should == 0
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
227
- end
228
-
229
- describe '#find_down_voted_items' do
230
- it 'does not return objects that a user has upvoted for' do
231
- @votable.vote :voter => @voter
232
- @voter.find_down_voted_items.size.should == 0
233
- end
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
-
240
- it 'returns objects that a user has downvoted for' do
241
- @votable.vote_down @voter
242
- @votable2.vote_down @voter2
243
- @voter.find_down_voted_items.should include @votable
244
- @voter.find_down_voted_items.size.should == 1
245
- 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
255
-
256
- describe '#get_voted' do
257
- subject { @voter.get_voted(@votable.class) }
258
-
259
- it 'returns objects of a class that a voter has voted for' do
260
- @votable.vote :voter => @voter
261
- @votable2.vote_down @voter
262
- subject.should include @votable
263
- subject.should include @votable2
264
- subject.size.should == 2
265
- end
266
-
267
- it 'does not return objects of a class that a voter has voted for' do
268
- @votable.vote :voter => @voter2
269
- @votable2.vote :voter => @voter2
270
- subject.size.should == 0
271
- end
272
- end
273
-
274
- describe '#get_up_voted' do
275
- subject { @voter.get_up_voted(@votable.class) }
276
-
277
- it 'returns up voted items that a voter has voted for' do
278
- @votable.vote :voter => @voter
279
- subject.should include @votable
280
- subject.size.should == 1
281
- end
282
-
283
- it 'does not return down voted items a voter has voted for' do
284
- @votable.vote_down @voter
285
- subject.size.should == 0
286
- end
287
- end
288
-
289
- describe '#get_down_voted' do
290
- subject { @voter.get_down_voted(@votable.class) }
291
-
292
- it 'does not return up voted items that a voter has voted for' do
293
- @votable.vote :voter => @voter
294
- subject.size.should == 0
295
- end
296
-
297
- it 'returns down voted items a voter has voted for' do
298
- @votable.vote_down @voter
299
- subject.should include @votable
300
- subject.size.should == 1
301
- end
302
- end
14
+ it_behaves_like "a voter_model" do
15
+ # TODO Replace with factories
16
+ let (:voter) { Voter.create(:name => 'i can vote!') }
17
+ let (:voter2) { Voter.create(:name => 'a new person') }
18
+ let (:votable) { Votable.create(:name => 'a voting model') }
19
+ let (:votable2) { Votable.create(:name => 'a 2nd voting model') }
303
20
  end
304
21
  end