acts_as_votable 0.8.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.
@@ -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
@@ -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,296 +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
- @voter.voted_for?(@votable).should be true
39
- end
40
-
41
- it "should not be voted on if a voter has not voted" do
42
- @voter.voted_on?(@votable).should be false
43
- end
44
-
45
- it "should be voted on after a voter has voted under scope" do
46
- @votable.vote :voter => @voter, :vote_scope => 'rank'
47
- @voter.voted_on?(@votable, :vote_scope => 'rank').should be true
48
- end
49
-
50
- it "should not be voted on other scope after a voter has voted under one scope" do
51
- @votable.vote :voter => @voter, :vote_scope => 'rank'
52
- @voter.voted_on?(@votable).should be false
53
- end
54
-
55
- it "should be voted as true when a voter has voted true" do
56
- @votable.vote :voter => @voter
57
- @voter.voted_as_when_voted_on(@votable).should be true
58
- @voter.voted_as_when_voted_for(@votable).should be true
59
- end
60
-
61
- it "should be voted as true when a voter has voted true under scope" do
62
- @votable.vote :voter => @voter, :vote_scope => 'rank'
63
- @voter.voted_as_when_voted_for(@votable, :vote_scope => 'rank').should be true
64
- end
65
-
66
- it "should be voted as false when a voter has voted false" do
67
- @votable.vote :voter => @voter, :vote => false
68
- @voter.voted_as_when_voted_for(@votable).should be false
69
- end
70
-
71
- it "should be voted as false when a voter has voted false under scope" do
72
- @votable.vote :voter => @voter, :vote => false, :vote_scope => 'rank'
73
- @voter.voted_as_when_voted_for(@votable, :vote_scope => 'rank').should be false
74
- end
75
-
76
- it "should be voted as nil when a voter has never voted" do
77
- @voter.voted_as_when_voting_on(@votable).should be nil
78
- end
79
-
80
- it "should be voted as nil when a voter has never voted under the scope" do
81
- @votable.vote :voter => @voter, :vote => false, :vote_scope => 'rank'
82
- @voter.voted_as_when_voting_on(@votable).should be nil
83
- end
84
-
85
- it "should return true if voter has voted true" do
86
- @votable.vote :voter => @voter
87
- @voter.voted_up_on?(@votable).should be true
88
- end
89
-
90
- it "should return false if voter has not voted true" do
91
- @votable.vote :voter => @voter, :vote => false
92
- @voter.voted_up_on?(@votable).should be false
93
- end
94
-
95
- it "should return true if the voter has voted false" do
96
- @votable.vote :voter => @voter, :vote => false
97
- @voter.voted_down_on?(@votable).should be true
98
- end
99
-
100
- it "should return false if the voter has not voted false" do
101
- @votable.vote :voter => @voter, :vote => true
102
- @voter.voted_down_on?(@votable).should be false
103
- end
104
-
105
- it "should provide reserve functionality, voter can vote on votable" do
106
- @voter.vote :votable => @votable, :vote => 'bad'
107
- @voter.voted_as_when_voting_on(@votable).should be false
108
- end
109
-
110
- it "should allow the voter to vote up a model" do
111
- @voter.vote_up_for @votable
112
- @votable.up_votes.first.voter.should == @voter
113
- @votable.votes.up.first.voter.should == @voter
114
- end
115
-
116
- it "should allow the voter to vote down a model" do
117
- @voter.vote_down_for @votable
118
- @votable.down_votes.first.voter.should == @voter
119
- @votable.votes.down.first.voter.should == @voter
120
- end
121
-
122
- it "should allow the voter to unvote a model" do
123
- @voter.vote_up_for @votable
124
- @voter.unvote_for @votable
125
- @votable.find_votes.size.should == 0
126
- @votable.votes.count.should == 0
127
- end
128
-
129
- it "should get all of the voters votes" do
130
- @voter.vote_up_for @votable
131
- @voter.find_votes.size.should == 1
132
- @voter.votes.up.count.should == 1
133
- end
134
-
135
- it "should get all of the voters up votes" do
136
- @voter.vote_up_for @votable
137
- @voter.find_up_votes.size.should == 1
138
- @voter.votes.up.count.should == 1
139
- end
140
-
141
- it "should get all of the voters down votes" do
142
- @voter.vote_down_for @votable
143
- @voter.find_down_votes.size.should == 1
144
- @voter.votes.down.count.should == 1
145
- end
146
-
147
- it "should get all of the votes votes for a class" do
148
- @votable.vote :voter => @voter
149
- @votable2.vote :voter => @voter, :vote => false
150
- @voter.find_votes_for_class(Votable).size.should == 2
151
- @voter.votes.for_type(Votable).count.should == 2
152
- end
153
-
154
- it "should get all of the voters up votes for a class" do
155
- @votable.vote :voter => @voter
156
- @votable2.vote :voter => @voter, :vote => false
157
- @voter.find_up_votes_for_class(Votable).size.should == 1
158
- @voter.votes.up.for_type(Votable).count.should == 1
159
- end
160
-
161
- it "should get all of the voters down votes for a class" do
162
- @votable.vote :voter => @voter
163
- @votable2.vote :voter => @voter, :vote => false
164
- @voter.find_down_votes_for_class(Votable).size.should == 1
165
- @voter.votes.down.for_type(Votable).count.should == 1
166
- end
167
-
168
- it "should be contained to instances" do
169
- @voter.vote :votable => @votable, :vote => false
170
- @voter2.vote :votable => @votable
171
-
172
- @voter.voted_as_when_voting_on(@votable).should be false
173
- end
174
-
175
- describe '#find_voted_items' do
176
- it 'returns objects that a user has upvoted for' do
177
- @votable.vote :voter => @voter
178
- @votable2.vote :voter => @voter2
179
- @voter.find_voted_items.should include @votable
180
- @voter.find_voted_items.size.should == 1
181
- end
182
-
183
- it 'returns objects that a user has upvoted for, using scope' do
184
- @votable.vote :voter => @voter, :vote_scope => 'rank'
185
- @votable2.vote :voter => @voter2, :vote_scope => 'rank'
186
- @voter.find_voted_items(:vote_scope => 'rank').should include @votable
187
- @voter.find_voted_items(:vote_scope => 'rank').size.should == 1
188
- end
189
-
190
- it 'returns objects that a user has downvoted for' do
191
- @votable.vote_down @voter
192
- @votable2.vote_down @voter2
193
- @voter.find_voted_items.should include @votable
194
- @voter.find_voted_items.size.should == 1
195
- end
196
-
197
- it 'returns objects that a user has downvoted for, using scope' do
198
- @votable.vote_down @voter, :vote_scope => 'rank'
199
- @votable2.vote_down @voter2, :vote_scope => 'rank'
200
- @voter.find_voted_items(:vote_scope => 'rank').should include @votable
201
- @voter.find_voted_items(:vote_scope => 'rank').size.should == 1
202
- end
203
- end
204
-
205
- describe '#find_up_voted_items' do
206
- it 'returns objects that a user has upvoted for' do
207
- @votable.vote :voter => @voter
208
- @votable2.vote :voter => @voter2
209
- @voter.find_up_voted_items.should include @votable
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
213
- end
214
-
215
- it 'returns objects that a user has upvoted for, using scope' do
216
- @votable.vote :voter => @voter, :vote_scope => 'rank'
217
- @votable2.vote :voter => @voter2, :vote_scope => 'rank'
218
- @voter.find_up_voted_items(:vote_scope => 'rank').should include @votable
219
- @voter.find_up_voted_items(:vote_scope => 'rank').size.should == 1
220
- end
221
-
222
- it 'does not return objects that a user has downvoted for' do
223
- @votable.vote_down @voter
224
- @voter.find_up_voted_items.size.should == 0
225
- end
226
-
227
- it 'does not return objects that a user has downvoted for, using scope' do
228
- @votable.vote_down @voter, :vote_scope => 'rank'
229
- @voter.find_up_voted_items(:vote_scope => 'rank').size.should == 0
230
- end
231
- end
232
-
233
- describe '#find_down_voted_items' do
234
- it 'does not return objects that a user has upvoted for' do
235
- @votable.vote :voter => @voter
236
- @voter.find_down_voted_items.size.should == 0
237
- end
238
-
239
- it 'does not return objects that a user has upvoted for, using scope' do
240
- @votable.vote :voter => @voter, :vote_scope => 'rank'
241
- @voter.find_down_voted_items(:vote_scope => 'rank').size.should == 0
242
- end
243
-
244
- it 'returns objects that a user has downvoted for' do
245
- @votable.vote_down @voter
246
- @votable2.vote_down @voter2
247
- @voter.find_down_voted_items.should include @votable
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
251
- end
252
-
253
- it 'returns objects that a user has downvoted for, using scope' do
254
- @votable.vote_down @voter, :vote_scope => 'rank'
255
- @votable2.vote_down @voter2, :vote_scope => 'rank'
256
- @voter.find_down_voted_items(:vote_scope => 'rank').should include @votable
257
- @voter.find_down_voted_items(:vote_scope => 'rank').size.should == 1
258
- end
259
-
260
- end
261
-
262
- describe '#get_voted' do
263
- subject { @voter.get_voted(@votable.class) }
264
-
265
- it 'returns objects of a class that a voter has voted for' do
266
- @votable.vote :voter => @voter
267
- @votable2.vote_down @voter
268
- subject.should include @votable
269
- subject.should include @votable2
270
- subject.size.should == 2
271
- end
272
-
273
- it 'does not return objects of a class that a voter has voted for' do
274
- @votable.vote :voter => @voter2
275
- @votable2.vote :voter => @voter2
276
- subject.size.should == 0
277
- end
278
- end
279
-
280
- describe '#get_up_voted' do
281
- subject { @voter.get_up_voted(@votable.class) }
282
-
283
- it 'returns up voted items that a voter has voted for' do
284
- @votable.vote :voter => @voter
285
- subject.should include @votable
286
- subject.size.should == 1
287
- end
288
-
289
- it 'does not return down voted items a voter has voted for' do
290
- @votable.vote_down @voter
291
- subject.size.should == 0
292
- end
293
- end
294
-
295
- describe '#get_down_voted' do
296
- subject { @voter.get_down_voted(@votable.class) }
297
-
298
- it 'does not return up voted items that a voter has voted for' do
299
- @votable.vote :voter => @voter
300
- subject.size.should == 0
301
- end
302
-
303
- it 'returns down voted items a voter has voted for' do
304
- @votable.vote_down @voter
305
- subject.should include @votable
306
- subject.size.should == 1
307
- end
308
- 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') }
309
20
  end
