acts-as-taggable-on 3.1.1 → 3.2.2

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 (73) 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 +27 -7
  6. data/Gemfile +1 -2
  7. data/README.md +36 -19
  8. data/Rakefile +5 -17
  9. data/UPGRADING.md +6 -0
  10. data/acts-as-taggable-on.gemspec +15 -15
  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 +2 -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 +103 -85
  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 +11 -11
  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 +97 -22
  28. data/lib/acts_as_taggable_on/taggable.rb +26 -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 +57 -35
  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 +129 -116
  41. data/spec/acts_as_taggable_on/taggable_spec.rb +539 -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 +7 -13
  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 +21 -0
  68. metadata +105 -43
  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
  73. data/spec/bm.rb +0 -52
@@ -2,124 +2,156 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe ActsAsTaggableOn::TagList do
5
- let(:tag_list) { ActsAsTaggableOn::TagList.new("awesome","radical") }
5
+ let(:tag_list) { ActsAsTaggableOn::TagList.new('awesome', 'radical') }
6
+ let(:another_tag_list) { ActsAsTaggableOn::TagList.new('awesome','crazy', 'alien') }
6
7
 
7
8
  it { should be_kind_of Array }
8
9
 
9
- it "#from should return empty array if empty array is passed" do
10
- ActsAsTaggableOn::TagList.from([]).should be_empty
10
+ it '#from should return empty array if empty array is passed' do
11
+ expect(ActsAsTaggableOn::TagList.from([])).to be_empty
11
12
  end
12
13
 
13
- describe "#add" do
14
- it "should be able to be add a new tag word" do
15
- tag_list.add("cool")
16
- tag_list.include?("cool").should be_true
14
+ describe '#add' do
15
+ it 'should be able to be add a new tag word' do
16
+ tag_list.add('cool')
17
+ expect(tag_list.include?('cool')).to be_truthy
17
18
  end
18
19
 
19
- it "should be able to add delimited lists of words" do
20
- tag_list.add("cool, wicked", :parse => true)
21
- tag_list.should include("cool", "wicked")
20
+ it 'should be able to add delimited lists of words' do
21
+ tag_list.add('cool, wicked', parse: true)
22
+ expect(tag_list).to include('cool', 'wicked')
22
23
  end
23
24
 
24
- it "should be able to add delimited list of words with quoted delimiters" do
25
- tag_list.add("'cool, wicked', \"really cool, really wicked\"", :parse => true)
26
- tag_list.should include("cool, wicked", "really cool, really wicked")
25
+ it 'should be able to add delimited list of words with quoted delimiters' do
26
+ tag_list.add("'cool, wicked', \"really cool, really wicked\"", parse: true)
27
+ expect(tag_list).to include('cool, wicked', 'really cool, really wicked')
27
28
  end
28
29
 
29
- it "should be able to handle other uses of quotation marks correctly" do
30
- tag_list.add("john's cool car, mary's wicked toy", :parse => true)
31
- tag_list.should include("john's cool car", "mary's wicked toy")
30
+ it 'should be able to handle other uses of quotation marks correctly' do
31
+ tag_list.add("john's cool car, mary's wicked toy", parse: true)
32
+ expect(tag_list).to include("john's cool car", "mary's wicked toy")
32
33
  end
33
34
 
34
- it "should be able to add an array of words" do
35
- tag_list.add(["cool", "wicked"], :parse => true)
36
- tag_list.should include("cool", "wicked")
35
+ it 'should be able to add an array of words' do
36
+ tag_list.add(%w(cool wicked), parse: true)
37
+ expect(tag_list).to include('cool', 'wicked')
37
38
  end
38
39
 
39
- it "should quote escape tags with commas in them" do
40
- tag_list.add("cool","rad,bodacious")
41
- tag_list.to_s.should == "awesome, radical, cool, \"rad,bodacious\""
40
+ it 'should quote escape tags with commas in them' do
41
+ tag_list.add('cool', 'rad,bodacious')
42
+ expect(tag_list.to_s).to eq("awesome, radical, cool, \"rad,bodacious\"")
42
43
  end
43
44
 
44
45
  end
45
46
 
