acts-as-taggable-on 2.4.0 → 2.4.1

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Appraisals +7 -0
  4. data/Gemfile +3 -1
  5. data/{MIT-LICENSE.md → LICENSE.md} +0 -0
  6. data/README.md +22 -16
  7. data/Rakefile +2 -2
  8. data/acts-as-taggable-on.gemspec +22 -19
  9. data/gemfiles/rails_3.gemfile +8 -0
  10. data/gemfiles/rails_4.gemfile +8 -0
  11. data/lib/acts-as-taggable-on.rb +2 -0
  12. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +5 -7
  13. data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +34 -0
  14. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +75 -50
  15. data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +1 -1
  16. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +21 -12
  17. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +27 -18
  18. data/lib/acts_as_taggable_on/tag.rb +8 -8
  19. data/lib/acts_as_taggable_on/taggable.rb +10 -7
  20. data/lib/acts_as_taggable_on/tagger.rb +12 -3
  21. data/lib/acts_as_taggable_on/tagging.rb +2 -2
  22. data/lib/acts_as_taggable_on/tags_helper.rb +0 -2
  23. data/lib/{acts-as-taggable-on → acts_as_taggable_on}/version.rb +1 -1
  24. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +1 -216
  25. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +8 -8
  26. data/spec/acts_as_taggable_on/related_spec.rb +143 -0
  27. data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +187 -0
  28. data/spec/acts_as_taggable_on/tag_list_spec.rb +2 -2
  29. data/spec/acts_as_taggable_on/tag_spec.rb +3 -4
  30. data/spec/acts_as_taggable_on/taggable_spec.rb +127 -116
  31. data/spec/acts_as_taggable_on/tagger_spec.rb +32 -33
  32. data/spec/acts_as_taggable_on/tagging_spec.rb +1 -1
  33. data/spec/acts_as_taggable_on/tags_helper_spec.rb +2 -2
  34. data/spec/acts_as_taggable_on/utils_spec.rb +2 -2
  35. data/spec/models.rb +2 -2
  36. data/spec/schema.rb +1 -1
  37. data/spec/spec_helper.rb +7 -4
  38. metadata +48 -34
  39. data/CHANGELOG.md +0 -35
  40. data/UPGRADING +0 -14
  41. data/rails/init.rb +0 -1
  42. data/uninstall.rb +0 -1
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "acts_as_tagger" do
4
4
  before(:each) do
@@ -7,15 +7,15 @@ describe "acts_as_tagger" do
7
7
 
8
8
  describe "Tagger Method Generation" do
9
9
  before(:each) do
10
- @tagger = TaggableUser.new()
10
+ @tagger = User.new
11
11
  end
12
12
 
13
13
  it "should add #is_tagger? query method to the class-side" do
14
- TaggableUser.should respond_to(:is_tagger?)
14
+ User.should respond_to(:is_tagger?)
15
15
  end
16
16
 
17
17
  it "should return true from the class-side #is_tagger?" do
18
- TaggableUser.is_tagger?.should be_true
18
+ User.is_tagger?.should be_true
19
19
  end
20
20
 
21
21
  it "should return false from the base #is_tagger?" do
@@ -38,7 +38,7 @@ describe "acts_as_tagger" do
38
38
  describe "#tag" do
39
39
  context 'when called with a non-existent tag context' do
40
40
  before(:each) do
41
- @tagger = TaggableUser.new()
41
+ @tagger = User.new
42
42
  @taggable = TaggableModel.new(:name=>"Richard Prior")
43
43
  end
44
44
 
@@ -86,8 +86,8 @@ describe "acts_as_tagger" do
86
86
 
87
87
  describe "when called by multiple tagger's" do
88
88
  before(:each) do
89
- @user_x = TaggableUser.create(:name => "User X")
90
- @user_y = TaggableUser.create(:name => "User Y")
89
+ @user_x = User.create(:name => "User X")
90
+ @user_y = User.create(:name => "User Y")
91
91
  @taggable = TaggableModel.create(:name => 'acts_as_taggable_on', :tag_list => 'plugin')
92
92
 
93
93
  @user_x.tag(@taggable, :with => 'ruby, rails', :on => :tags)
@@ -111,4 +111,4 @@ describe "acts_as_tagger" do
111
111
  end
112
112
  end
113
113
 
