acts-as-taggable-on 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -34,4 +34,4 @@ module ActsAsTaggableOn::Taggable
34
34
  end
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -37,10 +37,14 @@ module ActsAsTaggableOn::Taggable
37
37
  #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = ? AND
38
38
  #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = ?), context.to_s, owner.id, owner.class.base_class.to_s])
39
39
  end
40
+
40
41
  # when preserving tag order, return tags in created order
41
42
  # if we added the order to the association this would always apply
42
- scope = scope.order("#{ActsAsTaggableOn::Tagging.table_name}.id") if self.class.preserve_tag_order?
43
- scope.all
43
+ if self.class.preserve_tag_order?
44
+ scope.order("#{ActsAsTaggableOn::Tagging.table_name}.id")
45
+ else
46
+ scope
47
+ end
44
48
  end
45
49
 
46
50
  def cached_owned_tag_list_on(context)
@@ -52,7 +56,6 @@ module ActsAsTaggableOn::Taggable
52
56
  add_custom_context(context)
53
57
 
54
58
  cache = cached_owned_tag_list_on(context)
55
- cache.delete_if { |key, value| key.id == owner.id && key.class == owner.class }
56
59
 
57
60
  cache[owner] ||= ActsAsTaggableOn::TagList.new(*owner_tags_on(owner, context).map(&:name))
58
61
  end
@@ -61,7 +64,6 @@ module ActsAsTaggableOn::Taggable
61
64
  add_custom_context(context)
62
65
 
63
66
  cache = cached_owned_tag_list_on(context)
64
- cache.delete_if { |key, value| key.id == owner.id && key.class == owner.class }
65
67
 
66
68
  cache[owner] = ActsAsTaggableOn::TagList.from(new_list)
67
69
  end
@@ -86,13 +88,20 @@ module ActsAsTaggableOn::Taggable
86
88
 
87
89
  # Tag maintenance based on whether preserving the created order of tags
88
90
  if self.class.preserve_tag_order?
89
- # First off order the array of tag objects to match the tag list
90
- # rather than existing tags followed by new tags
91
- tags = tag_list.uniq.map{|s| tags.detect{|t| t.name.downcase == s.downcase}}
92
- # To preserve tags in the order in which they were added
93
- # delete all owned tags and create new tags if the content or order has changed
94
- old_tags = (tags == owned_tags ? [] : owned_tags)
95
- new_tags = (tags == owned_tags ? [] : tags)
91
+ old_tags, new_tags = owned_tags - tags, tags - owned_tags
92
+
93
+ shared_tags = owned_tags & tags
94
+
95
+ if shared_tags.any? && tags[0...shared_tags.size] != shared_tags
96
+ index = shared_tags.each_with_index { |_, i| break i unless shared_tags[i] == tags[i] }
97
+
98
+ # Update arrays of tag objects
99
+ old_tags |= owned_tags.from(index)
100
+ new_tags |= owned_tags.from(index) & shared_tags
101
+
102
+ # Order the array of tag objects to match the tag list
103
+ new_tags = tags.map { |t| new_tags.find { |n| n.name.downcase == t.name.downcase } }.compact
104
+ end
96
105
  else
97
106
  # Delete discarded tags and create new tags
98
107
  old_tags = owned_tags - tags
@@ -104,7 +113,7 @@ module ActsAsTaggableOn::Taggable
104
113
  if old_tags.present?
105
114
  old_taggings = ActsAsTaggableOn::Tagging.where(:taggable_id => id, :taggable_type => self.class.base_class.to_s,
106
115
  :tagger_type => owner.class.base_class.to_s, :tagger_id => owner.id,
107
- :tag_id => old_tags, :context => context).all
116
+ :tag_id => old_tags, :context => context)
108
117
  end
109
118
 
110
119
  # Destroy old taggings:
@@ -44,31 +44,40 @@ module ActsAsTaggableOn::Taggable
44
44
  def matching_contexts_for(search_context, result_context, klass, options = {})
45
45
  tags_to_find = tags_on(search_context).collect { |t| t.name }
46
46
 