46
- describe "#remove" do
47
- it "should be able to remove words" do
48
- tag_list.remove("awesome")
49
- tag_list.should_not include("awesome")
47
+ describe '#remove' do
48
+ it 'should be able to remove words' do
49
+ tag_list.remove('awesome')
50
+ expect(tag_list).to_not include('awesome')
50
51
  end
51
52
 
52
- it "should be able to remove delimited lists of words" do
53
- tag_list.remove("awesome, radical", :parse => true)
54
- tag_list.should be_empty
53
+ it 'should be able to remove delimited lists of words' do
54
+ tag_list.remove('awesome, radical', parse: true)
55
+ expect(tag_list).to be_empty
55
56
  end
56
57
 
57
- it "should be able to remove an array of words" do
58
- tag_list.remove(["awesome", "radical"], :parse => true)
59
- tag_list.should be_empty
58
+ it 'should be able to remove an array of words' do
59
+ tag_list.remove(%w(awesome radical), parse: true)
60
+ expect(tag_list).to be_empty
60
61
  end
61
62
  end
62
63
 
63
- describe "#to_s" do
64
- it "should give a delimited list of words when converted to string" do
65
- tag_list.to_s.should == "awesome, radical"
64
+ describe '#+' do
65
+ it 'should not have duplicate tags' do
66
+ new_tag_list = tag_list + another_tag_list
67
+ expect(tag_list).to eq(%w[awesome radical])
68
+ expect(another_tag_list).to eq(%w[awesome crazy alien])
69
+ expect(new_tag_list).to eq(%w[awesome radical crazy alien])
66
70
  end
67
71
 
68
- it "should be able to call to_s on a frozen tag list" do
72
+ it 'should have class : ActsAsTaggableOn::TagList' do
73
+ new_tag_list = tag_list + another_tag_list
74
+ expect(new_tag_list.class).to eq(ActsAsTaggableOn::TagList)
75
+ end
76
+ end
77
+
78
+ describe '#concat' do
79
+ it 'should not have duplicate tags' do
80
+ expect(tag_list.concat(another_tag_list)).to eq(%w[awesome radical crazy alien])
81
+ end
82
+
83
+ it 'should have class : ActsAsTaggableOn::TagList' do
84
+ new_tag_list = tag_list.concat(another_tag_list)
85
+ expect(new_tag_list.class).to eq(ActsAsTaggableOn::TagList)
86
+ end
87
+ end
88
+
89
+ describe '#to_s' do
90
+ it 'should give a delimited list of words when converted to string' do
91
+ expect(tag_list.to_s).to eq('awesome, radical')
92
+ end
93
+
94
+ it 'should be able to call to_s on a frozen tag list' do
69
95
  tag_list.freeze
70
- lambda { tag_list.add("cool","rad,bodacious") }.should raise_error
71
- lambda { tag_list.to_s }.should_not raise_error
96
+ expect(-> { tag_list.add('cool', 'rad,bodacious') }).to raise_error
97
+ expect(-> { tag_list.to_s }).to_not raise_error
72
98
  end
73
99
  end
74
100
 
75
- describe "cleaning" do
76
- it "should parameterize if force_parameterize is set to true" do
101
+ describe 'cleaning' do
102
+ it 'should parameterize if force_parameterize is set to true' do
77
103
  ActsAsTaggableOn.force_parameterize = true
78
- tag_list = ActsAsTaggableOn::TagList.new("awesome()","radical)(cc")
104
+ tag_list = ActsAsTaggableOn::TagList.new('awesome()', 'radical)(cc')
79
105
 
80
- tag_list.to_s.should == "awesome, radical-cc"
106
+ expect(tag_list.to_s).to eq('awesome, radical-cc')
81
107
  ActsAsTaggableOn.force_parameterize = false
82
108
  end
83
109
 
84
- it "should lowercase if force_lowercase is set to true" do
110
+ it 'should lowercase if force_lowercase is set to true' do
85
111
  ActsAsTaggableOn.force_lowercase = true
86
112
 
87
- tag_list = ActsAsTaggableOn::TagList.new("aweSomE","RaDicaL","Entrée")
88
- tag_list.to_s.should == "awesome, radical, entrée"
113
+ tag_list = ActsAsTaggableOn::TagList.new('aweSomE', 'RaDicaL', 'Entrée')
114
+ expect(tag_list.to_s).to eq('awesome, radical, entrée')
89
115
 
