acts-as-taggable-on 2.0.0.pre5 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/{spec/spec.opts → .rspec} +0 -0
  4. data/.travis.yml +40 -0
  5. data/Appraisals +16 -0
  6. data/CHANGELOG.md +208 -0
  7. data/CONTRIBUTING.md +44 -0
  8. data/Gemfile +10 -5
  9. data/Guardfile +5 -0
  10. data/{MIT-LICENSE → LICENSE.md} +1 -1
  11. data/README.md +477 -0
  12. data/Rakefile +14 -52
  13. data/UPGRADING.md +8 -0
  14. data/acts-as-taggable-on.gemspec +36 -0
  15. data/{lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb → db/migrate/1_acts_as_taggable_on_migration.rb} +5 -3
  16. data/db/migrate/2_add_missing_unique_indices.rb +19 -0
  17. data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +14 -0
  18. data/db/migrate/4_add_missing_taggable_index.rb +9 -0
  19. data/db/migrate/5_change_collation_for_tag_names.rb +9 -0
  20. data/gemfiles/activerecord_3.2.gemfile +15 -0
  21. data/gemfiles/activerecord_4.0.gemfile +15 -0
  22. data/gemfiles/activerecord_4.1.gemfile +15 -0
  23. data/gemfiles/activerecord_4.2.gemfile +16 -0
  24. data/lib/acts-as-taggable-on.rb +117 -22
  25. data/lib/acts_as_taggable_on/compatibility.rb +35 -0
  26. data/lib/acts_as_taggable_on/default_parser.rb +79 -0
  27. data/lib/acts_as_taggable_on/engine.rb +5 -0
  28. data/lib/acts_as_taggable_on/generic_parser.rb +19 -0
  29. data/lib/acts_as_taggable_on/tag.rb +137 -61
  30. data/lib/acts_as_taggable_on/tag_list.rb +96 -75
  31. data/lib/acts_as_taggable_on/tag_list_parser.rb +21 -0
  32. data/lib/acts_as_taggable_on/taggable/cache.rb +86 -0
  33. data/lib/acts_as_taggable_on/taggable/collection.rb +178 -0
  34. data/lib/acts_as_taggable_on/taggable/core.rb +459 -0
  35. data/lib/acts_as_taggable_on/taggable/dirty.rb +36 -0
  36. data/lib/acts_as_taggable_on/taggable/ownership.rb +125 -0
  37. data/lib/acts_as_taggable_on/taggable/related.rb +71 -0
  38. data/lib/acts_as_taggable_on/taggable.rb +102 -0
  39. data/lib/acts_as_taggable_on/tagger.rb +88 -0
  40. data/lib/acts_as_taggable_on/tagging.rb +38 -18
  41. data/lib/acts_as_taggable_on/tags_helper.rb +12 -14
  42. data/lib/acts_as_taggable_on/utils.rb +38 -0
  43. data/lib/acts_as_taggable_on/version.rb +4 -0
  44. data/lib/acts_as_taggable_on.rb +6 -0
  45. data/lib/tasks/tags_collate_utf8.rake +21 -0
  46. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +205 -195
  47. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +79 -81
  48. data/spec/acts_as_taggable_on/caching_spec.rb +83 -0
  49. data/spec/acts_as_taggable_on/default_parser_spec.rb +47 -0
  50. data/spec/acts_as_taggable_on/generic_parser_spec.rb +14 -0
  51. data/spec/acts_as_taggable_on/related_spec.rb +99 -0
  52. data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +211 -0
  53. data/spec/acts_as_taggable_on/tag_list_parser_spec.rb +46 -0
  54. data/spec/acts_as_taggable_on/tag_list_spec.rb +142 -62
  55. data/spec/acts_as_taggable_on/tag_spec.rb +274 -64
  56. data/spec/acts_as_taggable_on/taggable/dirty_spec.rb +127 -0
  57. data/spec/acts_as_taggable_on/taggable_spec.rb +704 -181
  58. data/spec/acts_as_taggable_on/tagger_spec.rb +134 -56
  59. data/spec/acts_as_taggable_on/tagging_spec.rb +54 -22
  60. data/spec/acts_as_taggable_on/tags_helper_spec.rb +39 -22
  61. data/spec/acts_as_taggable_on/utils_spec.rb +23 -0
  62. data/spec/internal/app/models/altered_inheriting_taggable_model.rb +3 -0
  63. data/spec/internal/app/models/cached_model.rb +3 -0
  64. data/spec/internal/app/models/cached_model_with_array.rb +5 -0
  65. data/spec/internal/app/models/company.rb +15 -0
  66. data/spec/internal/app/models/inheriting_taggable_model.rb +2 -0
  67. data/spec/internal/app/models/market.rb +2 -0
  68. data/spec/internal/app/models/models.rb +90 -0
  69. data/spec/internal/app/models/non_standard_id_taggable_model.rb +8 -0
  70. data/spec/internal/app/models/ordered_taggable_model.rb +4 -0
  71. data/spec/internal/app/models/other_cached_model.rb +3 -0
  72. data/spec/internal/app/models/other_taggable_model.rb +4 -0
  73. data/spec/internal/app/models/student.rb +2 -0
  74. data/spec/internal/app/models/taggable_model.rb +13 -0
  75. data/spec/internal/app/models/untaggable_model.rb +3 -0
  76. data/spec/internal/app/models/user.rb +3 -0
  77. data/spec/internal/config/database.yml.sample +19 -0
  78. data/spec/internal/db/schema.rb +97 -0
  79. data/spec/spec_helper.rb +12 -38
  80. data/spec/support/0-helpers.rb +32 -0
  81. data/spec/support/array.rb +9 -0
  82. data/spec/support/database.rb +42 -0
  83. data/spec/support/database_cleaner.rb +21 -0
  84. metadata +268 -73
  85. data/CHANGELOG +0 -25
  86. data/README.rdoc +0 -212
  87. data/VERSION +0 -1
  88. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +0 -56
  89. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +0 -97
  90. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +0 -220
  91. data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +0 -29
  92. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +0 -101
  93. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +0 -64
  94. data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +0 -41
  95. data/lib/acts_as_taggable_on/acts_as_tagger.rb +0 -47
  96. data/lib/acts_as_taggable_on/compatibility/Gemfile +0 -6
  97. data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
  98. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +0 -31
  99. data/rails/init.rb +0 -1
  100. data/spec/bm.rb +0 -52
  101. data/spec/models.rb +0 -36
  102. data/spec/schema.rb +0 -42
