acts-as-taggable-on 2.2.2 → 2.3.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.
@@ -1,3 +1,5 @@
1
+ #encoding: utf-8
2
+
1
3
  require File.expand_path('../../spec_helper', __FILE__)
2
4
 
3
5
  describe ActsAsTaggableOn::Tag do
@@ -40,6 +42,23 @@ describe ActsAsTaggableOn::Tag do
40
42
  end
41
43
  end
42
44
 
45
+ unless ActsAsTaggableOn::Tag.using_sqlite?
46
+ describe "find or create by unicode name" do
47
+ before(:each) do
48
+ @tag.name = "привет"
49
+ @tag.save
50
+ end
51
+
52
+ it "should find by name" do
53
+ ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("привет").should == @tag
54
+ end
55
+
56
+ it "should find by name case insensitive" do
57
+ ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("ПРИВЕТ").should == @tag
58
+ end
59
+ end
60
+ end
61
+
43
62
  describe "find or create all by any name" do
44
63
  before(:each) do
45
64
  @tag.name = "awesome"
@@ -82,6 +101,16 @@ describe ActsAsTaggableOn::Tag do
82
101
  @tag.errors[:name].should == []
83
102
  end
84
103
 
104
+ it "should limit the name length to 255 or less characters" do
105
+ @tag.name = "fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxranr"
106
+ @tag.valid?
107
+ @tag.errors[:name].should == ["is too long (maximum is 255 characters)"]
108
+
109
+ @tag.name = "fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxran"
110
+ @tag.valid?
111
+ @tag.errors[:name].should == []
112
+ end
113
+
85
114
  it "should equal a tag with the same name" do
86
115
  @tag.name = "awesome"
87
116
  new_tag = ActsAsTaggableOn::Tag.new(:name => "awesome")
@@ -120,35 +149,5 @@ describe ActsAsTaggableOn::Tag do
120
149
  end
121
150
 
122
151
  end
123
-
124
- describe ".remove_unused" do
125
- before do
126
- @taggable = TaggableModel.create(:name => "Bob Jones")
127
- @tag = ActsAsTaggableOn::Tag.create(:name => "awesome")
128
152
 
129
- @tagging = ActsAsTaggableOn::Tagging.create(:taggable => @taggable, :tag => @tag, :context => 'tags')
130
- end
131
-
132
- context "if set to true" do
133
- before do
134
- ActsAsTaggableOn::Tag.remove_unused = true
135
- end
136
-
137
- it "should remove unused tags after removing taggings" do
138
- @tagging.destroy
139
- ActsAsTaggableOn::Tag.find_by_name("awesome").should be_nil
140
- end
141
- end
142
-
143
- context "if set to false" do
144
- before do
145
- ActsAsTaggableOn::Tag.remove_unused = false
146
- end
147
-
148
- it "should not remove unused tags after removing taggings" do
149
- @tagging.destroy
150
- ActsAsTaggableOn::Tag.find_by_name("awesome").should == @tag
151
- end
152
- end
153
- end
154
153
  end