90
116
  ActsAsTaggableOn.force_lowercase = false
91
117
  end
92
118
 
93
119
  end
94
120
 
95
- describe "Multiple Delimiter" do
96
- before do
121
+ describe 'Multiple Delimiter' do
122
+ before do
97
123
  @old_delimiter = ActsAsTaggableOn.delimiter
98
124
  end
99
125
 
100
- after do
126
+ after do
101
127
  ActsAsTaggableOn.delimiter = @old_delimiter
102
128
  end
103
129
 
104
- it "should separate tags by delimiters" do
130
+ it 'should separate tags by delimiters' do
105
131
  ActsAsTaggableOn.delimiter = [',', ' ', '\|']
106
- tag_list = ActsAsTaggableOn::TagList.from "cool, data|I have"
107
- tag_list.to_s.should == 'cool, data, I, have'
132
+ tag_list = ActsAsTaggableOn::TagList.from 'cool, data|I have'
133
+ expect(tag_list.to_s).to eq('cool, data, I, have')
108
134
  end
109
135
 
110
- it "should escape quote" do
136
+ it 'should escape quote' do
111
137
  ActsAsTaggableOn.delimiter = [',', ' ', '\|']
112
138
  tag_list = ActsAsTaggableOn::TagList.from "'I have'|cool, data"
113
- tag_list.to_s.should == '"I have", cool, data'
139
+ expect(tag_list.to_s).to eq('"I have", cool, data')
114
140
 
115
141
  tag_list = ActsAsTaggableOn::TagList.from '"I, have"|cool, data'
116
- tag_list.to_s.should == '"I, have", cool, data'
142
+ expect(tag_list.to_s).to eq('"I, have", cool, data')
117
143
  end
118
144
 
119
- it "should work for utf8 delimiter and long delimiter" do
145
+ it 'should work for utf8 delimiter and long delimiter' do
120
146
  ActsAsTaggableOn.delimiter = [',', '的', '可能是']
121
- tag_list = ActsAsTaggableOn::TagList.from "我的东西可能是不见了,还好有备份"
122
- tag_list.to_s.should == "我, 东西, 不见了, 还好有备份"
147
+ tag_list = ActsAsTaggableOn::TagList.from '我的东西可能是不见了,还好有备份'
148
+ expect(tag_list.to_s).to eq('我, 东西, 不见了, 还好有备份')
149
+ end
150
+
151
+ it 'should work for multiple quoted tags' do
152
+ ActsAsTaggableOn.delimiter = [',']
153
+ tag_list = ActsAsTaggableOn::TagList.from '"Ruby Monsters","eat Katzenzungen"'
154
+ expect(tag_list.to_s).to eq('Ruby Monsters, eat Katzenzungen')
123
155
  end
124
156
  end
125
157
 
@@ -3,207 +3,219 @@ require 'spec_helper'
3
3
  require 'db/migrate/2_add_missing_unique_indices.rb'
4
4
 
5
5
  shared_examples_for 'without unique index' do
6
- before { AddMissingUniqueIndices.down }
7
- after { ActsAsTaggableOn::Tag.delete_all; AddMissingUniqueIndices.up }
6
+ prepend_before(:all) { AddMissingUniqueIndices.down }
7
+ append_after(:all) do
8
+ ActsAsTaggableOn::Tag.delete_all
9
+ AddMissingUniqueIndices.up
10
+ end
8
11
  end
9
12
 
10
13
  describe ActsAsTaggableOn::Tag do
11
14
  before(:each) do
12
- clean_database!
13
15
  @tag = ActsAsTaggableOn::Tag.new
14
- @user = TaggableModel.create(:name => "Pablo")
16
+ @user = TaggableModel.create(name: 'Pablo')
15
17
  end
16
18
 
17
- describe "named like any" do
18
- context "case insensitive collation and unique index on tag name" do
19
- if described_class.using_case_insensitive_collation?
19
+
20
+ describe 'named like any' do
21
+ if ActsAsTaggableOn::Utils.using_case_insensitive_collation?
22
+ context 'case insensitive collation and unique index on tag name' do
20
23
  before(:each) do