47
- exclude_self = "#{klass.table_name}.#{klass.primary_key} != #{id} AND" if [self.class.base_class, self.class].include? klass
48
-
49
- group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(klass) : "#{klass.table_name}.#{klass.primary_key}"
50
-
51
- klass.scoped({ :select => "#{klass.table_name}.*, COUNT(#{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key}) AS count",
52
- :from => "#{klass.table_name}, #{ActsAsTaggableOn::Tag.table_name}, #{ActsAsTaggableOn::Tagging.table_name}",
53
- :conditions => ["#{exclude_self} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class.to_s}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?) AND #{ActsAsTaggableOn::Tagging.table_name}.context = ?", tags_to_find, result_context],
54
- :group => group_columns,
55
- :order => "count DESC" }.update(options))
47
+ klass.select("#{klass.table_name}.*, COUNT(#{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key}) AS count") \
48
+ .from("#{klass.table_name}, #{ActsAsTaggableOn::Tag.table_name}, #{ActsAsTaggableOn::Tagging.table_name}") \
49
+ .where(["#{exclude_self(klass, id)} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class.to_s}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?) AND #{ActsAsTaggableOn::Tagging.table_name}.context = ?", tags_to_find, result_context]) \
50
+ .group(group_columns(klass)) \
51
+ .order("count DESC")
56
52
  end
57
53
 
58
54
  def related_tags_for(context, klass, options = {})
59
- tags_to_ignore = Array.wrap(options.delete(:ignore)) || []
60
- tags_to_ignore.map! { |t| t.to_s }
55
+ tags_to_ignore = Array.wrap(options.delete(:ignore)).map(&:to_s) || []
61
56
  tags_to_find = tags_on(context).collect { |t| t.name }.reject { |t| tags_to_ignore.include? t }
62
57
 
63
- exclude_self = "#{klass.table_name}.#{klass.primary_key} != #{id} AND" if [self.class.base_class, self.class].include? klass
58
+ klass.select("#{klass.table_name}.*, COUNT(#{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key}) AS count") \
59
+ .from("#{klass.table_name}, #{ActsAsTaggableOn::Tag.table_name}, #{ActsAsTaggableOn::Tagging.table_name}") \
60
+ .where(["#{exclude_self(klass, id)} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class.to_s}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?)", tags_to_find]) \
61
+ .group(group_columns(klass)) \
62
+ .order("count DESC")
63
+ end
64
64
 
65
- group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(klass) : "#{klass.table_name}.#{klass.primary_key}"
65
+ private
66
+
67
+ def exclude_self(klass, id)
68
+ if [self.class.base_class, self.class].include? klass
69
+ "#{klass.table_name}.#{klass.primary_key} != #{id} AND"
70
+ else
71
+ nil
72
+ end
73
+ end
66
74
 
67
- klass.scoped({ :select => "#{klass.table_name}.*, COUNT(#{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key}) AS count",
68
- :from => "#{klass.table_name}, #{ActsAsTaggableOn::Tag.table_name}, #{ActsAsTaggableOn::Tagging.table_name}",
69
- :conditions => ["#{exclude_self} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class.to_s}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?)", tags_to_find],
70
- :group => group_columns,
71
- :order => "count DESC" }.update(options))
75
+ def group_columns(klass)
76
+ if ActsAsTaggableOn::Tag.using_postgresql?
77
+ grouped_column_names_for(klass)
78
+ else
79
+ "#{klass.table_name}.#{klass.primary_key}"
80
+ end
72
81
  end
73
82
  end
74
83
  end
@@ -2,7 +2,7 @@ module ActsAsTaggableOn
2
2
  class Tag < ::ActiveRecord::Base
3
3
  include ActsAsTaggableOn::Utils
4
4
 
5
- attr_accessible :name
5
+ attr_accessible :name if defined?(ActiveModel::MassAssignmentSecurity)
6
6
 
7
7
  ### ASSOCIATIONS:
8
8
 
@@ -60,14 +60,14 @@ module ActsAsTaggableOn
60
60
 
61
61
  return [] if list.empty?
62
62
 
63
- existing_tags = Tag.named_any(list).all
64
- new_tag_names = list.reject do |name|
65
- name = comparable_name(name)
66
- existing_tags.any? { |tag| comparable_name(tag.name) == name }
67
- end
68
- created_tags = new_tag_names.map { |name| Tag.create(:name => name) }
63
+ existing_tags = Tag.named_any(list)
64
+
65
+ list.map do |tag_name|
66
+ comparable_tag_name = comparable_name(tag_name)
67
+ existing_tag = existing_tags.find { |tag| comparable_name(tag.name) == comparable_tag_name }
69
68
 
70
- existing_tags + created_tags
69
+ existing_tag || Tag.create(:name => tag_name)
70
+ end
71
71
  end
72
72
 
73
73
  ### INSTANCE METHODS:
@@ -80,7 +80,7 @@ module ActsAsTaggableOn
80
80
  self.preserve_tag_order = preserve_tag_order
81
81
 
82
82
  class_eval do
83
- has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "ActsAsTaggableOn::Tagging"
83
+ has_many :taggings, :as => :taggable, :dependent => :destroy, :class_name => "ActsAsTaggableOn::Tagging"
84
84
  has_many :base_tags, :through => :taggings, :source => :tag, :class_name => "ActsAsTaggableOn::Tag"
85
85
 
86
86
  def self.taggable?
@@ -88,14 +88,17 @@ module ActsAsTaggableOn
88
88
  end
89
89
 
90
90
  include ActsAsTaggableOn::Utils
91
- include ActsAsTaggableOn::Taggable::Core
92
- include ActsAsTaggableOn::Taggable::Collection
93
- include ActsAsTaggableOn::Taggable::Cache
94
- include ActsAsTaggableOn::Taggable::Ownership
95
- include ActsAsTaggableOn::Taggable::Related
96
- include ActsAsTaggableOn::Taggable::Dirty
97
91
  end
98
92
  end
93
+
94
+ # each of these add context-specific methods and must be
95
+ # called on each call of taggable_on
96
+ include ActsAsTaggableOn::Taggable::Core
97
+ include ActsAsTaggableOn::Taggable::Collection
98
+ include ActsAsTaggableOn::Taggable::Cache
99
+ include ActsAsTaggableOn::Taggable::Ownership
100
+ include ActsAsTaggableOn::Taggable::Related
101
+ include ActsAsTaggableOn::Taggable::Dirty
99
102
  end
100
103
 
101
104
  end
@@ -15,9 +15,18 @@ module ActsAsTaggableOn
15
15
  # end
16
16
  def acts_as_tagger(opts={})
17
17
  class_eval do
18
- has_many :owned_taggings, opts.merge(:as => :tagger, :dependent => :destroy,
19
- :include => :tag, :class_name => "ActsAsTaggableOn::Tagging")
20
- has_many :owned_tags, :through => :owned_taggings, :source => :tag, :uniq => true, :class_name => "ActsAsTaggableOn::Tag"
18
+ has_many_with_compatibility :owned_taggings,
19
+ opts.merge(
20
+ :as => :tagger,
21
+ :dependent => :destroy,
22
+ :class_name => "ActsAsTaggableOn::Tagging"
23
+ )
24
+
25
+ has_many_with_compatibility :owned_tags,
26
+ :through => :owned_taggings,
27
+ :source => :tag,
28
+ :class_name => "ActsAsTaggableOn::Tag",
29
+ :uniq => true
21
30
  end
22
31
 
23
32
  include ActsAsTaggableOn::Tagger::InstanceMethods
@@ -8,7 +8,7 @@ module ActsAsTaggableOn
8
8
  :taggable_id,
9
9
  :tagger,
10
10
  :tagger_type,
11
- :tagger_id
11
+ :tagger_id if defined?(ActiveModel::MassAssignmentSecurity)
12
12
 
13
13
  belongs_to :tag, :class_name => 'ActsAsTaggableOn::Tag'
14
14
  belongs_to :taggable, :polymorphic => true
@@ -31,4 +31,4 @@ module ActsAsTaggableOn
31
31
  end
32
32
  end
33
33
  end
34
- end
34
+ end
@@ -2,8 +2,6 @@ module ActsAsTaggableOn
2
2
  module TagsHelper
3
3
  # See the README for an example using tag_cloud.
4
4
  def tag_cloud(tags, classes)
5
- tags = tags.all if tags.respond_to?(:all)
6
-
7
5
  return [] if tags.empty?
8
6
 
9
7
  max_count = tags.sort_by(&:count).last.count.to_f
@@ -1,4 +1,4 @@
1
1
  module ActsAsTaggableOn
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.1'
3
3
  end
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Acts As Taggable On" do
4
4
  before(:each) do
@@ -77,23 +77,6 @@ describe "Acts As Taggable On" do
77
77
  end
78
78
  end
79
79
 
80
- describe "Single Table Inheritance" do
81
- before do
82
- @taggable = TaggableModel.new(:name => "taggable")
83
- @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
84
- @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
85
- end
86
-
87
- it "should pass on tag contexts to STI-inherited models" do
88
- @inherited_same.should respond_to(:tag_list, :skill_list, :language_list)
89
- @inherited_different.should respond_to(:tag_list, :skill_list, :language_list)
90
- end
91
-
92
- it "should have tag contexts added in altered STI models" do
93
- @inherited_different.should respond_to(:part_list)
94
- end
95
- end
96
-
97
80
  describe "Reloading" do