@@ -1,265 +1,275 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
2
3
 
3
- describe "Acts As Taggable On" do
4
- before(:each) do
5
- clean_database!
6
- end
4
+ describe 'Acts As Taggable On' do
7
5
 
8
6
  it "should provide a class method 'taggable?' that is false for untaggable models" do
9
- UntaggableModel.should_not be_taggable
7
+ expect(UntaggableModel).to_not be_taggable
10
8
  end
11
9
 
12
- describe "Taggable Method Generation" do
10
+ describe 'Taggable Method Generation To Preserve Order' do
13
11
  before(:each) do
14
- [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
15
- @taggable = TaggableModel.new(:name => "Bob Jones")
12
+ TaggableModel.tag_types = []
13
+ TaggableModel.preserve_tag_order = false
14
+ TaggableModel.acts_as_ordered_taggable_on(:ordered_tags)
15
+ @taggable = TaggableModel.new(name: 'Bob Jones')
16
+ end
17
+
18
+ it "should respond 'true' to preserve_tag_order?" do
19
+ expect(@taggable.class.preserve_tag_order?).to be_truthy
20
+ end
21
+ end
22
+
23
+ describe 'Taggable Method Generation' do
24
+ before(:each) do
25
+ TaggableModel.tag_types = []
26
+ TaggableModel.acts_as_taggable_on(:tags, :languages, :skills, :needs, :offerings)
27
+ @taggable = TaggableModel.new(name: 'Bob Jones')
16
28
  end
17
29
 
18
30
  it "should respond 'true' to taggable?" do
19
- @taggable.class.should be_taggable
31
+ expect(@taggable.class).to be_taggable
20
32
  end
21
33
 
22
- it "should create a class attribute for tag types" do
23
- @taggable.class.should respond_to(:tag_types)
34
+ it 'should create a class attribute for tag types' do
35
+ expect(@taggable.class).to respond_to(:tag_types)
24
36
  end
25
37
 
26
- it "should create an instance attribute for tag types" do
27
- @taggable.should respond_to(:tag_types)
38
+ it 'should create an instance attribute for tag types' do
39
+ expect(@taggable).to respond_to(:tag_types)
28
40
  end
29
-
30
- it "should have all tag types" do
31
- @taggable.tag_types.should == [:tags, :languages, :skills, :needs, :offerings]
41
+
42
+ it 'should have all tag types' do
43
+ expect(@taggable.tag_types).to eq([:tags, :languages, :skills, :needs, :offerings])
32
44
  end
33
45
 
34
- it "should generate an association for each tag type" do
35
- @taggable.should respond_to(:tags, :skills, :languages)
46
+ it 'should create a class attribute for preserve tag order' do
47
+ expect(@taggable.class).to respond_to(:preserve_tag_order?)
36
48
  end
37
49
 
38
- it "should add tagged_with and tag_counts to singleton" do
39
- TaggableModel.should respond_to(:tagged_with, :tag_counts)
50
+ it 'should create an instance attribute for preserve tag order' do
51
+ expect(@taggable).to respond_to(:preserve_tag_order?)
40
52
  end
41
53
 
42
- it "should generate a tag_list accessor/setter for each tag type" do
43
- @taggable.should respond_to(:tag_list, :skill_list, :language_list)
44
- @taggable.should respond_to(:tag_list=, :skill_list=, :language_list=)
54
+ it "should respond 'false' to preserve_tag_order?" do
55
+ expect(@taggable.class.preserve_tag_order?).to be_falsy
45
56
  end
46
-
47
- it "should generate a tag_list accessor, that includes owned tags, for each tag type" do
48
- @taggable.should respond_to(:all_tags_list, :all_skills_list, :all_languages_list)
57
+
58
+ it 'should generate an association for each tag type' do
59
+ expect(@taggable).to respond_to(:tags, :skills, :languages)
49
60
  end
50
- end
51
61
 
52
- describe "Single Table Inheritance" do
53
- before do
54
- @taggable = TaggableModel.new(:name => "taggable")
55
- @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
56
- @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
62
+ it 'should add tagged_with and tag_counts to singleton' do
63
+ expect(TaggableModel).to respond_to(:tagged_with, :tag_counts)
57
64
  end
58
-
59
- it "should pass on tag contexts to STI-inherited models" do
60
- @inherited_same.should respond_to(:tag_list, :skill_list, :language_list)
61
- @inherited_different.should respond_to(:tag_list, :skill_list, :language_list)
65
+
66
+ it 'should generate a tag_list accessor/setter for each tag type' do
67
+ expect(@taggable).to respond_to(:tag_list, :skill_list, :language_list)
68
+ expect(@taggable).to respond_to(:tag_list=, :skill_list=, :language_list=)
62
69
  end
63
-
64
- it "should have tag contexts added in altered STI models" do
65
- @inherited_different.should respond_to(:part_list)
70
+
71
+ it 'should generate a tag_list accessor, that includes owned tags, for each tag type' do
72
+ expect(@taggable).to respond_to(:all_tags_list, :all_skills_list, :all_languages_list)
66
73
  end
67
74
  end
68
-
69
- describe "Reloading" do
70
- it "should save a model instantiated by Model.find" do
71
- taggable = TaggableModel.create!(:name => "Taggable")
75
+
76
+ describe 'Reloading' do
77
+ it 'should save a model instantiated by Model.find' do
78
+ taggable = TaggableModel.create!(name: 'Taggable')
72
79
  found_taggable = TaggableModel.find(taggable.id)
73
80
  found_taggable.save
74
81
  end
75
82
  end
76
83
 
77
- describe "Related Objects" do
78
- it "should find related objects based on tag names on context" do
79
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
80
- taggable2 = TaggableModel.create!(:name => "Taggable 2")
81
- taggable3 = TaggableModel.create!(:name => "Taggable 3")
82
-
83
- taggable1.tag_list = "one, two"
84
- taggable1.save
85
-
86
- taggable2.tag_list = "three, four"
87
- taggable2.save
88
-
89
- taggable3.tag_list = "one, four"
90
- taggable3.save
91
-
92
- taggable1.find_related_tags.should include(taggable3)
93
- taggable1.find_related_tags.should_not include(taggable2)
94
- end
95
-
96
- it "should find other related objects based on tag names on context" do
97
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
98
- taggable2 = OtherTaggableModel.create!(:name => "Taggable 2")
99
- taggable3 = OtherTaggableModel.create!(:name => "Taggable 3")
100
-
101
- taggable1.tag_list = "one, two"
102
- taggable1.save
103
-
104
- taggable2.tag_list = "three, four"
105
- taggable2.save
106
-
107
- taggable3.tag_list = "one, four"
108
- taggable3.save
109
-
110
- taggable1.find_related_tags_for(OtherTaggableModel).should include(taggable3)
111
- taggable1.find_related_tags_for(OtherTaggableModel).should_not include(taggable2)
112
- end
113
-
114
- it "should not include the object itself in the list of related objects" do
115
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
116
- taggable2 = TaggableModel.create!(:name => "Taggable 2")
117
-
118
- taggable1.tag_list = "one"
119
- taggable1.save
120
-
121
- taggable2.tag_list = "one, two"
122
- taggable2.save
123
-
124
- taggable1.find_related_tags.should include(taggable2)
125
- taggable1.find_related_tags.should_not include(taggable1)
126
- end
127
- end
84
+ describe 'Matching Contexts' do
85
+ it 'should find objects with tags of matching contexts' do
86
+ taggable1 = TaggableModel.create!(name: 'Taggable 1')
87
+ taggable2 = TaggableModel.create!(name: 'Taggable 2')
88
+ taggable3 = TaggableModel.create!(name: 'Taggable 3')
128
89
 
129
- describe "Matching Contexts" do
130
- it "should find objects with tags of matching contexts" do
131
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
132
- taggable2 = TaggableModel.create!(:name => "Taggable 2")
133
- taggable3 = TaggableModel.create!(:name => "Taggable 3")
134
-
135
- taggable1.offering_list = "one, two"
90
+ taggable1.offering_list = 'one, two'
136
91
  taggable1.save!
137
-
138
- taggable2.need_list = "one, two"
92
+
93
+ taggable2.need_list = 'one, two'
139
94
  taggable2.save!
140
-
141
- taggable3.offering_list = "one, two"
95
+
96
+ taggable3.offering_list = 'one, two'
142
97
  taggable3.save!
143
-
144
- taggable1.find_matching_contexts(:offerings, :needs).should include(taggable2)
145
- taggable1.find_matching_contexts(:offerings, :needs).should_not include(taggable3)
98
+
99
+ expect(taggable1.find_matching_contexts(:offerings, :needs)).to include(taggable2)
100
+ expect(taggable1.find_matching_contexts(:offerings, :needs)).to_not include(taggable3)
146
101
  end
147
-
148
- it "should find other related objects with tags of matching contexts" do
149
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
150
- taggable2 = OtherTaggableModel.create!(:name => "Taggable 2")
151
- taggable3 = OtherTaggableModel.create!(:name => "Taggable 3")
152
-
153
- taggable1.offering_list = "one, two"
102
+
103
+ it 'should find other related objects with tags of matching contexts' do
104
+ taggable1 = TaggableModel.create!(name: 'Taggable 1')
105
+ taggable2 = OtherTaggableModel.create!(name: 'Taggable 2')
106
+ taggable3 = OtherTaggableModel.create!(name: 'Taggable 3')
107
+
108
+ taggable1.offering_list = 'one, two'
154
109
  taggable1.save
155
-
156
- taggable2.need_list = "one, two"
110
+
111
+ taggable2.need_list = 'one, two'
157
112
  taggable2.save
158
-
159
- taggable3.offering_list = "one, two"
113
+
114
+ taggable3.offering_list = 'one, two'
160
115
  taggable3.save
161
-
162
- taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs).should include(taggable2)
163
- taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs).should_not include(taggable3)
116
+
117
+ expect(taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs)).to include(taggable2)
118
+ expect(taggable1.find_matching_contexts_for(OtherTaggableModel, :offerings, :needs)).to_not include(taggable3)
164
119
  end