21
- ActsAsTaggableOn::Tag.create(:name => "Awesome")
22
- ActsAsTaggableOn::Tag.create(:name => "epic")
24
+ ActsAsTaggableOn::Tag.create(name: 'Awesome')
25
+ ActsAsTaggableOn::Tag.create(name: 'epic')
23
26
  end
24
27
 
25
- it "should find both tags" do
26
- ActsAsTaggableOn::Tag.named_like_any(["awesome", "epic"]).should have(2).items
28
+ it 'should find both tags' do
29
+ expect(ActsAsTaggableOn::Tag.named_like_any(%w(awesome epic)).count).to eq(2)
27
30
  end
28
31
  end
29
32
  end
30
33
 
31
- context "case insensitive collation without indexes or case sensitive collation with indexes" do
32
- if described_class.using_case_insensitive_collation?
34
+ context 'case insensitive collation without indexes or case sensitive collation with indexes' do
35
+ if ActsAsTaggableOn::Utils.using_case_insensitive_collation?
33
36
  include_context 'without unique index'
34
37
  end
35
38
 
36
39
  before(:each) do
37
- ActsAsTaggableOn::Tag.create(:name => "Awesome")
38
- ActsAsTaggableOn::Tag.create(:name => "awesome")
39
- ActsAsTaggableOn::Tag.create(:name => "epic")
40
+ ActsAsTaggableOn::Tag.create(name: 'Awesome')
41
+ ActsAsTaggableOn::Tag.create(name: 'awesome')
42
+ ActsAsTaggableOn::Tag.create(name: 'epic')
40
43
  end
41
44
 
42
- it "should find both tags" do
43
- ActsAsTaggableOn::Tag.named_like_any(["awesome", "epic"]).should have(3).items
45
+ it 'should find both tags' do
46
+ expect(ActsAsTaggableOn::Tag.named_like_any(%w(awesome epic)).count).to eq(3)
44
47
  end
45
48
  end
46
49
  end
47
50
 
48
- describe "find or create by name" do
51
+ describe 'find or create by name' do
49
52
  before(:each) do
50
- @tag.name = "awesome"
53
+ @tag.name = 'awesome'
51
54
  @tag.save
52
55
  end
53
56
 
54
- it "should find by name" do
55
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("awesome").should == @tag
57
+ it 'should find by name' do
58
+ expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('awesome')).to eq(@tag)
56
59
  end
57
60
 
58
- it "should find by name case insensitive" do
59
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("AWESOME").should == @tag
61
+ it 'should find by name case insensitive' do
62
+ expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('AWESOME')).to eq(@tag)
60
63
  end
61
64
 
62
- it "should create by name" do
63
- lambda {
64
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("epic")
65
- }.should change(ActsAsTaggableOn::Tag, :count).by(1)
65
+ it 'should create by name' do
66
+ expect(-> {
67
+ ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('epic')
68
+ }).to change(ActsAsTaggableOn::Tag, :count).by(1)
66
69
  end
67
70
  end
68
71
 
69
- unless ActsAsTaggableOn::Tag.using_sqlite?
70
- describe "find or create by unicode name" do
72
+ unless ActsAsTaggableOn::Utils.using_sqlite?
73
+ describe 'find or create by unicode name' do
71
74
  before(:each) do
72
- @tag.name = "привет"
75
+ @tag.name = 'привет'
73
76
  @tag.save
74
77
  end
75
78
 
76
- it "should find by name" do
77
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("привет").should == @tag
79
+ it 'should find by name' do
80
+ expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('привет')).to eq(@tag)
81
+ end
82
+
83
+ it 'should find by name case insensitive' do
84
+ expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('ПРИВЕТ')).to eq(@tag)
78
85
  end
79
86
 
80
- it "should find by name case insensitive" do
81
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("ПРИВЕТ").should == @tag
87
+ if ActsAsTaggableOn::Utils.using_case_insensitive_collation?
88
+ it 'should find by name accent insensitive' do
89
+ @tag.name = 'inupiat'
90
+ @tag.save
91
+ expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('Iñupiat')).to eq(@tag)
92
+ end
82
93
  end
83
94
  end
84
95
  end
85
96
 
86
- describe "find or create all by any name" do
97
+ describe 'find or create all by any name' do
87
98
  before(:each) do
