acts-as-taggable-on 3.1.1 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +9 -7
  4. data/Appraisals +13 -8
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +1 -2
  7. data/README.md +23 -13
  8. data/Rakefile +5 -17
  9. data/UPGRADING.md +6 -0
  10. data/acts-as-taggable-on.gemspec +13 -13
  11. data/db/migrate/1_acts_as_taggable_on_migration.rb +3 -3
  12. data/db/migrate/2_add_missing_unique_indices.rb +3 -5
  13. data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +1 -1
  14. data/gemfiles/activerecord_3.2.gemfile +15 -0
  15. data/gemfiles/activerecord_4.0.gemfile +15 -0
  16. data/gemfiles/activerecord_4.1.gemfile +15 -0
  17. data/gemfiles/activerecord_edge.gemfile +16 -0
  18. data/lib/acts-as-taggable-on.rb +23 -21
  19. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +1 -4
  20. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +29 -20
  21. data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +11 -10
  22. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +98 -80
  23. data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +5 -12
  24. data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +7 -7
  25. data/lib/acts_as_taggable_on/engine.rb +0 -1
  26. data/lib/acts_as_taggable_on/tag.rb +24 -19
  27. data/lib/acts_as_taggable_on/tag_list.rb +95 -21
  28. data/lib/acts_as_taggable_on/taggable.rb +28 -30
  29. data/lib/acts_as_taggable_on/tagger.rb +30 -18
  30. data/lib/acts_as_taggable_on/tagging.rb +7 -8
  31. data/lib/acts_as_taggable_on/tags_helper.rb +1 -1
  32. data/lib/acts_as_taggable_on/utils.rb +25 -3
  33. data/lib/acts_as_taggable_on/version.rb +1 -1
  34. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +133 -138
  35. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +55 -58
  36. data/spec/acts_as_taggable_on/caching_spec.rb +34 -35
  37. data/spec/acts_as_taggable_on/related_spec.rb +59 -113
  38. data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +118 -95
  39. data/spec/acts_as_taggable_on/tag_list_spec.rb +89 -57
  40. data/spec/acts_as_taggable_on/tag_spec.rb +125 -114
  41. data/spec/acts_as_taggable_on/taggable_spec.rb +538 -352
  42. data/spec/acts_as_taggable_on/tagger_spec.rb +81 -78
  43. data/spec/acts_as_taggable_on/tagging_spec.rb +13 -14
  44. data/spec/acts_as_taggable_on/tags_helper_spec.rb +25 -25
  45. data/spec/acts_as_taggable_on/utils_spec.rb +9 -9
  46. data/spec/internal/app/models/altered_inheriting_taggable_model.rb +3 -0
  47. data/spec/internal/app/models/cached_model.rb +3 -0
  48. data/spec/internal/app/models/cached_model_with_array.rb +5 -0
  49. data/spec/internal/app/models/company.rb +15 -0
  50. data/spec/internal/app/models/inheriting_taggable_model.rb +2 -0
  51. data/spec/internal/app/models/market.rb +2 -0
  52. data/spec/{models.rb → internal/app/models/models.rb} +34 -2
  53. data/spec/internal/app/models/non_standard_id_taggable_model.rb +8 -0
  54. data/spec/internal/app/models/ordered_taggable_model.rb +4 -0
  55. data/spec/internal/app/models/other_cached_model.rb +3 -0
  56. data/spec/internal/app/models/other_taggable_model.rb +4 -0
  57. data/spec/internal/app/models/student.rb +2 -0
  58. data/spec/internal/app/models/taggable_model.rb +13 -0
  59. data/spec/internal/app/models/untaggable_model.rb +3 -0
  60. data/spec/internal/app/models/user.rb +3 -0
  61. data/spec/{database.yml.sample → internal/config/database.yml.sample} +2 -2
  62. data/spec/internal/db/schema.rb +97 -0
  63. data/spec/schema.rb +11 -0
  64. data/spec/spec_helper.rb +9 -62
  65. data/spec/support/array.rb +9 -0
  66. data/spec/support/database.rb +42 -0
  67. data/spec/support/database_cleaner.rb +17 -0
  68. metadata +101 -37
  69. data/gemfiles/rails_3.2.gemfile +0 -7
  70. data/gemfiles/rails_4.0.gemfile +0 -7
  71. data/gemfiles/rails_4.1.gemfile +0 -7
  72. data/gemfiles/rails_edge.gemfile +0 -7