165
-
166
- it "should not include the object itself in the list of related objects" do
167
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
168
- taggable2 = TaggableModel.create!(:name => "Taggable 2")
169
-
170
- taggable1.tag_list = "one"
120
+
121
+ it 'should not include the object itself in the list of related objects with tags of matching contexts' do
122
+ taggable1 = TaggableModel.create!(name: 'Taggable 1')
123
+ taggable2 = TaggableModel.create!(name: 'Taggable 2')
124
+
125
+ taggable1.offering_list = 'one, two'
126
+ taggable1.need_list = 'one, two'
171
127
  taggable1.save
172
-
173
- taggable2.tag_list = "one, two"
128
+
129
+ taggable2.need_list = 'one, two'
174
130
  taggable2.save
175
-
176
- taggable1.find_related_tags.should include(taggable2)
177
- taggable1.find_related_tags.should_not include(taggable1)
131
+
132
+ expect(taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to include(taggable2)
133
+ expect(taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs)).to_not include(taggable1)
134
+ end
135
+
136
+ it 'should ensure joins to multiple taggings maintain their contexts when aliasing' do
137
+ taggable1 = TaggableModel.create!(name: 'Taggable 1')
138
+
139
+ taggable1.offering_list = 'one'
140
+ taggable1.need_list = 'two'
141
+
142
+ taggable1.save
143
+
144
+ column = TaggableModel.connection.quote_column_name("context")
145
+ offer_alias = TaggableModel.connection.quote_table_name("taggings")
146
+ need_alias = TaggableModel.connection.quote_table_name("need_taggings_taggable_models_join")
147
+
148
+ expect(TaggableModel.joins(:offerings, :needs).to_sql).to include "#{offer_alias}.#{column}"
149
+ expect(TaggableModel.joins(:offerings, :needs).to_sql).to include "#{need_alias}.#{column}"
178
150
  end