114
- end
114
+ end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Acts As Taggable On" do
4
+ before(:each) do
5
+ clean_database!
6
+ end
7
+
8
+ describe "Related Objects" do
9
+ it "should find related objects based on tag names on context" do
10
+ taggable1 = TaggableModel.create!(:name => "Taggable 1")
11
+ taggable2 = TaggableModel.create!(:name => "Taggable 2")
12
+ taggable3 = TaggableModel.create!(:name => "Taggable 3")
13
+
14
+ taggable1.tag_list = "one, two"
15
+ taggable1.save
16
+
17
+ taggable2.tag_list = "three, four"
18
+ taggable2.save
19
+
20
+ taggable3.tag_list = "one, four"
21
+ taggable3.save
22
+
23
+ taggable1.find_related_tags.should include(taggable3)
24
+ taggable1.find_related_tags.should_not include(taggable2)
25
+ end
26
+
27
+ it "finds related tags for ordered taggable on" do
28
+ taggable1 = OrderedTaggableModel.create!(:name => "Taggable 1")
29
+ taggable2 = OrderedTaggableModel.create!(:name => "Taggable 2")
30
+ taggable3 = OrderedTaggableModel.create!(:name => "Taggable 3")
31
+
32
+ taggable1.colour_list = "one, two"
33
+ taggable1.save
34
+
35
+ taggable2.colour_list = "three, four"
36
+ taggable2.save
37
+
38
+ taggable3.colour_list = "one, four"
39
+ taggable3.save
40
+
41
+ taggable1.find_related_colours.should include(taggable3)
42
+ taggable1.find_related_colours.should_not include(taggable2)
43
+ end
44
+
45
+ it "should find related objects based on tag names on context - non standard id" do
46
+ taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
47
+ taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
48
+ taggable3 = NonStandardIdTaggableModel.create!(:name => "Taggable 3")
49
+
50
+ taggable1.tag_list = "one, two"
51
+ taggable1.save
52
+
53
+ taggable2.tag_list = "three, four"
54
+ taggable2.save
55
+
56
+ taggable3.tag_list = "one, four"
57
+ taggable3.save
58
+
59
+ taggable1.find_related_tags.should include(taggable3)
60
+ taggable1.find_related_tags.should_not include(taggable2)
61
+ end
62
+
63
+ it "should find other related objects based on tag names on context" do
64
+ taggable1 = TaggableModel.create!(:name => "Taggable 1")
65
+ taggable2 = OtherTaggableModel.create!(:name => "Taggable 2")
66
+ taggable3 = OtherTaggableModel.create!(:name => "Taggable 3")
67
+
68
+ taggable1.tag_list = "one, two"
69
+ taggable1.save
70
+
71
+ taggable2.tag_list = "three, four"
72
+ taggable2.save
73
+
74
+ taggable3.tag_list = "one, four"
75
+ taggable3.save
76
+
77
+ taggable1.find_related_tags_for(OtherTaggableModel).should include(taggable3)
78
+ taggable1.find_related_tags_for(OtherTaggableModel).should_not include(taggable2)
79
+ end
80
+
81
+ it "should not include the object itself in the list of related objects" do
82
+ taggable1 = TaggableModel.create!(:name => "Taggable 1")
83
+ taggable2 = TaggableModel.create!(:name => "Taggable 2")
84
+
85
+ taggable1.tag_list = "one"
86
+ taggable1.save
87
+
88
+ taggable2.tag_list = "one, two"
89
+ taggable2.save
90
+
91
+ taggable1.find_related_tags.should include(taggable2)
92
+ taggable1.find_related_tags.should_not include(taggable1)
93
+ end
94
+
95
+ it "should not include the object itself in the list of related objects - non standard id" do
96
+ taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
97
+ taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
98
+
99
+ taggable1.tag_list = "one"
100
+ taggable1.save
101
+
102
+ taggable2.tag_list = "one, two"
103
+ taggable2.save
104
+
105
+ taggable1.find_related_tags.should include(taggable2)
106
+ taggable1.find_related_tags.should_not include(taggable1)
107
+ end
108
+
109
+ context "Ignored Tags" do
110
+ let(:taggable1) { TaggableModel.create!(:name => "Taggable 1") }
111
+ let(:taggable2) { TaggableModel.create!(:name => "Taggable 2") }
112
+ let(:taggable3) { TaggableModel.create!(:name => "Taggable 3") }
113
+ before(:each) do
114
+ taggable1.tag_list = "one, two, four"
115
+ taggable1.save
116
+
117
+ taggable2.tag_list = "two, three"
118
+ taggable2.save
119
+
120
+ taggable3.tag_list = "one, three"
121
+ taggable3.save
122
+ end
123
+ it "should not include ignored tags in related search" do
124
+ taggable1.find_related_tags(:ignore => 'two').should_not include(taggable2)
125
+ taggable1.find_related_tags(:ignore => 'two').should include(taggable3)
126
+ end
127
+
128
+ it "should accept array of ignored tags" do
129
+ taggable4 = TaggableModel.create!(:name => "Taggable 4")
130
+ taggable4.tag_list = "four"
131
+ taggable4.save
132
+
133
+ taggable1.find_related_tags(:ignore => ['two', 'four']).should_not include(taggable2)
134
+ taggable1.find_related_tags(:ignore => ['two', 'four']).should_not include(taggable4)
135
+ end
136
+
137
+ it "should accept symbols as ignored tags" do
138
+ taggable1.find_related_tags(:ignore => :two).should_not include(taggable2)
139
+ end
140
+ end
141
+
142
+ end
143
+ end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Single Table Inheritance" do
4
+
5
+ before(:each) do
6
+ clean_database!
7
+ end
8
+
9
+ let(:taggable) { TaggableModel.new(:name => "taggable model") }
10
+
11
+ let(:inheriting_model) { InheritingTaggableModel.new(:name => "Inheriting Taggable Model") }
12
+ let(:altered_inheriting) { AlteredInheritingTaggableModel.new(:name => "Altered Inheriting Model") }
13
+
14
+ 1.upto(4) do |n|
15
+ let(:"inheriting_#{n}") { InheritingTaggableModel.new(:name => "Inheriting Model #{n}") }
16
+ end
17
+
18
+ let(:student) { Student.create! }
19
+
20
+ describe "tag contexts" do
21
+ it "should pass on to STI-inherited models" do
22
+ inheriting_model.should respond_to(:tag_list, :skill_list, :language_list)
23
+ altered_inheriting.should respond_to(:tag_list, :skill_list, :language_list)
24
+ end
25
+
26
+ it "should pass on to altered STI models" do
27
+ altered_inheriting.should respond_to(:part_list)
28
+ end
29
+ end
30
+
31
+ context "matching contexts" do
32
+
33
+ before do
34
+ inheriting_1.offering_list = "one, two"
35
+ inheriting_1.need_list = "one, two"
36
+ inheriting_1.save!
37
+
38
+ inheriting_2.need_list = "one, two"
39
+ inheriting_2.save!
40
+
41
+ inheriting_3.offering_list = "one, two"
42
+ inheriting_3.save!
43
+
44
+ inheriting_4.tag_list = "one, two, three, four"
45
+ inheriting_4.save!
46
+
47
+ taggable.need_list = "one, two"
48
+ taggable.save!
49
+ end
50
+
51
+ it "should find objects with tags of matching contexts" do
52
+ inheriting_1.find_matching_contexts(:offerings, :needs).should include(inheriting_2)
53
+ inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(inheriting_3)
54
+ inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(inheriting_4)
55
+ inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(taggable)
56
+
57
+ inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(inheriting_2)
58
+ inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(inheriting_3)
59
+ inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(inheriting_4)
60
+ inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(taggable)
61
+ end
62
+
63
+ it "should not include the object itself in the list of related objects with tags of matching contexts" do
64
+ inheriting_1.find_matching_contexts(:offerings, :needs).should_not include(inheriting_1)
65
+ inheriting_1.find_matching_contexts_for(InheritingTaggableModel, :offerings, :needs).should_not include(inheriting_1)
66
+ inheriting_1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(inheriting_1)
67
+ end
68
+ end
69
+
70
+ context "find related tags" do
71
+ before do
72
+ inheriting_1.tag_list = "one, two"
73
+ inheriting_1.save
74
+
75
+ inheriting_2.tag_list = "three, four"
76
+ inheriting_2.save
77
+
78
+ inheriting_3.tag_list = "one, four"
79
+ inheriting_3.save
80
+
81
+ taggable.tag_list = "one, two, three, four"
82
+ taggable.save
83
+ end
84
+
85
+ it "should find related objects based on tag names on context" do
86
+ inheriting_1.find_related_tags.should include(inheriting_3)
87
+ inheriting_1.find_related_tags.should_not include(inheriting_2)
88
+ inheriting_1.find_related_tags.should_not include(taggable)
89
+
90
+ inheriting_1.find_related_tags_for(TaggableModel).should include(inheriting_3)
91
+ inheriting_1.find_related_tags_for(TaggableModel).should_not include(inheriting_2)
92
+ inheriting_1.find_related_tags_for(TaggableModel).should include(taggable)
93
+ end
94
+
95
+ it "should not include the object itself in the list of related objects" do
96
+ inheriting_1.find_related_tags.should_not include(inheriting_1)
97
+ inheriting_1.find_related_tags_for(InheritingTaggableModel).should_not include(inheriting_1)
98
+ inheriting_1.find_related_tags_for(TaggableModel).should_not include(inheriting_1)
99
+ end
100
+ end
101
+
102
+ describe "tag list" do
103
+ before do
104
+ @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
105
+ @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
106
+ end
107
+
108
+ it "should be able to save tags for inherited models" do
109
+ inheriting_model.tag_list = "bob, kelso"
110
+ inheriting_model.save
111
+ InheritingTaggableModel.tagged_with("bob").first.should == inheriting_model
112
+ end
113
+
114
+ it "should find STI tagged models on the superclass" do
115
+ inheriting_model.tag_list = "bob, kelso"
116
+ inheriting_model.save
117
+ TaggableModel.tagged_with("bob").first.should == inheriting_model
118
+ end
119
+
120
+ it "should be able to add on contexts only to some subclasses" do
121
+ altered_inheriting.part_list = "fork, spoon"
122
+ altered_inheriting.save
123
+ InheritingTaggableModel.tagged_with("fork", :on => :parts).should be_empty
124
+ AlteredInheritingTaggableModel.tagged_with("fork", :on => :parts).first.should == altered_inheriting
125
+ end
126
+
127
+ it "should have different tag_counts_on for inherited models" do
128
+ inheriting_model.tag_list = "bob, kelso"
129
+ inheriting_model.save!
130
+ altered_inheriting.tag_list = "fork, spoon"
131
+ altered_inheriting.save!
132
+
133
+ InheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
134
+ AlteredInheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
135
+ TaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
136
+ end
137
+
138
+ it "should have different tags_on for inherited models" do
139
+ inheriting_model.tag_list = "bob, kelso"
140
+ inheriting_model.save!
141
+ altered_inheriting.tag_list = "fork, spoon"
142
+ altered_inheriting.save!
143
+
144
+ InheritingTaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
145
+ AlteredInheritingTaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
146
+ TaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
147
+ end
148
+
149
+ it 'should store same tag without validation conflict' do
150
+ taggable.tag_list = 'one'
151
+ taggable.save!
152
+
153
+ inheriting_model.tag_list = 'one'
154
+ inheriting_model.save!
155
+
156
+ inheriting_model.update_attributes! :name => 'foo'
157
+ end
158
+ end
159
+
160
+ describe "ownership" do
161
+ it "should have taggings" do
162
+ student.tag(taggable, :with=>'ruby,scheme', :on=>:tags)
163
+ student.owned_taggings.should have(2).tags
164
+ end
165
+
166
+ it "should have tags" do
167
+ student.tag(taggable, :with=>'ruby,scheme', :on=>:tags)
168
+ student.owned_tags.should have(2).tags
169
+ end
170
+
171
+ it "should return tags for the inheriting tagger" do
172
+ student.tag(taggable, :with => 'ruby, scheme', :on => :tags)
173
+ taggable.tags_from(student).should match_array(%w(ruby scheme))
174
+ end
175
+
176
+ it "returns owner tags on the tagger" do
177
+ student.tag(taggable, :with => 'ruby, scheme', :on => :tags)
178
+ taggable.owner_tags_on(student, :tags).should have(2).tags
179
+ end
180
+
181
+ it "should scope objects returned by tagged_with by owners" do
182
+ student.tag(taggable, :with => 'ruby, scheme', :on => :tags)
183
+ TaggableModel.tagged_with(%w(ruby scheme), :owned_by => student).should have(1).tag
184
+ end
185
+ end
186
+
187
+ end
@@ -1,5 +1,5 @@
1
- # -*- coding: utf-8 -*-
2
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
3
 
