redmine_crm 0.0.23 → 0.0.53

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/README.md +166 -33
  4. data/Rakefile +3 -12
  5. data/app/controllers/redmine_crm_controller.rb +26 -0
  6. data/app/views/redmine_crm/_money.html.erb +44 -0
  7. data/app/views/redmine_crm/settings.html.erb +10 -0
  8. data/bitbucket-pipelines.yml +54 -0
  9. data/config/currency_iso.json +12 -0
  10. data/config/locales/en.yml +13 -0
  11. data/config/locales/ru.yml +13 -0
  12. data/config/routes.rb +5 -0
  13. data/doc/CHANGELOG +123 -2
  14. data/lib/redmine_crm/acts_as_draftable/draft.rb +40 -0
  15. data/lib/redmine_crm/acts_as_draftable/rcrm_acts_as_draftable.rb +172 -0
  16. data/lib/redmine_crm/acts_as_list/list.rb +282 -0
  17. data/lib/redmine_crm/{rcrm_acts_as_taggable.rb → acts_as_taggable/rcrm_acts_as_taggable.rb} +112 -93
  18. data/lib/redmine_crm/acts_as_taggable/tag.rb +81 -0
  19. data/lib/redmine_crm/acts_as_taggable/tag_list.rb +111 -0
  20. data/lib/redmine_crm/acts_as_taggable/tagging.rb +16 -0
  21. data/lib/redmine_crm/acts_as_viewed/rcrm_acts_as_viewed.rb +274 -0
  22. data/lib/redmine_crm/{rcrm_acts_as_votable.rb → acts_as_votable/rcrm_acts_as_votable.rb} +15 -14
  23. data/lib/redmine_crm/acts_as_votable/rcrm_acts_as_voter.rb +20 -0
  24. data/lib/redmine_crm/{votable.rb → acts_as_votable/votable.rb} +54 -65
  25. data/lib/redmine_crm/{vote.rb → acts_as_votable/vote.rb} +6 -8
  26. data/lib/redmine_crm/{voter.rb → acts_as_votable/voter.rb} +29 -34
  27. data/lib/redmine_crm/assets_manager.rb +43 -0
  28. data/lib/redmine_crm/colors_helper.rb +192 -0
  29. data/lib/redmine_crm/compatibility/application_controller_patch.rb +33 -0
  30. data/lib/redmine_crm/currency/formatting.rb +5 -8
  31. data/lib/redmine_crm/currency/heuristics.rb +1 -1
  32. data/lib/redmine_crm/currency/loader.rb +5 -6
  33. data/lib/redmine_crm/currency.rb +28 -17
  34. data/lib/redmine_crm/engine.rb +4 -0
  35. data/lib/redmine_crm/helpers/external_assets_helper.rb +19 -0
  36. data/lib/redmine_crm/helpers/form_tag_helper.rb +76 -0
  37. data/lib/redmine_crm/helpers/tags_helper.rb +1 -3
  38. data/lib/redmine_crm/helpers/vote_helper.rb +29 -32
  39. data/lib/redmine_crm/hooks/views_layouts_hook.rb +11 -0
  40. data/lib/redmine_crm/liquid/drops/issues_drop.rb +191 -0
  41. data/lib/redmine_crm/liquid/drops/news_drop.rb +54 -0
  42. data/lib/redmine_crm/liquid/drops/projects_drop.rb +86 -0
  43. data/lib/redmine_crm/liquid/drops/time_entries_drop.rb +65 -0
  44. data/lib/redmine_crm/liquid/drops/users_drop.rb +68 -0
  45. data/lib/redmine_crm/liquid/filters/arrays.rb +187 -0
  46. data/lib/redmine_crm/liquid/filters/base.rb +217 -0
  47. data/lib/redmine_crm/liquid/filters/colors.rb +31 -0
  48. data/lib/redmine_crm/money_helper.rb +17 -18
  49. data/lib/redmine_crm/settings/money.rb +46 -0
  50. data/lib/redmine_crm/settings.rb +53 -0
  51. data/lib/redmine_crm/version.rb +1 -1
  52. data/lib/redmine_crm.rb +60 -21
  53. data/redmine_crm.gemspec +12 -6
  54. data/test/acts_as_draftable/draft_test.rb +29 -0
  55. data/test/acts_as_draftable/rcrm_acts_as_draftable_test.rb +178 -0
  56. data/test/{acts_as_taggable_test.rb → acts_as_taggable/rcrm_acts_as_taggable_test.rb} +117 -156
  57. data/test/acts_as_taggable/tag_list_test.rb +34 -0
  58. data/test/acts_as_taggable/tag_test.rb +72 -0
  59. data/test/acts_as_taggable/tagging_test.rb +15 -0
  60. data/test/{viewed_test.rb → acts_as_viewed/rcrm_acts_as_viewed_test.rb} +17 -15
  61. data/test/acts_as_votable/rcrm_acts_as_votable_test.rb +19 -0
  62. data/test/acts_as_votable/rcrm_acts_as_voter_test.rb +14 -0
  63. data/test/{votable_model_test.rb → acts_as_votable/votable_test.rb} +34 -5
  64. data/test/{voter_model_test.rb → acts_as_votable/voter_test.rb} +8 -8
  65. data/test/currency_test.rb +10 -10
  66. data/test/database.yml +14 -14
  67. data/test/fixtures/issues.yml +13 -1
  68. data/test/fixtures/news.yml +8 -0
  69. data/test/fixtures/projects.yml +10 -0
  70. data/test/fixtures/users.yml +6 -2
  71. data/test/liquid/drops/issues_drop_test.rb +34 -0
  72. data/test/liquid/drops/news_drop_test.rb +38 -0
  73. data/test/liquid/drops/projects_drop_test.rb +44 -0
  74. data/test/liquid/drops/uses_drop_test.rb +36 -0
  75. data/test/liquid/filters/arrays_filter_test.rb +31 -0
  76. data/test/liquid/filters/base_filter_test.rb +63 -0
  77. data/test/liquid/filters/colors_filter_test.rb +33 -0
  78. data/test/liquid/liquid_helper.rb +34 -0
  79. data/test/models/issue.rb +14 -0
  80. data/test/models/news.rb +3 -0
  81. data/test/models/project.rb +8 -0
  82. data/test/{fixtures → models}/user.rb +5 -1
  83. data/test/{fixtures → models}/vote_classes.rb +0 -21
  84. data/test/money_helper_test.rb +5 -5
  85. data/test/schema.rb +33 -10
  86. data/test/test_helper.rb +20 -72
  87. data/vendor/assets/images/money.png +0 -0
  88. data/vendor/assets/images/vcard.png +0 -0
  89. data/vendor/assets/javascripts/Chart.bundle.min.js +16 -0
  90. data/vendor/assets/javascripts/select2.js +2 -0
  91. data/vendor/assets/javascripts/select2_helpers.js +192 -0
  92. data/vendor/assets/stylesheets/money.css +3 -0
  93. data/vendor/assets/stylesheets/select2.css +424 -0
  94. metadata +190 -40
  95. data/lib/redmine_crm/rcrm_acts_as_viewed.rb +0 -287
  96. data/lib/redmine_crm/rcrm_acts_as_voter.rb +0 -27
  97. data/lib/redmine_crm/tag.rb +0 -81
  98. data/lib/redmine_crm/tag_list.rb +0 -112
  99. data/lib/redmine_crm/tagging.rb +0 -20
  100. data/test/fixtures/issue.rb +0 -14
  101. data/test/tag_test.rb +0 -64
  102. data/test/tagging_test.rb +0 -14
  103. data/test/votable_test.rb +0 -17
