acts-as-taggable-on 12.0.0 → 13.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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/acts-as-taggable-on/tag.rb +5 -13
  3. data/lib/acts-as-taggable-on/tag_list.rb +1 -1
  4. data/lib/acts-as-taggable-on/taggable/core.rb +0 -3
  5. data/lib/acts-as-taggable-on/taggable/tagged_with_query.rb +0 -5
  6. data/lib/acts-as-taggable-on/version.rb +1 -1
  7. data/lib/acts-as-taggable-on.rb +1 -1
  8. metadata +10 -170
  9. data/.github/workflows/spec.yml +0 -73
  10. data/.gitignore +0 -13
  11. data/.rspec +0 -2
  12. data/Appraisals +0 -23
  13. data/CHANGELOG.md +0 -379
  14. data/CONTRIBUTING.md +0 -57
  15. data/Gemfile +0 -11
  16. data/Guardfile +0 -5
  17. data/README.md +0 -596
  18. data/Rakefile +0 -21
  19. data/acts-as-taggable-on.gemspec +0 -32
  20. data/docker-compose.yml +0 -15
  21. data/gemfiles/activerecord_7.1.gemfile +0 -18
  22. data/gemfiles/activerecord_7.2.gemfile +0 -18
  23. data/gemfiles/activerecord_8.0.gemfile +0 -19
  24. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +0 -272
  25. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +0 -112
  26. data/spec/acts_as_taggable_on/caching_spec.rb +0 -125
  27. data/spec/acts_as_taggable_on/default_parser_spec.rb +0 -47
  28. data/spec/acts_as_taggable_on/dirty_spec.rb +0 -142
  29. data/spec/acts_as_taggable_on/generic_parser_spec.rb +0 -14
  30. data/spec/acts_as_taggable_on/related_spec.rb +0 -99
  31. data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +0 -231
  32. data/spec/acts_as_taggable_on/tag_list_spec.rb +0 -176
  33. data/spec/acts_as_taggable_on/tag_spec.rb +0 -398
  34. data/spec/acts_as_taggable_on/taggable_spec.rb +0 -828
  35. data/spec/acts_as_taggable_on/tagger_spec.rb +0 -153
  36. data/spec/acts_as_taggable_on/tagging_spec.rb +0 -169
  37. data/spec/acts_as_taggable_on/tags_helper_spec.rb +0 -45
  38. data/spec/acts_as_taggable_on/utils_spec.rb +0 -23
  39. data/spec/internal/app/models/altered_inheriting_taggable_model.rb +0 -5
  40. data/spec/internal/app/models/cached_model.rb +0 -3
  41. data/spec/internal/app/models/cached_model_with_array.rb +0 -11
  42. data/spec/internal/app/models/columns_override_model.rb +0 -5
  43. data/spec/internal/app/models/company.rb +0 -15
  44. data/spec/internal/app/models/inheriting_taggable_model.rb +0 -4
  45. data/spec/internal/app/models/market.rb +0 -2
  46. data/spec/internal/app/models/non_standard_id_taggable_model.rb +0 -8
  47. data/spec/internal/app/models/ordered_taggable_model.rb +0 -4
  48. data/spec/internal/app/models/other_cached_model.rb +0 -3
  49. data/spec/internal/app/models/other_taggable_model.rb +0 -4
  50. data/spec/internal/app/models/student.rb +0 -4
  51. data/spec/internal/app/models/taggable_model.rb +0 -16
  52. data/spec/internal/app/models/untaggable_model.rb +0 -3
  53. data/spec/internal/app/models/user.rb +0 -3
  54. data/spec/internal/config/database.yml.sample +0 -15
  55. data/spec/internal/db/schema.rb +0 -113
  56. data/spec/spec_helper.rb +0 -20
  57. data/spec/support/0-helpers.rb +0 -32
  58. data/spec/support/array.rb +0 -9
  59. data/spec/support/database.rb +0 -38
  60. data/spec/support/database_cleaner.rb +0 -25