@@ -1,112 +1,109 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "acts_as_tagger" do
4
- before(:each) do
5
- clean_database!
6
- end
3
+ describe 'acts_as_tagger' do
7
4
 
8
- describe "Tagger Method Generation" do
5
+ describe 'Tagger Method Generation' do
9
6
  before(:each) do
10
7
  @tagger = User.new
11
8
  end
12
9
 
13
- it "should add #is_tagger? query method to the class-side" do
14
- User.should respond_to(:is_tagger?)
10
+ it 'should add #is_tagger? query method to the class-side' do
11
+ expect(User).to respond_to(:is_tagger?)
15
12
  end
16
13
 
17
- it "should return true from the class-side #is_tagger?" do
18
- User.is_tagger?.should be_true
14
+ it 'should return true from the class-side #is_tagger?' do
15
+ expect(User.is_tagger?).to be_truthy
19
16
  end
20
17
 
21
- it "should return false from the base #is_tagger?" do
22
- ActiveRecord::Base.is_tagger?.should be_false
18
+ it 'should return false from the base #is_tagger?' do
19
+ expect(ActiveRecord::Base.is_tagger?).to be_falsy
23
20
  end
24
21
 
25
- it "should add #is_tagger? query method to the singleton" do
26
- @tagger.should respond_to(:is_tagger?)
22
+ it 'should add #is_tagger? query method to the singleton' do
23
+ expect(@tagger).to respond_to(:is_tagger?)
27
24
  end
28
25
 
29
- it "should add #tag method on the instance-side" do
30
- @tagger.should respond_to(:tag)
26
+ it 'should add #tag method on the instance-side' do
27
+ expect(@tagger).to respond_to(:tag)
31
28
  end
32
29
 
33
- it "should generate an association for #owned_taggings and #owned_tags" do
34
- @tagger.should respond_to(:owned_taggings, :owned_tags)
30
+ it 'should generate an association for #owned_taggings and #owned_tags' do
31
+ expect(@tagger).to respond_to(:owned_taggings, :owned_tags)
35
32
  end
36
33
  end
37
34
 
38
- describe "#tag" do
35
+ describe '#tag' do
39
36
  context 'when called with a non-existent tag context' do
40
37
  before(:each) do
41
38
  @tagger = User.new
42
- @taggable = TaggableModel.new(:name=>"Richard Prior")
39
+ @taggable = TaggableModel.new(name: 'Richard Prior')
43
40
  end
44
41
 
45
- it "should by default not throw an exception " do
46
- @taggable.tag_list_on(:foo).should be_empty
47
- lambda {
48
- @tagger.tag(@taggable, :with=>'this, and, that', :on=>:foo)
49
- }.should_not raise_error
42
+ it 'should by default not throw an exception ' do
43
+ expect(@taggable.tag_list_on(:foo)).to be_empty
44
+ expect(-> {
45
+ @tagger.tag(@taggable, with: 'this, and, that', on: :foo)
46
+ }).to_not raise_error
50
47
  end
51
48
 
52
49
  it 'should by default create the tag context on-the-fly' do
53
- @taggable.tag_list_on(:here_ond_now).should be_empty
54
- @tagger.tag(@taggable, :with=>'that', :on => :here_ond_now)
55
- @taggable.tag_list_on(:here_ond_now).should_not include('that')
56
- @taggable.all_tags_list_on(:here_ond_now).should include('that')
50
+ expect(@taggable.tag_list_on(:here_ond_now)).to be_empty
51
+ @tagger.tag(@taggable, with: 'that', on: :here_ond_now)
52
+ expect(@taggable.tag_list_on(:here_ond_now)).to_not include('that')
53
+ expect(@taggable.all_tags_list_on(:here_ond_now)).to include('that')
57
54
  end