@@ -1,278 +1,263 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RcrmActsAsTaggableTest < 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
2
8
 
3
- class ActsAsTaggableTest < ActiveSupport::TestCase
4
9
  def test_find_related_tags_with
5
10
  assert_equivalent [tags(:feature), tags(:bug), tags(:question)], Issue.find_related_tags("error")
6
11
  assert_equivalent [tags(:feature), tags(:error), tags(:question)], Issue.find_related_tags(tags(:bug))
7
- assert_equivalent [tags(:error), tags(:question)], Issue.find_related_tags(["New feature", "bug"])
12
+ assert_equivalent [tags(:error), tags(:question)], Issue.find_related_tags(["New feature", "bug"])
8
13
  assert_equivalent [tags(:feature), tags(:bug)], Issue.find_related_tags([tags(:error), tags(:question)])
9
14
  end
10
-
15
+
11
16
  def test_find_tagged_with_include_and_order
12
17
  assert_equal issues(:third_issue, :first_issue, :second_issue), Issue.find_tagged_with("question", :order => "issues.description DESC", :include => :user).to_a
13
18
  end
14
-
19
+
15
20
  def test_find_related_tags_with_non_existent_tags
16
21
  assert_equal [], Issue.find_related_tags("ABCDEFG")
17
22
  assert_equal [], Issue.find_related_tags(['HIJKLM'])