98
81
  it "should save a model instantiated by Model.find" do
99
82
  taggable = TaggableModel.create!(:name => "Taggable")
@@ -102,161 +85,6 @@ describe "Acts As Taggable On" do
102
85
  end
103
86
  end
104
87
 
105
- describe "Related Objects" do
106
- it "should find related objects based on tag names on context" do
107
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
108
- taggable2 = TaggableModel.create!(:name => "Taggable 2")
109
- taggable3 = TaggableModel.create!(:name => "Taggable 3")
110
-
111
- taggable1.tag_list = "one, two"
112
- taggable1.save
113
-
114
- taggable2.tag_list = "three, four"
115
- taggable2.save
116
-
117
- taggable3.tag_list = "one, four"
118
- taggable3.save
119
-
120
- taggable1.find_related_tags.should include(taggable3)
121
- taggable1.find_related_tags.should_not include(taggable2)
122
- end
123
-
124
- it "should find related objects based on tag names on context - non standard id" do
125
- taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
126
- taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
127
- taggable3 = NonStandardIdTaggableModel.create!(:name => "Taggable 3")
128
-
129
- taggable1.tag_list = "one, two"
130
- taggable1.save
131
-
132
- taggable2.tag_list = "three, four"
133
- taggable2.save
134
-
135
- taggable3.tag_list = "one, four"
136
- taggable3.save
137
-
138
- taggable1.find_related_tags.should include(taggable3)
139
- taggable1.find_related_tags.should_not include(taggable2)
140
- end
141
-
142
- it "should find other related objects based on tag names on context" do
143
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
144
- taggable2 = OtherTaggableModel.create!(:name => "Taggable 2")
145
- taggable3 = OtherTaggableModel.create!(:name => "Taggable 3")
146
-
147
- taggable1.tag_list = "one, two"
148
- taggable1.save
149
-
150
- taggable2.tag_list = "three, four"
151
- taggable2.save
152
-
153
- taggable3.tag_list = "one, four"
154
- taggable3.save
155
-
156
- taggable1.find_related_tags_for(OtherTaggableModel).should include(taggable3)
157
- taggable1.find_related_tags_for(OtherTaggableModel).should_not include(taggable2)
158
- end
159
-
160
- it "should not include the object itself in the list of related objects" do
161
- taggable1 = TaggableModel.create!(:name => "Taggable 1")
162
- taggable2 = TaggableModel.create!(:name => "Taggable 2")
163
-
164
- taggable1.tag_list = "one"
165
- taggable1.save
166
-
167
- taggable2.tag_list = "one, two"
168
- taggable2.save
169
-
170
- taggable1.find_related_tags.should include(taggable2)
171
- taggable1.find_related_tags.should_not include(taggable1)
172
- end
173
-
174
- it "should not include the object itself in the list of related objects - non standard id" do
175
- taggable1 = NonStandardIdTaggableModel.create!(:name => "Taggable 1")
176
- taggable2 = NonStandardIdTaggableModel.create!(:name => "Taggable 2")
177
-
178
- taggable1.tag_list = "one"
179
- taggable1.save
180
-
181
- taggable2.tag_list = "one, two"
182
- taggable2.save
183
-
184
- taggable1.find_related_tags.should include(taggable2)
185
- taggable1.find_related_tags.should_not include(taggable1)
186
- end
187
-
188
- context "Ignored Tags" do
189
- let(:taggable1) { TaggableModel.create!(:name => "Taggable 1") }
190
- let(:taggable2) { TaggableModel.create!(:name => "Taggable 2") }
191
- let(:taggable3) { TaggableModel.create!(:name => "Taggable 3") }
192
- before(:each) do
193
- taggable1.tag_list = "one, two, four"
194
- taggable1.save
195
-
196
- taggable2.tag_list = "two, three"
197
- taggable2.save
198
-
199
- taggable3.tag_list = "one, three"
200
- taggable3.save
201
- end
202
- it "should not include ignored tags in related search" do
203
- taggable1.find_related_tags(:ignore => 'two').should_not include(taggable2)
204
- taggable1.find_related_tags(:ignore => 'two').should include(taggable3)
205
- end
206
-
207
- it "should accept array of ignored tags" do
208
- taggable4 = TaggableModel.create!(:name => "Taggable 4")
209
- taggable4.tag_list = "four"
210
- taggable4.save
211
-
212
- taggable1.find_related_tags(:ignore => ['two', 'four']).should_not include(taggable2)
213
- taggable1.find_related_tags(:ignore => ['two', 'four']).should_not include(taggable4)
214
- end
215
-
216
- it "should accept symbols as ignored tags" do
217
- taggable1.find_related_tags(:ignore => :two).should_not include(taggable2)
218
- end
219
- end
220
-
221
- context "Inherited Models" do
222
- before do
223
- @taggable1 = InheritingTaggableModel.create!(:name => "InheritingTaggable 1")
224
- @taggable2 = InheritingTaggableModel.create!(:name => "InheritingTaggable 2")
225
- @taggable3 = InheritingTaggableModel.create!(:name => "InheritingTaggable 3")
226
- @taggable4 = TaggableModel.create!(:name => "Taggable 4")
227
-
228
- @taggable1.tag_list = "one, two"
229
- @taggable1.save
230
-
231
- @taggable2.tag_list = "three, four"
232
- @taggable2.save
233
-
234
- @taggable3.tag_list = "one, four"
235
- @taggable3.save
236
-
237
- @taggable4.tag_list = "one, two, three, four"
238
- @taggable4.save
239
- end
240
-
241
- it "should find related objects based on tag names on context" do
242
- @taggable1.find_related_tags.should include(@taggable3)
243
- @taggable1.find_related_tags.should_not include(@taggable2)
244
- @taggable1.find_related_tags.should_not include(@taggable4)
245
-
246
- @taggable1.find_related_tags_for(TaggableModel).should include(@taggable3)
247
- @taggable1.find_related_tags_for(TaggableModel).should_not include(@taggable2)
248
- @taggable1.find_related_tags_for(TaggableModel).should include(@taggable4)
249
- end
250
-
251
- it "should not include the object itself in the list of related objects" do
252
- @taggable1.find_related_tags.should_not include(@taggable1)
253
- @taggable1.find_related_tags_for(InheritingTaggableModel).should_not include(@taggable1)
254
- @taggable1.find_related_tags_for(TaggableModel).should_not include(@taggable1)
255
- end
256
- end
257
-
258
- end
259
-
260
88
  describe "Matching Contexts" do