4
4
  describe ActsAsTaggableOn::TagList do
5
5
  let(:tag_list) { ActsAsTaggableOn::TagList.new("awesome","radical") }
@@ -1,6 +1,5 @@
1
- #encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # encoding: utf-8
2
+ require 'spec_helper'
4
3
 
5
4
  describe ActsAsTaggableOn::Tag do
6
5
  before(:each) do
@@ -209,4 +208,4 @@ describe ActsAsTaggableOn::Tag do
209
208
  end
210
209
  end
211
210
  end
212
- end
211
+ end
@@ -1,11 +1,11 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Taggable To Preserve Order" do
4
4
  before(:each) do
5
5
  clean_database!
6
6
  @taggable = OrderedTaggableModel.new(:name => "Bob Jones")
7
7
  end
8
-
8
+
9
9
  it "should have tag types" do
10
10
  [:tags, :colours].each do |type|
11
11
  OrderedTaggableModel.tag_types.should include type
@@ -13,21 +13,21 @@ describe "Taggable To Preserve Order" do
13
13
 
14
14
  @taggable.tag_types.should == OrderedTaggableModel.tag_types
15
15
  end
16
-
16
+
17
17
  it "should have tag associations" do
18
18
  [:tags, :colours].each do |type|
19
19
  @taggable.respond_to?(type).should be_true