88
- @tag.name = "awesome"
99
+ @tag.name = 'awesome'
89
100
  @tag.save
90
101
  end
91
102
 
92
- it "should find by name" do
93
- ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("awesome").should == [@tag]
103
+ it 'should find by name' do
104
+ expect(ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name('awesome')).to eq([@tag])
94
105
  end
95
106
 
96
- it "should find by name case insensitive" do
97
- ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("AWESOME").should == [@tag]
107
+ it 'should find by name case insensitive' do
108
+ expect(ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name('AWESOME')).to eq([@tag])
98
109
  end
99
110
 
100
- context "case sensitive" do
101
- if described_class.using_case_insensitive_collation?
111
+ context 'case sensitive' do
112
+ if ActsAsTaggableOn::Utils.using_case_insensitive_collation?
102
113
  include_context 'without unique index'
103
114
  end
104
115
 
105
- it "should find by name case sensitive" do
116
+ it 'should find by name case sensitive' do
106
117
  ActsAsTaggableOn.strict_case_match = true
107
118
  expect {
108
- ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("AWESOME")
119
+ ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name('AWESOME')
109
120
  }.to change(ActsAsTaggableOn::Tag, :count).by(1)
110
121
  end
111
122
  end
112
123
 
113
- it "should create by name" do
124
+ it 'should create by name' do
114
125
  expect {
115
- ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("epic")
126
+ ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name('epic')
116
127
  }.to change(ActsAsTaggableOn::Tag, :count).by(1)
117
128
  end
118
129
 
119
- context "case sensitive" do
120
- if described_class.using_case_insensitive_collation?
130
+ context 'case sensitive' do
131
+ if ActsAsTaggableOn::Utils.using_case_insensitive_collation?
121
132
  include_context 'without unique index'
122
133
  end
123
134
 
124
- it "should find or create by name case sensitive" do
135
+ it 'should find or create by name case sensitive' do
125
136
  ActsAsTaggableOn.strict_case_match = true
126
137
  expect {
127
- ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("AWESOME", 'awesome').map(&:name).should == ["AWESOME", "awesome"]
138
+ expect(ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name('AWESOME', 'awesome').map(&:name)).to eq(%w(AWESOME awesome))
128
139
  }.to change(ActsAsTaggableOn::Tag, :count).by(1)
129
140
  end
130
141
  end
131
142
 
132
- it "should find or create by name" do
143
+ it 'should find or create by name' do
133
144
  expect {
134
- ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name("awesome", "epic").map(&:name).should == ["awesome", "epic"]
145
+ expect(ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name('awesome', 'epic').map(&:name)).to eq(%w(awesome epic))
135
146
  }.to change(ActsAsTaggableOn::Tag, :count).by(1)
136
147
  end
137
148
 
138
- it "should return an empty array if no tags are specified" do
139
- ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name([]).should == []
149
+ it 'should return an empty array if no tags are specified' do
150
+ expect(ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name([])).to be_empty
140
151
  end
141
152
  end
142
153
 
143
- it "should require a name" do
154
+ it 'should require a name' do
144
155
  @tag.valid?
156
+ #TODO, we should find another way to check this
157
+ expect(@tag.errors[:name]).to eq(["can't be blank"])
145
158
 
146
- @tag.errors[:name].should == ["can't be blank"]
147
-
148
- @tag.name = "something"
159
+ @tag.name = 'something'
149
160
  @tag.valid?
150
161
 
151
- @tag.errors[:name].should == []
162
+ expect(@tag.errors[:name]).to be_empty
152
163
  end
153
164
 
154
- it "should limit the name length to 255 or less characters" do
155
- @tag.name = "fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxranr"
165
+ it 'should limit the name length to 255 or less characters' do
166
+ @tag.name = 'fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxranr'
156
167
  @tag.valid?
157
- @tag.errors[:name].should == ["is too long (maximum is 255 characters)"]
168
+ #TODO, we should find another way to check this
169
+ expect(@tag.errors[:name]).to eq(['is too long (maximum is 255 characters)'])
158
170
 