18
23
  end
19
-
24
+
20
25
  def test_find_related_tags_with_nothing
21
26
  assert_equal [], Issue.find_related_tags("")
22
- assert_equal [], Issue.find_related_tags([])
27
+ assert_equal [], Issue.find_related_tags([])
23
28
  end
24
-
29
+
25
30
  def test_find_tagged_with
26
31
  assert_equivalent [issues(:first_issue), issues(:second_issue), issues(:third_issue)], Issue.find_tagged_with('"error"')
27
32
  assert_equal Issue.find_tagged_with('"error"'), Issue.find_tagged_with(['error'])
28
33
  assert_equal Issue.find_tagged_with('"error"'), Issue.find_tagged_with([tags(:error)])
29
-
34
+
30
35
  assert_equivalent [issues(:second_issue),], Issue.find_tagged_with('New feature')
31
36
  assert_equal Issue.find_tagged_with('New feature'), Issue.find_tagged_with(['New feature'])
32
37
  assert_equal Issue.find_tagged_with('New feature'), Issue.find_tagged_with([tags(:feature)])
33
-
34
- # assert_equivalent [issues(:jonathan_bad_cat), issues(:jonathan_dog), issues(:second_issue)], Issue.find_tagged_with('"Crazy animal" Bad')
35
- # assert_equal Issue.find_tagged_with('"Crazy animal" Bad'), Issue.find_tagged_with(['Crazy animal', 'Bad'])
36
- # assert_equal Issue.find_tagged_with('"Crazy animal" Bad'), Issue.find_tagged_with([tags(:animal), tags(:bad)])
37
38
  end
38
-
39
+
39
40
  def test_find_tagged_with_nothing
40
41
  assert_equal [], Issue.find_tagged_with("")
41
42
  assert_equal [], Issue.find_tagged_with([])
42
43
  end
43
-
44
+
44
45
  def test_find_tagged_with_nonexistant_tags
45
46
  assert_equal [], Issue.find_tagged_with('ABCDEFG')
46
47
  assert_equal [], Issue.find_tagged_with(['HIJKLM'])
47
- assert_equal [], Issue.find_tagged_with([RedmineCrm::Tag.new(:name => 'unsaved tag')])
48
+ assert_equal [], Issue.find_tagged_with([RedmineCrm::ActsAsTaggable::Tag.new(:name => 'unsaved tag')])
48
49
  end
49
-
50
+
50
51
  def test_find_tagged_with_match_all
51
- assert_equivalent [issues(:second_issue)],
52
- Issue.find_tagged_with('error, "bug", "New feature", "question"', :match_all => true)
52
+ assert_equivalent [issues(:second_issue)], Issue.find_tagged_with('error, "bug", "New feature", "question"', :match_all => true)
53
53
  end
54
-
54
+
55
55
  def test_find_tagged_with_match_all_and_include
56
56
  assert_equivalent [issues(:first_issue), issues(:second_issue), issues(:third_issue)], Issue.find_tagged_with(['error', 'question'], :match_all => true, :include => :tags)
57
57
  end
58
-
58
+
59
59
  def test_find_tagged_with_conditions
60
60
  assert_equal [], Issue.find_tagged_with('"error", bug', :conditions => '1=0')