20
20
  @taggable.respond_to?("#{type.to_s.singularize}_taggings").should be_true
21
21
  end
22
22
  end
23
-
24
- it "should have tag associations ordered by id" do
25
- [:tags, :colours].each do |type|
26
- OrderedTaggableModel.reflect_on_association(type).options[:order].should include('id')
27
- OrderedTaggableModel.reflect_on_association("#{type.to_s.singularize}_taggings".to_sym).options[:order].should include('id')
28
- end
29
- end
30
-
23
+
24
+ # it "should have tag associations ordered by id" do
25
+ # [:tags, :colours].each do |type|
26
+ # OrderedTaggableModel.reflect_on_association(type).options[:order].should include('id')
27
+ # OrderedTaggableModel.reflect_on_association("#{type.to_s.singularize}_taggings".to_sym).options[:order].should include('id')
28
+ # end
29
+ # end
30
+
31
31
  it "should have tag methods" do
32
32
  [:tags, :colours].each do |type|
33
33
  @taggable.respond_to?("#{type.to_s.singularize}_list").should be_true
@@ -40,69 +40,69 @@ describe "Taggable To Preserve Order" do
40
40
  # create
41
41
  @taggable.tag_list = "rails, ruby, css"
42
42
  @taggable.instance_variable_get("@tag_list").instance_of?(ActsAsTaggableOn::TagList).should be_true