@@ -1,5 +1,114 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
+ describe "Taggable To Preserve Order" do
4
+ before(:each) do
5
+ clean_database!
6
+ @taggable = OrderedTaggableModel.new(:name => "Bob Jones")
7
+ end
8
+
9
+ it "should have tag types" do
10
+ [:tags, :colours].each do |type|
11
+ OrderedTaggableModel.tag_types.should include type
12
+ end
13
+
14
+ @taggable.tag_types.should == OrderedTaggableModel.tag_types
15
+ end
16
+
17
+ it "should have tag associations" do
18
+ [:tags, :colours].each do |type|
19
+ @taggable.respond_to?(type).should be_true
20
+ @taggable.respond_to?("#{type.to_s.singularize}_taggings").should be_true
21
+ end
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
+
31
+ it "should have tag methods" do
32
+ [:tags, :colours].each do |type|
33
+ @taggable.respond_to?("#{type.to_s.singularize}_list").should be_true
34
+ @taggable.respond_to?("#{type.to_s.singularize}_list=").should be_true
35
+ @taggable.respond_to?("all_#{type.to_s}_list").should be_true
36
+ end
37
+ end
38
+
39
+ it "should return tag list in the order the tags were created" do
40
+ # create
41
+ @taggable.tag_list = "rails, ruby, css"
42
+ @taggable.instance_variable_get("@tag_list").instance_of?(ActsAsTaggableOn::TagList).should be_true
43
+
44
+ lambda {
45
+ @taggable.save
46
+ }.should change(ActsAsTaggableOn::Tag, :count).by(3)
47
+
48
+ @taggable.reload
49
+ @taggable.tag_list.should == %w(rails ruby css)
50
+
51
+ # update
52
+ @taggable.tag_list = "pow, ruby, rails"
53
+ @taggable.save
54
+
55
+ @taggable.reload
56
+ @taggable.tag_list.should == %w(pow ruby rails)
57
+
58
+ # update with no change
59
+ @taggable.tag_list = "pow, ruby, rails"
60
+ @taggable.save
61
+
62
+ @taggable.reload
63
+ @taggable.tag_list.should == %w(pow ruby rails)
64
+
65
+ # update to clear tags
66
+ @taggable.tag_list = ""
67
+ @taggable.save
68
+
69
+ @taggable.reload
70
+ @taggable.tag_list.should == []
71
+ end
72
+
73
+ it "should return tag objects in the order the tags were created" do
74
+ # create
75
+ @taggable.tag_list = "pow, ruby, rails"
76
+ @taggable.instance_variable_get("@tag_list").instance_of?(ActsAsTaggableOn::TagList).should be_true
77
+
78
+ lambda {
79
+ @taggable.save
80
+ }.should change(ActsAsTaggableOn::Tag, :count).by(3)
81
+
82
+ @taggable.reload
83
+ @taggable.tags.map{|t| t.name}.should == %w(pow ruby rails)
84
+
85
+ # update
86
+ @taggable.tag_list = "rails, ruby, css, pow"
87
+ @taggable.save
88
+
89
+ @taggable.reload
90
+ @taggable.tags.map{|t| t.name}.should == %w(rails ruby css pow)
91
+ end
92
+
93
+ it "should return tag objects in tagging id order" do
94
+ # create
95
+ @taggable.tag_list = "pow, ruby, rails"
96
+ @taggable.save
97
+
98
+ @taggable.reload
99
+ ids = @taggable.tags.map{|t| t.taggings.first.id}
100
+ ids.should == ids.sort
101
+
102
+ # update
103
+ @taggable.tag_list = "rails, ruby, css, pow"
104
+ @taggable.save
105
+
106
+ @taggable.reload
107
+ ids = @taggable.tags.map{|t| t.taggings.first.id}
108
+ ids.should == ids.sort
109
+ end
110
+ end
111
+
3
112
  describe "Taggable" do
4
113
  before(:each) do
5
114
  clean_database!
@@ -224,19 +333,19 @@ describe "Taggable" do
224
333
  frank = TaggableModel.create(:name => "Frank", :tag_list => "bobby, jim")
225
334
  steve = TaggableModel.create(:name => "Steve", :tag_list => "john, patricia")
226
335
  jim = TaggableModel.create(:name => "Jim", :tag_list => "jim, steve")
227
-
228
-
229
- TaggableModel.tagged_with(["bob", "tricia"], :wild => true, :any => true).to_a.should == [bob, frank, steve]
230
- TaggableModel.tagged_with(["bob", "tricia"], :wild => true, :exclude => true).to_a.should == [jim]
336
+
337
+
338
+ TaggableModel.tagged_with(["bob", "tricia"], :wild => true, :any => true).to_a.sort_by{|o| o.id}.should == [bob, frank, steve]
339
+ TaggableModel.tagged_with(["bob", "tricia"], :wild => true, :exclude => true).to_a.should == [jim]
231
340
  end
232
341
  end
233
-
342
+
234
343
  it "should be able to find tagged on a custom tag context" do
235
344
  bob = TaggableModel.create(:name => "Bob")
236
345
  bob.set_tag_list_on(:rotors, "spinning, jumping")
237
346
  bob.tag_list_on(:rotors).should == ["spinning","jumping"]
238
347
  bob.save
239
-
348
+
240
349
  TaggableModel.tagged_with("spinning", :on => :rotors).to_a.should == [bob]
241
350
  end
242
351
 
@@ -407,6 +516,28 @@ describe "Taggable" do
407
516
  @taggable.tag_list_on(:test).should == ["hello"]
408
517
  end
409
518
  end
519
+
520
+ describe "Dirty Objects" do
521
+ before(:each) do
522
+ @taggable = TaggableModel.create(:tag_list => "awesome, epic")
523
+ end
524
+
525
+ it 'should show changes of dirty object' do
526
+ @taggable.changes.should == {}
527
+ @taggable.tag_list = 'one'
528
+ @taggable.changes.should == {"tag_list"=>["awesome, epic", ["one"]]}
529
+
530
+ @taggable.tag_list_changed?.should be_true
531
+ @taggable.tag_list_was.should == "awesome, epic"
532
+ @taggable.tag_list_change.should == ["awesome, epic", ["one"]]
533
+ end
534
+
535
+ it 'should show no changes if the same tag_list' do
536
+ @taggable.tag_list = "awesome, epic"
537
+ @taggable.tag_list_changed?.should be_false
538
+ @taggable.changes.should == {}
539
+ end
540
+ end
410
541
  end