58
55
 
59
- it "should show all the tag list when both public and owned tags exist" do
56
+ it 'should show all the tag list when both public and owned tags exist' do
60
57
  @taggable.tag_list = 'ruby, python'
61
- @tagger.tag(@taggable, :with => 'java, lisp', :on => :tags)
62
- @taggable.all_tags_on(:tags).map(&:name).sort.should == %w(ruby python java lisp).sort
58
+ @tagger.tag(@taggable, with: 'java, lisp', on: :tags)
59
+ expect(@taggable.all_tags_on(:tags).map(&:name).sort).to eq(%w(ruby python java lisp).sort)
63
60
  end
64
61
 
65
- it "should not add owned tags to the common list" do
62
+ it 'should not add owned tags to the common list' do
66
63
  @taggable.tag_list = 'ruby, python'
67
- @tagger.tag(@taggable, :with => 'java, lisp', :on => :tags)
68
- @taggable.tag_list.should == %w(ruby python)
69
- @tagger.tag(@taggable, :with => '', :on => :tags)
70
- @taggable.tag_list.should == %w(ruby python)
64
+ @tagger.tag(@taggable, with: 'java, lisp', on: :tags)
65
+ expect(@taggable.tag_list).to eq(%w(ruby python))
66
+ @tagger.tag(@taggable, with: '', on: :tags)
67
+ expect(@taggable.tag_list).to eq(%w(ruby python))
71
68
  end
72
69
 
73
- it "should throw an exception when the default is over-ridden" do
74
- @taggable.tag_list_on(:foo_boo).should be_empty
75
- lambda {
76
- @tagger.tag(@taggable, :with=>'this, and, that', :on=>:foo_boo, :force=>false)
77
- }.should raise_error
70
+ it 'should throw an exception when the default is over-ridden' do
71
+ expect(@taggable.tag_list_on(:foo_boo)).to be_empty
72
+ expect(-> {
73
+ @tagger.tag(@taggable, with: 'this, and, that', on: :foo_boo, force: false)
74
+ }).to raise_error
78
75
  end
79
76
 
80
- it "should not create the tag context on-the-fly when the default is over-ridden" do
81
- @taggable.tag_list_on(:foo_boo).should be_empty
82
- @tagger.tag(@taggable, :with=>'this, and, that', :on=>:foo_boo, :force=>false) rescue
83
- @taggable.tag_list_on(:foo_boo).should be_empty
77
+ it 'should not create the tag context on-the-fly when the default is over-ridden' do
78
+ expect(@taggable.tag_list_on(:foo_boo)).to be_empty
79
+ @tagger.tag(@taggable, with: 'this, and, that', on: :foo_boo, force: false) rescue
80
+ expect(@taggable.tag_list_on(:foo_boo)).to be_empty
84
81
  end
85
82
  end
86
83
 
87
84
  describe "when called by multiple tagger's" do
88
85
  before(:each) do
89
- @user_x = User.create(:name => "User X")
90
- @user_y = User.create(:name => "User Y")
91
- @taggable = TaggableModel.create(:name => 'acts_as_taggable_on', :tag_list => 'plugin')
86
+ @user_x = User.create(name: 'User X')
87
+ @user_y = User.create(name: 'User Y')
88
+ @taggable = TaggableModel.create(name: 'acts_as_taggable_on', tag_list: 'plugin')
92
89
 
93
- @user_x.tag(@taggable, :with => 'ruby, rails', :on => :tags)
94
- @user_y.tag(@taggable, :with => 'ruby, plugin', :on => :tags)
90
+ @user_x.tag(@taggable, with: 'ruby, rails', on: :tags)
91
+ @user_y.tag(@taggable, with: 'ruby, plugin', on: :tags)
95
92
 
