redmineup 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/README.md +204 -0
- data/Rakefile +11 -0
- data/app/controllers/redmineup_controller.rb +26 -0
- data/app/views/redmine_crm/redmineup_calendar/_calendar.html.erb +34 -0
- data/app/views/redmineup/_money.html.erb +44 -0
- data/app/views/redmineup/settings.html.erb +10 -0
- data/bitbucket-pipelines.yml +50 -0
- data/config/currency_iso.json +2544 -0
- data/config/locales/cs.yml +13 -0
- data/config/locales/de.yml +13 -0
- data/config/locales/en.yml +13 -0
- data/config/locales/es.yml +13 -0
- data/config/locales/ru.yml +13 -0
- data/config/routes.rb +5 -0
- data/doc/CHANGELOG +14 -0
- data/doc/LICENSE.txt +339 -0
- data/lib/redmineup/acts_as_draftable/draft.rb +40 -0
- data/lib/redmineup/acts_as_draftable/up_acts_as_draftable.rb +172 -0
- data/lib/redmineup/acts_as_list/list.rb +282 -0
- data/lib/redmineup/acts_as_priceable/up_acts_as_priceable.rb +33 -0
- data/lib/redmineup/acts_as_taggable/tag.rb +81 -0
- data/lib/redmineup/acts_as_taggable/tag_list.rb +111 -0
- data/lib/redmineup/acts_as_taggable/tagging.rb +16 -0
- data/lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb +357 -0
- data/lib/redmineup/acts_as_viewed/up_acts_as_viewed.rb +274 -0
- data/lib/redmineup/acts_as_votable/up_acts_as_votable.rb +80 -0
- data/lib/redmineup/acts_as_votable/up_acts_as_voter.rb +20 -0
- data/lib/redmineup/acts_as_votable/votable.rb +323 -0
- data/lib/redmineup/acts_as_votable/vote.rb +28 -0
- data/lib/redmineup/acts_as_votable/voter.rb +131 -0
- data/lib/redmineup/assets_manager.rb +43 -0
- data/lib/redmineup/colors_helper.rb +192 -0
- data/lib/redmineup/compatibility/application_controller_patch.rb +33 -0
- data/lib/redmineup/compatibility/routing_mapper_patch.rb +25 -0
- data/lib/redmineup/currency/formatting.rb +224 -0
- data/lib/redmineup/currency/heuristics.rb +151 -0
- data/lib/redmineup/currency/loader.rb +23 -0
- data/lib/redmineup/currency.rb +450 -0
- data/lib/redmineup/engine.rb +4 -0
- data/lib/redmineup/helpers/external_assets_helper.rb +20 -0
- data/lib/redmineup/helpers/form_tag_helper.rb +88 -0
- data/lib/redmineup/helpers/rup_calendar_helper.rb +146 -0
- data/lib/redmineup/helpers/tags_helper.rb +13 -0
- data/lib/redmineup/helpers/vote_helper.rb +35 -0
- data/lib/redmineup/hooks/views_layouts_hook.rb +11 -0
- data/lib/redmineup/liquid/drops/attachment_drop.rb +47 -0
- data/lib/redmineup/liquid/drops/issue_relations_drop.rb +41 -0
- data/lib/redmineup/liquid/drops/issues_drop.rb +217 -0
- data/lib/redmineup/liquid/drops/news_drop.rb +54 -0
- data/lib/redmineup/liquid/drops/projects_drop.rb +86 -0
- data/lib/redmineup/liquid/drops/time_entries_drop.rb +65 -0
- data/lib/redmineup/liquid/drops/users_drop.rb +68 -0
- data/lib/redmineup/liquid/filters/arrays.rb +254 -0
- data/lib/redmineup/liquid/filters/base.rb +249 -0
- data/lib/redmineup/liquid/filters/colors.rb +31 -0
- data/lib/redmineup/money_helper.rb +66 -0
- data/lib/redmineup/patches/liquid_patch.rb +33 -0
- data/lib/redmineup/settings/money.rb +46 -0
- data/lib/redmineup/settings.rb +53 -0
- data/lib/redmineup/version.rb +3 -0
- data/lib/redmineup.rb +108 -0
- data/redmineup.gemspec +29 -0
- data/test/acts_as_draftable/draft_test.rb +29 -0
- data/test/acts_as_draftable/rup_acts_as_draftable_test.rb +178 -0
- data/test/acts_as_taggable/rup_acts_as_taggable_test.rb +350 -0
- data/test/acts_as_taggable/tag_list_test.rb +34 -0
- data/test/acts_as_taggable/tag_test.rb +72 -0
- data/test/acts_as_taggable/tagging_test.rb +15 -0
- data/test/acts_as_viewed/rup_acts_as_viewed_test.rb +47 -0
- data/test/acts_as_votable/rup_acts_as_votable_test.rb +19 -0
- data/test/acts_as_votable/rup_acts_as_voter_test.rb +14 -0
- data/test/acts_as_votable/votable_test.rb +507 -0
- data/test/acts_as_votable/voter_test.rb +296 -0
- data/test/currency_test.rb +292 -0
- data/test/database.yml +17 -0
- data/test/fixtures/attachments.yml +14 -0
- data/test/fixtures/issues.yml +24 -0
- data/test/fixtures/news.yml +8 -0
- data/test/fixtures/projects.yml +10 -0
- data/test/fixtures/taggings.yml +32 -0
- data/test/fixtures/tags.yml +11 -0
- data/test/fixtures/users.yml +9 -0
- data/test/fixtures/votable_caches.yml +2 -0
- data/test/fixtures/votables.yml +4 -0
- data/test/fixtures/voters.yml +6 -0
- data/test/liquid/drops/attachment_drop_test.rb +15 -0
- data/test/liquid/drops/issue_relations_drop_test.rb +24 -0
- data/test/liquid/drops/issues_drop_test.rb +38 -0
- data/test/liquid/drops/news_drop_test.rb +38 -0
- data/test/liquid/drops/projects_drop_test.rb +44 -0
- data/test/liquid/drops/uses_drop_test.rb +36 -0
- data/test/liquid/filters/arrays_filter_test.rb +31 -0
- data/test/liquid/filters/base_filter_test.rb +67 -0
- data/test/liquid/filters/colors_filter_test.rb +33 -0
- data/test/liquid/liquid_helper.rb +34 -0
- data/test/models/attachment.rb +3 -0
- data/test/models/issue.rb +21 -0
- data/test/models/issue_relation.rb +10 -0
- data/test/models/news.rb +3 -0
- data/test/models/project.rb +8 -0
- data/test/models/user.rb +11 -0
- data/test/models/vote_classes.rb +33 -0
- data/test/money_helper_test.rb +12 -0
- data/test/schema.rb +144 -0
- data/test/tags_helper_test.rb +29 -0
- data/test/test_helper.rb +66 -0
- data/test/vote_helper_test.rb +28 -0
- data/vendor/assets/images/money.png +0 -0
- data/vendor/assets/images/vcard.png +0 -0
- data/vendor/assets/javascripts/Chart.bundle.min.js +16 -0
- data/vendor/assets/javascripts/select2.js +2 -0
- data/vendor/assets/javascripts/select2_helpers.js +192 -0
- data/vendor/assets/stylesheets/money.css +96 -0
- data/vendor/assets/stylesheets/select2.css +424 -0
- metadata +295 -0
@@ -0,0 +1,296 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class VoterTest < ActiveSupport::TestCase
|
4
|
+
def votable
|
5
|
+
votables(:votable)
|
6
|
+
end
|
7
|
+
|
8
|
+
def voter
|
9
|
+
voters(:voter)
|
10
|
+
end
|
11
|
+
|
12
|
+
def votable_cache
|
13
|
+
votable_caches(:votable_cache)
|
14
|
+
end
|
15
|
+
|
16
|
+
def votable_klass
|
17
|
+
votable.class
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_be_voted_on_after_a_voter_has_voted
|
21
|
+
votable.vote_by :voter => voter
|
22
|
+
assert voter.voted_on?(votable)
|
23
|
+
assert voter.voted_for?(votable)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_not_be_voted_on_if_a_voter_has_not_voted
|
27
|
+
assert !voter.voted_on?(votable)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_be_voted_on_after_a_voter_has_voted_under_scope
|
31
|
+
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
32
|
+
assert voter.voted_on?(votable, :vote_scope => 'rank')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_not_be_voted_on_other_scope_after_a_voter_has_voted_under_one_scope
|
36
|
+
votable.vote_by(:voter => voter, :vote_scope => 'rank')
|
37
|
+
assert !voter.voted_on?(votable)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_be_voted_as_true_when_a_voter_has_voted_true
|
41
|
+
votable.vote_by(:voter => voter)
|
42
|
+
assert voter.voted_as_when_voted_on(votable)
|
43
|
+
assert voter.voted_as_when_voted_for(votable)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_be_voted_as_true_when_a_voter_has_voted_true_under_scope
|
47
|
+
votable.vote_by(:voter => voter, :vote_scope => 'rank')
|
48
|
+
assert voter.voted_as_when_voted_for(votable, :vote_scope => 'rank')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_be_voted_as_false_when_a_voter_has_voted_false
|
52
|
+
votable.vote_by(:voter => voter, :vote => false)
|
53
|
+
assert !voter.voted_as_when_voted_for(votable)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_be_voted_as_false_when_a_voter_has_voted_false_under_scope
|
57
|
+
votable.vote_by(:voter => voter, :vote => false, :vote_scope => 'rank')
|
58
|
+
assert !voter.voted_as_when_voted_for(votable, :vote_scope => 'rank')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_be_voted_as_nil_when_a_voter_has_never_voted
|
62
|
+
assert_nil voter.voted_as_when_voting_on(votable)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_be_voted_as_nil_when_a_voter_has_never_voted_under_the_scope
|
66
|
+
votable.vote_by :voter => voter, :vote => false, :vote_scope => 'rank'
|
67
|
+
assert_nil voter.voted_as_when_voting_on(votable)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_return_true_if_voter_has_voted_true
|
71
|
+
votable.vote_by(:voter => voter)
|
72
|
+
assert voter.voted_up_on?(votable)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_return_false_if_voter_has_not_voted_true
|
76
|
+
votable.vote_by(:voter => voter, :vote => false)
|
77
|
+
assert !voter.voted_up_on?(votable)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_return_true_if_the_voter_has_voted_false
|
81
|
+
votable.vote_by(:voter => voter, :vote => false)
|
82
|
+
assert voter.voted_down_on?(votable)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_return_false_if_the_voter_has_not_voted_false
|
86
|
+
votable.vote_by(:voter => voter, :vote => true)
|
87
|
+
assert !voter.voted_down_on?(votable)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_provide_reserve_functionality_voter_can_vote_on_votable
|
91
|
+
voter.vote(:votable => votable, :vote => 'bad')
|
92
|
+
assert !voter.voted_as_when_voting_on(votable)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_allow_the_voter_to_vote_up_a_model
|
96
|
+
voter.vote_up_for(votable)
|
97
|
+
assert_equal votable.get_up_votes.first.voter, voter
|
98
|
+
assert_equal votable.votes_for.up.first.voter, voter
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_allow_the_voter_to_vote_down_a_model
|
102
|
+
voter.vote_down_for(votable)
|
103
|
+
assert_equal votable.get_down_votes.first.voter, voter
|
104
|
+
assert_equal votable.votes_for.down.first.voter, voter
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_allow_the_voter_to_unvote_a_model
|
108
|
+
voter.vote_up_for(votable)
|
109
|
+
voter.unvote_for(votable)
|
110
|
+
assert_equal votable.find_votes_for.size, 0
|
111
|
+
assert_equal votable.votes_for.count, 0
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_get_all_of_the_voters_votes
|
115
|
+
voter.vote_up_for(votable)
|
116
|
+
assert_equal voter.find_votes.size, 1
|
117
|
+
assert_equal voter.votes.up.count, 1
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_get_all_of_the_voters_up_votes
|
121
|
+
voter.vote_up_for(votable)
|
122
|
+
assert_equal voter.find_up_votes.size, 1
|
123
|
+
assert_equal voter.votes.up.count, 1
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_get_all_of_the_voters_down_votes
|
127
|
+
voter.vote_down_for(votable)
|
128
|
+
assert_equal voter.find_down_votes.size, 1
|
129
|
+
assert_equal voter.votes.down.count, 1
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_get_all_of_the_votes_otes_for_a_class
|
133
|
+
votable.vote_by(:voter => voter)
|
134
|
+
votables(:votable2).vote_by(:voter => voter, :vote => false)
|
135
|
+
assert_equal voter.find_votes_for_class(votable_klass).size, 2
|
136
|
+
assert_equal voter.votes.for_type(votable_klass).count, 2
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_get_all_of_the_voters_up_votes_for_a_class
|
140
|
+
votable.vote_by(:voter => voter)
|
141
|
+
votables(:votable2).vote_by(:voter => voter, :vote => false)
|
142
|
+
assert_equal voter.find_up_votes_for_class(votable_klass).size, 1
|
143
|
+
assert_equal voter.votes.up.for_type(votable_klass).count, 1
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_get_all_of_the_voters_down_votes_for_a_class
|
147
|
+
votable.vote_by(:voter => voter)
|
148
|
+
votables(:votable2).vote_by( :voter => voter, :vote => false)
|
149
|
+
assert_equal voter.find_down_votes_for_class(votable_klass).size, 1
|
150
|
+
assert_equal voter.votes.down.for_type(votable_klass).count, 1
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_be_contained_to_instances
|
154
|
+
voter.vote(:votable => votable, :vote => false)
|
155
|
+
voters(:voter2).vote(:votable => votable)
|
156
|
+
|
157
|
+
assert !voter.voted_as_when_voting_on(votable)
|
158
|
+
end
|
159
|
+
|
160
|
+
# describe '#find_voted_items
|
161
|
+
|
162
|
+
def test_returns_objects_that_a_user_has_upvoted_for
|
163
|
+
votable.vote_by(:voter => voter)
|
164
|
+
votables(:votable2).vote_by(:voter => voters(:voter2))
|
165
|
+
assert voter.find_voted_items.include? votable
|
166
|
+
assert_equal voter.find_voted_items.size, 1
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_returns_objects_that_a_user_has_upvoted_for_using_scope
|
170
|
+
votable.vote_by(:voter => voter, :vote_scope => 'rank')
|
171
|
+
votables(:votable2).vote_by(:voter => voters(:voter2), :vote_scope => 'rank')
|
172
|
+
assert voter.find_voted_items(:vote_scope => 'rank').include? votable
|
173
|
+
assert_equal voter.find_voted_items(:vote_scope => 'rank').size, 1
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_returns_objects_that_a_user_has_downvoted_for
|
177
|
+
votable.vote_down(voter)
|
178
|
+
votables(:votable2).vote_down(voters(:voter2))
|
179
|
+
assert voter.find_voted_items.include? votable
|
180
|
+
assert_equal voter.find_voted_items.size, 1
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_returns_objects_that_a_user_has_downvoted_for_using_scope
|
184
|
+
votable.vote_down voter, :vote_scope => 'rank'
|
185
|
+
votables(:votable2).vote_down(voters(:voter2), :vote_scope => 'rank')
|
186
|
+
assert voter.find_voted_items(:vote_scope => 'rank').include? votable
|
187
|
+
assert_equal voter.find_voted_items(:vote_scope => 'rank').size, 1
|
188
|
+
end
|
189
|
+
|
190
|
+
# describe '#find_up_voted_items
|
191
|
+
def test_returns_objects_that_a_user_has_upvoted_for
|
192
|
+
votable.vote_by(:voter => voter)
|
193
|
+
votables(:votable2).vote_by :voter => voters(:voter2)
|
194
|
+
assert voter.find_up_voted_items.include? votable
|
195
|
+
assert_equal voter.find_up_voted_items.size, 1
|
196
|
+
assert voter.find_liked_items.include? votable
|
197
|
+
assert_equal voter.find_liked_items.size, 1
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_returns_objects_that_a_user_has_upvoted_for_using_scope
|
201
|
+
votable.vote_by(:voter => voter, :vote_scope => 'rank')
|
202
|
+
votables(:votable2).vote_by(:voter => voters(:voter2), :vote_scope => 'rank')
|
203
|
+
assert voter.find_up_voted_items(:vote_scope => 'rank').include? votable
|
204
|
+
assert_equal voter.find_up_voted_items(:vote_scope => 'rank').size, 1
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_does_not_return_objects_that_a_user_has_downvoted_for
|
208
|
+
votable.vote_down voter
|
209
|
+
assert_equal voter.find_up_voted_items.size, 0
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_does_not_return_objects_that_a_user_has_downvoted_for_using_scope
|
213
|
+
votable.vote_down voter, :vote_scope => 'rank'
|
214
|
+
assert_equal voter.find_up_voted_items(:vote_scope => 'rank').size, 0
|
215
|
+
end
|
216
|
+
|
217
|
+
# describe '#find_down_voted_items
|
218
|
+
|
219
|
+
def test_does_not_return_objects_that_a_user_has_upvoted_for
|
220
|
+
votable.vote_by :voter => voter
|
221
|
+
assert_equal voter.find_down_voted_items.size, 0
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_does_not_return_objects_that_a_user_has_upvoted_for_using_scope
|
225
|
+
votable.vote_by :voter => voter, :vote_scope => 'rank'
|
226
|
+
assert_equal voter.find_down_voted_items(:vote_scope => 'rank').size, 0
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_returns_objects_that_a_user_has_downvoted_for
|
230
|
+
votable.vote_down voter
|
231
|
+
votables(:votable2).vote_down voters(:voter2)
|
232
|
+
assert voter.find_down_voted_items.include? votable
|
233
|
+
assert_equal voter.find_down_voted_items.size, 1
|
234
|
+
assert voter.find_disliked_items.include? votable
|
235
|
+
assert_equal voter.find_disliked_items.size, 1
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_returns_objects_that_a_user_has_downvoted_for_using_scope
|
239
|
+
votable.vote_down voter, :vote_scope => 'rank'
|
240
|
+
votables(:votable2).vote_down voters(:voter2), :vote_scope => 'rank'
|
241
|
+
assert voter.find_down_voted_items(:vote_scope => 'rank').include? votable
|
242
|
+
assert_equal voter.find_down_voted_items(:vote_scope => 'rank').size, 1
|
243
|
+
end
|
244
|
+
|
245
|
+
# describe '#get_voted
|
246
|
+
def get_voted
|
247
|
+
voter.get_voted(votable.class)
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_returns_objects_of_a_class_that_a_voter_has_voted_for
|
251
|
+
votable.vote_by :voter => voter
|
252
|
+
votables(:votable2).vote_down voter
|
253
|
+
assert get_voted.include? votable
|
254
|
+
assert get_voted.include? votables(:votable2)
|
255
|
+
assert_equal get_voted.size, 2
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_does_not_return_objects_of_a_class_that_a_voter_has_voted_for
|
259
|
+
votable.vote_by :voter => voters(:voter2)
|
260
|
+
votables(:votable2).vote_by :voter => voters(:voter2)
|
261
|
+
assert_equal get_voted.size, 0
|
262
|
+
end
|
263
|
+
|
264
|
+
# describe '#get_up_voted
|
265
|
+
|
266
|
+
def get_up_voted
|
267
|
+
voter.get_up_voted(votable.class)
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_returns_up_voted_items_that_a_voter_has_voted_for
|
271
|
+
votable.vote_by :voter => voter
|
272
|
+
assert get_up_voted.include? votable
|
273
|
+
assert_equal get_up_voted.size, 1
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_does_not_return_down_voted_items_a_voter_has_voted_for
|
277
|
+
votable.vote_down voter
|
278
|
+
assert_equal get_up_voted.size, 0
|
279
|
+
end
|
280
|
+
|
281
|
+
# describe '#get_down_voted
|
282
|
+
def get_down_voted
|
283
|
+
voter.get_down_voted(votable.class)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_does_not_return_up_voted_items_that_a_voter_has_voted_for
|
287
|
+
votable.vote_by :voter => voter
|
288
|
+
assert_equal get_down_voted.size, 0
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_returns_down_voted_items_a_voter_has_voted_for
|
292
|
+
votable.vote_down voter
|
293
|
+
assert get_down_voted.include? votable
|
294
|
+
assert_equal get_down_voted.size, 1
|
295
|
+
end
|
296
|
+
end
|
@@ -0,0 +1,292 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
module Redmineup
|
4
|
+
class CurrencyTest < ActiveSupport::TestCase
|
5
|
+
FOO = '{ "priority": 1, "iso_code": "FOO", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 100, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "smallest_denomination": 1 }'
|
6
|
+
def register_foo(opts={})
|
7
|
+
foo_attrs = JSON.parse(FOO, :symbolize_names => true)
|
8
|
+
# Pass an array of attribute names to 'skip' to remove them from the 'FOO'
|
9
|
+
# json before registering foo as a currency.
|
10
|
+
Array(opts[:skip]).each { |attr| foo_attrs.delete(attr) }
|
11
|
+
Redmineup::Currency.register(foo_attrs)
|
12
|
+
end
|
13
|
+
|
14
|
+
def unregister_foo
|
15
|
+
Currency.unregister(JSON.parse(FOO, :symbolize_names => true))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_unknown_currency
|
19
|
+
assert_equal true, (Currency::UnknownCurrency < ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_matching_by_id
|
23
|
+
register_foo
|
24
|
+
foo = Currency.new(:foo)
|
25
|
+
assert_equal Currency.find(:foo), foo
|
26
|
+
assert_equal Currency.find(:FOO), foo
|
27
|
+
assert_equal Currency.find("foo"), foo
|
28
|
+
assert_equal Currency.find("FOO"), foo
|
29
|
+
unregister_foo
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_nil_unless_matching_given_id
|
33
|
+
assert_nil Currency.find("ZZZ")
|
34
|
+
end
|
35
|
+
|
36
|
+
class Mock
|
37
|
+
def to_s
|
38
|
+
'208'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_matching_by_given_numeric_code
|
43
|
+
assert_equal Currency.find_by_iso_numeric(978), Currency.new(:eur)
|
44
|
+
assert_not_equal Currency.find_by_iso_numeric(208), Currency.new(:eur)
|
45
|
+
assert_equal Currency.find_by_iso_numeric('840'), Currency.new(:usd)
|
46
|
+
|
47
|
+
assert_equal Currency.find_by_iso_numeric(Mock.new), Currency.new(:dkk)
|
48
|
+
assert_not_equal Currency.find_by_iso_numeric(Mock.new), Currency.new(:usd)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_nil_if_no_currency_has_the_given_num_code
|
52
|
+
assert_nil Currency.find_by_iso_numeric("non iso 4217 numeric code")
|
53
|
+
assert_nil Currency.find_by_iso_numeric(0)
|
54
|
+
end
|
55
|
+
|
56
|
+
# .all
|
57
|
+
def test_array_of_currencies
|
58
|
+
assert Currency.all.include?(Currency.new(:usd))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_include_register_currencies
|
62
|
+
register_foo
|
63
|
+
assert Currency.all.include?(Currency.new(:foo))
|
64
|
+
unregister_foo
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_sort_by_priority
|
68
|
+
assert_equal Currency.all.first.priority, 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_raises_missing_attributes_error_if_no_priority
|
72
|
+
register_foo(:skip => :priority)
|
73
|
+
assert_raises Currency::MissingAttributeError do
|
74
|
+
Currency.all
|
75
|
+
end
|
76
|
+
unregister_foo
|
77
|
+
end
|
78
|
+
|
79
|
+
#.register
|
80
|
+
def test_register_new_currency
|
81
|
+
Currency.register(
|
82
|
+
iso_code: "XXX",
|
83
|
+
name: "Golden Doubloon",
|
84
|
+
symbol: "%",
|
85
|
+
subunit_to_unit: 100
|
86
|
+
)
|
87
|
+
new_currency = Currency.find("XXX")
|
88
|
+
assert_not_equal nil, new_currency
|
89
|
+
assert_equal "Golden Doubloon", new_currency.name
|
90
|
+
assert_equal "%", new_currency.symbol
|
91
|
+
Currency.unregister(iso_code: "XXX")
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_present_iso_code
|
95
|
+
assert_raises KeyError do
|
96
|
+
Currency.register(name: "New currency")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# .unregister
|
101
|
+
def test_unregister_currency
|
102
|
+
Currency.register(iso_code: "XXX")
|
103
|
+
assert_not_equal nil, Currency.find("XXX")
|
104
|
+
Currency.unregister(iso_code: "XXX")
|
105
|
+
assert_nil Currency.find("XXX")
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_exitred_currency
|
109
|
+
Currency.register(iso_code: "XXX")
|
110
|
+
assert_equal true, Currency.unregister(iso_code: "XXX")
|
111
|
+
assert_equal false, Currency.unregister(iso_code: "XXX")
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_passed_iso_code
|
115
|
+
Currency.register(iso_code: "XXX")
|
116
|
+
Currency.register(iso_code: "YYZ")
|
117
|
+
#test with string
|
118
|
+
Currency.unregister("XXX")
|
119
|
+
assert_nil Currency.find("XXX")
|
120
|
+
#test with symbol
|
121
|
+
Currency.unregister(:yyz)
|
122
|
+
assert_nil Currency.find(:yyz)
|
123
|
+
end
|
124
|
+
|
125
|
+
# .each
|
126
|
+
def test_each_currency_to_block
|
127
|
+
assert_equal true, Currency.respond_to?(:each)
|
128
|
+
currencies = []
|
129
|
+
Currency.each do |currency|
|
130
|
+
currencies.push(currency)
|
131
|
+
end
|
132
|
+
|
133
|
+
assert_equal currencies[0], Currency.all[0]
|
134
|
+
assert_equal currencies[1], Currency.all[1]
|
135
|
+
assert_equal currencies[-1], Currency.all[-1]
|
136
|
+
end
|
137
|
+
|
138
|
+
# enumerable
|
139
|
+
def test_implemants_enumerable
|
140
|
+
assert_equal true, Currency.respond_to?(:all?)
|
141
|
+
assert_equal true, Currency.respond_to?(:each_with_index)
|
142
|
+
assert_equal true, Currency.respond_to?(:map)
|
143
|
+
assert_equal true, Currency.respond_to?(:select)
|
144
|
+
assert_equal true, Currency.respond_to?(:reject)
|
145
|
+
end
|
146
|
+
|
147
|
+
# #initialize
|
148
|
+
def test_lookups_data_from_loading_config
|
149
|
+
currency = Currency.new("USD")
|
150
|
+
assert_equal :usd, currency.id
|
151
|
+
assert_equal 1, currency.priority
|
152
|
+
assert_equal "USD", currency.iso_code
|
153
|
+
assert_equal "840", currency.iso_numeric
|
154
|
+
assert_equal "United States Dollar", currency.name
|
155
|
+
assert_equal ".", currency.decimal_mark
|
156
|
+
assert_equal ".", currency.separator
|
157
|
+
assert_equal ",", currency.thousands_separator
|
158
|
+
assert_equal ",", currency.delimiter
|
159
|
+
assert_equal 1, currency.smallest_denomination
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_raises_with_unknown_currency
|
163
|
+
assert_raises Currency::UnknownCurrency do
|
164
|
+
Currency.new("xxx")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# #<=>
|
169
|
+
def test_compare_by_priority
|
170
|
+
assert Currency.new(:cad) > Currency.new(:usd)
|
171
|
+
assert Currency.new(:usd) < Currency.new(:eur)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_compares_by_id_with_same_priority
|
175
|
+
Currency.register(iso_code: "ABD", priority: 15)
|
176
|
+
Currency.register(iso_code: "ABC", priority: 15)
|
177
|
+
Currency.register(iso_code: "ABE", priority: 15)
|
178
|
+
abd = Currency.find("ABD")
|
179
|
+
abc = Currency.find("ABC")
|
180
|
+
abe = Currency.find("ABE")
|
181
|
+
assert abd > abc
|
182
|
+
assert abe > abd
|
183
|
+
Currency.unregister("ABD")
|
184
|
+
Currency.unregister("ABC")
|
185
|
+
Currency.unregister("ABE")
|
186
|
+
end
|
187
|
+
|
188
|
+
# when one of the currencies has no 'priority' set
|
189
|
+
def test_compare_by_id
|
190
|
+
Currency.register(iso_code: "ABD") # No priority
|
191
|
+
abd = Currency.find(:abd)
|
192
|
+
usd = Currency.find(:usd)
|
193
|
+
assert abd < usd
|
194
|
+
Currency.unregister(iso_code: "ABD")
|
195
|
+
end
|
196
|
+
|
197
|
+
# "#=="
|
198
|
+
def test_strong_equal
|
199
|
+
eur = Currency.new(:eur)
|
200
|
+
assert eur === eur
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_equal_id_in_different_case
|
204
|
+
assert_equal Currency.new(:eur), Currency.new(:eur)
|
205
|
+
assert_equal Currency.new(:eur), Currency.new(:EUR)
|
206
|
+
assert_not_equal Currency.new(:eur), Currency.new(:usd)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_direct_comparison_currency_and_symbol_string
|
210
|
+
assert_equal Currency.new(:eur), 'eur'
|
211
|
+
assert_equal Currency.new(:eur), 'EUR'
|
212
|
+
assert_equal Currency.new(:eur), :eur
|
213
|
+
assert_equal Currency.new(:eur), :EUR
|
214
|
+
assert_not_equal Currency.new(:eur), 'usd'
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_comparison_with_nil
|
218
|
+
assert_not_equal nil, Currency.new(:eur)
|
219
|
+
end
|
220
|
+
|
221
|
+
#eql?
|
222
|
+
def test_eql
|
223
|
+
assert Currency.new(:eur).eql?(Currency.new(:eur))
|
224
|
+
assert !Currency.new(:eur).eql?(Currency.new(:usd))
|
225
|
+
end
|
226
|
+
|
227
|
+
# hash
|
228
|
+
def test_return_same_value_for_equal_objects
|
229
|
+
assert_equal Currency.new(:eur).hash, Currency.new(:eur).hash
|
230
|
+
assert_not_equal Currency.new(:eur).hash, Currency.new(:usd).hash
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_return_intersection_for_array_of_object
|
234
|
+
intersection = [Currency.new(:eur), Currency.new(:usd)] & [Currency.new(:eur)]
|
235
|
+
assert_equal intersection, [Currency.new(:eur)]
|
236
|
+
end
|
237
|
+
|
238
|
+
# inspect
|
239
|
+
def test_work_as_documented
|
240
|
+
assert_equal Currency.new(:usd).inspect, %Q{#<Redmineup::Currency id: usd, priority: 1, symbol_first: true, thousands_separator: ,, html_entity: $, decimal_mark: ., name: United States Dollar, symbol: $, subunit_to_unit: 100, exponent: 2.0, iso_code: USD, iso_numeric: 840, subunit: Cent, smallest_denomination: 1>}
|
241
|
+
end
|
242
|
+
|
243
|
+
# to_s
|
244
|
+
def test_to_s
|
245
|
+
assert_equal Currency.new(:usd).to_s, "USD"
|
246
|
+
assert_equal Currency.new(:eur).to_s, "EUR"
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_to_sym
|
250
|
+
assert_equal Currency.new(:usd).to_sym, :USD
|
251
|
+
assert_equal Currency.new(:eur).to_sym, :EUR
|
252
|
+
end
|
253
|
+
|
254
|
+
# to_currency
|
255
|
+
def test_to_currency
|
256
|
+
usd = Currency.new(:usd)
|
257
|
+
assert_equal usd.to_currency, usd
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_doesnt_create_new_symbol_indefiniteily
|
261
|
+
assert_raises Currency::UnknownCurrency do
|
262
|
+
Currency.new("bogus")
|
263
|
+
end
|
264
|
+
assert !Symbol.all_symbols.map{|s| s.to_s}.include?("bogus")
|
265
|
+
end
|
266
|
+
|
267
|
+
# code
|
268
|
+
def test_code_as_documented
|
269
|
+
assert_equal Currency.new(:usd).code, "$"
|
270
|
+
assert_equal Currency.new(:azn).code, "\u20BC"
|
271
|
+
end
|
272
|
+
|
273
|
+
# exponent
|
274
|
+
def test_conform_to_iso_4217
|
275
|
+
assert Currency.new(:jpy).exponent == 0
|
276
|
+
assert Currency.new(:usd).exponent == 2
|
277
|
+
assert Currency.new(:iqd).exponent == 3
|
278
|
+
end
|
279
|
+
|
280
|
+
# decimal_places
|
281
|
+
def test_proper_place_for_know_currency
|
282
|
+
assert Currency.new(:mro).decimal_places == 1
|
283
|
+
assert Currency.new(:usd).decimal_places == 2
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_proper_place_for_custom_currency
|
287
|
+
register_foo
|
288
|
+
assert_equal 2, Currency.new(:foo).decimal_places
|
289
|
+
unregister_foo
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
data/test/database.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sqlite:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: ':memory:'
|
4
|
+
|
5
|
+
mysql:
|
6
|
+
adapter: mysql2
|
7
|
+
database: redmineup_test
|
8
|
+
username: root
|
9
|
+
password: password
|
10
|
+
host: 127.0.0.1
|
11
|
+
|
12
|
+
postgresql:
|
13
|
+
adapter: postgresql
|
14
|
+
database: redmineup_test
|
15
|
+
user: postgres
|
16
|
+
password: password
|
17
|
+
host: 127.0.0.1
|
@@ -0,0 +1,14 @@
|
|
1
|
+
attachment_001:
|
2
|
+
created_on: 2006-07-19 21:07:27 +02:00
|
3
|
+
downloads: 0
|
4
|
+
content_type: text/plain
|
5
|
+
disk_filename: 060719210727_error281.txt
|
6
|
+
disk_directory: "2006/07"
|
7
|
+
container_id: 3
|
8
|
+
digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
|
9
|
+
id: 1
|
10
|
+
container_type: Issue
|
11
|
+
filesize: 28
|
12
|
+
filename: error281.txt
|
13
|
+
author: jonathan
|
14
|
+
description: An attachment
|
@@ -0,0 +1,24 @@
|
|
1
|
+
first_issue:
|
2
|
+
subject: Issue 1 subject
|
3
|
+
description: Some description for the issue
|
4
|
+
user: jonathan
|
5
|
+
author: jonathan
|
6
|
+
project: first_project
|
7
|
+
second_issue:
|
8
|
+
subject: Issue 2 subject
|
9
|
+
description: Second issue
|
10
|
+
user: jonathan
|
11
|
+
author: jonathan
|
12
|
+
project: first_project
|
13
|
+
third_issue:
|
14
|
+
subject: Issue 3 subject
|
15
|
+
description: Third issue
|
16
|
+
user: sam
|
17
|
+
author: homer
|
18
|
+
project: second_project
|
19
|
+
fourth_issue:
|
20
|
+
subject: Issue 4 subject
|
21
|
+
description: Fourth issue
|
22
|
+
user: sam
|
23
|
+
author: sam
|
24
|
+
project: second_project
|
@@ -0,0 +1,32 @@
|
|
1
|
+
tag_for_error:
|
2
|
+
tag: error
|
3
|
+
taggable: first_issue (Issue)
|
4
|
+
created_at: 2014-01-01
|
5
|
+
tag_for_error1:
|
6
|
+
tag: error
|
7
|
+
taggable: second_issue (Issue)
|
8
|
+
created_at: 2015-01-01
|
9
|
+
tag_for_error2:
|
10
|
+
tag: error
|
11
|
+
taggable: third_issue (Issue)
|
12
|
+
created_at: 2015-01-01
|
13
|
+
tag_for_feature:
|
14
|
+
tag: feature
|
15
|
+
taggable: second_issue (Issue)
|
16
|
+
created_at: 2015-01-01
|
17
|
+
tag_for_bug:
|
18
|
+
tag: bug
|
19
|
+
taggable: second_issue (Issue)
|
20
|
+
created_at: 2015-01-01
|
21
|
+
tag_for_question1:
|
22
|
+
tag: question
|
23
|
+
taggable: third_issue (Issue)
|
24
|
+
created_at: 2015-01-01
|
25
|
+
tag_for_question2:
|
26
|
+
tag: question
|
27
|
+
taggable: first_issue (Issue)
|
28
|
+
created_at: 2015-01-01
|
29
|
+
tag_for_question3:
|
30
|
+
tag: question
|
31
|
+
taggable: second_issue (Issue)
|
32
|
+
created_at: 2015-02-01
|