61
61
  end
62
-
62
+
63
63
  def test_find_tagged_with_duplicates_options_hash
64
64
  options = { :conditions => '1=1' }.freeze
65
65
  assert_nothing_raised { Issue.find_tagged_with("error", options) }
66
66
  end
67
-
67
+
68
68
  def test_find_tagged_with_exclusions
69
69
  assert_equivalent [issues(:first_issue), issues(:third_issue)], Issue.find_tagged_with("bug", :exclude => true)
70
70
  assert_equivalent [issues(:first_issue), issues(:third_issue)], Issue.find_tagged_with("'bug', feature", :exclude => true)
71
71
  end
72
-
72
+
73
73
  def test_find_options_for_find_tagged_with_no_tags_returns_empty_hash
74
74
  assert_equal Hash.new, Issue.find_options_for_find_tagged_with("")
75
75
  assert_equal Hash.new, Issue.find_options_for_find_tagged_with([nil])
76
76
  end
77
-
77
+
78
78
  def test_find_options_for_find_tagged_with_leaves_arguments_unchanged
79
79
  original_tags = issues(:second_issue).tags.dup
80
80
  Issue.find_options_for_find_tagged_with(issues(:second_issue).tags)
81
81
  assert_equal original_tags, issues(:second_issue).tags
82
82
  end
83
-
83
+
84
84
  def test_find_options_for_find_tagged_with_respects_custom_table_name
85
- RedmineCrm::Tagging.table_name = "categorisations"
86
- RedmineCrm::Tag.table_name = "categories"
87
-
85
+ RedmineCrm::ActsAsTaggable::Tagging.table_name = "categorisations"
86
+ RedmineCrm::ActsAsTaggable::Tag.table_name = "categories"
87
+
88
88
  options = Issue.find_options_for_find_tagged_with("Hello")
89
-
89
+
90
90
  assert_no_match(/ taggings /, options[:joins])
91
91
  assert_no_match(/ tags /, options[:joins])
92
-
92
+
93
93
  assert_match(/ categorisations /, options[:joins])
94
94
  assert_match(/ categories /, options[:joins])
95
95
  ensure
96
- RedmineCrm::Tagging.table_name = "taggings"
97
- RedmineCrm::Tag.table_name = "tags"
96
+ RedmineCrm::ActsAsTaggable::Tagging.table_name = "taggings"
97
+ RedmineCrm::ActsAsTaggable::Tag.table_name = "tags"
98
98
  end
99
-
99
+
100
100
  def test_include_tags_on_find_tagged_with
101
101
  assert_nothing_raised do
102
102
  Issue.find_tagged_with('error', :include => :tags)
103
103
  Issue.find_tagged_with("error", :include => { :taggings => :tag })
104
104
  end
105
105
  end
106
-
106
+
107
107
  def test_basic_tag_counts_on_class
108
108
  assert_tag_counts Issue.tag_counts, :error => 3, :feature => 1, :question => 3, :bug => 1
109
- # assert_tag_counts Issue.tag_counts, :good => 1, :question => 3, :question => 1, :bad => 1, :animal => 3
110
109
  end
111
-
110
+
112
111
  def test_tag_counts_on_class_with_date_conditions
113
112
  assert_tag_counts Issue.tag_counts(:start_at => Date.new(2015, 1, 1)), :error => 2, :feature => 1, :question => 3, :bug => 1
114
113
  assert_tag_counts Issue.tag_counts(:end_at => Date.new(2014, 12, 31)), :error => 1
115
114
  assert_tag_counts Issue.tag_counts(:start_at => Date.new(2015, 1, 31), :end_at => Date.new(2015, 3, 1)), :question => 1
116
-
117
- # assert_tag_counts Issue.tag_counts(:start_at => Date.new(2006, 8, 12), :end_at => Date.new(2006, 8, 19)), :good => 1, :question => 2, :bad => 1, :question => 1, :animal => 3
118
115
  end
119
-
116
+
120
117
  def test_tag_counts_on_class_with_frequencies
121
118
  assert_tag_counts Issue.tag_counts(:at_least => 2), :question => 3, :error => 3