96
- @user_y.tag(@taggable, :with => '', :on => :tags)
97
- @user_y.tag(@taggable, :with => '', :on => :tags)
93
+ @user_y.tag(@taggable, with: '', on: :tags)
94
+ @user_y.tag(@taggable, with: '', on: :tags)
98
95
  end
99
96
 
100
- it "should delete owned tags" do
101
- @user_y.owned_tags.should == []
97
+ it 'should delete owned tags' do
98
+ expect(@user_y.owned_tags).to be_empty
102
99
  end
103
100
 
104
- it "should not delete other taggers tags" do
105
- @user_x.owned_tags.should have(2).items
101
+ it 'should not delete other taggers tags' do
102
+ expect(@user_x.owned_tags.count).to eq(2)
106
103
  end
107
104
 
108
- it "should not delete original tags" do
109
- @taggable.all_tags_list_on(:tags).should include('plugin')
105
+ it 'should not delete original tags' do
106
+ expect(@taggable.all_tags_list_on(:tags)).to include('plugin')
110
107
  end
111
108
  end
112
109
  end
@@ -1,77 +1,76 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Acts As Taggable On" do
4
-
5
- before(:each) do
6
- clean_database!
7
- end
3
+ describe 'Acts As Taggable On' do
8
4
 
9
5
  describe 'Caching' do
10
6
  before(:each) do
11
- @taggable = CachedModel.new(:name => "Bob Jones")
12
- @another_taggable = OtherCachedModel.new(:name => "John Smith")
7
+ @taggable = CachedModel.new(name: 'Bob Jones')
8
+ @another_taggable = OtherCachedModel.new(name: 'John Smith')
13
9
  end
14
10
 
15
- it "should add saving of tag lists and cached tag lists to the instance" do
16
- @taggable.should respond_to(:save_cached_tag_list)
17
- @another_taggable.should respond_to(:save_cached_tag_list)
11
+ it 'should add saving of tag lists and cached tag lists to the instance' do
12
+ expect(@taggable).to respond_to(:save_cached_tag_list)
13
+ expect(@another_taggable).to respond_to(:save_cached_tag_list)
18
14
 
19
- @taggable.should respond_to(:save_tags)
15
+ expect(@taggable).to respond_to(:save_tags)
20
16
  end
21
17
 
22
- it "should add cached tag lists to the instance if cached column is not present" do
23
- TaggableModel.new(:name => "Art Kram").should_not respond_to(:save_cached_tag_list)
18
+ it 'should add cached tag lists to the instance if cached column is not present' do
19
+ expect(TaggableModel.new(name: 'Art Kram')).to_not respond_to(:save_cached_tag_list)
24
20
  end
25
21
 
26
- it "should generate a cached column checker for each tag type" do
27
- CachedModel.should respond_to(:caching_tag_list?)
28
- OtherCachedModel.should respond_to(:caching_language_list?)
22
+ it 'should generate a cached column checker for each tag type' do
23
+ expect(CachedModel).to respond_to(:caching_tag_list?)
24
+ expect(OtherCachedModel).to respond_to(:caching_language_list?)
29
25
  end
30
26
 
31
27
  it 'should not have cached tags' do
32
- @taggable.cached_tag_list.should be_blank
33
- @another_taggable.cached_language_list.should be_blank
28
+ expect(@taggable.cached_tag_list).to be_blank
29
+ expect(@another_taggable.cached_language_list).to be_blank
34
30
  end
35
31
 
36
32
  it 'should cache tags' do
37
- @taggable.update_attributes(:tag_list => 'awesome, epic')
38
- @taggable.cached_tag_list.should == 'awesome, epic'
33
+ @taggable.update_attributes(tag_list: 'awesome, epic')
34
+ expect(@taggable.cached_tag_list).to eq('awesome, epic')
39
35
 
40
- @another_taggable.update_attributes(:language_list => 'ruby, .net')
41
- @another_taggable.cached_language_list.should == 'ruby, .net'
36
+ @another_taggable.update_attributes(language_list: 'ruby, .net')
37
+ expect(@another_taggable.cached_language_list).to eq('ruby, .net')
42
38
  end