310
21
  end
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.8.0
4
+ version: 0.9.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-11 00:00:00.000000000 Z
11
+ date: 2014-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -62,8 +62,11 @@ files:
62
62
  - lib/acts_as_votable/voter.rb
63
63
  - lib/generators/acts_as_votable/migration/migration_generator.rb
64
64
  - lib/generators/acts_as_votable/migration/templates/active_record/migration.rb
65
+ - spec/shared_example/votable_model_spec.rb
66
+ - spec/shared_example/voter_model_spec.rb
65
67
  - spec/spec_helper.rb
66
68
  - spec/votable_spec.rb
69
+ - spec/votable_voter_spec.rb
67
70
  - spec/voter_spec.rb
68
71
  - spec/words_spec.rb
69
72
  homepage: http://rubygems.org/gems/acts_as_votable
@@ -89,4 +92,11 @@ rubygems_version: 2.0.3
89
92
  signing_key:
90
93
  specification_version: 4
91
94
  summary: Rails gem to allowing records to be votable
92
- test_files: []
95
+ test_files:
96
+ - spec/shared_example/votable_model_spec.rb
97
+ - spec/shared_example/voter_model_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/votable_spec.rb
100
+ - spec/votable_voter_spec.rb
101
+ - spec/voter_spec.rb
102
+ - spec/words_spec.rb