122
119
  assert_tag_counts Issue.tag_counts(:at_most => 2), :bug => 1, :feature => 1
123
120
  end
124
-
121
+
125
122
  def test_tag_counts_on_class_with_frequencies_and_conditions
126
123
  assert_tag_counts Issue.tag_counts(:at_least => 2, :conditions => '1=1'), :question => 3, :error => 3
127
124
  end
128
-
125
+
129
126
  def test_tag_counts_duplicates_options_hash
130
127
  options = { :at_least => 2, :conditions => '1=1' }.freeze
131
128
  assert_nothing_raised { Issue.tag_counts(options) }
132
129
  end
133
-
130
+
134
131
  def test_tag_counts_with_limit
135
132
  assert_equal 2, Issue.tag_counts(:limit => 2).to_a.size
136
133
  assert_equal 2, Issue.tag_counts(:at_least => 3, :limit => 2).to_a.size
137
134
  end
138
-
135
+
139
136
  def test_tag_counts_with_limit_and_order
140
- assert_equivalent RedmineCrm::Tag.where(:id => [tags(:error), tags(:question)]), Issue.tag_counts(:order => 'count desc', :limit => 2)
137
+ assert_equivalent RedmineCrm::ActsAsTaggable::Tag.where(:id => [tags(:error), tags(:question)]), Issue.tag_counts(:order => 'count desc', :limit => 2)
141
138
  end
142
-
139
+
143
140
  def test_tag_counts_on_association
144
141
  assert_tag_counts users(:jonathan).issues.tag_counts, :error => 2, :bug => 1, :question => 2, :feature => 1
145
142
  assert_tag_counts users(:sam).issues.tag_counts, :error => 1, :question => 1
146
-
147
- # assert_tag_counts users(:jonathan).issues.tag_counts, :animal => 3, :question => 1, :question => 1, :bad => 1
148
- # assert_tag_counts users(:sam).issues.tag_counts, :question => 2, :good => 1
149
143
  end
150
-
144
+
151
145
  def test_tag_counts_on_association_with_options
152
146
  assert_equal [], users(:jonathan).issues.tag_counts(:conditions => '1=0')
153
- assert_tag_counts users(:jonathan).issues.tag_counts(:at_most => 2), :bug => 1,
147
+ assert_tag_counts users(:jonathan).issues.tag_counts(:at_most => 2), :bug => 1,
154
148
  :feature => 1, :error => 2, :question => 2
155
149
  end
156
-
157
- # def test_tag_counts_on_has_many_through
158
- # assert_tag_counts users(:jonathan).magazines.tag_counts, :good => 1
159
- # end
160
-
150
+
161
151
  def test_tag_counts_on_model_instance
162
152
  assert_tag_counts issues(:third_issue).tag_counts, :error => 3, :question => 3
163
153
  end
164
-
154
+
165
155
  def test_tag_counts_on_model_instance_merges_conditions
166
156
  assert_tag_counts issues(:first_issue).tag_counts(:conditions => "tags.name = 'error'"), :error => 3
167
157
  end
168
-
158
+
169
159
  def test_tag_counts_on_model_instance_with_no_tags
170
160
  issue = Issue.create!(:description => "desc")
171
-
161
+
172
162
  assert_tag_counts issue.tag_counts, {}
173
163
  end
174
-
164
+
175
165
  def test_tag_counts_should_sanitize_scope_conditions
176
166
  Issue.send :where, { "tags.id = ?" => tags(:error).id } do
177
167
  assert_tag_counts Issue.tag_counts, :error => 3
178
168
  end
179
169
  end
180
-
170
+
181
171
  def test_tag_counts_respects_custom_table_names
182
- RedmineCrm::Tagging.table_name = "categorisations"
183
- RedmineCrm::Tag.table_name = "categories"
184
-
172
+ RedmineCrm::ActsAsTaggable::Tagging.table_name = "categorisations"
173
+ RedmineCrm::ActsAsTaggable::Tag.table_name = "categories"
174
+
185
175
  options = Issue.find_options_for_tag_counts(:start_at => 2.weeks.ago, :end_at => Date.today)
