acts-as-taggable-on 3.2.1 → 3.4.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.
- checksums.yaml +4 -4
- data/.travis.yml +21 -1
- data/Appraisals +8 -6
- data/CHANGELOG.md +99 -10
- data/README.md +78 -11
- data/acts-as-taggable-on.gemspec +2 -4
- data/db/migrate/4_add_missing_taggable_index.rb +9 -0
- data/gemfiles/activerecord_3.2.gemfile +0 -1
- data/gemfiles/activerecord_4.0.gemfile +1 -2
- data/gemfiles/activerecord_4.1.gemfile +1 -2
- data/gemfiles/activerecord_4.2.gemfile +16 -0
- data/gemfiles/activerecord_edge.gemfile +0 -1
- data/lib/acts-as-taggable-on.rb +40 -21
- data/lib/acts_as_taggable_on/default_parser.rb +79 -0
- data/lib/acts_as_taggable_on/generic_parser.rb +19 -0
- data/lib/acts_as_taggable_on/tag.rb +6 -1
- data/lib/acts_as_taggable_on/tag_list.rb +20 -79
- data/lib/acts_as_taggable_on/tag_list_parser.rb +21 -0
- data/lib/acts_as_taggable_on/{acts_as_taggable_on → taggable}/cache.rb +1 -0
- data/lib/acts_as_taggable_on/{acts_as_taggable_on → taggable}/collection.rb +3 -1
- data/lib/acts_as_taggable_on/{acts_as_taggable_on → taggable}/core.rb +87 -51
- data/lib/acts_as_taggable_on/{acts_as_taggable_on → taggable}/ownership.rb +1 -1
- data/lib/acts_as_taggable_on/{acts_as_taggable_on → taggable}/related.rb +6 -6
- data/lib/acts_as_taggable_on/taggable.rb +7 -8
- data/lib/acts_as_taggable_on/tagging.rb +7 -1
- data/lib/acts_as_taggable_on/tags_helper.rb +2 -2
- data/lib/acts_as_taggable_on/utils.rb +26 -50
- data/lib/acts_as_taggable_on/version.rb +1 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +1 -1
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +1 -0
- data/spec/acts_as_taggable_on/caching_spec.rb +1 -0
- data/spec/acts_as_taggable_on/default_parser_spec.rb +47 -0
- data/spec/acts_as_taggable_on/generic_parser_spec.rb +14 -0
- data/spec/acts_as_taggable_on/related_spec.rb +1 -0
- data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +1 -0
- data/spec/acts_as_taggable_on/tag_list_parser_spec.rb +46 -0
- data/spec/acts_as_taggable_on/tag_list_spec.rb +23 -31
- data/spec/acts_as_taggable_on/tag_spec.rb +54 -38
- data/spec/acts_as_taggable_on/taggable/dirty_spec.rb +127 -0
- data/spec/acts_as_taggable_on/taggable_spec.rb +84 -164
- data/spec/acts_as_taggable_on/tagger_spec.rb +1 -1
- data/spec/acts_as_taggable_on/tagging_spec.rb +37 -1
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +1 -0
- data/spec/acts_as_taggable_on/utils_spec.rb +6 -11
- data/spec/internal/app/models/cached_model_with_array.rb +1 -1
- data/spec/internal/app/models/models.rb +2 -2
- data/spec/internal/db/schema.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/0-helpers.rb +32 -0
- data/spec/support/database_cleaner.rb +4 -0
- metadata +29 -52
- data/spec/bm.rb +0 -52
- data/spec/schema.rb +0 -82
- /data/lib/acts_as_taggable_on/{acts_as_taggable_on/compatibility.rb → compatibility.rb} +0 -0
- /data/lib/acts_as_taggable_on/{acts_as_taggable_on → taggable}/dirty.rb +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe ActsAsTaggableOn::DefaultParser do
|
|
5
|
+
it '#parse should return empty array if empty array is passed' do
|
|
6
|
+
parser = ActsAsTaggableOn::DefaultParser.new([])
|
|
7
|
+
expect(parser.parse).to be_empty
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe 'Multiple Delimiter' do
|
|
11
|
+
before do
|
|
12
|
+
@old_delimiter = ActsAsTaggableOn.delimiter
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after do
|
|
16
|
+
ActsAsTaggableOn.delimiter = @old_delimiter
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should separate tags by delimiters' do
|
|
20
|
+
ActsAsTaggableOn.delimiter = [',', ' ', '\|']
|
|
21
|
+
parser = ActsAsTaggableOn::DefaultParser.new('cool, data|I have')
|
|
22
|
+
expect(parser.parse.to_s).to eq('cool, data, I, have')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should escape quote' do
|
|
26
|
+
ActsAsTaggableOn.delimiter = [',', ' ', '\|']
|
|
27
|
+
parser = ActsAsTaggableOn::DefaultParser.new("'I have'|cool, data")
|
|
28
|
+
expect(parser.parse.to_s).to eq('"I have", cool, data')
|
|
29
|
+
|
|
30
|
+
parser = ActsAsTaggableOn::DefaultParser.new('"I, have"|cool, data')
|
|
31
|
+
expect(parser.parse.to_s).to eq('"I, have", cool, data')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'should work for utf8 delimiter and long delimiter' do
|
|
35
|
+
ActsAsTaggableOn.delimiter = [',', '的', '可能是']
|
|
36
|
+
parser = ActsAsTaggableOn::DefaultParser.new('我的东西可能是不见了,还好有备份')
|
|
37
|
+
expect(parser.parse.to_s).to eq('我, 东西, 不见了, 还好有备份')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'should work for multiple quoted tags' do
|
|
41
|
+
ActsAsTaggableOn.delimiter = [',']
|
|
42
|
+
parser = ActsAsTaggableOn::DefaultParser.new('"Ruby Monsters","eat Katzenzungen"')
|
|
43
|
+
expect(parser.parse.to_s).to eq('Ruby Monsters, eat Katzenzungen')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe ActsAsTaggableOn::GenericParser do
|
|
5
|
+
it '#parse should return empty array if empty tag string is passed' do
|
|
6
|
+
tag_list = ActsAsTaggableOn::GenericParser.new('')
|
|
7
|
+
expect(tag_list.parse).to be_empty
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it '#parse should separate tags by comma' do
|
|
11
|
+
tag_list = ActsAsTaggableOn::GenericParser.new('cool,data,,I,have')
|
|
12
|
+
expect(tag_list.parse).to eq(%w(cool data I have))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe ActsAsTaggableOn::TagListParser do
|
|
5
|
+
it '#parse should return empty array if empty array is passed' do
|
|
6
|
+
expect(ActsAsTaggableOn::TagListParser.parse([])).to be_empty
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe 'Multiple Delimiter' do
|
|
10
|
+
before do
|
|
11
|
+
@old_delimiter = ActsAsTaggableOn.delimiter
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
after do
|
|
15
|
+
ActsAsTaggableOn.delimiter = @old_delimiter
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should separate tags by delimiters' do
|
|
19
|
+
ActsAsTaggableOn.delimiter = [',', ' ', '\|']
|
|
20
|
+
tag_list = ActsAsTaggableOn::TagListParser.parse('cool, data|I have')
|
|
21
|
+
expect(tag_list.to_s).to eq('cool, data, I, have')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'should escape quote' do
|
|
25
|
+
ActsAsTaggableOn.delimiter = [',', ' ', '\|']
|
|
26
|
+
tag_list = ActsAsTaggableOn::TagListParser.parse "'I have'|cool, data"
|
|
27
|
+
expect(tag_list.to_s).to eq('"I have", cool, data')
|
|
28
|
+
|
|
29
|
+
tag_list = ActsAsTaggableOn::TagListParser.parse '"I, have"|cool, data'
|
|
30
|
+
expect(tag_list.to_s).to eq('"I, have", cool, data')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should work for utf8 delimiter and long delimiter' do
|
|
34
|
+
ActsAsTaggableOn.delimiter = [',', '的', '可能是']
|
|
35
|
+
tag_list = ActsAsTaggableOn::TagListParser.parse('我的东西可能是不见了,还好有备份')
|
|
36
|
+
expect(tag_list.to_s).to eq('我, 东西, 不见了, 还好有备份')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should work for multiple quoted tags' do
|
|
40
|
+
ActsAsTaggableOn.delimiter = [',']
|
|
41
|
+
tag_list = ActsAsTaggableOn::TagListParser.parse('"Ruby Monsters","eat Katzenzungen"')
|
|
42
|
+
expect(tag_list.to_s).to eq('Ruby Monsters, eat Katzenzungen')
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
5
|
describe ActsAsTaggableOn::TagList do
|
|
@@ -7,9 +8,7 @@ describe ActsAsTaggableOn::TagList do
|
|
|
7
8
|
|
|
8
9
|
it { should be_kind_of Array }
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
expect(ActsAsTaggableOn::TagList.from([])).to be_empty
|
|
12
|
-
end
|
|
11
|
+
|
|
13
12
|
|
|
14
13
|
describe '#add' do
|
|
15
14
|
it 'should be able to be add a new tag word' do
|
|
@@ -115,44 +114,37 @@ describe ActsAsTaggableOn::TagList do
|
|
|
115
114
|
|
|
116
115
|
ActsAsTaggableOn.force_lowercase = false
|
|
117
116
|
end
|
|
118
|
-
|
|
119
117
|
end
|
|
120
118
|
|
|
121
|
-
describe '
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
end
|
|
119
|
+
describe 'custom parser' do
|
|
120
|
+
let(:parser) { double(parse: %w(cool wicked)) }
|
|
121
|
+
let(:parser_class) { stub_const('MyParser', Class) }
|
|
125
122
|
|
|
126
|
-
|
|
127
|
-
ActsAsTaggableOn.
|
|
128
|
-
|
|
123
|
+
it 'should use a the default parser if none is set as parameter' do
|
|
124
|
+
allow(ActsAsTaggableOn.default_parser).to receive(:new).and_return(parser)
|
|
125
|
+
ActsAsTaggableOn::TagList.new('cool, wicked', parse: true)
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
ActsAsTaggableOn.delimiter = [',', ' ', '\|']
|
|
132
|
-
tag_list = ActsAsTaggableOn::TagList.from 'cool, data|I have'
|
|
133
|
-
expect(tag_list.to_s).to eq('cool, data, I, have')
|
|
127
|
+
expect(parser).to have_received(:parse)
|
|
134
128
|
end
|
|
135
129
|
|
|
136
|
-
it 'should
|
|
137
|
-
|
|
138
|
-
tag_list = ActsAsTaggableOn::TagList.from "'I have'|cool, data"
|
|
139
|
-
expect(tag_list.to_s).to eq('"I have", cool, data')
|
|
130
|
+
it 'should use the custom parser passed as parameter' do
|
|
131
|
+
allow(parser_class).to receive(:new).and_return(parser)
|
|
140
132
|
|
|
141
|
-
|
|
142
|
-
expect(tag_list.to_s).to eq('"I, have", cool, data')
|
|
143
|
-
end
|
|
133
|
+
ActsAsTaggableOn::TagList.new('cool, wicked', parser: parser_class)
|
|
144
134
|
|
|
145
|
-
|
|
146
|
-
ActsAsTaggableOn.delimiter = [',', '的', '可能是']
|
|
147
|
-
tag_list = ActsAsTaggableOn::TagList.from '我的东西可能是不见了,还好有备份'
|
|
148
|
-
expect(tag_list.to_s).to eq('我, 东西, 不见了, 还好有备份')
|
|
135
|
+
expect(parser).to have_received(:parse)
|
|
149
136
|
end
|
|
150
137
|
|
|
151
|
-
it 'should
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
138
|
+
it 'should use the parser setted as attribute' do
|
|
139
|
+
allow(parser_class).to receive(:new).with('new, tag').and_return(parser)
|
|
140
|
+
|
|
141
|
+
tag_list = ActsAsTaggableOn::TagList.new('example')
|
|
142
|
+
tag_list.parser = parser_class
|
|
143
|
+
tag_list.add('new, tag', parse: true)
|
|
144
|
+
|
|
145
|
+
expect(parser).to have_received(:parse)
|
|
155
146
|
end
|
|
156
147
|
end
|
|
157
148
|
|
|
149
|
+
|
|
158
150
|
end
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
2
|
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
|
-
|
|
7
|
-
|
|
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
|
|
@@ -14,23 +17,20 @@ describe ActsAsTaggableOn::Tag do
|
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
|
|
17
|
-
|
|
18
20
|
describe 'named like any' do
|
|
19
|
-
context 'case insensitive collation and unique index on tag name' do
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(ActsAsTaggableOn::Tag.named_like_any(%w(awesome epic)).count).to eq(2)
|
|
28
|
-
end
|
|
21
|
+
context 'case insensitive collation and unique index on tag name', if: using_case_insensitive_collation? do
|
|
22
|
+
before(:each) do
|
|
23
|
+
ActsAsTaggableOn::Tag.create(name: 'Awesome')
|
|
24
|
+
ActsAsTaggableOn::Tag.create(name: 'epic')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should find both tags' do
|
|
28
|
+
expect(ActsAsTaggableOn::Tag.named_like_any(%w(awesome epic)).count).to eq(2)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
context 'case insensitive collation without indexes or case sensitive collation with indexes' do
|
|
33
|
-
if
|
|
33
|
+
if using_case_insensitive_collation?
|
|
34
34
|
include_context 'without unique index'
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -67,28 +67,24 @@ describe ActsAsTaggableOn::Tag do
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
unless
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
end
|
|
70
|
+
describe 'find or create by unicode name', unless: using_sqlite? do
|
|
71
|
+
before(:each) do
|
|
72
|
+
@tag.name = 'привет'
|
|
73
|
+
@tag.save
|
|
74
|
+
end
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
it 'should find by name' do
|
|
77
|
+
expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('привет')).to eq(@tag)
|
|
78
|
+
end
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
it 'should find by name case insensitive' do
|
|
81
|
+
expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('ПРИВЕТ')).to eq(@tag)
|
|
82
|
+
end
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('Iñupiat')).to eq(@tag)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
84
|
+
it 'should find by name accent insensitive', if: using_case_insensitive_collation? do
|
|
85
|
+
@tag.name = 'inupiat'
|
|
86
|
+
@tag.save
|
|
87
|
+
expect(ActsAsTaggableOn::Tag.find_or_create_with_like_by_name('Iñupiat')).to eq(@tag)
|
|
92
88
|
end
|
|
93
89
|
end
|
|
94
90
|
|
|
@@ -107,7 +103,7 @@ describe ActsAsTaggableOn::Tag do
|
|
|
107
103
|
end
|
|
108
104
|
|
|
109
105
|
context 'case sensitive' do
|
|
110
|
-
if
|
|
106
|
+
if using_case_insensitive_collation?
|
|
111
107
|
include_context 'without unique index'
|
|
112
108
|
end
|
|
113
109
|
|
|
@@ -126,7 +122,7 @@ describe ActsAsTaggableOn::Tag do
|
|
|
126
122
|
end
|
|
127
123
|
|
|
128
124
|
context 'case sensitive' do
|
|
129
|
-
if
|
|
125
|
+
if using_case_insensitive_collation?
|
|
130
126
|
include_context 'without unique index'
|
|
131
127
|
end
|
|
132
128
|
|
|
@@ -226,7 +222,7 @@ describe ActsAsTaggableOn::Tag do
|
|
|
226
222
|
end
|
|
227
223
|
|
|
228
224
|
context 'case sensitive' do
|
|
229
|
-
if
|
|
225
|
+
if using_case_insensitive_collation?
|
|
230
226
|
include_context 'without unique index'
|
|
231
227
|
end
|
|
232
228
|
|
|
@@ -240,7 +236,7 @@ describe ActsAsTaggableOn::Tag do
|
|
|
240
236
|
end
|
|
241
237
|
|
|
242
238
|
context 'case sensitive' do
|
|
243
|
-
if
|
|
239
|
+
if using_case_insensitive_collation?
|
|
244
240
|
include_context 'without unique index'
|
|
245
241
|
end
|
|
246
242
|
|
|
@@ -290,4 +286,24 @@ describe ActsAsTaggableOn::Tag do
|
|
|
290
286
|
end
|
|
291
287
|
end
|
|
292
288
|
end
|
|
289
|
+
|
|
290
|
+
describe 'popular tags' do
|
|
291
|
+
before do
|
|
292
|
+
%w(sports rails linux tennis golden_syrup).each_with_index do |t, i|
|
|
293
|
+
tag = ActsAsTaggableOn::Tag.new(name: t)
|
|
294
|
+
tag.taggings_count = i
|
|
295
|
+
tag.save!
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
it 'should find the most popular tags' do
|
|
300
|
+
expect(ActsAsTaggableOn::Tag.most_used(3).first.name).to eq("golden_syrup")
|
|
301
|
+
expect(ActsAsTaggableOn::Tag.most_used(3).length).to eq(3)
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
it 'should find the least popular tags' do
|
|
305
|
+
expect(ActsAsTaggableOn::Tag.least_used(3).first.name).to eq("sports")
|
|
306
|
+
expect(ActsAsTaggableOn::Tag.least_used(3).length).to eq(3)
|
|
307
|
+
end
|
|
308
|
+
end
|
|
293
309
|
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe ActsAsTaggableOn::Taggable::Dirty do
|
|
5
|
+
context 'with un-contexted tags' do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@taggable = TaggableModel.create(tag_list: 'awesome, epic')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context 'when tag_list changed' do
|
|
11
|
+
before(:each) do
|
|
12
|
+
expect(@taggable.changes).to be_empty
|
|
13
|
+
@taggable.tag_list = 'one'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'should show changes of dirty object' do
|
|
17
|
+
expect(@taggable.changes).to eq({'tag_list' => ['awesome, epic', ['one']]})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'flags tag_list as changed' do
|
|
21
|
+
expect(@taggable.tag_list_changed?).to be_truthy
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'preserves original value' do
|
|
25
|
+
expect(@taggable.tag_list_was).to eq('awesome, epic')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'shows what the change was' do
|
|
29
|
+
expect(@taggable.tag_list_change).to eq(['awesome, epic', ['one']])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context 'without order' do
|
|
33
|
+
it 'should not mark attribute if order change ' do
|
|
34
|
+
taggable = TaggableModel.create(name: 'Dirty Harry', tag_list: %w(d c b a))
|
|
35
|
+
taggable.tag_list = %w(a b c d)
|
|
36
|
+
expect(taggable.tag_list_changed?).to be_falsey
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context 'with order' do
|
|
41
|
+
it 'should mark attribute if order change' do
|
|
42
|
+
taggable = OrderedTaggableModel.create(name: 'Clean Harry', tag_list: 'd,c,b,a')
|
|
43
|
+
taggable.save
|
|
44
|
+
taggable.tag_list = %w(a b c d)
|
|
45
|
+
expect(taggable.tag_list_changed?).to be_truthy
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context 'when tag_list is the same' do
|
|
51
|
+
before(:each) do
|
|
52
|
+
@taggable.tag_list = 'awesome, epic'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'is not flagged as changed' do
|
|
56
|
+
expect(@taggable.tag_list_changed?).to be_falsy
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'does not show any changes to the taggable item' do
|
|
60
|
+
expect(@taggable.changes).to be_empty
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "and using a delimiter different from a ','" do
|
|
64
|
+
before do
|
|
65
|
+
@old_delimiter = ActsAsTaggableOn.delimiter
|
|
66
|
+
ActsAsTaggableOn.delimiter = ';'
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
after do
|
|
70
|
+
ActsAsTaggableOn.delimiter = @old_delimiter
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'does not show any changes to the taggable item when using array assignments' do
|
|
74
|
+
@taggable.tag_list = %w(awesome epic)
|
|
75
|
+
expect(@taggable.changes).to be_empty
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context 'with context tags' do
|
|
82
|
+
before(:each) do
|
|
83
|
+
@taggable = TaggableModel.create('language_list' => 'awesome, epic')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context 'when language_list changed' do
|
|
87
|
+
before(:each) do
|
|
88
|
+
expect(@taggable.changes).to be_empty
|
|
89
|
+
@taggable.language_list = 'one'
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should show changes of dirty object' do
|
|
93
|
+
expect(@taggable.changes).to eq({'language_list' => ['awesome, epic', ['one']]})
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'flags language_list as changed' do
|
|
97
|
+
expect(@taggable.language_list_changed?).to be_truthy
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'preserves original value' do
|
|
101
|
+
expect(@taggable.language_list_was).to eq('awesome, epic')
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'shows what the change was' do
|
|
105
|
+
expect(@taggable.language_list_change).to eq(['awesome, epic', ['one']])
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'shows what the changes were' do
|
|
109
|
+
expect(@taggable.language_list_changes).to eq(['awesome, epic', ['one']])
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context 'when language_list is the same' do
|
|
114
|
+
before(:each) do
|
|
115
|
+
@taggable.language_list = 'awesome, epic'
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'is not flagged as changed' do
|
|
119
|
+
expect(@taggable.language_list_changed?).to be_falsy
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'does not show any changes to the taggable item' do
|
|
123
|
+
expect(@taggable.changes).to be_empty
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|