151
+
179
152
  end
180
153
 
181
154
  describe 'Tagging Contexts' do
182
155
  it 'should eliminate duplicate tagging contexts ' do
183
156
  TaggableModel.acts_as_taggable_on(:skills, :skills)
184
- TaggableModel.tag_types.freq[:skills].should_not == 3
157
+ expect(TaggableModel.tag_types.freq[:skills]).to_not eq(3)
185
158
  end
186
159
 
187
- it "should not contain embedded/nested arrays" do
160
+ it 'should not contain embedded/nested arrays' do
188
161
  TaggableModel.acts_as_taggable_on([:array], [:array])
189
- TaggableModel.tag_types.freq[[:array]].should == 0
162
+ expect(TaggableModel.tag_types.freq[[:array]]).to eq(0)
190
163
  end
191
164
 
192
- it "should _flatten_ the content of arrays" do
165
+ it 'should _flatten_ the content of arrays' do
193
166
  TaggableModel.acts_as_taggable_on([:array], [:array])
194
- TaggableModel.tag_types.freq[:array].should == 1
167
+ expect(TaggableModel.tag_types.freq[:array]).to eq(1)
195
168
  end
196
169
 
197
- it "should not raise an error when passed nil" do
198
- lambda {
199
- TaggableModel.acts_as_taggable_on()
200
- }.should_not raise_error
170
+ it 'should not raise an error when passed nil' do
171
+ expect(-> {
172
+ TaggableModel.acts_as_taggable_on
173
+ }).to_not raise_error
201
174
  end