159
- @tag.name = "fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxran"
171
+ @tag.name = 'fgkgnkkgjymkypbuozmwwghblmzpqfsgjasflblywhgkwndnkzeifalfcpeaeqychjuuowlacmuidnnrkprgpcpybarbkrmziqihcrxirlokhnzfvmtzixgvhlxzncyywficpraxfnjptxxhkqmvicbcdcynkjvziefqzyndxkjmsjlvyvbwraklbalykyxoliqdlreeykuphdtmzfdwpphmrqvwvqffojkqhlzvinqajsxbszyvrqqyzusxran'
160
172
  @tag.valid?
161
- @tag.errors[:name].should == []
173
+ expect(@tag.errors[:name]).to be_empty
162
174
  end
163
175
 
164
- it "should equal a tag with the same name" do
165
- @tag.name = "awesome"
166
- new_tag = ActsAsTaggableOn::Tag.new(:name => "awesome")
167
- new_tag.should == @tag
176
+ it 'should equal a tag with the same name' do
177
+ @tag.name = 'awesome'
178
+ new_tag = ActsAsTaggableOn::Tag.new(name: 'awesome')
179
+ expect(new_tag).to eq(@tag)
168
180
  end
169
181
 
170
- it "should return its name when to_s is called" do
171
- @tag.name = "cool"
172
- @tag.to_s.should == "cool"
182
+ it 'should return its name when to_s is called' do
183
+ @tag.name = 'cool'
184
+ expect(@tag.to_s).to eq('cool')
173
185
  end
174
186
 
175
- it "have named_scope named(something)" do
176
- @tag.name = "cool"
187
+ it 'have named_scope named(something)' do
188
+ @tag.name = 'cool'
177
189
  @tag.save!
178
- ActsAsTaggableOn::Tag.named('cool').should include(@tag)
190
+ expect(ActsAsTaggableOn::Tag.named('cool')).to include(@tag)
179
191
  end
180
192
 
181
- it "have named_scope named_like(something)" do
182
- @tag.name = "cool"
193
+ it 'have named_scope named_like(something)' do
194
+ @tag.name = 'cool'
183
195
  @tag.save!
184
- @another_tag = ActsAsTaggableOn::Tag.create!(:name => "coolip")
185
- ActsAsTaggableOn::Tag.named_like('cool').should include(@tag, @another_tag)
196
+ @another_tag = ActsAsTaggableOn::Tag.create!(name: 'coolip')
197
+ expect(ActsAsTaggableOn::Tag.named_like('cool')).to include(@tag, @another_tag)
186
198
  end
187
199
 
188
- describe "escape wildcard symbols in like requests" do
200
+ describe 'escape wildcard symbols in like requests' do
189
201
  before(:each) do
190
- @tag.name = "cool"
202
+ @tag.name = 'cool'
191
203
  @tag.save
192
- @another_tag = ActsAsTaggableOn::Tag.create!(:name => "coo%")
193
- @another_tag2 = ActsAsTaggableOn::Tag.create!(:name => "coolish")
204
+ @another_tag = ActsAsTaggableOn::Tag.create!(name: 'coo%')
205
+ @another_tag2 = ActsAsTaggableOn::Tag.create!(name: 'coolish')
194
206
  end
195
207
 
196
208
  it "return escaped result when '%' char present in tag" do
197
- ActsAsTaggableOn::Tag.named_like('coo%').should_not include(@tag)
198
- ActsAsTaggableOn::Tag.named_like('coo%').should include(@another_tag)
209
+ expect(ActsAsTaggableOn::Tag.named_like('coo%')).to_not include(@tag)
210
+ expect(ActsAsTaggableOn::Tag.named_like('coo%')).to include(@another_tag)
199
211
  end
200
212
 
201
213
  end
202
214
 
203
- describe "when using strict_case_match" do
215
+ describe 'when using strict_case_match' do
204
216
  before do
205
217
  ActsAsTaggableOn.strict_case_match = true
206
- @tag.name = "awesome"
218
+ @tag.name = 'awesome'
207
219
  @tag.save!
208
220
  end
209
221
 
@@ -211,71 +223,72 @@ describe ActsAsTaggableOn::Tag do
211
223
  ActsAsTaggableOn.strict_case_match = false
212
224
  end
213
225
 
214
- it "should find by name" do
215
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("awesome").should == @tag
226
+ it 'should find by name' do
227
+ expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('awesome')).to eq(@tag)
216
228
  end
217
229
 