411
542
 
412
543
 
@@ -16,7 +16,7 @@ describe "Tagger" do
16
16
  @user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
17
17
  @user.owned_tags.size == 2
18
18
  end
19
-
19
+
20
20
  it "should scope objects returned by tagged_with by owners" do
21
21
  @taggable2 = TaggableModel.create(:name => "Jim Jones")
22
22
  @taggable3 = TaggableModel.create(:name => "Jane Doe")
@@ -30,7 +30,7 @@ describe "Tagger" do
30
30
  TaggableModel.tagged_with(%w(ruby scheme), :owned_by => @user2).count.should == 2
31
31
 
32
32
  end
33
-
33
+
34
34
  it "should not overlap tags from different taggers" do
35
35
  @user2 = TaggableUser.new
36
36
  lambda{
@@ -42,35 +42,35 @@ describe "Tagger" do
42
42
 
43
43
  @user.owned_tags.map(&:name).sort.should == %w(ruby scheme).sort
44
44
  @user2.owned_tags.map(&:name).sort.should == %w(java python lisp ruby).sort
45
-
45
+
46
46
  @taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
47
47
  @taggable.tags_from(@user2).sort.should == %w(java lisp python ruby).sort
48
-
48
+
49
49
  @taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
50
50
  @taggable.all_tags_on(:tags).size.should == 5
51
51
  end
52
-
52
+
53
53
  it "should not lose tags from different taggers" do
54
54
  @user2 = TaggableUser.create
55
55
  @user2.tag(@taggable, :with => 'java, python, lisp, ruby', :on => :tags)
56
- @user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
57
-
56
+ @user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
57
+
58
58
  lambda {
59
59
  @user2.tag(@taggable, :with => 'java, python, lisp', :on => :tags)
60
60
  }.should change(ActsAsTaggableOn::Tagging, :count).by(-1)
61
61
 
62
62
  [@user, @user2, @taggable].each(&:reload)
63
-
63
+
64
64
  @taggable.tags_from(@user).sort.should == %w(ruby scheme).sort
65
65
  @taggable.tags_from(@user2).sort.should == %w(java python lisp).sort
66
-
66
+
67
67
  @taggable.all_tags_list.sort.should == %w(ruby scheme java python lisp).sort
68
68
  @taggable.all_tags_on(:tags).length.should == 5
69
69
  end
70
70
 
71
71
  it "should not lose tags" do
72
72
  @user2 = TaggableUser.create
73
-
73
+
74
74
  @user.tag(@taggable, :with => 'awesome', :on => :tags)
75
75
  @user2.tag(@taggable, :with => 'awesome, epic', :on => :tags)
76
76
 
@@ -78,28 +78,35 @@ describe "Tagger" do
78
78
  @user2.tag(@taggable, :with => 'epic', :on => :tags)
79
79
  }.should change(ActsAsTaggableOn::Tagging, :count).by(-1)
80
80
 
81
- @taggable.reload
81
+ @taggable.reload
82
82
  @taggable.all_tags_list.should include('awesome')
83
83
  @taggable.all_tags_list.should include('epic')
84
84
  end
85
-
85
+
86
86
  it "should not lose tags" do
87
87
  @taggable.update_attributes(:tag_list => 'ruby')
88
88
  @user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
89
-
89
+
90
90
  [@taggable, @user].each(&:reload)
91
91
  @taggable.tag_list.should == %w(ruby)
92
92
  @taggable.all_tags_list.sort.should == %w(ruby scheme).sort
93
-
93
+
94
94
  lambda {
95
95
  @taggable.update_attributes(:tag_list => "")
96
96
  }.should change(ActsAsTaggableOn::Tagging, :count).by(-1)
97
-
97
+
98
98
  @taggable.tag_list.should == []
99
99
  @taggable.all_tags_list.sort.should == %w(ruby scheme).sort
100
100
  end
101
101
 
102
102
  it "is tagger" do
103
103
  @user.is_tagger?.should(be_true)
