yeshoua_crm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +11 -0
  3. data/lib/yeshoua_crm.rb +87 -0
  4. data/lib/yeshoua_crm/acts_as_draftable/draft.rb +40 -0
  5. data/lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb +154 -0
  6. data/lib/yeshoua_crm/acts_as_list/list.rb +282 -0
  7. data/lib/yeshoua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb +350 -0
  8. data/lib/yeshoua_crm/acts_as_taggable/tag.rb +81 -0
  9. data/lib/yeshoua_crm/acts_as_taggable/tag_list.rb +111 -0
  10. data/lib/yeshoua_crm/acts_as_taggable/tagging.rb +16 -0
  11. data/lib/yeshoua_crm/acts_as_viewed/rcrm_acts_as_viewed.rb +274 -0
  12. data/lib/yeshoua_crm/acts_as_votable/rcrm_acts_as_votable.rb +80 -0
  13. data/lib/yeshoua_crm/acts_as_votable/rcrm_acts_as_voter.rb +20 -0
  14. data/lib/yeshoua_crm/acts_as_votable/votable.rb +323 -0
  15. data/lib/yeshoua_crm/acts_as_votable/vote.rb +28 -0
  16. data/lib/yeshoua_crm/acts_as_votable/voter.rb +131 -0
  17. data/lib/yeshoua_crm/assets_manager.rb +43 -0
  18. data/lib/yeshoua_crm/currency.rb +439 -0
  19. data/lib/yeshoua_crm/currency/formatting.rb +224 -0
  20. data/lib/yeshoua_crm/currency/heuristics.rb +151 -0
  21. data/lib/yeshoua_crm/currency/loader.rb +24 -0
  22. data/lib/yeshoua_crm/helpers/external_assets_helper.rb +17 -0
  23. data/lib/yeshoua_crm/helpers/form_tag_helper.rb +123 -0
  24. data/lib/yeshoua_crm/helpers/tags_helper.rb +13 -0
  25. data/lib/yeshoua_crm/helpers/vote_helper.rb +35 -0
  26. data/lib/yeshoua_crm/liquid/drops/cells_drop.rb +86 -0
  27. data/lib/yeshoua_crm/liquid/drops/issues_drop.rb +66 -0
  28. data/lib/yeshoua_crm/liquid/drops/news_drop.rb +54 -0
  29. data/lib/yeshoua_crm/liquid/drops/users_drop.rb +72 -0
  30. data/lib/yeshoua_crm/liquid/filters/arrays.rb +177 -0
  31. data/lib/yeshoua_crm/liquid/filters/base.rb +208 -0
  32. data/lib/yeshoua_crm/money_helper.rb +65 -0
  33. data/lib/yeshoua_crm/version.rb +3 -0
  34. data/test/acts_as_draftable/draft_test.rb +29 -0
  35. data/test/acts_as_draftable/rcrm_acts_as_draftable_test.rb +185 -0
  36. data/test/acts_as_taggable/rcrm_acts_as_taggable_test.rb +345 -0
  37. data/test/acts_as_taggable/tag_list_test.rb +34 -0
  38. data/test/acts_as_taggable/tag_test.rb +72 -0
  39. data/test/acts_as_taggable/tagging_test.rb +15 -0
  40. data/test/acts_as_viewed/rcrm_acts_as_viewed_test.rb +47 -0
  41. data/test/acts_as_votable/rcrm_acts_as_votable_test.rb +19 -0
  42. data/test/acts_as_votable/rcrm_acts_as_voter_test.rb +14 -0
  43. data/test/acts_as_votable/votable_test.rb +507 -0
  44. data/test/acts_as_votable/voter_test.rb +296 -0
  45. data/test/currency_test.rb +292 -0
  46. data/test/liquid/drops/issues_drop_test.rb +34 -0
  47. data/test/liquid/drops/news_drop_test.rb +38 -0
  48. data/test/liquid/drops/projects_drop_test.rb +44 -0
  49. data/test/liquid/drops/uses_drop_test.rb +36 -0
  50. data/test/liquid/filters/arrays_filter_test.rb +24 -0
  51. data/test/liquid/filters/base_filter_test.rb +63 -0
  52. data/test/liquid/liquid_helper.rb +32 -0
  53. data/test/models/issue.rb +14 -0
  54. data/test/models/news.rb +3 -0
  55. data/test/models/project.rb +8 -0
  56. data/test/models/user.rb +11 -0
  57. data/test/models/vote_classes.rb +33 -0
  58. data/test/money_helper_test.rb +12 -0
  59. data/test/schema.rb +121 -0
  60. data/test/tags_helper_test.rb +29 -0
  61. data/test/test_helper.rb +66 -0
  62. data/test/vote_helper_test.rb +28 -0
  63. data/yeshoua_crm.gemspec +28 -0
  64. metadata +206 -0