186
176
  sql = options.values.join(' ')
187
-
188
- assert_no_match /taggings/, sql
189
- assert_no_match /tags/, sql
190
-
177
+
178
+ assert_no_match %r{taggings}, sql
179
+ assert_no_match %r{tags}, sql
180
+
191
181
  assert_match /categorisations/, sql
192
182
  assert_match /categories/, sql
193
183
  ensure
194
- RedmineCrm::Tagging.table_name = "taggings"
195
- RedmineCrm::Tag.table_name = "tags"
184
+ RedmineCrm::ActsAsTaggable::Tagging.table_name = "taggings"
185
+ RedmineCrm::ActsAsTaggable::Tag.table_name = "tags"
196
186
  end
197
-
187
+
198
188
  def test_tag_list_reader
199
189
  assert_equivalent ["error", "question"], issues(:first_issue).tag_list
200
190
  assert_equivalent ["error", "New feature", "bug", "question"], issues(:second_issue).tag_list
201
191
  end
202
-
192
+
203
193
  def test_reassign_tag_list
204
194
  assert_equivalent ["error", "question"], issues(:first_issue).tag_list
205
195
  issues(:first_issue).taggings.reload
206
-
196
+
207
197
  # Only an update of the issues table should be executed, the other two queries are for savepoints
208
198
  # assert_queries 3 do
209
199
  # issues(:first_issue).update_attributes!(:description => "new name", :tag_list => issues(:first_issue).tag_list.to_s)
210
200
  # end
211
-
201
+
212
202
  assert_equivalent ["error", "question"], issues(:first_issue).tag_list
213
203
  end
214
-
204
+
215
205
  def test_new_tags
216
206
  assert_equivalent ["error", "question"], issues(:first_issue).tag_list
217
207
  issues(:first_issue).update_attributes!(:tag_list => "#{issues(:first_issue).tag_list}, One, Two")
218
208
  assert_equivalent ["error", "question", "One", "Two"], issues(:first_issue).tag_list
219
209
  end
220
-
210
+
221
211
  def test_remove_tag
222
212
  assert_equivalent ["error", "question"], issues(:first_issue).tag_list
223
213
  issues(:first_issue).update_attributes!(:tag_list => "error")
224
214
  assert_equivalent ["error"], issues(:first_issue).tag_list
225
215
  end
226
-
227
- # def test_change_case_of_tags
228
- # original_tag_names = issues(:second_issue).tag_list
229
- # issues(:second_issue).update_attributes!(:tag_list => issues(:second_issue).tag_list.to_s.upcase)
230
-
231
- # # The new tag list is not uppercase becuase the AR finders are not case-sensitive
232
- # # and find the old tags when re-tagging with the uppercase tags.
233
- # assert_equivalent original_tag_names, issues(:second_issue).reload.tag_list
234
- # end
235
-
216
+
236
217
  def test_remove_and_add_tag
237
218
  assert_equivalent ["error", "question"], issues(:first_issue).tag_list
238
219
  issues(:first_issue).update_attributes!(:tag_list => "question, Beautiful")
239
220
  assert_equivalent ["question", "Beautiful"], issues(:first_issue).tag_list
240
221
  end
241
-
222
+
242
223
  def test_tags_not_saved_if_validation_fails
243
- assert_equivalent ["error", "question"], issues(:first_issue).tag_list
244
- assert !issues(:first_issue).update_attributes(:tag_list => "One, Two", :description => "")
245
- assert_equivalent ["error", "question"], Issue.find(issues(:first_issue).id).tag_list
224
+ issue = issues(:first_issue)
225
+ assert_equivalent ["error", "question"], issue.tag_list
226
+
227
+ issue.stub(:valid?, false) do
228
+ assert !issue.update_attributes(tag_list: "One, Two")
229
+ end
230
+ assert_equivalent ["error", "question"], Issue.find(issue.id).tag_list
246
231
  end
247
-
232
+
248
233
  def test_tag_list_accessors_on_new_record
249
234
  p = Issue.new(:description => 'Test')
250
-
235
+
251
236
  assert p.tag_list.blank?
