redmineup 1.0.2

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