acts_as_votable 0.10.0 → 0.13.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.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +44 -0
- data/.gitignore +10 -6
- data/.rubocop.yml +121 -0
- data/.ruby-version +1 -0
- data/Appraisals +23 -0
- data/Gemfile +3 -14
- data/{README.markdown → README.md} +87 -52
- data/Rakefile +6 -4
- data/acts_as_votable.gemspec +12 -7
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/gemfiles/rails_5.gemfile +7 -0
- data/gemfiles/rails_5_1.gemfile +7 -0
- data/gemfiles/rails_5_2.gemfile +7 -0
- data/gemfiles/rails_6.gemfile +8 -0
- data/gemfiles/rails_6_1.gemfile +8 -0
- data/gemfiles/rails_6_rc1.gemfile +8 -0
- data/lib/acts_as_votable.rb +9 -9
- data/lib/acts_as_votable/cacheable.rb +174 -0
- data/lib/acts_as_votable/extenders/controller.rb +3 -4
- data/lib/acts_as_votable/extenders/votable.rb +17 -6
- data/lib/acts_as_votable/extenders/voter.rb +4 -6
- data/lib/acts_as_votable/helpers/words.rb +7 -10
- data/lib/acts_as_votable/version.rb +3 -1
- data/lib/acts_as_votable/votable.rb +74 -194
- data/lib/acts_as_votable/vote.rb +10 -12
- data/lib/acts_as_votable/voter.rb +55 -56
- data/lib/generators/acts_as_votable/migration/migration_generator.rb +25 -4
- data/lib/generators/acts_as_votable/migration/templates/active_record/{migration.rb → migration.erb} +1 -6
- data/spec/factories/votable.rb +6 -0
- data/spec/factories/votable_cache.rb +6 -0
- data/spec/factories/votable_cache_update_attributes.rb +6 -0
- data/spec/factories/votable_cache_update_columns.rb +6 -0
- data/spec/factories/votable_child_of_sti_not_votable.rb +6 -0
- data/spec/factories/votable_child_of_sti_votable.rb +6 -0
- data/spec/factories/votable_voter.rb +6 -0
- data/spec/factories/vote.rb +6 -0
- data/spec/factories/voter.rb +6 -0
- data/spec/generators/active_record_generator_spec.rb +13 -0
- data/spec/shared_example/votable_model.rb +542 -0
- data/spec/shared_example/voter_model.rb +280 -0
- data/spec/spec_helper.rb +28 -18
- data/spec/support/factory_bot.rb +9 -0
- data/spec/votable_spec.rb +10 -9
- data/spec/votable_voter_spec.rb +12 -12
- data/spec/voter_spec.rb +9 -10
- data/spec/words_spec.rb +9 -12
- metadata +116 -26
- data/.travis.yml +0 -25
- data/spec/shared_example/votable_model_spec.rb +0 -421
- data/spec/shared_example/voter_model_spec.rb +0 -279
@@ -1,279 +0,0 @@
|
|
1
|
-
shared_examples "a voter_model" do
|
2
|
-
let (:votable_klass) { votable.class }
|
3
|
-
|
4
|
-
it "should be voted on after a voter has voted" do
|
5
|
-
votable.vote_by :voter => voter
|
6
|
-
voter.voted_on?(votable).should be true
|
7
|
-
voter.voted_for?(votable).should be true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should not be voted on if a voter has not voted" do
|
11
|
-
voter.voted_on?(votable).should be false
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be voted on after a voter has voted under scope" do
|
15
|
-
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
16
|
-
voter.voted_on?(votable, :vote_scope => 'rank').should be true
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should not be voted on other scope after a voter has voted under one scope" do
|
20
|
-
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
21
|
-
voter.voted_on?(votable).should be false
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should be voted as true when a voter has voted true" do
|
25
|
-
votable.vote_by :voter => voter
|
26
|
-
voter.voted_as_when_voted_on(votable).should be true
|
27
|
-
voter.voted_as_when_voted_for(votable).should be true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should be voted as true when a voter has voted true under scope" do
|
31
|
-
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
32
|
-
voter.voted_as_when_voted_for(votable, :vote_scope => 'rank').should be true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should be voted as false when a voter has voted false" do
|
36
|
-
votable.vote_by :voter => voter, :vote => false
|
37
|
-
voter.voted_as_when_voted_for(votable).should be false
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should be voted as false when a voter has voted false under scope" do
|
41
|
-
votable.vote_by :voter => voter, :vote => false, :vote_scope => 'rank'
|
42
|
-
voter.voted_as_when_voted_for(votable, :vote_scope => 'rank').should be false
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should be voted as nil when a voter has never voted" do
|
46
|
-
voter.voted_as_when_voting_on(votable).should be nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should be voted as nil when a voter has never voted under the scope" do
|
50
|
-
votable.vote_by :voter => voter, :vote => false, :vote_scope => 'rank'
|
51
|
-
voter.voted_as_when_voting_on(votable).should be nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should return true if voter has voted true" do
|
55
|
-
votable.vote_by :voter => voter
|
56
|
-
voter.voted_up_on?(votable).should be true
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should return false if voter has not voted true" do
|
60
|
-
votable.vote_by :voter => voter, :vote => false
|
61
|
-
voter.voted_up_on?(votable).should be false
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should return true if the voter has voted false" do
|
65
|
-
votable.vote_by :voter => voter, :vote => false
|
66
|
-
voter.voted_down_on?(votable).should be true
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should return false if the voter has not voted false" do
|
70
|
-
votable.vote_by :voter => voter, :vote => true
|
71
|
-
voter.voted_down_on?(votable).should be false
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should provide reserve functionality, voter can vote on votable" do
|
75
|
-
voter.vote :votable => votable, :vote => 'bad'
|
76
|
-
voter.voted_as_when_voting_on(votable).should be false
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should allow the voter to vote up a model" do
|
80
|
-
voter.vote_up_for votable
|
81
|
-
votable.get_up_votes.first.voter.should == voter
|
82
|
-
votable.votes_for.up.first.voter.should == voter
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should allow the voter to vote down a model" do
|
86
|
-
voter.vote_down_for votable
|
87
|
-
votable.get_down_votes.first.voter.should == voter
|
88
|
-
votable.votes_for.down.first.voter.should == voter
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should allow the voter to unvote a model" do
|
92
|
-
voter.vote_up_for votable
|
93
|
-
voter.unvote_for votable
|
94
|
-
votable.find_votes_for.size.should == 0
|
95
|
-
votable.votes_for.count.should == 0
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should get all of the voters votes" do
|
99
|
-
voter.vote_up_for votable
|
100
|
-
voter.find_votes.size.should == 1
|
101
|
-
voter.votes.up.count.should == 1
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should get all of the voters up votes" do
|
105
|
-
voter.vote_up_for votable
|
106
|
-
voter.find_up_votes.size.should == 1
|
107
|
-
voter.votes.up.count.should == 1
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should get all of the voters down votes" do
|
111
|
-
voter.vote_down_for votable
|
112
|
-
voter.find_down_votes.size.should == 1
|
113
|
-
voter.votes.down.count.should == 1
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should get all of the votes votes for a class" do
|
117
|
-
votable.vote_by :voter => voter
|
118
|
-
votable2.vote_by :voter => voter, :vote => false
|
119
|
-
voter.find_votes_for_class(votable_klass).size.should == 2
|
120
|
-
voter.votes.for_type(votable_klass).count.should == 2
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should get all of the voters up votes for a class" do
|
124
|
-
votable.vote_by :voter => voter
|
125
|
-
votable2.vote_by :voter => voter, :vote => false
|
126
|
-
voter.find_up_votes_for_class(votable_klass).size.should == 1
|
127
|
-
voter.votes.up.for_type(votable_klass).count.should == 1
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should get all of the voters down votes for a class" do
|
131
|
-
votable.vote_by :voter => voter
|
132
|
-
votable2.vote_by :voter => voter, :vote => false
|
133
|
-
voter.find_down_votes_for_class(votable_klass).size.should == 1
|
134
|
-
voter.votes.down.for_type(votable_klass).count.should == 1
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should be contained to instances" do
|
138
|
-
voter.vote :votable => votable, :vote => false
|
139
|
-
voter2.vote :votable => votable
|
140
|
-
|
141
|
-
voter.voted_as_when_voting_on(votable).should be false
|
142
|
-
end
|
143
|
-
|
144
|
-
describe '#find_voted_items' do
|
145
|
-
it 'returns objects that a user has upvoted for' do
|
146
|
-
votable.vote_by :voter => voter
|
147
|
-
votable2.vote_by :voter => voter2
|
148
|
-
voter.find_voted_items.should include votable
|
149
|
-
voter.find_voted_items.size.should == 1
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'returns objects that a user has upvoted for, using scope' do
|
153
|
-
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
154
|
-
votable2.vote_by :voter => voter2, :vote_scope => 'rank'
|
155
|
-
voter.find_voted_items(:vote_scope => 'rank').should include votable
|
156
|
-
voter.find_voted_items(:vote_scope => 'rank').size.should == 1
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'returns objects that a user has downvoted for' do
|
160
|
-
votable.vote_down voter
|
161
|
-
votable2.vote_down voter2
|
162
|
-
voter.find_voted_items.should include votable
|
163
|
-
voter.find_voted_items.size.should == 1
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'returns objects that a user has downvoted for, using scope' do
|
167
|
-
votable.vote_down voter, :vote_scope => 'rank'
|
168
|
-
votable2.vote_down voter2, :vote_scope => 'rank'
|
169
|
-
voter.find_voted_items(:vote_scope => 'rank').should include votable
|
170
|
-
voter.find_voted_items(:vote_scope => 'rank').size.should == 1
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe '#find_up_voted_items' do
|
175
|
-
it 'returns objects that a user has upvoted for' do
|
176
|
-
votable.vote_by :voter => voter
|
177
|
-
votable2.vote_by :voter => voter2
|
178
|
-
voter.find_up_voted_items.should include votable
|
179
|
-
voter.find_up_voted_items.size.should == 1
|
180
|
-
voter.find_liked_items.should include votable
|
181
|
-
voter.find_liked_items.size.should == 1
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'returns objects that a user has upvoted for, using scope' do
|
185
|
-
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
186
|
-
votable2.vote_by :voter => voter2, :vote_scope => 'rank'
|
187
|
-
voter.find_up_voted_items(:vote_scope => 'rank').should include votable
|
188
|
-
voter.find_up_voted_items(:vote_scope => 'rank').size.should == 1
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'does not return objects that a user has downvoted for' do
|
192
|
-
votable.vote_down voter
|
193
|
-
voter.find_up_voted_items.size.should == 0
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'does not return objects that a user has downvoted for, using scope' do
|
197
|
-
votable.vote_down voter, :vote_scope => 'rank'
|
198
|
-
voter.find_up_voted_items(:vote_scope => 'rank').size.should == 0
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe '#find_down_voted_items' do
|
203
|
-
it 'does not return objects that a user has upvoted for' do
|
204
|
-
votable.vote_by :voter => voter
|
205
|
-
voter.find_down_voted_items.size.should == 0
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'does not return objects that a user has upvoted for, using scope' do
|
209
|
-
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
210
|
-
voter.find_down_voted_items(:vote_scope => 'rank').size.should == 0
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'returns objects that a user has downvoted for' do
|
214
|
-
votable.vote_down voter
|
215
|
-
votable2.vote_down voter2
|
216
|
-
voter.find_down_voted_items.should include votable
|
217
|
-
voter.find_down_voted_items.size.should == 1
|
218
|
-
voter.find_disliked_items.should include votable
|
219
|
-
voter.find_disliked_items.size.should == 1
|
220
|
-
end
|
221
|
-
|
222
|
-
it 'returns objects that a user has downvoted for, using scope' do
|
223
|
-
votable.vote_down voter, :vote_scope => 'rank'
|
224
|
-
votable2.vote_down voter2, :vote_scope => 'rank'
|
225
|
-
voter.find_down_voted_items(:vote_scope => 'rank').should include votable
|
226
|
-
voter.find_down_voted_items(:vote_scope => 'rank').size.should == 1
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
describe '#get_voted' do
|
232
|
-
subject { voter.get_voted(votable.class) }
|
233
|
-
|
234
|
-
it 'returns objects of a class that a voter has voted for' do
|
235
|
-
votable.vote_by :voter => voter
|
236
|
-
votable2.vote_down voter
|
237
|
-
subject.should include votable
|
238
|
-
subject.should include votable2
|
239
|
-
subject.size.should == 2
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'does not return objects of a class that a voter has voted for' do
|
243
|
-
votable.vote_by :voter => voter2
|
244
|
-
votable2.vote_by :voter => voter2
|
245
|
-
subject.size.should == 0
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe '#get_up_voted' do
|
250
|
-
subject { voter.get_up_voted(votable.class) }
|
251
|
-
|
252
|
-
it 'returns up voted items that a voter has voted for' do
|
253
|
-
votable.vote_by :voter => voter
|
254
|
-
subject.should include votable
|
255
|
-
subject.size.should == 1
|
256
|
-
end
|
257
|
-
|
258
|
-
it 'does not return down voted items a voter has voted for' do
|
259
|
-
votable.vote_down voter
|
260
|
-
subject.size.should == 0
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe '#get_down_voted' do
|
265
|
-
subject { voter.get_down_voted(votable.class) }
|
266
|
-
|
267
|
-
it 'does not return up voted items that a voter has voted for' do
|
268
|
-
votable.vote_by :voter => voter
|
269
|
-
subject.size.should == 0
|
270
|
-
end
|
271
|
-
|
272
|
-
it 'returns down voted items a voter has voted for' do
|
273
|
-
votable.vote_down voter
|
274
|
-
subject.should include votable
|
275
|
-
subject.size.should == 1
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
end
|