acts-as-taggable-on 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -395,14 +395,16 @@ module ActiveRecord
395
395
  transaction do
396
396
  contexts.each do |context|
397
397
  cache = tag_list_cache_on(context)
398
-
398
+
399
399
  cache.each do |owner, list|
400
400
  new_tags = Tag.find_or_create_all_with_like_by_name(list.uniq)
401
+ taggings = Tagging.find(:all, :conditions => { :taggable_id => self.id, :taggable_type => self.class.to_s })
401
402
 
402
403
  # Destroy old taggings:
403
404
  if owner
404
405
  old_tags = tags_on(context, owner) - new_tags
405
- old_taggings = taggings.find(:all, :conditions => { :tag_id => old_tags, :tagger_id => owner, :tagger_type => owner.class.to_s, :context => context })
406
+ old_taggings = Tagging.find(:all, :conditions => { :taggable_id => self.id, :taggable_type => self.class.to_s, :tag_id => old_tags, :tagger_id => owner, :tagger_type => owner.class.to_s, :context => context })
407
+
406
408
  old_taggings.each(&:destroy)
407
409
  else
408
410
  old_tags = tags_on(context) - new_tags
@@ -415,7 +417,7 @@ module ActiveRecord
415
417
 
416
418
  # create new taggings:
417
419
  new_tags.each do |tag|
418
- taggings.create!(:tag_id => tag.id, :context => context, :tagger => owner)
420
+ Tagging.create!(:tag_id => tag.id, :context => context, :tagger => owner, :taggable => self)
419
421
  end
420
422
  end
421
423
  end
@@ -26,6 +26,8 @@ class Tag < ActiveRecord::Base
26
26
 
27
27
  def self.find_or_create_all_with_like_by_name(*list)
28
28
  list = [list].flatten
29
+
30
+ return [] if list.empty?
29
31
 
30
32
  existing_tags = Tag.named_any(list).all
31
33
  new_tag_names = list.reject { |name| existing_tags.any? { |tag| tag.name.downcase == name.downcase } }
@@ -85,21 +85,25 @@ describe "acts_as_tagger" do
85
85
 
86
86
  context "when called by multiple tagger's" do
87
87
  before(:each) do
88
- @user_x = TaggableUser.new
89
- @user_y = TaggableUser.new
88
+ @user_x = TaggableUser.new(:name => "User X")
89
+ @user_y = TaggableUser.new(:name => "User Y")
90
90
  @taggable = TaggableModel.new(:name => 'acts_as_taggable_on', :tag_list => 'plugin')
91
91
 
92
92
  @user_x.tag(@taggable, :with => 'ruby, rails', :on => :tags)
93
93
  @user_y.tag(@taggable, :with => 'ruby, plugin', :on => :tags)
94
+
95
+ @user_y.tag(@taggable, :with => '', :on => :tags)
96
+ end
97
+
98
+ it "should delete owned tags" do
99
+ @user_y.owned_tags.should be_empty
94
100
  end
95
101
 
96
102
  it "should not delete other taggers tags" do
97
- @user_y.tag(@taggable, :with => '', :on => :tags)
98
- @taggable.all_tags_list_on(:tags).should include('ruby')
103
+ @user_x.owned_tags.should have(2).items
99
104
  end
100
105
 
101
106
  it "should not delete original tags" do
102
- @user_y.tag(@taggable, :with => '', :on => :tags)
103
107
  @taggable.all_tags_list_on(:tags).should include('plugin')
104
108
  end
105
109
  end
@@ -64,6 +64,10 @@ describe Tag do
64
64
  Tag.find_or_create_all_with_like_by_name("awesome", "epic").map(&:name).should == ["awesome", "epic"]
65
65
  }.should change(Tag, :count).by(1)
66
66
  end
67
+
68
+ it "should return an empty array if no tags are specified" do
69
+ Tag.find_or_create_all_with_like_by_name([]).should == []
70
+ end
67
71
  end
68
72
 
69
73
  it "should require a name" do
@@ -24,10 +24,12 @@ describe "Tagger" do
24
24
  @user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
25
25
  }.should change(Tagging, :count).by(6)
26
26
 
27
- @user.owned_tags.map(&:name).sort.should == %w(ruby scheme)
27
+ @user.owned_tags.map(&:name).sort.should == %w(ruby scheme).sort
28
28
  @user2.owned_tags.map(&:name).sort.should == %w(java python lisp ruby).sort
29
- @taggable.tags_from(@user).sort.should == %w(ruby scheme)
30
- @taggable.tags_from(@user2).sort.should == %w(java lisp python ruby)
29
+
30
+ @taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
31
+ @taggable.tags_from(@user2).sort.should == %w(java lisp python ruby).sort
32
+
31
33
  @taggable.all_tags_list_on(:tags).sort.should == %w(ruby scheme java python lisp).sort
32
34
  @taggable.all_tags_on(:tags).size.should == 6
33
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-06 00:00:00 +01:00
12
+ date: 2010-02-07 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15