252
237
  p.tag_list = "One, Two"
253
238
  assert_equal "One, Two", p.tag_list.to_s
254
239
  end
255
-
240
+
256
241
  def test_clear_tag_list_with_nil
257
242
  p = issues(:second_issue)
258
-
243
+
259
244
  assert !p.tag_list.blank?
260
245
  assert p.update_attributes(:tag_list => nil)
261
246
  assert p.tag_list.blank?
262
-
247
+
263
248
  assert p.reload.tag_list.blank?
264
249
  end
265
-
250
+
266
251
  def test_clear_tag_list_with_string
267
252
  p = issues(:second_issue)
268
-
253
+
269
254
  assert !p.tag_list.blank?
270
255
  assert p.update_attributes(:tag_list => ' ')
271
256
  assert p.tag_list.blank?
272
-
257
+
273
258
  assert p.reload.tag_list.blank?
274
259
  end
275
-
260
+
276
261
  def test_tag_list_reset_on_reload
277
262
  p = issues(:second_issue)
278
263
  assert !p.tag_list.blank?
@@ -280,105 +265,81 @@ class ActsAsTaggableTest < ActiveSupport::TestCase
280
265
  assert p.tag_list.blank?
281
266
  assert !p.reload.tag_list.blank?
282
267
  end
283
-
268
+
284
269
  def test_instance_tag_counts
285
270
  assert_tag_counts issues(:first_issue).tag_counts, :error => 3, :question => 3
286
271
  end
287
-
272
+
288
273
  def test_tag_list_populated_when_cache_nil
289
274
  assert_nil issues(:first_issue).cached_tag_list
290
275
  issues(:first_issue).save!
291
276
  assert_equal issues(:first_issue).tag_list.to_s, issues(:first_issue).cached_tag_list
292
277
  end
293
-
294
- # def test_cached_tag_list_used
295
- # issues(:first_issue).save!
296
- # issues(:first_issue).reload
297
-
298
- # assert_no_queries do
299
- # assert_equivalent ["error", "question"], issues(:first_issue).tag_list
300
- # end
301
- # end
302
-
303
- def test_cached_tag_list_not_used
304
- # Load fixture and column information
305
- issues(:first_issue).taggings(:reload)
306
-
307
- # assert_queries 1 do
308
- # # Tags association will be loaded
309
- # issues(:first_issue).tag_list
310
- # end
311
- end
312
-
278
+
313
279
  def test_cached_tag_list_updated
314
280
  assert_nil issues(:first_issue).cached_tag_list
315
281
  issues(:first_issue).save!
316
- assert_equivalent ["question", "error"], RedmineCrm::TagList.from(issues(:first_issue).cached_tag_list)
282
+ assert_equivalent ["question", "error"], RedmineCrm::ActsAsTaggable::TagList.from(issues(:first_issue).cached_tag_list)
317
283
  issues(:first_issue).update_attributes!(:tag_list => "None")
318
-
284
+
319
285
  assert_equal 'None', issues(:first_issue).cached_tag_list
320
286
  assert_equal 'None', issues(:first_issue).reload.cached_tag_list
321
287
  end
322
-
288
+
323
289
  def test_clearing_cached_tag_list
324
290
  # Generate the cached tag list
325
291
  issues(:first_issue).save!
326
-
292
+
327
293
  issues(:first_issue).update_attributes!(:tag_list => "")
328
294
  assert_equal "", issues(:first_issue).cached_tag_list
329
295
  end
330
296
 
331
297
  def test_find_tagged_with_using_sti
332
- special_Issue = SpecialIssue.create!(:description => "Test", :tag_list => "Random")
333
-
334
- assert_equal [special_Issue], SpecialIssue.find_tagged_with("Random")
335
- assert SpecialIssue.find_tagged_with("Random").include?(special_Issue)
336
- end
337
-
338
- # def test_tag_counts_using_sti
339
- # SpecialIssue.create!(:description => "Test", :tag_list => "question")
340
- # assert_tag_counts SpecialIssue.tag_counts, :question => 1
341
- # end
342
-
298
+ issue = Issue.create!(description: 'Test', tag_list: 'Random')
299
+ assert_equal [issue], Issue.find_tagged_with('Random')
300
+ end
301
+
343
302
  def test_case_insensitivity