202
175
 
203
- it "should not raise an error when passed [nil]" do
204
- lambda {
176
+ it 'should not raise an error when passed [nil]' do
177
+ expect(-> {
205
178
  TaggableModel.acts_as_taggable_on([nil])
206
- }.should_not raise_error
179
+ }).to_not raise_error
207
180
  end
208
181
  end
209
-
210
- describe 'Caching' do
211
- before(:each) do
212
- @taggable = CachedModel.new(:name => "Bob Jones")
213
- end
214
-
215
- it "should add saving of tag lists and cached tag lists to the instance" do
216
- @taggable.should respond_to(:save_cached_tag_list)
217
- @taggable.should respond_to(:save_tags)
218
- end
219
-
220
- it "should generate a cached column checker for each tag type" do
221
- CachedModel.should respond_to(:caching_tag_list?)
222
- end
223
-
224
- it 'should not have cached tags' do
225
- @taggable.cached_tag_list.should be_blank
226
- end
227
-
228
- it 'should cache tags' do
229
- @taggable.update_attributes(:tag_list => 'awesome, epic')
230
- @taggable.cached_tag_list.should == 'awesome, epic'
182
+
183
+ context 'when tagging context ends in an "s" when singular (ex. "status", "glass", etc.)' do
184
+ describe 'caching' do
185
+ before { @taggable = OtherCachedModel.new(name: 'John Smith') }
186
+ subject { @taggable }
187
+
188
+ it { should respond_to(:save_cached_tag_list) }
189
+ its(:cached_language_list) { should be_blank }
190
+ its(:cached_status_list) { should be_blank }
191
+ its(:cached_glass_list) { should be_blank }
192
+
193
+ context 'language taggings cache after update' do
194
+ before { @taggable.update_attributes(language_list: 'ruby, .net') }
195
+ subject { @taggable }
196
+
197
+ its(:language_list) { should == ['ruby', '.net']}
198
+ its(:cached_language_list) { should == 'ruby, .net' } # passes
199
+ its(:instance_variables) { should include((RUBY_VERSION < '1.9' ? '@language_list' : :@language_list)) }
200
+ end
201
+
202
+ context 'status taggings cache after update' do
203
+ before { @taggable.update_attributes(status_list: 'happy, married') }
204
+ subject { @taggable }
205
+
206
+ its(:status_list) { should == ['happy', 'married'] }
207
+ its(:cached_status_list) { should == 'happy, married' } # fails
208
+ its(:cached_status_list) { should_not == '' } # fails, is blank
209
+ its(:instance_variables) { should include((RUBY_VERSION < '1.9' ? '@status_list' : :@status_list)) }
210
+ its(:instance_variables) { should_not include((RUBY_VERSION < '1.9' ? '@statu_list' : :@statu_list)) } # fails, note: one "s"
211
+
212
+ end
213
+
214
+ context 'glass taggings cache after update' do
215
+ before do
216
+ @taggable.update_attributes(glass_list: 'rectangle, aviator')
217
+ end
218
+
219
+ subject { @taggable }
220
+ its(:glass_list) { should == ['rectangle', 'aviator'] }
221
+ its(:cached_glass_list) { should == 'rectangle, aviator' } # fails
222
+ its(:cached_glass_list) { should_not == '' } # fails, is blank
223
+ if RUBY_VERSION < '1.9'
224
+ its(:instance_variables) { should include('@glass_list') }
225
+ its(:instance_variables) { should_not include('@glas_list') } # fails, note: one "s"
226
+ else
227
+ its(:instance_variables) { should include(:@glass_list) }
228
+ its(:instance_variables) { should_not include(:@glas_list) } # fails, note: one "s"
229
+ end
230
+
231
+ end
231
232
  end