261
89
  it "should find objects with tags of matching contexts" do
262
90
  taggable1 = TaggableModel.create!(:name => "Taggable 1")
@@ -309,49 +137,6 @@ describe "Acts As Taggable On" do
309
137
  taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(taggable1)
310
138
  end
311
139
 
312
- context "Inherited Models" do
313
- before do
314
- @taggable1 = InheritingTaggableModel.create!(:name => "InheritingTaggable 1")
315
- @taggable2 = InheritingTaggableModel.create!(:name => "InheritingTaggable 2")
316
- @taggable3 = InheritingTaggableModel.create!(:name => "InheritingTaggable 3")
317
- @taggable4 = InheritingTaggableModel.create!(:name => "InheritingTaggable 4")
318
- @taggable5 = TaggableModel.create!(:name => "Taggable 5")
319
-
320
- @taggable1.offering_list = "one, two"
321
- @taggable1.need_list = "one, two"
322
- @taggable1.save!
323
-
324
- @taggable2.need_list = "one, two"
325
- @taggable2.save!
326
-
327
- @taggable3.offering_list = "one, two"
328
- @taggable3.save!
329
-
330
- @taggable4.tag_list = "one, two, three, four"
331
- @taggable4.save!
332
-
333
- @taggable5.need_list = "one, two"
334
- @taggable5.save!
335
- end
336
-
337
- it "should find objects with tags of matching contexts" do
338
- @taggable1.find_matching_contexts(:offerings, :needs).should include(@taggable2)
339
- @taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable3)
340
- @taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable4)
341
- @taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable5)
342
-
343
- @taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(@taggable2)
344
- @taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(@taggable3)
345
- @taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(@taggable4)
346
- @taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should include(@taggable5)
347
- end
348
-
349
- it "should not include the object itself in the list of related objects with tags of matching contexts" do
350
- @taggable1.find_matching_contexts(:offerings, :needs).should_not include(@taggable1)
351
- @taggable1.find_matching_contexts_for(InheritingTaggableModel, :offerings, :needs).should_not include(@taggable1)
352
- @taggable1.find_matching_contexts_for(TaggableModel, :offerings, :needs).should_not include(@taggable1)
353
- end
354
- end
355
140
  end
356
141
 
357
142
  describe 'Tagging Contexts' do