@@ -1,142 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe 'Dirty behavior of taggable objects' do
5
- context 'with un-contexted tags' do
6
- before(:each) do
7
- @taggable = TaggableModel.create(tag_list: 'awesome, epic')
8
- end
9
-
10
- context 'when tag_list changed' do
11
- before(:each) do
12
- expect(@taggable.changes).to be_empty
13
- @taggable.tag_list = 'one'
14
- end
15
-
16
- it 'should show changes of dirty object' do
17
- expect(@taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
18
- end
19
-
20
- it 'should show changes of freshly initialized dirty object' do
21
- taggable = TaggableModel.find(@taggable.id)
22
- taggable.tag_list = 'one'
23
- expect(taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
24
- end
25
-
26
- if Rails.version >= "5.1"
27
- it 'flags tag_list as changed' do
28
- expect(@taggable.will_save_change_to_tag_list?).to be_truthy
29
- end
30
- end
31
-
32
- it 'preserves original value' do
33
- expect(@taggable.tag_list_was).to eq(['awesome', 'epic'])
34
- end
35
-
36
- it 'shows what the change was' do
37
- expect(@taggable.tag_list_change).to eq([['awesome', 'epic'], ['one']])
38
- end
39
-
40
- context 'without order' do
41
- it 'should not mark attribute if order change ' do
42
- taggable = TaggableModel.create(name: 'Dirty Harry', tag_list: %w(d c b a))
43
- taggable.tag_list = %w(a b c d)
44
- expect(taggable.tag_list_changed?).to be_falsey
45
- end
46
- end
47
-
48
- context 'with order' do
49
- it 'should mark attribute if order change' do
50
- taggable = OrderedTaggableModel.create(name: 'Clean Harry', tag_list: 'd,c,b,a')
51
- taggable.save
52
- taggable.tag_list = %w(a b c d)
53
- expect(taggable.tag_list_changed?).to be_truthy
54
- end
55
- end
56
- end
57
-
58
- context 'when tag_list is the same' do
59
- before(:each) do
60
- @taggable.tag_list = 'awesome, epic'
61
- end
62
-
63
- it 'is not flagged as changed' do
64
- expect(@taggable.tag_list_changed?).to be_falsy
65
- end
66
-
67
- it 'does not show any changes to the taggable item' do
68
- expect(@taggable.changes).to be_empty
69
- end
70
-
71
- context "and using a delimiter different from a ','" do
72
- before do
73
- @old_delimiter = ActsAsTaggableOn.delimiter
74
- ActsAsTaggableOn.delimiter = ';'
75
- end
76
-
77
- after do
78
- ActsAsTaggableOn.delimiter = @old_delimiter
79
- end
80
-
81
- it 'does not show any changes to the taggable item when using array assignments' do
82
- @taggable.tag_list = %w(awesome epic)
83
- expect(@taggable.changes).to be_empty
84
- end
85
- end
86
- end
87
- end
88
-
89
- context 'with context tags' do
90
- before(:each) do
91
- @taggable = TaggableModel.create('language_list' => 'awesome, epic')
92
- end
93
-
94
- context 'when language_list changed' do
95
- before(:each) do
96
- expect(@taggable.changes).to be_empty
97
- @taggable.language_list = 'one'
98
- end
99
-
100
- it 'should show changes of dirty object' do
101
- expect(@taggable.changes).to eq({'language_list' => [['awesome', 'epic'], ['one']]})
102
- end
103
-
104
- it 'flags language_list as changed' do
105
- expect(@taggable.language_list_changed?).to be_truthy
106
- end
107
-
108
- it 'preserves original value' do
109
- expect(@taggable.language_list_was).to eq(['awesome', 'epic'])
110
- end
111
-
112
- it 'shows what the change was' do
113
- expect(@taggable.language_list_change).to eq([['awesome', 'epic'], ['one']])
114
- end
115
- end
116
-
117
- context 'when language_list is the same' do
118
- before(:each) do
119
- @taggable.language_list = 'awesome, epic'
120
- end
121
-
122
- it 'is not flagged as changed' do
123
- expect(@taggable.language_list_changed?).to be_falsy
124
- end
125
-
126
- it 'does not show any changes to the taggable item' do
127
- expect(@taggable.changes).to be_empty
128
- end
129
- end
130
-
131
- context 'when language_list changed by association' do
132
- let(:tag) { ActsAsTaggableOn::Tag.new(name: 'one') }
133
-
134
- it 'flags language_list as changed' do
135
- expect(@taggable.changes).to be_empty
136
- @taggable.languages << tag
137
- expect(@taggable.language_list_changed?).to be_truthy
138
- end
139
- end
140
-
141
- end
142
- end
@@ -1,14 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe ActsAsTaggableOn::GenericParser do
5
- it '#parse should return empty array if empty tag string is passed' do
6
- tag_list = ActsAsTaggableOn::GenericParser.new('')
7
- expect(tag_list.parse).to be_empty
8
- end
9
-
10
- it '#parse should separate tags by comma' do
11
- tag_list = ActsAsTaggableOn::GenericParser.new('cool,data,,I,have')
12
- expect(tag_list.parse).to eq(%w(cool data I have))
13
- end
14
- end
@@ -1,99 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe 'Acts As Taggable On' do
5
-
6
- describe 'Related Objects' do
7
-
8
- #TODO, shared example
9
- it 'should find related objects based on tag names on context' do
10
- taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
11
- taggable2 = TaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
12
- taggable3 = TaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
13
-
14
- expect(taggable1.find_related_tags).to include(taggable3)
15
- expect(taggable1.find_related_tags).to_not include(taggable2)
16
- end
17
-
18
- it 'finds related tags for ordered taggable on' do
19
- taggable1 = OrderedTaggableModel.create!(name: 'Taggable 1',colour_list: 'one, two')
20
- taggable2 = OrderedTaggableModel.create!(name: 'Taggable 2',colour_list: 'three, four')
21
- taggable3 = OrderedTaggableModel.create!(name: 'Taggable 3',colour_list: 'one, four')
22
-
23
- expect(taggable1.find_related_colours).to include(taggable3)
24
- expect(taggable1.find_related_colours).to_not include(taggable2)
25
- end
26
-
27
- it 'should find related objects based on tag names on context - non standard id' do
28
- taggable1 = NonStandardIdTaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
29
- taggable2 = NonStandardIdTaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
30
- taggable3 = NonStandardIdTaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
31
-
32
- expect(taggable1.find_related_tags).to include(taggable3)
33
- expect(taggable1.find_related_tags).to_not include(taggable2)
34
- end
35
-
36
- it 'should find other related objects based on tag names on context' do
37
- taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
38
- taggable2 = OtherTaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
39
- taggable3 = OtherTaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
40
-
41
- expect(taggable1.find_related_tags_for(OtherTaggableModel)).to include(taggable3)
42
- expect(taggable1.find_related_tags_for(OtherTaggableModel)).to_not include(taggable2)
43
- end
44
-
45
- it 'should find other related objects based on tags only from particular context' do
46
- taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
47
- taggable2 = TaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four', skill_list: 'one, two')
48
- taggable3 = TaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
49
-
50
- expect(taggable1.find_related_tags).to include(taggable3)
51
- expect(taggable1.find_related_tags).to_not include(taggable2)
52
- end
53
-
54
-
55
- shared_examples "a collection" do
56
- it do
57
- taggable1 = described_class.create!(name: 'Taggable 1', tag_list: 'one')
58
- taggable2 = described_class.create!(name: 'Taggable 2', tag_list: 'one, two')
59
-
60
- expect(taggable1.find_related_tags).to include(taggable2)
61
- expect(taggable1.find_related_tags).to_not include(taggable1)
62
- end
63
- end
64
-
65
- # it 'should not include the object itself in the list of related objects' do
66
- describe TaggableModel do
67
- it_behaves_like "a collection"
68
- end
69
-
70
- # it 'should not include the object itself in the list of related objects - non standard id' do
71
- describe NonStandardIdTaggableModel do
72
- it_behaves_like "a collection"
73
- end
74
-
75
- context 'Ignored Tags' do
76
- let(:taggable1) { TaggableModel.create!(name: 'Taggable 1', tag_list: 'one, two, four') }
77
- let(:taggable2) { TaggableModel.create!(name: 'Taggable 2', tag_list: 'two, three') }
78
- let(:taggable3) { TaggableModel.create!(name: 'Taggable 3', tag_list: 'one, three') }
79
-
80
- it 'should not include ignored tags in related search' do
81
- expect(taggable1.find_related_tags(ignore: 'two')).to_not include(taggable2)
82
- expect(taggable1.find_related_tags(ignore: 'two')).to include(taggable3)
83
- end
84
-
85
- it 'should accept array of ignored tags' do
86
- taggable4 = TaggableModel.create!(name: 'Taggable 4', tag_list: 'four')
87
-
88
-
89
- expect(taggable1.find_related_tags(ignore: ['two', 'four'])).to_not include(taggable2)
90
- expect(taggable1.find_related_tags(ignore: ['two', 'four'])).to_not include(taggable4)
91
- end
92
-
93
- it 'should accept symbols as ignored tags' do
94
- expect(taggable1.find_related_tags(ignore: :two)).to_not include(taggable2)
95
- end
96
- end
97
-
98
- end
99
- end
@@ -1,231 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe 'Single Table Inheritance' do
5
- let(:taggable) { TaggableModel.new(name: 'taggable model') }
6
-
7
- let(:inheriting_model) { InheritingTaggableModel.new(name: 'Inheriting Taggable Model') }
8
- let(:altered_inheriting) { AlteredInheritingTaggableModel.new(name: 'Altered Inheriting Model') }
9
-
10
- 1.upto(4) do |n|
11
- let(:"inheriting_#{n}") { InheritingTaggableModel.new(name: "Inheriting Model #{n}") }
12
- end
13
-
14
- let(:student) { Student.create! }
15
-
16
- describe 'tag contexts' do
17
- it 'should pass on to STI-inherited models' do
18
- expect(inheriting_model).to respond_to(:tag_list, :skill_list, :language_list)
19
- expect(altered_inheriting).to respond_to(:tag_list, :skill_list, :language_list)
20
- end
21
-
22
- it 'should pass on to altered STI models' do
23
- expect(altered_inheriting).to respond_to(:part_list)
24
- end
25
- end
26
-
27
- context 'matching contexts' do
28
-
29
- before do
30
- inheriting_1.offering_list = 'one, two'
31
- inheriting_1.need_list = 'one, two'
32
- inheriting_1.save!
33
-
34
- inheriting_2.need_list = 'one, two'
35
- inheriting_2.save!
36
-
37
- inheriting_3.offering_list = 'one, two'
38
- inheriting_3.save!
39
-
40
- inheriting_4.tag_list = 'one, two, three, four'
41
- inheriting_4.save!
42
-
43
- taggable.need_list = 'one, two'
44
- taggable.save!
45
- end
46
-
47
- it 'should find objects with tags of matching contexts' do
48
- expect(inheriting_1.find_matching_contexts(:offerings, :needs)).to include(inheriting_2)
49
- expect(inheriting_1.find_matching_contexts(:offerings, :needs)).to_not include(inheriting_3)
50
- expect(inheriting_1.find_matching_contexts(:offerings, :needs)).to_not include(inheriting_4)
51
- expect(inheriting_1.find_matching_contexts(:offerings, :needs)).to_not include(taggable)
52
-
53
- expect(inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to include(inheriting_2)
54
- expect(inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to_not include(inheriting_3)
55
- expect(inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to_not include(inheriting_4)
56
- expect(inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to include(taggable)
57
- end
58
-
59
- it 'should not include the object itself in the list of related objects with tags of matching contexts' do
60
- expect(inheriting_1.find_matching_contexts(:offerings, :needs)).to_not include(inheriting_1)
61
- expect(inheriting_1.find_matching_contexts_for(InheritingTaggableModel, :offerings, :needs)).to_not include(inheriting_1)
62
- expect(inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to_not include(inheriting_1)
63
- end
64
- end
65
-
66
- context 'find related tags' do
67
- before do
68
- inheriting_1.tag_list = 'one, two'
69
- inheriting_1.save
70
-
71
- inheriting_2.tag_list = 'three, four'
72
- inheriting_2.save
73
-
74
- inheriting_3.tag_list = 'one, four'
75
- inheriting_3.save
76
-
77
- taggable.tag_list = 'one, two, three, four'
78
- taggable.save
79
- end
80
-
81
- it 'should find related objects based on tag names on context' do
82
- expect(inheriting_1.find_related_tags).to include(inheriting_3)
83
- expect(inheriting_1.find_related_tags).to_not include(inheriting_2)
84
- expect(inheriting_1.find_related_tags).to_not include(taggable)
85
-
86
- expect(inheriting_1.find_related_tags_for(TaggableModel)).to include(inheriting_3)
87
- expect(inheriting_1.find_related_tags_for(TaggableModel)).to_not include(inheriting_2)
88
- expect(inheriting_1.find_related_tags_for(TaggableModel)).to include(taggable)
89
- end
90
-
91
- it 'should not include the object itself in the list of related objects' do
92
- expect(inheriting_1.find_related_tags).to_not include(inheriting_1)
93
- expect(inheriting_1.find_related_tags_for(InheritingTaggableModel)).to_not include(inheriting_1)
94
- expect(inheriting_1.find_related_tags_for(TaggableModel)).to_not include(inheriting_1)
95
- end
96
- end
97
-
98
- describe 'tag list' do
99
- before do
100
- @inherited_same = InheritingTaggableModel.new(name: 'inherited same')
101
- @inherited_different = AlteredInheritingTaggableModel.new(name: 'inherited different')
102
- end
103
-
104
- #TODO, shared example
105
- it 'should be able to save tags for inherited models' do
106
- inheriting_model.tag_list = 'bob, kelso'
107
- inheriting_model.save
108
- expect(InheritingTaggableModel.tagged_with('bob').first).to eq(inheriting_model)
109
- end
110
-
111
- it 'should find STI tagged models on the superclass' do
112
- inheriting_model.tag_list = 'bob, kelso'
113
- inheriting_model.save
114
- expect(TaggableModel.tagged_with('bob').first).to eq(inheriting_model)
115
- end
116
-
117
- it 'should be able to add on contexts only to some subclasses' do
118
- altered_inheriting.part_list = 'fork, spoon'
119
- altered_inheriting.save
120
- expect(InheritingTaggableModel.tagged_with('fork', on: :parts)).to be_empty
121
- expect(AlteredInheritingTaggableModel.tagged_with('fork', on: :parts).first).to eq(altered_inheriting)
122
- end
123
-
124
- it 'should have different tag_counts_on for inherited models' do
125
- inheriting_model.tag_list = 'bob, kelso'
126
- inheriting_model.save!
127
- altered_inheriting.tag_list = 'fork, spoon'
128
- altered_inheriting.save!
129
-
130
- expect(InheritingTaggableModel.tag_counts_on(:tags, order: "#{ActsAsTaggableOn.tags_table}.id").map(&:name)).to eq(%w(bob kelso))
131
- expect(AlteredInheritingTaggableModel.tag_counts_on(:tags, order: "#{ActsAsTaggableOn.tags_table}.id").map(&:name)).to eq(%w(fork spoon))
132
- expect(TaggableModel.tag_counts_on(:tags, order: "#{ActsAsTaggableOn.tags_table}.id").map(&:name)).to eq(%w(bob kelso fork spoon))
133
- end
134
-
135
- it 'should have different tags_on for inherited models' do
136
- inheriting_model.tag_list = 'bob, kelso'
137
- inheriting_model.save!
138
- altered_inheriting.tag_list = 'fork, spoon'
139
- altered_inheriting.save!
140
-
141
- expect(InheritingTaggableModel.tags_on(:tags, order: "#{ActsAsTaggableOn.tags_table}.id").map(&:name)).to eq(%w(bob kelso))
142
- expect(AlteredInheritingTaggableModel.tags_on(:tags, order: "#{ActsAsTaggableOn.tags_table}.id").map(&:name)).to eq(%w(fork spoon))
143
- expect(TaggableModel.tags_on(:tags, order: "#{ActsAsTaggableOn.tags_table}.id").map(&:name)).to eq(%w(bob kelso fork spoon))
144
- end
145
-
146
- it 'should store same tag without validation conflict' do
147
- taggable.tag_list = 'one'
148
- taggable.save!
149
-
150
- inheriting_model.tag_list = 'one'
151
- inheriting_model.save!
152
-
153
- inheriting_model.update! name: 'foo'
154
- end
155
-
156
- it "should only join with taggable's table to check type for inherited models" do
157
- expect(TaggableModel.tag_counts_on(:tags).to_sql).to_not match /INNER JOIN taggable_models ON/
158
- expect(InheritingTaggableModel.tag_counts_on(:tags).to_sql).to match /INNER JOIN taggable_models ON/
159
- end
160
- end
161
-
162
- describe 'ownership' do
163
- it 'should have taggings' do
164
- student.tag(taggable, with: 'ruby,scheme', on: :tags)
165
- expect(student.owned_taggings.count).to eq(2)
166
- end
167
-
168
- it 'should have tags' do
169
- student.tag(taggable, with: 'ruby,scheme', on: :tags)
170
- expect(student.owned_tags.count).to eq(2)
171
- end
172
-
173
- it 'should return tags for the inheriting tagger' do
174
- student.tag(taggable, with: 'ruby, scheme', on: :tags)
175
- expect(taggable.tags_from(student)).to eq(%w(ruby scheme))
176
- end
177
-
178
- it 'returns all owner tags on the taggable' do
179
- student.tag(taggable, with: 'ruby, scheme', on: :tags)
180
- student.tag(taggable, with: 'skill_one', on: :skills)
181
- student.tag(taggable, with: 'english, spanish', on: :language)
182
- expect(taggable.owner_tags(student).count).to eq(5)
183
- expect(taggable.owner_tags(student).sort == %w(english ruby scheme skill_one spanish))
184
- end
185
-
186
-
187
- it 'returns owner tags on the tagger' do
188
- student.tag(taggable, with: 'ruby, scheme', on: :tags)
189
- expect(taggable.owner_tags_on(student, :tags).count).to eq(2)
190
- end
191
-
192
- it 'returns owner tags on the taggable for an array of contexts' do
193
- student.tag(taggable, with: 'ruby, scheme', on: :tags)
194
- student.tag(taggable, with: 'skill_one, skill_two', on: :skills)
195
- expect(taggable.owner_tags_on(student, [:tags, :skills]).count).to eq(4)
196
- expect(taggable.owner_tags_on(student, [:tags, :skills]).sort == %w(ruby scheme skill_one skill_two))
197
- end
198
-
199
- it 'should scope objects returned by tagged_with by owners' do
200
- student.tag(taggable, with: 'ruby, scheme', on: :tags)
201
- expect(TaggableModel.tagged_with(%w(ruby scheme), owned_by: student).count).to eq(1)
202
- end
203
- end
204
-
205
- describe 'a subclass of Tag' do
206
- let(:company) { Company.new(:name => 'Dewey, Cheatham & Howe') }
207
- let(:user) { User.create! }
208
-
209
- subject { Market.create! :name => 'finance' }
210
-
211
- its(:type) { should eql 'Market' }
212
-
213
- it 'sets STI type through string list' do
214
- company.market_list = 'law, accounting'
215
- company.save!
216
- expect(Market.count).to eq(2)
217
- end
218
-
219
- it 'does not interfere with a normal Tag context on the same model' do
220
- company.location_list = 'cambridge'
221
- company.save!
222
- expect(ActsAsTaggableOn::Tag.where(name: 'cambridge', type: nil)).to_not be_empty
223
- end
224
-
225
- it 'is returned with proper type through ownership' do
226
- user.tag(company, :with => 'ripoffs, rackets', :on => :markets)
227
- tags = company.owner_tags_on(user, :markets)
228
- expect(tags.all? { |tag| tag.is_a? Market }).to be_truthy
229
- end
230
- end
231
- end
@@ -1,176 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- require 'spec_helper'
4
-
5
- describe ActsAsTaggableOn::TagList do
6
- let(:tag_list) { ActsAsTaggableOn::TagList.new('awesome', 'radical') }
7
- let(:another_tag_list) { ActsAsTaggableOn::TagList.new('awesome','crazy', 'alien') }
8
-
9
- it { should be_kind_of Array }
10
-
11
-
12
-
13
- describe '#add' do
14
- it 'should be able to be add a new tag word' do
15
- tag_list.add('cool')
16
- expect(tag_list.include?('cool')).to be_truthy
17
- end
18
-
19
- it 'should be able to add delimited lists of words' do
20
- tag_list.add('cool, wicked', parse: true)
21
- expect(tag_list).to include('cool', 'wicked')
22
- end
23
-
24
- it 'should be able to add delimited list of words with quoted delimiters' do
25
- tag_list.add("'cool, wicked', \"really cool, really wicked\"", parse: true)
26
- expect(tag_list).to include('cool, wicked', 'really cool, really wicked')
27
- end
28
-
29
- it 'should be able to handle other uses of quotation marks correctly' do
30
- tag_list.add("john's cool car, mary's wicked toy", parse: true)
31
- expect(tag_list).to include("john's cool car", "mary's wicked toy")
32
- end
33
-
34
- it 'should be able to add an array of words' do
35
- tag_list.add(%w(cool wicked), parse: true)
36
- expect(tag_list).to include('cool', 'wicked')
37
- end
38
-
39
- it 'should quote escape tags with commas in them' do
40
- tag_list.add('cool', 'rad,bodacious')
41
- expect(tag_list.to_s).to eq("awesome, radical, cool, \"rad,bodacious\"")
42
- end
43
-
44
- end
45
-
46
- describe '#remove' do
47
- it 'should be able to remove words' do
48
- tag_list.remove('awesome')
49
- expect(tag_list).to_not include('awesome')
50
- end
51
-
52
- it 'should be able to remove delimited lists of words' do
53
- tag_list.remove('awesome, radical', parse: true)
54
- expect(tag_list).to be_empty
55
- end
56
-
57
- it 'should be able to remove an array of words' do
58
- tag_list.remove(%w(awesome radical), parse: true)
59
- expect(tag_list).to be_empty
60
- end
61
- end
62
-
63
- describe '#+' do
64
- it 'should not have duplicate tags' do
65
- new_tag_list = tag_list + another_tag_list
66
- expect(tag_list).to eq(%w[awesome radical])
67
- expect(another_tag_list).to eq(%w[awesome crazy alien])
68
- expect(new_tag_list).to eq(%w[awesome radical crazy alien])
69
- end
70
-
71
- it 'should have class : ActsAsTaggableOn::TagList' do
72
- new_tag_list = tag_list + another_tag_list
73
- expect(new_tag_list.class).to eq(ActsAsTaggableOn::TagList)
74
- end
75
- end
76
-
77
- describe '#concat' do
78
- it 'should not have duplicate tags' do
79
- expect(tag_list.concat(another_tag_list)).to eq(%w[awesome radical crazy alien])
80
- end
81
-
82
- it 'should have class : ActsAsTaggableOn::TagList' do
83
- new_tag_list = tag_list.concat(another_tag_list)
84
- expect(new_tag_list.class).to eq(ActsAsTaggableOn::TagList)
85
- end
86
-
87
- context 'without duplicates' do
88
- let(:arr) { ['crazy', 'alien'] }
89
- let(:another_tag_list) { ActsAsTaggableOn::TagList.new(*arr) }
90
- it 'adds other list' do
91
- expect(tag_list.concat(another_tag_list)).to eq(%w[awesome radical crazy alien])
92
- end
93
-
94
- it 'adds other array' do
95
- expect(tag_list.concat(arr)).to eq(%w[awesome radical crazy alien])
96
- end
97
- end
98
- end
99
-
100
- describe '#to_s' do
101
- it 'should give a delimited list of words when converted to string' do
102
- expect(tag_list.to_s).to eq('awesome, radical')
103
- end
104
-
105
- it 'should be able to call to_s on a frozen tag list' do
106
- tag_list.freeze
107
- expect { tag_list.add('cool', 'rad,bodacious') }.to raise_error(RuntimeError)
108
- expect { tag_list.to_s }.to_not raise_error
109
- end
110
- end
111
-
112
- describe 'cleaning' do
113
- it 'should parameterize if force_parameterize is set to true' do
114
- ActsAsTaggableOn.force_parameterize = true
115
- tag_list = ActsAsTaggableOn::TagList.new('awesome()', 'radical)(cc')
116
-
117
- expect(tag_list.to_s).to eq('awesome, radical-cc')
118
- ActsAsTaggableOn.force_parameterize = false
119
- end
120
-
121
- it 'should lowercase if force_lowercase is set to true' do
122
- ActsAsTaggableOn.force_lowercase = true
123
-
124
- tag_list = ActsAsTaggableOn::TagList.new('aweSomE', 'RaDicaL', 'Entrée')
125
- expect(tag_list.to_s).to eq('awesome, radical, entrée')
126
-
127
- ActsAsTaggableOn.force_lowercase = false
128
- end
129
-
130
- it 'should ignore case when removing duplicates if strict_case_match is false' do
131
- tag_list = ActsAsTaggableOn::TagList.new('Junglist', 'JUNGLIST', 'Junglist', 'Massive', 'MASSIVE', 'MASSIVE')
132
-
133
- expect(tag_list.to_s).to eq('Junglist, Massive')
134
- end
135
-
136
- it 'should not ignore case when removing duplicates if strict_case_match is true' do
137
- ActsAsTaggableOn.strict_case_match = true
138
- tag_list = ActsAsTaggableOn::TagList.new('Junglist', 'JUNGLIST', 'Junglist', 'Massive', 'MASSIVE', 'MASSIVE')
139
-
140
- expect(tag_list.to_s).to eq('Junglist, JUNGLIST, Massive, MASSIVE')
141
- ActsAsTaggableOn.strict_case_match = false
142
- end
143
- end
144
-
145
- describe 'custom parser' do
146
- let(:parser) { double(parse: %w(cool wicked)) }
147
- let(:parser_class) { stub_const('MyParser', Class) }
148
-
149
- it 'should use a the default parser if none is set as parameter' do
150
- allow(ActsAsTaggableOn.default_parser).to receive(:new).and_return(parser)
151
- ActsAsTaggableOn::TagList.new('cool, wicked', parse: true)
152
-
153
- expect(parser).to have_received(:parse)
154
- end
155
-
156
- it 'should use the custom parser passed as parameter' do
157
- allow(parser_class).to receive(:new).and_return(parser)
158
-
159
- ActsAsTaggableOn::TagList.new('cool, wicked', parser: parser_class)
160
-
161
- expect(parser).to have_received(:parse)
162
- end
163
-
164
- it 'should use the parser set as attribute' do
165
- allow(parser_class).to receive(:new).with('new, tag').and_return(parser)
166
-
167
- tag_list = ActsAsTaggableOn::TagList.new('example')
168
- tag_list.parser = parser_class
169
- tag_list.add('new, tag', parse: true)
170
-
171
- expect(parser).to have_received(:parse)
172
- end
173
- end
174
-
175
-
176
- end