232
-
233
- it 'should keep the cache' do
234
- @taggable.update_attributes(:tag_list => 'awesome, epic')
235
- @taggable = CachedModel.find(@taggable)
236
- @taggable.save!
237
- @taggable.cached_tag_list.should == 'awesome, epic'
233
+ end
234
+
235
+ describe 'taggings' do
236
+ before(:each) do
237
+ @taggable = TaggableModel.new(name: 'Art Kram')
238
238
  end
239
-
240
- it 'should update the cache' do
241
- @taggable.update_attributes(:tag_list => 'awesome, epic')
242
- @taggable.update_attributes(:tag_list => 'awesome')
243
- @taggable.cached_tag_list.should == 'awesome'
239
+
240
+ it 'should return no taggings' do
241
+ expect(@taggable.taggings).to be_empty
244
242
  end
245
-
246
- it 'should remove the cache' do
247
- @taggable.update_attributes(:tag_list => 'awesome, epic')
248
- @taggable.update_attributes(:tag_list => '')
249
- @taggable.cached_tag_list.should be_blank
243
+ end
244
+
245
+ describe '@@remove_unused_tags' do
246
+ before do
247
+ @taggable = TaggableModel.create(name: 'Bob Jones')
248
+ @tag = ActsAsTaggableOn::Tag.create(name: 'awesome')
249
+
250
+ @tagging = ActsAsTaggableOn::Tagging.create(taggable: @taggable, tag: @tag, context: 'tags')
250
251
  end
251
-
252
- it 'should have a tag list' do
253
- @taggable.update_attributes(:tag_list => 'awesome, epic')
254
- @taggable = CachedModel.find(@taggable.id)
255
- @taggable.tag_list.sort.should == %w(awesome epic).sort
252
+
253
+ context 'if set to true' do
254
+ before do
255
+ ActsAsTaggableOn.remove_unused_tags = true
256
+ end
257
+
258
+ it 'should remove unused tags after removing taggings' do
259
+ @tagging.destroy
260
+ expect(ActsAsTaggableOn::Tag.find_by_name('awesome')).to be_nil
261
+ end
256
262
  end
257
-
258
- it 'should keep the tag list' do
259
- @taggable.update_attributes(:tag_list => 'awesome, epic')
260
- @taggable = CachedModel.find(@taggable.id)
261
- @taggable.save!
262
- @taggable.tag_list.sort.should == %w(awesome epic).sort
263
+
264
+ context 'if set to false' do
265
+ before do
266
+ ActsAsTaggableOn.remove_unused_tags = false
267
+ end
268
+
269
+ it 'should not remove unused tags after removing taggings' do
270
+ @tagging.destroy
271
+ expect(ActsAsTaggableOn::Tag.find_by_name('awesome')).to eq(@tag)
272
+ end
263
273
  end
264
274
  end
265
275