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,350 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RupActsAsTaggableTest < ActiveSupport::TestCase
4
+ def test_available_tags
5
+ assert_equivalent [tags(:feature), tags(:bug), tags(:error), tags(:question)], Issue.available_tags(Project.first)
6
+ assert_equivalent [tags(:error), tags(:question)], Issue.available_tags(project: Project.first, limit: 2)
7
+ end
8
+
9
+ def test_find_related_tags_with
10
+ assert_equivalent [tags(:feature), tags(:bug), tags(:question)], Issue.find_related_tags('error')
11
+ assert_equivalent [tags(:feature), tags(:error), tags(:question)], Issue.find_related_tags(tags(:bug))
12
+ assert_equivalent [tags(:error), tags(:question)], Issue.find_related_tags(['New feature', 'bug'])
13
+ assert_equivalent [tags(:feature), tags(:bug)], Issue.find_related_tags([tags(:error), tags(:question)])
14
+ end
15
+
16
+ def test_find_tagged_with_include_and_order
17
+ assert_equal issues(:third_issue, :first_issue, :second_issue),
18
+ Issue.find_tagged_with('question', order: 'issues.description DESC', include: :user).to_a
19
+ end
20
+
21
+ def test_find_related_tags_with_non_existent_tags
22
+ assert_equal [], Issue.find_related_tags('ABCDEFG')
23
+ assert_equal [], Issue.find_related_tags(['HIJKLM'])
24
+ end
25
+
26
+ def test_find_related_tags_with_nothing
27
+ assert_equal [], Issue.find_related_tags('')
28
+ assert_equal [], Issue.find_related_tags([])
29
+ end
30
+
31
+ def test_find_tagged_with
32
+ assert_equivalent [issues(:first_issue), issues(:second_issue), issues(:third_issue)],
33
+ Issue.find_tagged_with('"error"')
34
+ assert_equal Issue.find_tagged_with('"error"'), Issue.find_tagged_with(['error'])
35
+ assert_equal Issue.find_tagged_with('"error"'), Issue.find_tagged_with([tags(:error)])
36
+
37
+ assert_equivalent [issues(:second_issue)], Issue.find_tagged_with('New feature')
38
+ assert_equal Issue.find_tagged_with('New feature'), Issue.find_tagged_with(['New feature'])
39
+ assert_equal Issue.find_tagged_with('New feature'), Issue.find_tagged_with([tags(:feature)])
40
+ end
41
+
42
+ def test_find_tagged_with_nothing
43
+ assert_equal [], Issue.find_tagged_with('')
44
+ assert_equal [], Issue.find_tagged_with([])
45
+ end
46
+
47
+ def test_find_tagged_with_nonexistant_tags
48
+ assert_equal [], Issue.find_tagged_with('ABCDEFG')
49
+ assert_equal [], Issue.find_tagged_with(['HIJKLM'])
50
+ assert_equal [], Issue.find_tagged_with([Redmineup::ActsAsTaggable::Tag.new(name: 'unsaved tag')])
51
+ end
52
+
53
+ def test_find_tagged_with_match_all
54
+ assert_equivalent [issues(:second_issue)],
55
+ Issue.find_tagged_with('error, "bug", "New feature", "question"', match_all: true)
56
+ end
57
+
58
+ def test_find_tagged_with_match_all_and_include
59
+ assert_equivalent [issues(:first_issue), issues(:second_issue), issues(:third_issue)],
60
+ Issue.find_tagged_with(%w[error question], match_all: true, include: :tags)
61
+ end
62
+
63
+ def test_find_tagged_with_conditions
64
+ assert_equal [], Issue.find_tagged_with('"error", bug', conditions: '1=0')
65
+ end
66
+
67
+ def test_find_tagged_with_duplicates_options_hash
68
+ options = { conditions: '1=1' }.freeze
69
+ assert_nothing_raised { Issue.find_tagged_with('error', options) }
70
+ end
71
+
72
+ def test_find_tagged_with_exclusions
73
+ assert_equivalent [issues(:first_issue), issues(:third_issue)], Issue.find_tagged_with('bug', exclude: true)
74
+ assert_equivalent [issues(:first_issue), issues(:third_issue)],
75
+ Issue.find_tagged_with("'bug', feature", exclude: true)
76
+ end
77
+
78
+ def test_find_options_for_find_tagged_with_no_tags_returns_empty_hash
79
+ assert_equal({}, Issue.find_options_for_find_tagged_with(''))
80
+ assert_equal({}, Issue.find_options_for_find_tagged_with([nil]))
81
+ end
82
+
83
+ def test_find_options_for_find_tagged_with_leaves_arguments_unchanged
84
+ original_tags = issues(:second_issue).tags.dup
85
+ Issue.find_options_for_find_tagged_with(issues(:second_issue).tags)
86
+ assert_equal original_tags, issues(:second_issue).tags
87
+ end
88
+
89
+ def test_find_options_for_find_tagged_with_respects_custom_table_name
90
+ Redmineup::ActsAsTaggable::Tagging.table_name = 'categorisations'
91
+ Redmineup::ActsAsTaggable::Tag.table_name = 'categories'
92
+
93
+ options = Issue.find_options_for_find_tagged_with('Hello')
94
+
95
+ assert_no_match(/ taggings /, options[:joins])
96
+ assert_no_match(/ tags /, options[:joins])
97
+
98
+ assert_match(/ categorisations /, options[:joins])
99
+ assert_match(/ categories /, options[:joins])
100
+ ensure
101
+ Redmineup::ActsAsTaggable::Tagging.table_name = 'taggings'
102
+ Redmineup::ActsAsTaggable::Tag.table_name = 'tags'
103
+ end
104
+
105
+ def test_include_tags_on_find_tagged_with
106
+ assert_nothing_raised do
107
+ Issue.find_tagged_with('error', include: :tags)
108
+ Issue.find_tagged_with('error', include: { taggings: :tag })
109
+ end
110
+ end
111
+
112
+ def test_basic_tag_counts_on_class
113
+ assert_tag_counts Issue.tag_counts, error: 3, feature: 1, question: 3, bug: 1
114
+ end
115
+
116
+ def test_tag_counts_on_class_with_date_conditions
117
+ assert_tag_counts Issue.tag_counts(start_at: Date.new(2015, 1, 1)), error: 2, feature: 1, question: 3, bug: 1
118
+ assert_tag_counts Issue.tag_counts(end_at: Date.new(2014, 12, 31)), error: 1
119
+ assert_tag_counts Issue.tag_counts(start_at: Date.new(2015, 1, 31), end_at: Date.new(2015, 3, 1)), question: 1
120
+ end
121
+
122
+ def test_tag_counts_on_class_with_frequencies
123
+ assert_tag_counts Issue.tag_counts(at_least: 2), question: 3, error: 3
124
+ assert_tag_counts Issue.tag_counts(at_most: 2), bug: 1, feature: 1
125
+ end
126
+
127
+ def test_tag_counts_on_class_with_frequencies_and_conditions
128
+ assert_tag_counts Issue.tag_counts(at_least: 2, conditions: '1=1'), question: 3, error: 3
129
+ end
130
+
131
+ def test_tag_counts_duplicates_options_hash
132
+ options = { at_least: 2, conditions: '1=1' }.freeze
133
+ assert_nothing_raised { Issue.tag_counts(options) }
134
+ end
135
+
136
+ def test_tag_counts_with_limit
137
+ assert_equal 2, Issue.tag_counts(limit: 2).to_a.size
138
+ assert_equal 2, Issue.tag_counts(at_least: 3, limit: 2).to_a.size
139
+ end
140
+
141
+ def test_tag_counts_with_limit_and_order
142
+ assert_equivalent Redmineup::ActsAsTaggable::Tag.where(id: [tags(:error), tags(:question)]),
143
+ Issue.tag_counts(order: 'count desc', limit: 2)
144
+ end
145
+
146
+ def test_tag_counts_on_association
147
+ assert_tag_counts users(:jonathan).issues.tag_counts, error: 2, bug: 1, question: 2, feature: 1
148
+ assert_tag_counts users(:sam).issues.tag_counts, error: 1, question: 1
149
+ end
150
+
151
+ def test_tag_counts_on_association_with_options
152
+ assert_equal [], users(:jonathan).issues.tag_counts(conditions: '1=0')
153
+ assert_tag_counts users(:jonathan).issues.tag_counts(at_most: 2), bug: 1, feature: 1, error: 2, question: 2
154
+ end
155
+
156
+ def test_tag_counts_on_model_instance
157
+ assert_tag_counts issues(:third_issue).tag_counts, error: 3, question: 3
158
+ end
159
+
160
+ def test_tag_counts_on_model_instance_merges_conditions
161
+ assert_tag_counts issues(:first_issue).tag_counts(conditions: "tags.name = 'error'"), error: 3
162
+ end
163
+
164
+ def test_tag_counts_on_model_instance_with_no_tags
165
+ issue = Issue.create!(description: 'desc')
166
+
167
+ assert_tag_counts issue.tag_counts, {}
168
+ end
169
+
170
+ def test_tag_counts_should_sanitize_scope_conditions
171
+ Issue.send :where, { 'tags.id = ?' => tags(:error).id } do
172
+ assert_tag_counts Issue.tag_counts, error: 3
173
+ end
174
+ end
175
+
176
+ def test_tag_counts_respects_custom_table_names
177
+ Redmineup::ActsAsTaggable::Tagging.table_name = 'categorisations'
178
+ Redmineup::ActsAsTaggable::Tag.table_name = 'categories'
179
+
180
+ options = Issue.find_options_for_tag_counts(start_at: 2.weeks.ago, end_at: Date.today)
181
+ sql = options.values.join(' ')
182
+
183
+ assert_no_match(/taggings/, sql)
184
+ assert_no_match(/tags/, sql)
185
+
186
+ assert_match(/categorisations/, sql)
187
+ assert_match(/categories/, sql)
188
+ ensure
189
+ Redmineup::ActsAsTaggable::Tagging.table_name = 'taggings'
190
+ Redmineup::ActsAsTaggable::Tag.table_name = 'tags'
191
+ end
192
+
193
+ def test_tag_list_reader
194
+ assert_equivalent %w[error question], issues(:first_issue).tag_list
195
+ assert_equivalent ['error', 'New feature', 'bug', 'question'], issues(:second_issue).tag_list
196
+ end
197
+
198
+ def test_reassign_tag_list
199
+ assert_equivalent %w[error question], issues(:first_issue).tag_list
200
+ issues(:first_issue).taggings.reload
201
+
202
+ # Only an update of the issues table should be executed, the other two queries are for savepoints
203
+ # assert_queries 3 do
204
+ # issues(:first_issue).update!(:description => "new name", :tag_list => issues(:first_issue).tag_list.to_s)
205
+ # end
206
+
207
+ assert_equivalent %w[error question], issues(:first_issue).tag_list
208
+ end
209
+
210
+ def test_new_tags
211
+ assert_equivalent %w[error question], issues(:first_issue).tag_list
212
+ issues(:first_issue).update!(tag_list: "#{issues(:first_issue).tag_list}, One, Two")
213
+ assert_equivalent %w[error question One Two], issues(:first_issue).tag_list
214
+ end
215
+
216
+ def test_remove_tag
217
+ assert_equivalent %w[error question], issues(:first_issue).tag_list
218
+ issues(:first_issue).update!(tag_list: 'error')
219
+ assert_equivalent ['error'], issues(:first_issue).tag_list
220
+ end
221
+
222
+ def test_remove_and_add_tag
223
+ assert_equivalent %w[error question], issues(:first_issue).tag_list
224
+ issues(:first_issue).update!(tag_list: 'question, Beautiful')
225
+ assert_equivalent %w[question Beautiful], issues(:first_issue).tag_list
226
+ end
227
+
228
+ def test_tags_not_saved_if_validation_fails
229
+ issue = issues(:first_issue)
230
+ assert_equivalent %w[error question], issue.tag_list
231
+
232
+ issue.stub(:valid?, false) do
233
+ assert !issue.update(tag_list: 'One, Two')
234
+ end
235
+ assert_equivalent %w[error question], Issue.find(issue.id).tag_list
236
+ end
237
+
238
+ def test_tag_list_accessors_on_new_record
239
+ p = Issue.new(description: 'Test')
240
+
241
+ assert p.tag_list.blank?
242
+ p.tag_list = 'One, Two'
243
+ assert_equal 'One, Two', p.tag_list.to_s
244
+ end
245
+
246
+ def test_clear_tag_list_with_nil
247
+ p = issues(:second_issue)
248
+
249
+ assert !p.tag_list.blank?
250
+ assert p.update(tag_list: nil)
251
+ assert p.tag_list.blank?
252
+
253
+ assert p.reload.tag_list.blank?
254
+ end
255
+
256
+ def test_clear_tag_list_with_string
257
+ p = issues(:second_issue)
258
+
259
+ assert !p.tag_list.blank?
260
+ assert p.update(tag_list: ' ')
261
+ assert p.tag_list.blank?
262
+
263
+ assert p.reload.tag_list.blank?
264
+ end
265
+
266
+ def test_tag_list_reset_on_reload
267
+ p = issues(:second_issue)
268
+ assert !p.tag_list.blank?
269
+ p.tag_list = nil
270
+ assert p.tag_list.blank?
271
+ assert !p.reload.tag_list.blank?
272
+ end
273
+
274
+ def test_instance_tag_counts
275
+ assert_tag_counts issues(:first_issue).tag_counts, error: 3, question: 3
276
+ end
277
+
278
+ def test_tag_list_populated_when_cache_nil
279
+ assert_nil issues(:first_issue).cached_tag_list
280
+ issues(:first_issue).save!
281
+ assert_equal issues(:first_issue).tag_list.to_s, issues(:first_issue).cached_tag_list
282
+ end
283
+
284
+ def test_cached_tag_list_updated
285
+ assert_nil issues(:first_issue).cached_tag_list
286
+ issues(:first_issue).save!
287
+ assert_equivalent %w[question error], Redmineup::ActsAsTaggable::TagList.from(issues(:first_issue).cached_tag_list)
288
+ issues(:first_issue).update!(tag_list: 'None')
289
+
290
+ assert_equal 'None', issues(:first_issue).cached_tag_list
291
+ assert_equal 'None', issues(:first_issue).reload.cached_tag_list
292
+ end
293
+
294
+ def test_clearing_cached_tag_list
295
+ # Generate the cached tag list
296
+ issues(:first_issue).save!
297
+
298
+ issues(:first_issue).update!(tag_list: '')
299
+ assert_equal '', issues(:first_issue).cached_tag_list
300
+ end
301
+
302
+ def test_find_tagged_with_using_sti
303
+ issue = Issue.create!(description: 'Test', tag_list: 'Random')
304
+ assert_equal [issue], Issue.find_tagged_with('Random')
305
+ end
306
+
307
+ def test_case_insensitivity
308
+ assert_difference 'Redmineup::ActsAsTaggable::Tag.count', 1 do
309
+ Issue.create!(description: 'Test', tag_list: 'one')
310
+ Issue.create!(description: 'Test', tag_list: 'One')
311
+ end
312
+ assert_equal Issue.find_tagged_with('question'), Issue.find_tagged_with('question')
313
+ end
314
+
315
+ def test_tag_not_destroyed_when_unused
316
+ issues(:first_issue).tag_list.add('Random')
317
+ issues(:first_issue).save!
318
+
319
+ assert_no_difference 'Redmineup::ActsAsTaggable::Tag.count' do
320
+ issues(:first_issue).tag_list.remove('Random')
321
+ issues(:first_issue).save!
322
+ end
323
+ end
324
+
325
+ def test_tag_destroyed_when_unused
326
+ Redmineup::ActsAsTaggable::Tag.destroy_unused = true
327
+
328
+ issues(:first_issue).tag_list.add('Random')
329
+ issues(:first_issue).save!
330
+
331
+ assert_difference 'Redmineup::ActsAsTaggable::Tag.count', -1 do
332
+ issues(:first_issue).tag_list.remove('Random')
333
+ issues(:first_issue).save!
334
+ end
335
+ ensure
336
+ Redmineup::ActsAsTaggable::Tag.destroy_unused = false
337
+ end
338
+
339
+ def test_tags_condition
340
+ assert_equal "(tags_TABLE.name LIKE #{tags(:feature).id} OR tags_TABLE.name LIKE #{tags(:bug).id})",
341
+ Issue.send(:tags_condition, [tags(:feature), tags(:bug)], 'tags_TABLE')
342
+ end
343
+
344
+ def test_all_tags_list
345
+ issues(:first_issue).tag_list.remove('error')
346
+ issues(:first_issue).tag_list.add('new')
347
+ issues(:first_issue).save!
348
+ assert_equal %w[question new], issues(:first_issue).reload.all_tags_list
349
+ end
350
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class TagListTest < ActiveSupport::TestCase
4
+ def setup
5
+ @tag_list = Redmineup::ActsAsTaggable::TagList.new(%w(error bug))
6
+ end
7
+
8
+ def test_from
9
+ assert_equal %w(one two three), Redmineup::ActsAsTaggable::TagList.from('one, two, two, three, three, three')
10
+ end
11
+
12
+ def test_add
13
+ @tag_list.add(['new_tag'])
14
+ assert_equal %w(error bug new_tag), @tag_list
15
+ end
16
+
17
+ def test_remove
18
+ @tag_list.remove(['old_tag'])
19
+ assert_equal %w(error bug), @tag_list
20
+ @tag_list.remove(['error'])
21
+ assert_equal %w(bug), @tag_list
22
+ end
23
+
24
+ def test_toggle
25
+ @tag_list.toggle(['new_tag'])
26
+ assert_equal %w(error bug new_tag), @tag_list
27
+ @tag_list.toggle(['error'])
28
+ assert_equal %w(bug new_tag), @tag_list
29
+ end
30
+
31
+ def test_to_s
32
+ assert_equal 'error, bug', @tag_list.to_s
33
+ end
34
+ end
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class TagTest < ActiveSupport::TestCase
4
+ def test_find_or_create_with_like_by_name
5
+ assert_no_difference 'Redmineup::ActsAsTaggable::Tag.count' do
6
+ Redmineup::ActsAsTaggable::Tag.find_or_create_with_like_by_name('error')
7
+ end
8
+
9
+ assert_difference 'Redmineup::ActsAsTaggable::Tag.count', 1 do
10
+ Redmineup::ActsAsTaggable::Tag.find_or_create_with_like_by_name('new_tag')
11
+ end
12
+ end
13
+
14
+ def test_name_required
15
+ tag = Redmineup::ActsAsTaggable::Tag.new
16
+ tag.valid?
17
+ assert_match /blank/, tag.errors[:name].to_s
18
+ end
19
+
20
+ def test_name_unique
21
+ tag = Redmineup::ActsAsTaggable::Tag.create!(name: 'My tag')
22
+ tag_with_same_name = tag.dup
23
+ assert !tag_with_same_name.valid?
24
+ assert_match /not uniq/, tag_with_same_name.errors[:name].to_s
25
+ end
26
+
27
+ def test_taggings
28
+ assert_equivalent [taggings(:tag_for_error), taggings(:tag_for_error1), taggings(:tag_for_error2)], tags(:error).taggings
29
+ assert_equivalent [taggings(:tag_for_question1), taggings(:tag_for_question2), taggings(:tag_for_question3)], tags(:question).taggings
30
+ end
31
+
32
+ def test_to_s
33
+ assert_equal tags(:error).name, tags(:error).to_s
34
+ end
35
+
36
+ def test_tag_is_equal_to_itself
37
+ tag = tags(:error)
38
+ assert_equal tag, tag
39
+ end
40
+
41
+ def test_tag_is_equal_to_tag_with_same_name
42
+ tag = tags(:error)
43
+ assert_equal tag, tag.dup
44
+ end
45
+
46
+ def test_tag_is_not_equal_to_tag_with_other_name
47
+ tag = tags(:error)
48
+ other_tag = tag.dup
49
+ other_tag.name = 'not error'
50
+ assert_not_equal tag, other_tag
51
+ end
52
+
53
+ def test_taggings_removed_when_tag_destroyed
54
+ assert_difference("Redmineup::ActsAsTaggable::Tagging.count", -Redmineup::ActsAsTaggable::Tagging.where(tag_id: tags(:error).id).count) do
55
+ assert tags(:error).destroy
56
+ end
57
+ end
58
+
59
+ def test_all_counts
60
+ assert_tag_counts Redmineup::ActsAsTaggable::Tag.counts, error: 3, feature: 1, bug: 1, question: 3
61
+ end
62
+
63
+ def test_all_counts_with_string_conditions
64
+ assert_tag_counts Redmineup::ActsAsTaggable::Tag.counts(conditions: 'taggings.created_at >= \'2015-01-01\''),
65
+ question: 3, error: 2, feature: 1, bug: 1
66
+ end
67
+
68
+ def test_all_counts_with_array_conditions
69
+ assert_tag_counts Redmineup::ActsAsTaggable::Tag.counts(conditions: ['taggings.created_at >= ?', '2015-01-01']),
70
+ question: 3, error: 2, feature: 1, bug: 1
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ module Redmineup
4
+ module ActsAsTaggable
5
+ class TaggingTest < ActiveSupport::TestCase
6
+ def test_tag
7
+ assert_equal tags(:error), taggings(:tag_for_error).tag
8
+ end
9
+
10
+ def test_taggable
11
+ assert_equal issues(:first_issue), taggings(:tag_for_error).taggable
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RupActsAsViewedTest < ActiveSupport::TestCase
4
+ def user
5
+ users(:jonathan)
6
+ end
7
+
8
+ def issue
9
+ issues(:first_issue)
10
+ end
11
+
12
+ def test_zero_of_view_count
13
+ assert_equal issue.view_count, '0(0)'
14
+ end
15
+
16
+ def test_can_view
17
+ issue.view '127.0.0.1', user
18
+ assert_equal issue.view_count, '1(1)'
19
+ # second view change only total count
20
+ issue.view '127.0.0.1', user
21
+ assert_equal issue.view_count, '2(1)'
22
+ end
23
+
24
+ def test_viewed_by
25
+ assert !issue.viewed_by?('127.0.0.1', user)
26
+ issue.view '127.0.0.1', user
27
+ assert issue.viewed_by?('127.0.0.1', user)
28
+ end
29
+
30
+ def test_twice_view
31
+ issue.view '127.0.0.1', user
32
+ issue.view '127.0.0.1', user
33
+ assert_equal '2(1)', issue.view_count
34
+ end
35
+
36
+ def test_viewed?
37
+ assert !issue.viewed?
38
+ issue.view '127.0.0.1', user
39
+ assert issue.viewed?
40
+ end
41
+
42
+ def test_find_viewed_by
43
+ assert_equal [], Issue.find_viewed_by(user)
44
+ issue.view '127.0.0.1', user
45
+ assert_equal [issue], Issue.find_viewed_by(user)
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RupActsAsVotableTest < ActiveSupport::TestCase
4
+
5
+ class NotVotable < ActiveRecord::Base; end
6
+ def test_that_votable_returns_false_unless_included
7
+ assert_equal NotVotable.votable?, false
8
+ end
9
+
10
+ def test_that_votable_returns_true_if_included
11
+ assert_equal Votable.votable?, true
12
+ end
13
+
14
+ def test_behaves_like_votable_model
15
+ assert Voter.create(:name => 'i can vote!')
16
+ assert VotableCache.create(:name => 'voting model with cache')
17
+ assert VotableVoter.create(:name => 'i can vote too!')
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RupActsAsVoterTest < ActiveSupport::TestCase
4
+
5
+ class NotVoter < ActiveRecord::Base; end
6
+ def test_that_voter_returns_false_unless_included
7
+ assert_equal NotVoter.voter?, false
8
+ end
9
+
10
+ def test_that_voter_returns_true_if_included
11
+ assert_equal Voter.voter?, true
12
+ assert_equal VotableVoter.voter?, true
13
+ end
14
+ end