104
- end
104
+ end
105
+
106
+ it "should skip save if skip_save is passed as option" do
107
+ lambda {
108
+ @user.tag(@taggable, :with => 'epic', :on => :tags, :skip_save => true)
109
+ }.should_not change(ActsAsTaggableOn::Tagging, :count)
110
+
111
+ end
105
112
  end
data/spec/models.rb CHANGED
@@ -42,3 +42,8 @@ class NonStandardIdTaggableModel < ActiveRecord::Base
42
42
  acts_as_taggable_on :needs, :offerings
43
43
  has_many :untaggable_models
44
44
  end
45
+
46
+ class OrderedTaggableModel < ActiveRecord::Base
47
+ acts_as_ordered_taggable
48
+ acts_as_ordered_taggable_on :colours
49
+ end
data/spec/schema.rb CHANGED
@@ -53,4 +53,9 @@ ActiveRecord::Schema.define :version => 0 do
53
53
  t.column :name, :string
54
54
  t.column :type, :string
55
55
  end
56
+
57
+ create_table :ordered_taggable_models, :force => true do |t|
58
+ t.column :name, :string
59
+ t.column :type, :string
60
+ end
56
61
  end
data/spec/spec_helper.rb CHANGED
@@ -31,6 +31,8 @@ unless [].respond_to?(:freq)
31
31
  end
32
32
  end
33
33
 
34
+ # set adapter to use, default is sqlite3
35
+ # to use an alternative adapter run => rake spec DB='postgresql'
34
36
  db_name = ENV['DB'] || 'sqlite3'
35
37
  database_yml = File.expand_path('../database.yml', __FILE__)
36
38
 
@@ -72,7 +74,7 @@ end
72
74
 
73
75
  def clean_database!
74
76
  models = [ActsAsTaggableOn::Tag, ActsAsTaggableOn::Tagging, TaggableModel, OtherTaggableModel, InheritingTaggableModel,
75
- AlteredInheritingTaggableModel, TaggableUser, UntaggableModel]
77
+ AlteredInheritingTaggableModel, TaggableUser, UntaggableModel, OrderedTaggableModel]
76
78
  models.each do |model|
77
79
  ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
78
80
  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: 2.2.2
4
+ version: 2.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70356686875400 !ruby/object:Gem::Requirement
16
+ requirement: &70275758086480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70356686875400
24
+ version_requirements: *70275758086480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70356686901300 !ruby/object:Gem::Requirement
27
+ requirement: &70275758085980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: '2.5'
32
+ version: '2.6'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70356686901300
35
+ version_requirements: *70275758085980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ammeter
38
- requirement: &70356686900800 !ruby/object:Gem::Requirement
38
+ requirement: &70275758085520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.1.3
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70356686900800
46
+ version_requirements: *70275758085520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &70356686900420 !ruby/object:Gem::Requirement
49
+ requirement: &70275758103040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70356686900420
57
+ version_requirements: *70275758103040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mysql2
60
- requirement: &70356686899780 !ruby/object:Gem::Requirement
60
+ requirement: &70275758102400 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.3.7
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70356686899780
68
+ version_requirements: *70275758102400
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pg
71
- requirement: &70356686899280 !ruby/object:Gem::Requirement
71
+ requirement: &70275758101640 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70356686899280
79
+ version_requirements: *70275758101640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard
82
- requirement: &70356686898580 !ruby/object:Gem::Requirement
82
+ requirement: &70275758100980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70356686898580
90
+ version_requirements: *70275758100980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-rspec
93
- requirement: &70356686897920 !ruby/object:Gem::Requirement
93
+ requirement: &70275758100180 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70356686897920
101
+ version_requirements: *70275758100180
102
102
  description: With ActsAsTaggableOn, you can tag a single model on several contexts,
103
103
  such as skills, interests, and awards. It also provides other advanced functionality.
104
104
  email: michael@intridea.com
@@ -121,6 +121,7 @@ files:
121
121
  - lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
122
122
  - lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
123
123
  - lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
124
+ - lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
124
125
  - lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
125
126
  - lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
126
127
  - lib/acts_as_taggable_on/tag.rb
@@ -163,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
164
  version: '0'
164
165
  segments:
165
166
  - 0
166
- hash: -1793358145648125
167
+ hash: 3587969812961176900
167
168
  required_rubygems_version: !ruby/object:Gem::Requirement
168
169
  none: false
169
170
  requirements:
@@ -172,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
173
  version: '0'
173
174
  segments:
174
175
  - 0
175
- hash: -1793358145648125
176
+ hash: 3587969812961176900
176
177
  requirements: []
177
178
  rubyforge_project:
178
179
  rubygems_version: 1.8.10