test_redmine_vz 0.0.24
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/README.md +71 -0
- data/Rakefile +20 -0
- data/config/currency_iso.json +2532 -0
- data/doc/CHANGELOG +55 -0
- data/doc/LICENSE.txt +339 -0
- data/lib/redmine_crm.rb +67 -0
- data/lib/redmine_crm/currency.rb +439 -0
- data/lib/redmine_crm/currency/formatting.rb +227 -0
- data/lib/redmine_crm/currency/heuristics.rb +151 -0
- data/lib/redmine_crm/currency/loader.rb +24 -0
- data/lib/redmine_crm/helpers/tags_helper.rb +15 -0
- data/lib/redmine_crm/helpers/vote_helper.rb +38 -0
- data/lib/redmine_crm/liquid/drops/issues_drop.rb +61 -0
- data/lib/redmine_crm/liquid/drops/news_drop.rb +45 -0
- data/lib/redmine_crm/liquid/drops/projects_drop.rb +78 -0
- data/lib/redmine_crm/liquid/drops/users_drop.rb +59 -0
- data/lib/redmine_crm/liquid/filters.rb +85 -0
- data/lib/redmine_crm/money_helper.rb +67 -0
- data/lib/redmine_crm/rcrm_acts_as_taggable.rb +342 -0
- data/lib/redmine_crm/rcrm_acts_as_viewed.rb +287 -0
- data/lib/redmine_crm/rcrm_acts_as_votable.rb +79 -0
- data/lib/redmine_crm/rcrm_acts_as_voter.rb +27 -0
- data/lib/redmine_crm/tag.rb +81 -0
- data/lib/redmine_crm/tag_list.rb +112 -0
- data/lib/redmine_crm/tagging.rb +20 -0
- data/lib/redmine_crm/version.rb +3 -0
- data/lib/redmine_crm/votable.rb +334 -0
- data/lib/redmine_crm/vote.rb +30 -0
- data/lib/redmine_crm/voter.rb +136 -0
- data/redmine_crm.gemspec +22 -0
- data/test/acts_as_taggable_test.rb +384 -0
- data/test/currency_test.rb +292 -0
- data/test/database.yml +17 -0
- data/test/fixtures/issue.rb +14 -0
- data/test/fixtures/issues.yml +12 -0
- data/test/fixtures/taggings.yml +32 -0
- data/test/fixtures/tags.yml +11 -0
- data/test/fixtures/user.rb +7 -0
- data/test/fixtures/users.yml +5 -0
- data/test/fixtures/votable_caches.yml +2 -0
- data/test/fixtures/votables.yml +4 -0
- data/test/fixtures/vote_classes.rb +54 -0
- data/test/fixtures/voters.yml +6 -0
- data/test/liquid_test.rb +80 -0
- data/test/money_helper_test.rb +12 -0
- data/test/schema.rb +100 -0
- data/test/tag_test.rb +63 -0
- data/test/tagging_test.rb +14 -0
- data/test/tags_helper_test.rb +29 -0
- data/test/test_helper.rb +118 -0
- data/test/viewed_test.rb +45 -0
- data/test/votable_model_test.rb +478 -0
- data/test/votable_test.rb +17 -0
- data/test/vote_helper_test.rb +28 -0
- data/test/voter_model_test.rb +296 -0
- metadata +141 -0
@@ -0,0 +1,478 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class VotableModelTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def votable
|
6
|
+
votables(:votable)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_vote_without_voter
|
10
|
+
assert !votables(:votable).vote_by
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_have_vote_when_saved
|
14
|
+
votable.vote_by(:voter => voters(:voter), :vote => "yes")
|
15
|
+
assert_equal votable.votes_for.size, 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_voted_twice_by_same_person
|
19
|
+
votable.vote_by(:voter => voters(:voter), :vote => "yes")
|
20
|
+
votable.vote_by(:voter => voters(:voter), :vote => "no")
|
21
|
+
assert_equal votable.votes_for.size, 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_voted_twice_by_same_person_with_duplicate_params
|
25
|
+
votable.vote_by(:voter => voters(:voter), :vote => "yes")
|
26
|
+
votable.vote_by(:voter => voters(:voter), :vote => "no", :duplicate => true)
|
27
|
+
assert_equal votable.votes_for.size, 2
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_one_scoped_vote
|
31
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'rank')
|
32
|
+
assert_equal votable.find_votes_for(:vote_scope => 'rank').size, 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_one_scoped_vote_when_using_scope_by_same_person
|
36
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'rank')
|
37
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'rank')
|
38
|
+
assert_equal votable.find_votes_for(:vote_scope => 'rank').size, 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_two_votes_for_when_voting_on_two_diff_scopes
|
42
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'weekly_rank')
|
43
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'yes', :vote_scope => 'monthly_rank')
|
44
|
+
assert_equal votable.votes_for.size, 2
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_called_with_vote_up
|
48
|
+
votables(:votable).vote_up voters(:voter)
|
49
|
+
assert_equal votables(:votable).get_up_votes.first.voter, voters(:voter)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_called_with_vote_down
|
53
|
+
votables(:votable).vote_down voters(:voter)
|
54
|
+
assert_equal votables(:votable).get_down_votes.first.voter, voters(:voter)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_have_two_votes_when_voted_two_different_people
|
58
|
+
votable.vote_by(:voter => voters(:voter))
|
59
|
+
votable.vote_by(:voter => voters(:voter2))
|
60
|
+
assert_equal votable.votes_for.size, 2
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_one_true_vote
|
64
|
+
votable.vote_by(:voter => voters(:voter))
|
65
|
+
votable.vote_by(:voter => voters(:voter2), :vote => "dislike")
|
66
|
+
assert_equal votable.get_up_votes.size, 1
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_two_false_votes
|
70
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'no')
|
71
|
+
votable.vote_by(:voter => voters(:voter2), :vote => "dislike")
|
72
|
+
assert_equal votable.get_down_votes.size, 2
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_have_been_voted_on_by_voter2
|
76
|
+
votable.vote_by(:voter => voters(:voter2), :vote => true)
|
77
|
+
assert_equal votable.find_votes_for.first.voter.id, voters(:voter2).id
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_count_the_vote_as_registered_if_this_the_voters_first_vote
|
81
|
+
votable.vote_by(:voter => voters(:voter))
|
82
|
+
assert votable.vote_registered?
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_not_count_the_vote_as_being_registered_if_that_voter_has_alredy_voted_and_voted_has_not_chanded
|
86
|
+
votable.vote_by(:voter => voters(:voter), :vote => true)
|
87
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'yes')
|
88
|
+
assert !votable.vote_registered?
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_count_the_vote_as_registered_if_the_voter_has_voted_and_the_flag_has_changed
|
92
|
+
votable.vote_by(:voter => voters(:voter), :vote => true)
|
93
|
+
votable.vote_by(:voter => voters(:voter), :vote => 'dislike')
|
94
|
+
assert votable.vote_registered?
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_count_the_vote_as_registered_if_the_voter_has_voted_and_vote_weight_has_changed
|
98
|
+
votable.vote_by(:voter => voters(:voter), :vote => true, :vote_weight => 1)
|
99
|
+
votable.vote_by(:voter => voters(:voter), :vote => true, :vote_weight => 2)
|
100
|
+
assert votable.vote_registered?
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_voted_on_by_voter
|
104
|
+
votable.vote_by(:voter => voters(:voter))
|
105
|
+
assert votable.voted_on_by?(voters(:voter))
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_unvoted
|
109
|
+
votable.liked_by(voters(:voter))
|
110
|
+
votable.unliked_by(voters(:voter))
|
111
|
+
assert !votable.voted_on_by?(voters(:voter))
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_unvoted_positive_vote
|
115
|
+
votable.vote_by(:voter => voters(:voter))
|
116
|
+
votable.unvote(:voter => voters(:voter))
|
117
|
+
assert_equal votable.find_votes_for.count, 0
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_set_the_votable_to_unregistered_after_unvoting
|
121
|
+
votable.vote_by(:voter => voters(:voter))
|
122
|
+
votable.unvote(:voter => voters(:voter))
|
123
|
+
assert !votable.vote_registered?
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_unvote_a_negative_vote
|
127
|
+
votable.vote_by(:voter => voters(:voter), :vote => "no")
|
128
|
+
votable.unvote(:voter => voters(:voter))
|
129
|
+
assert_equal votable.find_votes_for.count, 0
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_unvote_only_the_from_a_single_voter
|
133
|
+
votable.vote_by(:voter => voters(:voter))
|
134
|
+
votable.vote_by(:voter => voters(:voter2))
|
135
|
+
votable.unvote(:voter => voters(:voter))
|
136
|
+
assert_equal votable.find_votes_for.count, 1
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_contained_to_instance
|
140
|
+
votable2 = Votable.new(:name => "2nd votable")
|
141
|
+
votable2.save
|
142
|
+
|
143
|
+
votable.vote_by(:voter => voters(:voter), :vote => false)
|
144
|
+
votable2.vote_by(:voter => voters(:voter), :vote => true)
|
145
|
+
votable2.vote_by(:voter => voters(:voter), :vote => true)
|
146
|
+
|
147
|
+
assert votable.vote_registered?
|
148
|
+
assert !votable2.vote_registered?
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_default_weight_if_not_specified
|
152
|
+
votable.upvote_by(voters(:voter))
|
153
|
+
assert_equal votable.find_votes_for.first.vote_weight, 1
|
154
|
+
end
|
155
|
+
|
156
|
+
# with cached votes_for
|
157
|
+
|
158
|
+
def voter
|
159
|
+
voters(:voter)
|
160
|
+
end
|
161
|
+
|
162
|
+
def votable_cache
|
163
|
+
votable_caches(:votable_cache)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_not_update_cached_votes_for_if_there_are_no_colums
|
167
|
+
votable.vote_by(:voter => voter)
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_update_chaced_votes_for_if_there_is_a_total_column
|
171
|
+
votable_cache.cached_votes_total = 50
|
172
|
+
votable_cache.vote_by(voter: voter)
|
173
|
+
assert_equal votable_cache.cached_votes_total, 1
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_update_cached_total_votes_for_when_a_vote_up_is_removed
|
177
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true')
|
178
|
+
votable_cache.unvote(:voter => voter)
|
179
|
+
assert_equal votable_cache.cached_votes_total, 0
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_update_cachded_score_votes_for_if_there_is_a_score_column
|
183
|
+
votable_cache.cached_votes_score = 50
|
184
|
+
votable_cache.vote_by(:voter => voter)
|
185
|
+
assert_equal votable_cache.cached_votes_score, 1
|
186
|
+
votable_cache.vote_by(:voter => voters(:voter2), :vote => 'false')
|
187
|
+
assert_equal votable_cache.cached_votes_score, 0
|
188
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false')
|
189
|
+
assert_equal votable_cache.cached_votes_score, -2
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_update_cached_score_votef_for_when_a_vote_up_is_removed
|
193
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true')
|
194
|
+
assert_equal votable_cache.cached_votes_score, 1
|
195
|
+
votable_cache.unvote(:voter => voter)
|
196
|
+
assert_equal votable_cache.cached_votes_score, 0
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_update_cached_score_votef_for_when_a_vote_down_is_removed
|
200
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false')
|
201
|
+
assert_equal votable_cache.cached_votes_score, -1
|
202
|
+
votable_cache.unvote(:voter => voter)
|
203
|
+
assert_equal votable_cache.cached_votes_score, 0
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_updata_cached_weighted_total_if_there_is_a_weighted_total_column
|
207
|
+
votable_cache.cached_weighted_total = 50
|
208
|
+
votable_cache.vote_by(:voter => voter)
|
209
|
+
assert_equal votable_cache.cached_weighted_total, 1
|
210
|
+
votable_cache.vote_by(:voter => voters(:voter2), :vote => 'false')
|
211
|
+
assert_equal votable_cache.cached_weighted_total, 2
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_update_cached_weighted_total_votes_for_when_a_vote_up_is_removed
|
215
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_weight => 3)
|
216
|
+
assert_equal votable_cache.cached_weighted_total, 3
|
217
|
+
votable_cache.unvote(:voter => voter)
|
218
|
+
assert_equal votable_cache.cached_weighted_total, 0
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_update_cached_weighted_total_votes_for_when_a_vote_down_is_removed
|
222
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_weight => 4)
|
223
|
+
assert_equal votable_cache.cached_weighted_total, 4
|
224
|
+
votable_cache.unvote(:voter => voter)
|
225
|
+
assert_equal votable_cache.cached_weighted_total, 0
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_update_cached_weighted_score_if_there_is_a_weighted_score_column
|
229
|
+
votable_cache.cached_weighted_score = 50
|
230
|
+
votable_cache.vote_by(:voter => voter, :vote_weight => 3)
|
231
|
+
assert_equal votable_cache.cached_weighted_score, 3
|
232
|
+
votable_cache.vote_by(:voter => voters(:voter2), :vote => 'false', :vote_weight => 5)
|
233
|
+
assert_equal votable_cache.cached_weighted_score, -2
|
234
|
+
# voter changes her vote from 3 to 5
|
235
|
+
votable_cache.vote_by(:voter => voter, :vote_weight => 5)
|
236
|
+
assert_equal votable_cache.cached_weighted_score, 0
|
237
|
+
votable_cache.vote_by :voter => voters(:voter3), :vote_weight => 4
|
238
|
+
assert_equal votable_cache.cached_weighted_score, 4
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_update_cached_weighted_score_votes_for_when_a_vote_up_is_removed
|
242
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_weight => 3)
|
243
|
+
assert_equal votable_cache.cached_weighted_score, 3
|
244
|
+
votable_cache.unvote :voter => voter
|
245
|
+
assert_equal votable_cache.cached_weighted_score, 0
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_update_cached_weighted_score_votes_for_when_a_vote_down_is_removed
|
249
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_weight => 4)
|
250
|
+
assert_equal votable_cache.cached_weighted_score, -4
|
251
|
+
votable_cache.unvote :voter => voter
|
252
|
+
assert_equal votable_cache.cached_weighted_score, 0
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_update_cached_weighted_average_if_there_is_a_weighted_average_column
|
256
|
+
votable_cache.cached_weighted_average = 50.0
|
257
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_weight => 5)
|
258
|
+
assert_equal votable_cache.cached_weighted_average, 5.0
|
259
|
+
votable_cache.vote_by(:voter => voters(:voter2), :vote => 'true', :vote_weight => 3)
|
260
|
+
assert_equal votable_cache.cached_weighted_average, 4.0
|
261
|
+
# voter changes her vote from 5 to 4
|
262
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_weight => 4)
|
263
|
+
assert_equal votable_cache.cached_weighted_average, 3.5
|
264
|
+
votable_cache.vote_by(:voter => voters(:voter3), :vote => 'true', :vote_weight => 5)
|
265
|
+
assert_equal votable_cache.cached_weighted_average, 4.0
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_update_cached_weighted_average_votes_for_when_a_vote_up_is_removed
|
269
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_weight => 5)
|
270
|
+
votable_cache.vote_by(:voter => voters(:voter2), :vote => 'true', :vote_weight => 3)
|
271
|
+
assert_equal votable_cache.cached_weighted_average, 4
|
272
|
+
votable_cache.unvote :voter => voter
|
273
|
+
assert_equal votable_cache.cached_weighted_average, 3
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_update_cached_up_votes_for_if_there_is_an_up_vote_column
|
277
|
+
votable_cache.cached_votes_up = 50
|
278
|
+
votable_cache.vote_by(:voter => voter)
|
279
|
+
votable_cache.vote_by(:voter => voter)
|
280
|
+
assert_equal votable_cache.cached_votes_up, 1
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_update_cached_down_votes_for_if_there_is_a_down_vote_column
|
284
|
+
votable_cache.cached_votes_down = 50
|
285
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false')
|
286
|
+
assert_equal votable_cache.cached_votes_down, 1
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_update_cached_up_votes_for_when_a_vote_up_is_removed
|
290
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true')
|
291
|
+
votable_cache.unvote(:voter => voter)
|
292
|
+
assert_equal votable_cache.cached_votes_up, 0
|
293
|
+
end
|
294
|
+
|
295
|
+
def test_update_cached_down_votes_for_when_a_vote_down_is_removed
|
296
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false')
|
297
|
+
votable_cache.unvote(:voter => voter)
|
298
|
+
assert_equal votable_cache.cached_votes_down, 0
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_select_from_cached_total_votes_for_if_there_a_total_column
|
302
|
+
votable_cache.vote_by(:voter => voter)
|
303
|
+
votable_cache.cached_votes_total = 50
|
304
|
+
assert_equal votable_cache.count_votes_total, 50
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_select_from_cached_up_votes_for_if_there_is_an_up_vote_column
|
308
|
+
votable_cache.vote_by(:voter => voter)
|
309
|
+
votable_cache.cached_votes_up = 50
|
310
|
+
assert_equal votable_cache.count_votes_up, 50
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_select_from_cached_down_votes_for_if_there_is_a_down_vote_column
|
314
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false')
|
315
|
+
votable_cache.cached_votes_down = 50
|
316
|
+
assert_equal votable_cache.count_votes_down, 50
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_select_from_cached_weighted_total_if_there_is_a_weighted_total_column
|
320
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false')
|
321
|
+
votable_cache.cached_weighted_total = 50
|
322
|
+
assert_equal votable_cache.weighted_total, 50
|
323
|
+
end
|
324
|
+
|
325
|
+
def test_select_from_cached_weighted_score_if_there_is_a_weighted_score_column
|
326
|
+
votable_cache.vote_by( :voter => voter, :vote => 'false')
|
327
|
+
votable_cache.cached_weighted_score = 50
|
328
|
+
assert_equal votable_cache.weighted_score, 50
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_select_from_cached_weighted_average_if_there_is_a_weighted_average_column
|
332
|
+
votable_cache.vote_by( :voter => voter, :vote => 'false')
|
333
|
+
votable_cache.cached_weighted_average = 50
|
334
|
+
assert_equal votable_cache.weighted_average, 50
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_update_cached_total_votes_for_when_voting_under_an_scope
|
338
|
+
votable_cache.vote_by( :voter => voter, :vote => 'true', :vote_scope => 'rank')
|
339
|
+
assert_equal votable_cache.cached_votes_total, 1
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_update_cached_up_votes_for_when_voting_under_an_scope
|
343
|
+
votable_cache.vote_by( :voter => voter, :vote => 'true', :vote_scope => 'rank')
|
344
|
+
assert_equal votable_cache.cached_votes_up, 1
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_update_cached_total_votes_for_when_a_scoped_vote_down_is_removed
|
348
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_scope => 'rank')
|
349
|
+
votable_cache.unvote( :voter => voter, :vote_scope => 'rank')
|
350
|
+
assert_equal votable_cache.cached_votes_total, 0
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_update_cached_up_votes_for_when_a_scoped_vote_down_is_removed
|
354
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_scope => 'rank')
|
355
|
+
votable_cache.unvote(:voter => voter, :vote_scope => 'rank')
|
356
|
+
assert_equal votable_cache.cached_votes_up, 0
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_update_cached_down_votes_for_when_downvoting_under_a_scope
|
360
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => 'rank')
|
361
|
+
assert_equal votable_cache.cached_votes_down, 1
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_update_cached_down_votes_for_when_a_scoped_vote_down_is_removed
|
365
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => 'rank')
|
366
|
+
votable_cache.unvote(:voter => voter, :vote_scope => 'rank')
|
367
|
+
assert_equal votable_cache.cached_votes_down, 0
|
368
|
+
end
|
369
|
+
|
370
|
+
# describe "with scoped cached votes_for
|
371
|
+
|
372
|
+
def test_update_cached_total_votes_for_if_there_is_a_total_column
|
373
|
+
votable_cache.cached_scoped_test_votes_total = 50
|
374
|
+
votable_cache.vote_by(:voter => voter, :vote_scope => "test")
|
375
|
+
assert_equal votable_cache.cached_scoped_test_votes_total, 1
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_update_cached_total_votes_for_when_a_vote_up_is_removed
|
379
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_scope => "test")
|
380
|
+
votable_cache.unvote(:voter => voter, :vote_scope => "test")
|
381
|
+
assert_equal votable_cache.cached_scoped_test_votes_total, 0
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_update_cached_total_votes_for_when_a_vote_down_is_removed
|
385
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => "test")
|
386
|
+
votable_cache.unvote(:voter => voter, :vote_scope => "test")
|
387
|
+
assert_equal votable_cache.cached_scoped_test_votes_total, 0
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_update_cached_score_votes_for_if_there_is_a_score_column
|
391
|
+
votable_cache.cached_scoped_test_votes_score = 50
|
392
|
+
votable_cache.vote_by(:voter => voter, :vote_scope => "test")
|
393
|
+
assert_equal votable_cache.cached_scoped_test_votes_score, 1
|
394
|
+
votable_cache.vote_by(:voter => voters(:voter2), :vote => 'false', :vote_scope => "test")
|
395
|
+
assert_equal votable_cache.cached_scoped_test_votes_score, 0
|
396
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => "test")
|
397
|
+
assert_equal votable_cache.cached_scoped_test_votes_score, -2
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_update_cached_score_votes_for_when_a_vote_up_is_removed
|
401
|
+
votable_cache.vote_by(:voter => voter, :vote => 'true', :vote_scope => "test")
|
402
|
+
assert_equal votable_cache.cached_scoped_test_votes_score, 1
|
403
|
+
votable_cache.unvote(:voter => voter, :vote_scope => "test")
|
404
|
+
assert_equal votable_cache.cached_scoped_test_votes_score, 0
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_update_cached_score_votes_for_when_a_vote_down_is_removed
|
408
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => "test")
|
409
|
+
assert_equal votable_cache.cached_scoped_test_votes_score, -1
|
410
|
+
votable_cache.unvote(:voter => voter, :vote_scope => "test")
|
411
|
+
assert_equal votable_cache.cached_scoped_test_votes_score, 0
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_update_cached_up_votes_for_if_there_is_an_up_vote_column
|
415
|
+
votable_cache.cached_scoped_test_votes_up = 50
|
416
|
+
votable_cache.vote_by(:voter => voter, :vote_scope => "test")
|
417
|
+
votable_cache.vote_by(:voter => voter, :vote_scope => "test")
|
418
|
+
assert_equal votable_cache.cached_scoped_test_votes_up, 1
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_update_cached_down_votes_for_if_there_is_a_down_vote_column
|
422
|
+
votable_cache.cached_scoped_test_votes_down = 50
|
423
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => "test")
|
424
|
+
assert_equal votable_cache.cached_scoped_test_votes_down, 1
|
425
|
+
end
|
426
|
+
|
427
|
+
def test_update_cached_up_votes_for_when_a_vote_up_is_removed
|
428
|
+
votable_cache.vote_by :voter => voter, :vote => 'true', :vote_scope => "test"
|
429
|
+
votable_cache.unvote :voter => voter, :vote_scope => "test"
|
430
|
+
assert_equal votable_cache.cached_scoped_test_votes_up, 0
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_update_cached_down_votes_for_when_a_vote_down_is_removed
|
434
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => "test")
|
435
|
+
votable_cache.unvote(:voter => voter, :vote_scope => "test")
|
436
|
+
assert_equal votable_cache.cached_scoped_test_votes_down, 0
|
437
|
+
end
|
438
|
+
|
439
|
+
def test_select_from_cached_total_votes_for_if_there_a_total_column
|
440
|
+
votable_cache.vote_by(:voter => voter, :vote_scope => "test")
|
441
|
+
votable_cache.cached_scoped_test_votes_total = 50
|
442
|
+
assert_equal votable_cache.count_votes_total(false, "test"), 50
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_select_from_cached_up_votes_for_if_there_is_an_up_vote_column
|
446
|
+
votable_cache.vote_by(:voter => voter, :vote_scope => "test")
|
447
|
+
votable_cache.cached_scoped_test_votes_up = 50
|
448
|
+
assert_equal votable_cache.count_votes_up(false, "test"), 50
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_select_from_cached_down_votes_for_if_there_is_a_down_vote_column
|
452
|
+
votable_cache.vote_by(:voter => voter, :vote => 'false', :vote_scope => "test")
|
453
|
+
votable_cache.cached_scoped_test_votes_down = 50
|
454
|
+
assert_equal votable_cache.count_votes_down(false, "test"), 50
|
455
|
+
end
|
456
|
+
|
457
|
+
# describe "sti models
|
458
|
+
|
459
|
+
def test_be_able_to_vote_on_a_votable_child_of_a_non_votable_sti_model
|
460
|
+
votable = VotableChildOfStiNotVotable.create(:name => 'sti child')
|
461
|
+
|
462
|
+
votable.vote_by(:voter => voter, :vote => 'yes')
|
463
|
+
assert_equal votable.votes_for.size, 1
|
464
|
+
end
|
465
|
+
|
466
|
+
def test_not_be_able_to_vote_on_a_parent_non_votable
|
467
|
+
assert !StiNotVotable.votable?
|
468
|
+
end
|
469
|
+
|
470
|
+
def test_be_able_to_vote_on_a_child_when_its_parent_is_votable
|
471
|
+
votable = ChildOfStiVotable.create(:name => 'sti child')
|
472
|
+
|
473
|
+
votable.vote_by(:voter => voter, :vote => 'yes')
|
474
|
+
assert_equal votable.votes_for.size, 1
|
475
|
+
end
|
476
|
+
|
477
|
+
|
478
|
+
end
|