43
-
43
+
44
44
  lambda {
45
45
  @taggable.save
46
46
  }.should change(ActsAsTaggableOn::Tag, :count).by(3)
47
-
47
+
48
48
  @taggable.reload
49
49
  @taggable.tag_list.should == %w(rails ruby css)
50
-
50
+
51
51
  # update
52
52
  @taggable.tag_list = "pow, ruby, rails"
53
53
  @taggable.save
54
-
54
+
55
55
  @taggable.reload
56
56
  @taggable.tag_list.should == %w(pow ruby rails)
57
-
57
+
58
58
  # update with no change
59
59
  @taggable.tag_list = "pow, ruby, rails"
60
60
  @taggable.save
61
-
61
+
62
62
  @taggable.reload
63
63
  @taggable.tag_list.should == %w(pow ruby rails)
64
-
64
+
65
65
  # update to clear tags
66
66
  @taggable.tag_list = ""
67
67
  @taggable.save
68
-
68
+
69
69
  @taggable.reload
70
70
  @taggable.tag_list.should == []
71
71
  end
72
-
72
+
73
73
  it "should return tag objects in the order the tags were created" do
74
74
  # create
75
75
  @taggable.tag_list = "pow, ruby, rails"
76
76
  @taggable.instance_variable_get("@tag_list").instance_of?(ActsAsTaggableOn::TagList).should be_true