218
- context "case sensitive" do
219
- if described_class.using_case_insensitive_collation?
230
+ context 'case sensitive' do
231
+ if ActsAsTaggableOn::Utils.using_case_insensitive_collation?
220
232
  include_context 'without unique index'
221
233
  end
222
234
 
223
- it "should find by name case sensitively" do
235
+ it 'should find by name case sensitively' do
224
236
  expect {
225
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name("AWESOME")
237
+ ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('AWESOME')
226
238
  }.to change(ActsAsTaggableOn::Tag, :count)
227
239
 
228
- ActsAsTaggableOn::Tag.last.name.should == "AWESOME"
240
+ expect(ActsAsTaggableOn::Tag.last.name).to eq('AWESOME')
229
241
  end
230
242
  end
231
243
 
232
- context "case sensitive" do
233
- if described_class.using_case_insensitive_collation?
244
+ context 'case sensitive' do
245
+ if ActsAsTaggableOn::Utils.using_case_insensitive_collation?
234
246
  include_context 'without unique index'
235
247
  end
236
248
 
237
- it "should have a named_scope named(something) that matches exactly" do
238
- uppercase_tag = ActsAsTaggableOn::Tag.create(:name => "Cool")
239
- @tag.name = "cool"
249
+ it 'should have a named_scope named(something) that matches exactly' do
250
+ uppercase_tag = ActsAsTaggableOn::Tag.create(name: 'Cool')
251
+ @tag.name = 'cool'
240
252
  @tag.save!
241
253
 
242
- ActsAsTaggableOn::Tag.named('cool').should include(@tag)
243
- ActsAsTaggableOn::Tag.named('cool').should_not include(uppercase_tag)
254
+ expect(ActsAsTaggableOn::Tag.named('cool')).to include(@tag)
255
+ expect(ActsAsTaggableOn::Tag.named('cool')).to_not include(uppercase_tag)
244
256
  end
245
257
  end
246
258
 
247
- it "should not change enconding" do
259
+ it 'should not change enconding' do
248
260
  name = "\u3042"
249
261
  original_encoding = name.encoding
250
- ActsAsTaggableOn::Tag.find_or_create_with_like_by_name(name)
251
- name.encoding.should == original_encoding
262
+ record = ActsAsTaggableOn::Tag.find_or_create_with_like_by_name(name)
263
+ record.reload
264
+ expect(record.name.encoding).to eq(original_encoding)
252
265
  end
253
266
  end
254
267
 
255
- describe "name uniqeness validation" do
256
- let(:duplicate_tag) { ActsAsTaggableOn::Tag.new(:name => 'ror') }
268
+ describe 'name uniqeness validation' do
269
+ let(:duplicate_tag) { ActsAsTaggableOn::Tag.new(name: 'ror') }
257
270
 
258
- before { ActsAsTaggableOn::Tag.create(:name => 'ror') }
271
+ before { ActsAsTaggableOn::Tag.create(name: 'ror') }
259
272
 
260
273
  context "when don't need unique names" do
261
274
  include_context 'without unique index'
262
- it "should not run uniqueness validation" do
263
- duplicate_tag.stub(:validates_name_uniqueness?).and_return(false)
275
+ it 'should not run uniqueness validation' do
276
+ allow(duplicate_tag).to receive(:validates_name_uniqueness?) { false }
264
277
  duplicate_tag.save
265
- duplicate_tag.should be_persisted
278
+ expect(duplicate_tag).to be_persisted
266
279
  end
267
280
  end
268
281
 
269
- context "when do need unique names" do
270
- it "should run uniqueness validation" do
271
- duplicate_tag.should_not be_valid
282
+ context 'when do need unique names' do
283
+ it 'should run uniqueness validation' do
284
+ expect(duplicate_tag).to_not be_valid
272
285
  end
273
286
 
274
- it "add error to name" do
287
+ it 'add error to name' do
275
288
  duplicate_tag.save
276
289
 
277
- duplicate_tag.should have(1).errors
278
- duplicate_tag.errors.messages[:name].should include('has already been taken')
290
+ expect(duplicate_tag.errors.size).to eq(1)
291
+ expect(duplicate_tag.errors.messages[:name]).to include('has already been taken')
279
292
  end
280
293
  end
281
294
  end