43
39
 
44
40
  it 'should keep the cache' do
45
- @taggable.update_attributes(:tag_list => 'awesome, epic')
46
- @taggable = CachedModel.find(@taggable)
41
+ @taggable.update_attributes(tag_list: 'awesome, epic')
42
+ @taggable = CachedModel.find(@taggable.id)
47
43
  @taggable.save!
48
- @taggable.cached_tag_list.should == 'awesome, epic'
44
+ expect(@taggable.cached_tag_list).to eq('awesome, epic')
49
45
  end
50
46
 
51
47
  it 'should update the cache' do
52
- @taggable.update_attributes(:tag_list => 'awesome, epic')
53
- @taggable.update_attributes(:tag_list => 'awesome')
54
- @taggable.cached_tag_list.should == 'awesome'
48
+ @taggable.update_attributes(tag_list: 'awesome, epic')
49
+ @taggable.update_attributes(tag_list: 'awesome')
50
+ expect(@taggable.cached_tag_list).to eq('awesome')
55
51
  end
56
52
 
57
53
  it 'should remove the cache' do
58
- @taggable.update_attributes(:tag_list => 'awesome, epic')
59
- @taggable.update_attributes(:tag_list => '')
60
- @taggable.cached_tag_list.should be_blank
54
+ @taggable.update_attributes(tag_list: 'awesome, epic')
55
+ @taggable.update_attributes(tag_list: '')
56
+ expect(@taggable.cached_tag_list).to be_blank
61
57
  end
62
58
 
63
59
  it 'should have a tag list' do
64
- @taggable.update_attributes(:tag_list => 'awesome, epic')
60
+ @taggable.update_attributes(tag_list: 'awesome, epic')
65
61
  @taggable = CachedModel.find(@taggable.id)
66
- @taggable.tag_list.sort.should == %w(awesome epic).sort
62
+ expect(@taggable.tag_list.sort).to eq(%w(awesome epic).sort)
67
63
  end
68
64
 
69
65
  it 'should keep the tag list' do
70
- @taggable.update_attributes(:tag_list => 'awesome, epic')
66
+ @taggable.update_attributes(tag_list: 'awesome, epic')
71
67
  @taggable = CachedModel.find(@taggable.id)
72
68
  @taggable.save!
73
- @taggable.tag_list.sort.should == %w(awesome epic).sort
69
+ expect(@taggable.tag_list.sort).to eq(%w(awesome epic).sort)
74
70
  end
75
71
  end
76
72
 
73
+ describe 'CachingWithArray' do
74
+ pending '#TODO'
75
+ end
77
76
  end
@@ -1,143 +1,89 @@
1
1
  require 'spec_helper'
2
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")
3
+ describe 'Acts As Taggable On' do
13
4
 
14
- taggable1.tag_list = "one, two"
15
- taggable1.save
5
+ describe 'Related Objects' do
16
6
 
17
- taggable2.tag_list = "three, four"
18
- taggable2.save
7
+ #TODO, shared example
8
+ it 'should find related objects based on tag names on context' do
9
+ taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
10
+ taggable2 = TaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
11
+ taggable3 = TaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
19
12
 
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)
13
+ expect(taggable1.find_related_tags).to include(taggable3)
14
+ expect(taggable1.find_related_tags).to_not include(taggable2)
25
15
  end
26
16
 
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
17
+ it 'finds related tags for ordered taggable on' do
18
+ taggable1 = OrderedTaggableModel.create!(name: 'Taggable 1',colour_list: 'one, two')
19
+ taggable2 = OrderedTaggableModel.create!(name: 'Taggable 2',colour_list: 'three, four')
20
+ taggable3 = OrderedTaggableModel.create!(name: 'Taggable 3',colour_list: 'one, four')
34
21
 
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)
22
+ expect(taggable1.find_related_colours).to include(taggable3)
23
+ expect(taggable1.find_related_colours).to_not include(taggable2)
43
24
  end