77
-
77
+
78
78
  lambda {
79
79
  @taggable.save
80
80
  }.should change(ActsAsTaggableOn::Tag, :count).by(3)
81
-
81
+
82
82
  @taggable.reload
83
83
  @taggable.tags.map{|t| t.name}.should == %w(pow ruby rails)
84
-
84
+
85
85
  # update
86
86
  @taggable.tag_list = "rails, ruby, css, pow"
87
87
  @taggable.save
88
-
88
+
89
89
  @taggable.reload
90
90
  @taggable.tags.map{|t| t.name}.should == %w(rails ruby css pow)
91
91
  end
92
-
92
+
93
93
  it "should return tag objects in tagging id order" do
94
94
  # create
95
95
  @taggable.tag_list = "pow, ruby, rails"
96
96
  @taggable.save
97
-
97
+
98
98
  @taggable.reload
99
99
  ids = @taggable.tags.map{|t| t.taggings.first.id}
100
100
  ids.should == ids.sort
101
-
101
+
102
102
  # update
103
103
  @taggable.tag_list = "rails, ruby, css, pow"
104
104
  @taggable.save
105
-
105
+
106
106
  @taggable.reload
107
107
  ids = @taggable.tags.map{|t| t.taggings.first.id}
108
108
  ids.should == ids.sort
@@ -125,7 +125,7 @@ describe "Taggable" do
125
125
  end
126
126
 
127
127
  it "should have tag_counts_on" do
128
- TaggableModel.tag_counts_on(:tags).all.should be_empty
128
+ TaggableModel.tag_counts_on(:tags).should be_empty
129
129
 
130
130
  @taggable.tag_list = ["awesome", "epic"]
131
131
  @taggable.save
@@ -135,7 +135,7 @@ describe "Taggable" do
135
135
  end
136
136
 
137
137
  it "should have tags_on" do
138
- TaggableModel.tags_on(:tags).all.should be_empty
138
+ TaggableModel.tags_on(:tags).should be_empty
139
139
 
140
140
  @taggable.tag_list = ["awesome", "epic"]
141
141
  @taggable.save
@@ -231,7 +231,7 @@ describe "Taggable" do
231
231
  bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby")
232
232
  frank = TaggableModel.create(:name => "Frank", :tag_list => "Ruby")
233
233
 
234
- ActsAsTaggableOn::Tag.find(:all).size.should == 1
234
+ ActsAsTaggableOn::Tag.all.size.should == 1
235
235
  TaggableModel.tagged_with("ruby").to_a.should == TaggableModel.tagged_with("Ruby").to_a
236
236
  end
237
237
 
@@ -239,8 +239,8 @@ describe "Taggable" do
239
239
  bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
240
240
  frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
241
241
  charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
242
- TaggableModel.tag_counts.all.should_not be_empty
243
- TaggableModel.skill_counts.all.should_not be_empty
242
+ TaggableModel.tag_counts.should_not be_empty
243
+ TaggableModel.skill_counts.should_not be_empty
244
244
  end
245
245
 
246
246
  it "should be able to get all tag counts on model as whole" do
@@ -248,7 +248,7 @@ describe "Taggable" do
248
248
  frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
249
249
  charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
250
250
 
251
- TaggableModel.all_tag_counts.all.should_not be_empty
251
+ TaggableModel.all_tag_counts.should_not be_empty
252
252
  TaggableModel.all_tag_counts(:order => 'tags.id').first.count.should == 3 # ruby
253
253
  end
254
254
 
@@ -257,7 +257,7 @@ describe "Taggable" do
257
257
  frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
258
258
  charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
259
259
 
260
- TaggableModel.all_tags.all.should_not be_empty
260
+ TaggableModel.all_tags.should_not be_empty
261
261
  TaggableModel.all_tags(:order => 'tags.id').first.name.should == "ruby"
262
262
  end
263
263
 
@@ -310,9 +310,9 @@ describe "Taggable" do
310
310
 
311
311
  # Test specific join syntaxes:
312
312
  frank.untaggable_models.create!