@@ -0,0 +1,345 @@
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(Cell.first)
6
+ assert_equivalent [tags(:error), tags(:question)], Issue.available_tags(:cell => Cell.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), Issue.find_tagged_with("question", :order => "issues.description DESC", :include => :user).to_a
18
+ end
19
+
20
+ def test_find_related_tags_with_non_existent_tags
21
+ assert_equal [], Issue.find_related_tags("ABCDEFG")
22
+ assert_equal [], Issue.find_related_tags(['HIJKLM'])
23
+ end
24
+
25
+ def test_find_related_tags_with_nothing
26
+ assert_equal [], Issue.find_related_tags("")
27
+ assert_equal [], Issue.find_related_tags([])
28
+ end
29
+
30
+ def test_find_tagged_with
31
+ assert_equivalent [issues(:first_issue), issues(:second_issue), issues(:third_issue)], Issue.find_tagged_with('"error"')
32
+ assert_equal Issue.find_tagged_with('"error"'), Issue.find_tagged_with(['error'])
33
+ assert_equal Issue.find_tagged_with('"error"'), Issue.find_tagged_with([tags(:error)])
34
+
35
+ assert_equivalent [issues(:second_issue),], Issue.find_tagged_with('New feature')
36
+ assert_equal Issue.find_tagged_with('New feature'), Issue.find_tagged_with(['New feature'])
37
+ assert_equal Issue.find_tagged_with('New feature'), Issue.find_tagged_with([tags(:feature)])
38
+ end
39
+
40
+ def test_find_tagged_with_nothing
41
+ assert_equal [], Issue.find_tagged_with("")
42
+ assert_equal [], Issue.find_tagged_with([])
43
+ end
44
+
45
+ def test_find_tagged_with_nonexistant_tags
46
+ assert_equal [], Issue.find_tagged_with('ABCDEFG')
47
+ assert_equal [], Issue.find_tagged_with(['HIJKLM'])
48
+ assert_equal [], Issue.find_tagged_with([YeshouaCrm::ActsAsTaggable::Tag.new(:name => 'unsaved tag')])
49
+ end
50
+
51
+ def test_find_tagged_with_match_all
52
+ assert_equivalent [issues(:second_issue)], Issue.find_tagged_with('error, "bug", "New feature", "question"', :match_all => true)
53
+ end
54
+
55
+ def test_find_tagged_with_match_all_and_include
56
+ assert_equivalent [issues(:first_issue), issues(:second_issue), issues(:third_issue)], Issue.find_tagged_with(['error', 'question'], :match_all => true, :include => :tags)
57
+ end
58
+
59
+ def test_find_tagged_with_conditions
60
+ assert_equal [], Issue.find_tagged_with('"error", bug', :conditions => '1=0')
61
+ end
62
+
63
+ def test_find_tagged_with_duplicates_options_hash
64
+ options = { :conditions => '1=1' }.freeze
65
+ assert_nothing_raised { Issue.find_tagged_with("error", options) }
66
+ end
67
+
68
+ def test_find_tagged_with_exclusions
69
+ assert_equivalent [issues(:first_issue), issues(:third_issue)], Issue.find_tagged_with("bug", :exclude => true)
70
+ assert_equivalent [issues(:first_issue), issues(:third_issue)], Issue.find_tagged_with("'bug', feature", :exclude => true)
71
+ end
72
+
73
+ def test_find_options_for_find_tagged_with_no_tags_returns_empty_hash
74
+ assert_equal Hash.new, Issue.find_options_for_find_tagged_with("")
75
+ assert_equal Hash.new, Issue.find_options_for_find_tagged_with([nil])
76
+ end
77
+
78
+ def test_find_options_for_find_tagged_with_leaves_arguments_unchanged
79
+ original_tags = issues(:second_issue).tags.dup
80
+ Issue.find_options_for_find_tagged_with(issues(:second_issue).tags)
81
+ assert_equal original_tags, issues(:second_issue).tags
82
+ end
83
+
84
+ def test_find_options_for_find_tagged_with_respects_custom_table_name
85
+ YeshouaCrm::ActsAsTaggable::Tagging.table_name = "categorisations"
86
+ YeshouaCrm::ActsAsTaggable::Tag.table_name = "categories"
87
+
88
+ options = Issue.find_options_for_find_tagged_with("Hello")
89
+
90
+ assert_no_match(/ taggings /, options[:joins])
91
+ assert_no_match(/ tags /, options[:joins])
92
+
93
+ assert_match(/ categorisations /, options[:joins])
94
+ assert_match(/ categories /, options[:joins])
95
+ ensure
96
+ YeshouaCrm::ActsAsTaggable::Tagging.table_name = "taggings"
97
+ YeshouaCrm::ActsAsTaggable::Tag.table_name = "tags"
98
+ end
99
+
100
+ def test_include_tags_on_find_tagged_with
101
+ assert_nothing_raised do
102
+ Issue.find_tagged_with('error', :include => :tags)
103
+ Issue.find_tagged_with("error", :include => { :taggings => :tag })
104
+ end
105
+ end
106
+
107
+ def test_basic_tag_counts_on_class
108
+ assert_tag_counts Issue.tag_counts, :error => 3, :feature => 1, :question => 3, :bug => 1
109
+ end
110
+
111
+ def test_tag_counts_on_class_with_date_conditions
112
+ assert_tag_counts Issue.tag_counts(:start_at => Date.new(2015, 1, 1)), :error => 2, :feature => 1, :question => 3, :bug => 1
113
+ assert_tag_counts Issue.tag_counts(:end_at => Date.new(2014, 12, 31)), :error => 1
114
+ assert_tag_counts Issue.tag_counts(:start_at => Date.new(2015, 1, 31), :end_at => Date.new(2015, 3, 1)), :question => 1
115
+ end
116
+
117
+ def test_tag_counts_on_class_with_frequencies
118
+ assert_tag_counts Issue.tag_counts(:at_least => 2), :question => 3, :error => 3
119
+ assert_tag_counts Issue.tag_counts(:at_most => 2), :bug => 1, :feature => 1
120
+ end
121
+
122
+ def test_tag_counts_on_class_with_frequencies_and_conditions
123
+ assert_tag_counts Issue.tag_counts(:at_least => 2, :conditions => '1=1'), :question => 3, :error => 3
124
+ end
125
+
126
+ def test_tag_counts_duplicates_options_hash
127
+ options = { :at_least => 2, :conditions => '1=1' }.freeze
128
+ assert_nothing_raised { Issue.tag_counts(options) }
129
+ end
130
+
131
+ def test_tag_counts_with_limit
132
+ assert_equal 2, Issue.tag_counts(:limit => 2).to_a.size
133
+ assert_equal 2, Issue.tag_counts(:at_least => 3, :limit => 2).to_a.size
134
+ end
135
+
136
+ def test_tag_counts_with_limit_and_order
137
+ assert_equivalent YeshouaCrm::ActsAsTaggable::Tag.where(:id => [tags(:error), tags(:question)]), Issue.tag_counts(:order => 'count desc', :limit => 2)
138
+ end
139
+
140
+ def test_tag_counts_on_association
141
+ assert_tag_counts users(:jonathan).issues.tag_counts, :error => 2, :bug => 1, :question => 2, :feature => 1
142
+ assert_tag_counts users(:sam).issues.tag_counts, :error => 1, :question => 1
143
+ end
144
+
145
+ def test_tag_counts_on_association_with_options
146
+ assert_equal [], users(:jonathan).issues.tag_counts(:conditions => '1=0')
147
+ assert_tag_counts users(:jonathan).issues.tag_counts(:at_most => 2), :bug => 1,
148
+ :feature => 1, :error => 2, :question => 2
149
+ end
150
+
151
+ def test_tag_counts_on_model_instance
152
+ assert_tag_counts issues(:third_issue).tag_counts, :error => 3, :question => 3
153
+ end
154
+
155
+ def test_tag_counts_on_model_instance_merges_conditions
156
+ assert_tag_counts issues(:first_issue).tag_counts(:conditions => "tags.name = 'error'"), :error => 3
157
+ end
158
+
159
+ def test_tag_counts_on_model_instance_with_no_tags
160
+ issue = Issue.create!(:description => "desc")
161
+
162
+ assert_tag_counts issue.tag_counts, {}
163
+ end
164
+
165
+ def test_tag_counts_should_sanitize_scope_conditions
166
+ Issue.send :where, { "tags.id = ?" => tags(:error).id } do
167
+ assert_tag_counts Issue.tag_counts, :error => 3
168
+ end
169
+ end
170
+
171
+ def test_tag_counts_respects_custom_table_names
172
+ YeshouaCrm::ActsAsTaggable::Tagging.table_name = "categorisations"
173
+ YeshouaCrm::ActsAsTaggable::Tag.table_name = "categories"
174
+
175
+ options = Issue.find_options_for_tag_counts(:start_at => 2.weeks.ago, :end_at => Date.today)
176
+ sql = options.values.join(' ')
177
+
178
+ assert_no_match %r{taggings}, sql
179
+ assert_no_match %r{tags}, sql
180
+
181
+ assert_match /categorisations/, sql
182
+ assert_match /categories/, sql
183
+ ensure
184
+ YeshouaCrm::ActsAsTaggable::Tagging.table_name = "taggings"
185
+ YeshouaCrm::ActsAsTaggable::Tag.table_name = "tags"
186
+ end
187
+
188
+ def test_tag_list_reader
189
+ assert_equivalent ["error", "question"], issues(:first_issue).tag_list
190
+ assert_equivalent ["error", "New feature", "bug", "question"], issues(:second_issue).tag_list
191
+ end
192
+
193
+ def test_reassign_tag_list
194
+ assert_equivalent ["error", "question"], issues(:first_issue).tag_list
195
+ issues(:first_issue).taggings.reload
196
+
197
+ # Only an update of the issues table should be executed, the other two queries are for savepoints
198
+ # assert_queries 3 do
199
+ # issues(:first_issue).update_attributes!(:description => "new name", :tag_list => issues(:first_issue).tag_list.to_s)
200
+ # end
201
+
202
+ assert_equivalent ["error", "question"], issues(:first_issue).tag_list
203
+ end
204
+
205
+ def test_new_tags
206
+ assert_equivalent ["error", "question"], issues(:first_issue).tag_list
207
+ issues(:first_issue).update_attributes!(:tag_list => "#{issues(:first_issue).tag_list}, One, Two")
208
+ assert_equivalent ["error", "question", "One", "Two"], issues(:first_issue).tag_list
209
+ end
210
+
211
+ def test_remove_tag
212
+ assert_equivalent ["error", "question"], issues(:first_issue).tag_list
213
+ issues(:first_issue).update_attributes!(:tag_list => "error")
214
+ assert_equivalent ["error"], issues(:first_issue).tag_list
215
+ end
216
+
217
+ def test_remove_and_add_tag
218
+ assert_equivalent ["error", "question"], issues(:first_issue).tag_list
219
+ issues(:first_issue).update_attributes!(:tag_list => "question, Beautiful")
220
+ assert_equivalent ["question", "Beautiful"], issues(:first_issue).tag_list
221
+ end
222
+
223
+ def test_tags_not_saved_if_validation_fails
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
231
+ end
232
+
233
+ def test_tag_list_accessors_on_new_record
234
+ p = Issue.new(:description => 'Test')
235
+
236
+ assert p.tag_list.blank?
237
+ p.tag_list = "One, Two"
238
+ assert_equal "One, Two", p.tag_list.to_s
239
+ end
240
+
241
+ def test_clear_tag_list_with_nil
242
+ p = issues(:second_issue)
243
+
244
+ assert !p.tag_list.blank?
245
+ assert p.update_attributes(:tag_list => nil)
246
+ assert p.tag_list.blank?
247
+
248
+ assert p.reload.tag_list.blank?
249
+ end
250
+
251
+ def test_clear_tag_list_with_string
252
+ p = issues(:second_issue)
253
+
254
+ assert !p.tag_list.blank?
255
+ assert p.update_attributes(:tag_list => ' ')
256
+ assert p.tag_list.blank?
257
+
258
+ assert p.reload.tag_list.blank?
259
+ end
260
+
261
+ def test_tag_list_reset_on_reload
262
+ p = issues(:second_issue)
263
+ assert !p.tag_list.blank?
264
+ p.tag_list = nil
265
+ assert p.tag_list.blank?
266
+ assert !p.reload.tag_list.blank?
267
+ end
268
+
269
+ def test_instance_tag_counts
270
+ assert_tag_counts issues(:first_issue).tag_counts, :error => 3, :question => 3
271
+ end
272
+
273
+ def test_tag_list_populated_when_cache_nil
274
+ assert_nil issues(:first_issue).cached_tag_list
275
+ issues(:first_issue).save!
276
+ assert_equal issues(:first_issue).tag_list.to_s, issues(:first_issue).cached_tag_list
277
+ end
278
+
279
+ def test_cached_tag_list_updated
280
+ assert_nil issues(:first_issue).cached_tag_list
281
+ issues(:first_issue).save!
282
+ assert_equivalent ["question", "error"], YeshouaCrm::ActsAsTaggable::TagList.from(issues(:first_issue).cached_tag_list)
283
+ issues(:first_issue).update_attributes!(:tag_list => "None")
284
+
285
+ assert_equal 'None', issues(:first_issue).cached_tag_list
286
+ assert_equal 'None', issues(:first_issue).reload.cached_tag_list
287
+ end
288
+
289
+ def test_clearing_cached_tag_list
290
+ # Generate the cached tag list
291
+ issues(:first_issue).save!
292
+
293
+ issues(:first_issue).update_attributes!(:tag_list => "")
294
+ assert_equal "", issues(:first_issue).cached_tag_list
295
+ end
296
+
297
+ def test_find_tagged_with_using_sti
298
+ issue = Issue.create!(description: 'Test', tag_list: 'Random')
299
+ assert_equal [issue], Issue.find_tagged_with('Random')
300
+ end
301
+
302
+ def test_case_insensitivity
303
+ assert_difference "YeshouaCrm::ActsAsTaggable::Tag.count", 1 do
304
+ Issue.create!(:description => "Test", :tag_list => "one")
305
+ Issue.create!(:description => "Test", :tag_list => "One")
306
+ end
307
+ assert_equal Issue.find_tagged_with("question"), Issue.find_tagged_with("question")
308
+ end
309
+
310
+ def test_tag_not_destroyed_when_unused
311
+ issues(:first_issue).tag_list.add("Random")
312
+ issues(:first_issue).save!
313
+
314
+ assert_no_difference 'YeshouaCrm::ActsAsTaggable::Tag.count' do
315
+ issues(:first_issue).tag_list.remove("Random")
316
+ issues(:first_issue).save!
317
+ end
318
+ end
319
+
320
+ def test_tag_destroyed_when_unused
321
+ YeshouaCrm::ActsAsTaggable::Tag.destroy_unused = true
322
+
323
+ issues(:first_issue).tag_list.add("Random")
324
+ issues(:first_issue).save!
325
+
326
+ assert_difference 'YeshouaCrm::ActsAsTaggable::Tag.count', -1 do
327
+ issues(:first_issue).tag_list.remove("Random")
328
+ issues(:first_issue).save!
329
+ end
330
+ ensure
331
+ YeshouaCrm::ActsAsTaggable::Tag.destroy_unused = false
332
+ end
333
+
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 = YeshouaCrm::ActsAsTaggable::TagList.new(%w(error bug))
6
+ end
7
+
8
+ def test_from
9
+ assert_equal %w(one two three), YeshouaCrm::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 'YeshouaCrm::ActsAsTaggable::Tag.count' do
6
+ YeshouaCrm::ActsAsTaggable::Tag.find_or_create_with_like_by_name('error')
7
+ end
8
+
9
+ assert_difference 'YeshouaCrm::ActsAsTaggable::Tag.count', 1 do
10
+ YeshouaCrm::ActsAsTaggable::Tag.find_or_create_with_like_by_name('new_tag')
11
+ end
12
+ end
13
+
14
+ def test_name_required
15
+ tag = YeshouaCrm::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 = YeshouaCrm::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("YeshouaCrm::ActsAsTaggable::Tagging.count", -YeshouaCrm::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 YeshouaCrm::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 YeshouaCrm::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 YeshouaCrm::ActsAsTaggable::Tag.counts(conditions: ['taggings.created_at >= ?', '2015-01-01']),
70
+ question: 3, error: 2, feature: 1, bug: 1
71
+ end
72
+ end