44
25
 
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
26
+ it 'should find related objects based on tag names on context - non standard id' do
27
+ taggable1 = NonStandardIdTaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
28
+ taggable2 = NonStandardIdTaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
29
+ taggable3 = NonStandardIdTaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
52
30
 
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)
31
+ expect(taggable1.find_related_tags).to include(taggable3)
32
+ expect(taggable1.find_related_tags).to_not include(taggable2)
61
33
  end
62
34
 
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")
35
+ it 'should find other related objects based on tag names on context' do
36
+ taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
37
+ taggable2 = OtherTaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
38
+ taggable3 = OtherTaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
67
39
 
68
- taggable1.tag_list = "one, two"
69
- taggable1.save
40
+ expect(taggable1.find_related_tags_for(OtherTaggableModel)).to include(taggable3)
41
+ expect(taggable1.find_related_tags_for(OtherTaggableModel)).to_not include(taggable2)
42
+ end
70
43
 
71
- taggable2.tag_list = "three, four"
72
- taggable2.save
73
44
 
74
- taggable3.tag_list = "one, four"
75
- taggable3.save
45
+ shared_examples "a collection" do
46
+ it do
47
+ taggable1 = described_class.create!(name: 'Taggable 1', tag_list: 'one')
48
+ taggable2 = described_class.create!(name: 'Taggable 2', tag_list: 'one, two')
76
49
 
77
- taggable1.find_related_tags_for(OtherTaggableModel).should include(taggable3)
78
- taggable1.find_related_tags_for(OtherTaggableModel).should_not include(taggable2)
50
+ expect(taggable1.find_related_tags).to include(taggable2)
51
+ expect(taggable1.find_related_tags).to_not include(taggable1)
52
+ end
79
53
  end
80
54
 
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")
55
+ # it 'should not include the object itself in the list of related objects' do
56
+ describe TaggableModel do
57
+ it_behaves_like "a collection"
58
+ end
84
59
 
85
- taggable1.tag_list = "one"
86
- taggable1.save
60
+ # it 'should not include the object itself in the list of related objects - non standard id' do
61
+ describe NonStandardIdTaggableModel do
62
+ it_behaves_like "a collection"
63
+ end
87
64
 
88
- taggable2.tag_list = "one, two"
89
- taggable2.save
65
+ context 'Ignored Tags' do
66
+ let(:taggable1) { TaggableModel.create!(name: 'Taggable 1', tag_list: 'one, two, four') }
67
+ let(:taggable2) { TaggableModel.create!(name: 'Taggable 2', tag_list: 'two, three') }
68
+ let(:taggable3) { TaggableModel.create!(name: 'Taggable 3', tag_list: 'one, three') }
90
69
 
91
- taggable1.find_related_tags.should include(taggable2)
92
- taggable1.find_related_tags.should_not include(taggable1)
93
- end
70
+ it 'should not include ignored tags in related search' do
71
+ expect(taggable1.find_related_tags(ignore: 'two')).to_not include(taggable2)
72
+ expect(taggable1.find_related_tags(ignore: 'two')).to include(taggable3)
73
+ end
94
74
 
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")
75
+ it 'should accept array of ignored tags' do
76
+ taggable4 = TaggableModel.create!(name: 'Taggable 4', tag_list: 'four')
98
77
 
99
- taggable1.tag_list = "one"
100
- taggable1.save
101
78
 
102
- taggable2.tag_list = "one, two"
103
- taggable2.save
79
+ expect(taggable1.find_related_tags(ignore: ['two', 'four'])).to_not include(taggable2)
80
+ expect(taggable1.find_related_tags(ignore: ['two', 'four'])).to_not include(taggable4)
81
+ end
104
82
 
105
- taggable1.find_related_tags.should include(taggable2)
106
- taggable1.find_related_tags.should_not include(taggable1)
83
+ it 'should accept symbols as ignored tags' do
84
+ expect(taggable1.find_related_tags(ignore: :two)).to_not include(taggable2)
85
+ end
107
86
  end
108
87
 
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
88
  end
143
89
  end