313
- TaggableModel.tagged_with('rails').scoped(:joins => :untaggable_models).all_tag_counts.should have(2).items
314
- TaggableModel.tagged_with('rails').scoped(:joins => { :untaggable_models => :taggable_model }).all_tag_counts.should have(2).items
315
- TaggableModel.tagged_with('rails').scoped(:joins => [:untaggable_models]).all_tag_counts.should have(2).items
313
+ TaggableModel.tagged_with('rails').joins(:untaggable_models).all_tag_counts.should have(2).items
314
+ TaggableModel.tagged_with('rails').joins(:untaggable_models => :taggable_model).all_tag_counts.should have(2).items
315
+ TaggableModel.tagged_with('rails').joins([:untaggable_models]).all_tag_counts.should have(2).items
316
316
  end
317
317
 
318
318
  it 'should only return tags for the available scope' do
@@ -325,9 +325,9 @@ describe "Taggable" do
325
325
 
326
326
  # Test specific join syntaxes:
327
327
  frank.untaggable_models.create!
328
- TaggableModel.tagged_with('rails').scoped(:joins => :untaggable_models).all_tags.should have(2).items
329
- TaggableModel.tagged_with('rails').scoped(:joins => { :untaggable_models => :taggable_model }).all_tags.should have(2).items
330
- TaggableModel.tagged_with('rails').scoped(:joins => [:untaggable_models]).all_tags.should have(2).items
328
+ TaggableModel.tagged_with('rails').joins(:untaggable_models).all_tags.should have(2).items
329
+ TaggableModel.tagged_with('rails').joins({ :untaggable_models => :taggable_model }).all_tags.should have(2).items
330
+ TaggableModel.tagged_with('rails').joins([:untaggable_models]).all_tags.should have(2).items
331
331
  end
332
332
 
333
333
  it "should be able to set a custom tag context list" do
@@ -461,65 +461,6 @@ describe "Taggable" do
461
461
  end
462
462
  end
463
463
 
464
- describe "Single Table Inheritance" do
465
- before do
466
- @taggable = TaggableModel.new(:name => "taggable")
467
- @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
468
- @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
469
- end
470
-
471
- it "should be able to save tags for inherited models" do
472
- @inherited_same.tag_list = "bob, kelso"
473
- @inherited_same.save
474
- InheritingTaggableModel.tagged_with("bob").first.should == @inherited_same
475
- end
476
-
477
- it "should find STI tagged models on the superclass" do
478
- @inherited_same.tag_list = "bob, kelso"
479
- @inherited_same.save
480
- TaggableModel.tagged_with("bob").first.should == @inherited_same
481
- end
482
-
483
- it "should be able to add on contexts only to some subclasses" do
484
- @inherited_different.part_list = "fork, spoon"
485
- @inherited_different.save
486
- InheritingTaggableModel.tagged_with("fork", :on => :parts).should be_empty
487
- AlteredInheritingTaggableModel.tagged_with("fork", :on => :parts).first.should == @inherited_different
488
- end
489
-
490
- it "should have different tag_counts_on for inherited models" do
491
- @inherited_same.tag_list = "bob, kelso"
492
- @inherited_same.save!
493
- @inherited_different.tag_list = "fork, spoon"
494
- @inherited_different.save!
495
-
496
- InheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
497
- AlteredInheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
498
- TaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
499
- end
500
-
501
- it "should have different tags_on for inherited models" do
502
- @inherited_same.tag_list = "bob, kelso"
503
- @inherited_same.save!
504
- @inherited_different.tag_list = "fork, spoon"
505
- @inherited_different.save!
506
-
507
- InheritingTaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
508
- AlteredInheritingTaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
509
- TaggableModel.tags_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
510
- end
511
-
512
- it 'should store same tag without validation conflict' do
513
- @taggable.tag_list = 'one'
514
- @taggable.save!
515
-
516
- @inherited_same.tag_list = 'one'
517
- @inherited_same.save!
518
-
519
- @inherited_same.update_attributes! :name => 'foo'
520
- end
521
- end
522
-
523
464
  describe "NonStandardIdTaggable" do
524
465
  before(:each) do
525
466
  clean_database!
@@ -536,7 +477,7 @@ describe "Taggable" do
536
477
  end
537
478
 
538
479
  it "should have tag_counts_on" do
539
- NonStandardIdTaggableModel.tag_counts_on(:tags).all.should be_empty
480
+ NonStandardIdTaggableModel.tag_counts_on(:tags).should be_empty
540
481
 
541
482
  @taggable.tag_list = ["awesome", "epic"]