344
- assert_difference "RedmineCrm::Tag.count", 1 do
303
+ assert_difference "RedmineCrm::ActsAsTaggable::Tag.count", 1 do
345
304
  Issue.create!(:description => "Test", :tag_list => "one")
346
305
  Issue.create!(:description => "Test", :tag_list => "One")
347
306
  end
348
307
  assert_equal Issue.find_tagged_with("question"), Issue.find_tagged_with("question")
349
308
  end
350
-
309
+
351
310
  def test_tag_not_destroyed_when_unused
352
311
  issues(:first_issue).tag_list.add("Random")
353
312
  issues(:first_issue).save!
354
-
355
- assert_no_difference 'RedmineCrm::Tag.count' do
313
+
314
+ assert_no_difference 'RedmineCrm::ActsAsTaggable::Tag.count' do
356
315
  issues(:first_issue).tag_list.remove("Random")
357
316
  issues(:first_issue).save!
358
317
  end
359
318
  end
360
-
319
+
361
320
  def test_tag_destroyed_when_unused
362
- RedmineCrm::Tag.destroy_unused = true
363
-
321
+ RedmineCrm::ActsAsTaggable::Tag.destroy_unused = true
322
+
364
323
  issues(:first_issue).tag_list.add("Random")
365
324
  issues(:first_issue).save!
366
-
367
- assert_difference 'RedmineCrm::Tag.count', -1 do
325
+
326
+ assert_difference 'RedmineCrm::ActsAsTaggable::Tag.count', -1 do
368
327
  issues(:first_issue).tag_list.remove("Random")
369
328
  issues(:first_issue).save!
370
329
  end
371
330
  ensure
372
- RedmineCrm::Tag.destroy_unused = false
331
+ RedmineCrm::ActsAsTaggable::Tag.destroy_unused = false
373
332
  end
374
- end
375
333
 
376
- # class ActsAsTaggableOnSteroidsFormTest < ActiveSupport::TestCase
377
- # include ActionView::Helpers::FormHelper
378
-
379
- # def test_tag_list_contents
380
- # fields_for :Issue, issues(:first_issue) do |f|
381
- # assert_match issues(:first_issue).tag_list.to_s, f.text_field(:tag_list)
382
- # end
383
- # end
384
- # end
334
+ def test_tags_condition
335
+ assert_equal "(tags_TABLE.name LIKE #{tags(:feature).id} OR tags_TABLE.name LIKE #{tags(:bug).id})",
336
+ Issue.send(:tags_condition, [tags(:feature), tags(:bug)], 'tags_TABLE')
337
+ end
338
+
339
+ def test_all_tags_list
340
+ issues(:first_issue).tag_list.remove('error')
341
+ issues(:first_issue).tag_list.add('new')
342
+ issues(:first_issue).save!
343
+ assert_equal %w(question new), issues(:first_issue).reload.all_tags_list
344
+ end
345
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class TagListTest < ActiveSupport::TestCase
4
+ def setup
5
+ @tag_list = RedmineCrm::ActsAsTaggable::TagList.new(%w(error bug))
6
+ end
7
+
8
+ def test_from
9
+ assert_equal %w(one two three), RedmineCrm::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 'RedmineCrm::ActsAsTaggable::Tag.count' do
6
+ RedmineCrm::ActsAsTaggable::Tag.find_or_create_with_like_by_name('error')
7
+ end
8
+
9
+ assert_difference 'RedmineCrm::ActsAsTaggable::Tag.count', 1 do
10
+ RedmineCrm::ActsAsTaggable::Tag.find_or_create_with_like_by_name('new_tag')
11
+ end
12
+ end
13
+
14
+ def test_name_required
15
+ tag = RedmineCrm::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 = RedmineCrm::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("RedmineCrm::ActsAsTaggable::Tagging.count", -RedmineCrm::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 RedmineCrm::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 RedmineCrm::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 RedmineCrm::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 RedmineCrm
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