542
483
  @taggable.save
@@ -546,7 +487,7 @@ describe "Taggable" do
546
487
  end
547
488
 
548
489
  it "should have tags_on" do
549
- NonStandardIdTaggableModel.tags_on(:tags).all.should be_empty
490
+ NonStandardIdTaggableModel.tags_on(:tags).should be_empty
550
491
 
551
492
  @taggable.tag_list = ["awesome", "epic"]
552
493
  @taggable.save
@@ -581,24 +522,94 @@ describe "Taggable" do
581
522
  end
582
523
 
583
524
  describe "Dirty Objects" do
584
- before(:each) do
585
- @taggable = TaggableModel.create(:tag_list => "awesome, epic")
586
- end
525
+ context "with un-contexted tags" do
526
+ before(:each) do
527
+ @taggable = TaggableModel.create(:tag_list => "awesome, epic")
528
+ end
587
529
 
588
- it 'should show changes of dirty object' do
589
- @taggable.changes.should == {}
590
- @taggable.tag_list = 'one'
591
- @taggable.changes.should == {"tag_list"=>["awesome, epic", ["one"]]}
530
+ context "when tag_list changed" do
531
+ before(:each) do
532
+ @taggable.changes.should == {}
533
+ @taggable.tag_list = 'one'
534
+ end
592
535
 
593
- @taggable.tag_list_changed?.should be_true
594
- @taggable.tag_list_was.should == "awesome, epic"
595
- @taggable.tag_list_change.should == ["awesome, epic", ["one"]]
536
+ it 'should show changes of dirty object' do
537
+ @taggable.changes.should == {"tag_list"=>["awesome, epic", ["one"]]}
538
+ end
539
+
540
+ it 'flags tag_list as changed' do
541
+ @taggable.tag_list_changed?.should be_true
542
+ end
543
+
544
+ it 'preserves original value' do
545
+ @taggable.tag_list_was.should == "awesome, epic"
546
+ end
547
+
548
+ it 'shows what the change was' do
549
+ @taggable.tag_list_change.should == ["awesome, epic", ["one"]]
550
+ end
551
+ end
552
+
553
+ context 'when tag_list is the same' do
554
+ before(:each) do
555
+ @taggable.tag_list = "awesome, epic"
556
+ end
557
+
558
+ it 'is not flagged as changed' do
559
+ @taggable.tag_list_changed?.should be_false
560
+ end
561
+
562
+ it 'does not show any changes to the taggable item' do
563
+ @taggable.changes.should == {}
564
+ end
565
+ end
596
566
  end
597
567
 
598
- it 'should show no changes if the same tag_list' do
599
- @taggable.tag_list = "awesome, epic"
600
- @taggable.tag_list_changed?.should be_false
601
- @taggable.changes.should == {}
568
+ context "with context tags" do
569
+ before(:each) do
570
+ @taggable = TaggableModel.create(:language_list => "awesome, epic")
571
+ end
572
+
573
+ context "when language_list changed" do
574
+ before(:each) do
575
+ @taggable.changes.should == {}
576
+ @taggable.language_list = 'one'
577
+ end
578
+
579
+ it 'should show changes of dirty object' do
580
+ @taggable.changes.should == {"language_list"=>["awesome, epic", ["one"]]}
581
+ end
582
+
583
+ it 'flags language_list as changed' do
584
+ @taggable.language_list_changed?.should be_true
585
+ end
586
+
587
+ it 'preserves original value' do
588
+ @taggable.language_list_was.should == "awesome, epic"
589
+ end
590
+
591
+ it 'shows what the change was' do
592
+ @taggable.language_list_change.should == ["awesome, epic", ["one"]]
593
+ end
594
+
595
+ it 'shows what the changes were' do
596
+ @taggable.language_list_changes.should == ["awesome, epic", ["one"]]
597
+ end
598
+ end
599
+
600
+ context 'when language_list is the same' do
601
+ before(:each) do
602
+ @taggable.language_list = "awesome, epic"
603
+ end
604
+
605
+ it 'is not flagged as changed' do
606
+ @taggable.language_list_changed?.should be_false
607
+ end
608
+
609
+ it 'does not show any changes to the taggable item' do
610
+ @taggable.changes.should == {}
611
+ end
612
+ end
602
613
  end
603
614
  end
604
615