sb-acts-as-taggable-on 6.5.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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +39 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +330 -0
- data/CONTRIBUTING.md +57 -0
- data/Gemfile +11 -0
- data/Guardfile +5 -0
- data/LICENSE.md +20 -0
- data/README.md +555 -0
- data/Rakefile +21 -0
- data/UPGRADING.md +8 -0
- data/acts-as-taggable-on.gemspec +32 -0
- data/db/migrate/1_acts_as_taggable_on_migration.rb +36 -0
- data/db/migrate/2_add_missing_unique_indices.rb +25 -0
- data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +19 -0
- data/db/migrate/4_add_missing_taggable_index.rb +14 -0
- data/db/migrate/5_change_collation_for_tag_names.rb +14 -0
- data/db/migrate/6_add_missing_indexes_on_taggings.rb +22 -0
- data/gemfiles/activerecord_5.0.gemfile +21 -0
- data/gemfiles/activerecord_5.1.gemfile +21 -0
- data/gemfiles/activerecord_5.2.gemfile +21 -0
- data/gemfiles/activerecord_6.0.gemfile +21 -0
- data/lib/acts-as-taggable-on.rb +133 -0
- data/lib/acts_as_taggable_on.rb +6 -0
- data/lib/acts_as_taggable_on/default_parser.rb +79 -0
- data/lib/acts_as_taggable_on/engine.rb +4 -0
- data/lib/acts_as_taggable_on/generic_parser.rb +19 -0
- data/lib/acts_as_taggable_on/tag.rb +139 -0
- data/lib/acts_as_taggable_on/tag_list.rb +106 -0
- data/lib/acts_as_taggable_on/taggable.rb +101 -0
- data/lib/acts_as_taggable_on/taggable/cache.rb +90 -0
- data/lib/acts_as_taggable_on/taggable/collection.rb +183 -0
- data/lib/acts_as_taggable_on/taggable/core.rb +322 -0
- data/lib/acts_as_taggable_on/taggable/ownership.rb +136 -0
- data/lib/acts_as_taggable_on/taggable/related.rb +71 -0
- data/lib/acts_as_taggable_on/taggable/tag_list_type.rb +4 -0
- data/lib/acts_as_taggable_on/taggable/tagged_with_query.rb +16 -0
- data/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb +111 -0
- data/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb +70 -0
- data/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb +82 -0
- data/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb +61 -0
- data/lib/acts_as_taggable_on/tagger.rb +89 -0
- data/lib/acts_as_taggable_on/tagging.rb +36 -0
- data/lib/acts_as_taggable_on/tags_helper.rb +15 -0
- data/lib/acts_as_taggable_on/utils.rb +37 -0
- data/lib/acts_as_taggable_on/version.rb +3 -0
- data/lib/tasks/tags_collate_utf8.rake +21 -0
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +285 -0
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +112 -0
- data/spec/acts_as_taggable_on/caching_spec.rb +129 -0
- data/spec/acts_as_taggable_on/default_parser_spec.rb +47 -0
- data/spec/acts_as_taggable_on/dirty_spec.rb +142 -0
- data/spec/acts_as_taggable_on/generic_parser_spec.rb +14 -0
- data/spec/acts_as_taggable_on/related_spec.rb +99 -0
- data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +231 -0
- data/spec/acts_as_taggable_on/tag_list_spec.rb +176 -0
- data/spec/acts_as_taggable_on/tag_spec.rb +340 -0
- data/spec/acts_as_taggable_on/taggable_spec.rb +817 -0
- data/spec/acts_as_taggable_on/tagger_spec.rb +153 -0
- data/spec/acts_as_taggable_on/tagging_spec.rb +117 -0
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +45 -0
- data/spec/acts_as_taggable_on/utils_spec.rb +23 -0
- data/spec/internal/app/models/altered_inheriting_taggable_model.rb +5 -0
- data/spec/internal/app/models/cached_model.rb +3 -0
- data/spec/internal/app/models/cached_model_with_array.rb +11 -0
- data/spec/internal/app/models/columns_override_model.rb +5 -0
- data/spec/internal/app/models/company.rb +15 -0
- data/spec/internal/app/models/inheriting_taggable_model.rb +4 -0
- data/spec/internal/app/models/market.rb +2 -0
- data/spec/internal/app/models/non_standard_id_taggable_model.rb +8 -0
- data/spec/internal/app/models/ordered_taggable_model.rb +4 -0
- data/spec/internal/app/models/other_cached_model.rb +3 -0
- data/spec/internal/app/models/other_taggable_model.rb +4 -0
- data/spec/internal/app/models/student.rb +4 -0
- data/spec/internal/app/models/taggable_model.rb +14 -0
- data/spec/internal/app/models/untaggable_model.rb +3 -0
- data/spec/internal/app/models/user.rb +3 -0
- data/spec/internal/config/database.yml.sample +19 -0
- data/spec/internal/db/schema.rb +110 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/0-helpers.rb +32 -0
- data/spec/support/array.rb +9 -0
- data/spec/support/database.rb +36 -0
- data/spec/support/database_cleaner.rb +21 -0
- metadata +269 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'acts_as_tagger' do
|
5
|
+
|
6
|
+
describe 'Tagger Method Generation' do
|
7
|
+
before(:each) do
|
8
|
+
@tagger = User.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should add #is_tagger? query method to the class-side' do
|
12
|
+
expect(User).to respond_to(:is_tagger?)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return true from the class-side #is_tagger?' do
|
16
|
+
expect(User.is_tagger?).to be_truthy
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return false from the base #is_tagger?' do
|
20
|
+
expect(ActiveRecord::Base.is_tagger?).to be_falsy
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should add #is_tagger? query method to the singleton' do
|
24
|
+
expect(@tagger).to respond_to(:is_tagger?)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should add #tag method on the instance-side' do
|
28
|
+
expect(@tagger).to respond_to(:tag)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should generate an association for #owned_taggings and #owned_tags' do
|
32
|
+
expect(@tagger).to respond_to(:owned_taggings, :owned_tags)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#tag' do
|
37
|
+
context 'when called with a non-existent tag context' do
|
38
|
+
before(:each) do
|
39
|
+
@tagger = User.new
|
40
|
+
@taggable = TaggableModel.new(name: 'Richard Prior')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should by default not throw an exception ' do
|
44
|
+
expect(@taggable.tag_list_on(:foo)).to be_empty
|
45
|
+
expect(-> {
|
46
|
+
@tagger.tag(@taggable, with: 'this, and, that', on: :foo)
|
47
|
+
}).to_not raise_error
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should by default create the tag context on-the-fly' do
|
51
|
+
expect(@taggable.tag_list_on(:here_ond_now)).to be_empty
|
52
|
+
@tagger.tag(@taggable, with: 'that', on: :here_ond_now)
|
53
|
+
expect(@taggable.tag_list_on(:here_ond_now)).to_not include('that')
|
54
|
+
expect(@taggable.all_tags_list_on(:here_ond_now)).to include('that')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should show all the tag list when both public and owned tags exist' do
|
58
|
+
@taggable.tag_list = 'ruby, python'
|
59
|
+
@tagger.tag(@taggable, with: 'java, lisp', on: :tags)
|
60
|
+
expect(@taggable.all_tags_on(:tags).map(&:name).sort).to eq(%w(ruby python java lisp).sort)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should not add owned tags to the common list' do
|
64
|
+
@taggable.tag_list = 'ruby, python'
|
65
|
+
@tagger.tag(@taggable, with: 'java, lisp', on: :tags)
|
66
|
+
expect(@taggable.tag_list).to eq(%w(ruby python))
|
67
|
+
@tagger.tag(@taggable, with: '', on: :tags)
|
68
|
+
expect(@taggable.tag_list).to eq(%w(ruby python))
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should throw an exception when the default is over-ridden' do
|
72
|
+
expect(@taggable.tag_list_on(:foo_boo)).to be_empty
|
73
|
+
expect(-> {
|
74
|
+
@tagger.tag(@taggable, with: 'this, and, that', on: :foo_boo, force: false)
|
75
|
+
}).to raise_error(RuntimeError)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should not create the tag context on-the-fly when the default is over-ridden' do
|
79
|
+
expect(@taggable.tag_list_on(:foo_boo)).to be_empty
|
80
|
+
@tagger.tag(@taggable, with: 'this, and, that', on: :foo_boo, force: false) rescue
|
81
|
+
expect(@taggable.tag_list_on(:foo_boo)).to be_empty
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "when called by multiple tagger's" do
|
86
|
+
before(:each) do
|
87
|
+
@user_x = User.create(name: 'User X')
|
88
|
+
@user_y = User.create(name: 'User Y')
|
89
|
+
@taggable = TaggableModel.create(name: 'acts_as_taggable_on', tag_list: 'plugin')
|
90
|
+
|
91
|
+
@user_x.tag(@taggable, with: 'ruby, rails', on: :tags)
|
92
|
+
@user_y.tag(@taggable, with: 'ruby, plugin', on: :tags)
|
93
|
+
|
94
|
+
@user_y.tag(@taggable, with: '', on: :tags)
|
95
|
+
@user_y.tag(@taggable, with: '', on: :tags)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should delete owned tags' do
|
99
|
+
expect(@user_y.owned_tags).to be_empty
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should not delete other taggers tags' do
|
103
|
+
expect(@user_x.owned_tags.count).to eq(2)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should not delete original tags' do
|
107
|
+
expect(@taggable.all_tags_list_on(:tags)).to include('plugin')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Acts As Taggable On' do
|
5
|
+
|
6
|
+
describe 'Caching' do
|
7
|
+
before(:each) do
|
8
|
+
@taggable = CachedModel.new(name: 'Bob Jones')
|
9
|
+
@another_taggable = OtherCachedModel.new(name: 'John Smith')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should add saving of tag lists and cached tag lists to the instance' do
|
13
|
+
expect(@taggable).to respond_to(:save_cached_tag_list)
|
14
|
+
expect(@another_taggable).to respond_to(:save_cached_tag_list)
|
15
|
+
|
16
|
+
expect(@taggable).to respond_to(:save_tags)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should add cached tag lists to the instance if cached column is not present' do
|
20
|
+
expect(TaggableModel.new(name: 'Art Kram')).to_not respond_to(:save_cached_tag_list)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should generate a cached column checker for each tag type' do
|
24
|
+
expect(CachedModel).to respond_to(:caching_tag_list?)
|
25
|
+
expect(OtherCachedModel).to respond_to(:caching_language_list?)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should not have cached tags' do
|
29
|
+
expect(@taggable.cached_tag_list).to be_blank
|
30
|
+
expect(@another_taggable.cached_language_list).to be_blank
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should cache tags' do
|
34
|
+
@taggable.update(tag_list: 'awesome, epic')
|
35
|
+
expect(@taggable.cached_tag_list).to eq('awesome, epic')
|
36
|
+
|
37
|
+
@another_taggable.update(language_list: 'ruby, .net')
|
38
|
+
expect(@another_taggable.cached_language_list).to eq('ruby, .net')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should keep the cache' do
|
42
|
+
@taggable.update(tag_list: 'awesome, epic')
|
43
|
+
@taggable = CachedModel.find(@taggable.id)
|
44
|
+
@taggable.save!
|
45
|
+
expect(@taggable.cached_tag_list).to eq('awesome, epic')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should update the cache' do
|
49
|
+
@taggable.update(tag_list: 'awesome, epic')
|
50
|
+
@taggable.update(tag_list: 'awesome')
|
51
|
+
expect(@taggable.cached_tag_list).to eq('awesome')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should remove the cache' do
|
55
|
+
@taggable.update(tag_list: 'awesome, epic')
|
56
|
+
@taggable.update(tag_list: '')
|
57
|
+
expect(@taggable.cached_tag_list).to be_blank
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should have a tag list' do
|
61
|
+
@taggable.update(tag_list: 'awesome, epic')
|
62
|
+
@taggable = CachedModel.find(@taggable.id)
|
63
|
+
expect(@taggable.tag_list.sort).to eq(%w(awesome epic).sort)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should keep the tag list' do
|
67
|
+
@taggable.update(tag_list: 'awesome, epic')
|
68
|
+
@taggable = CachedModel.find(@taggable.id)
|
69
|
+
@taggable.save!
|
70
|
+
expect(@taggable.tag_list.sort).to eq(%w(awesome epic).sort)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should clear the cache on reset_column_information' do
|
74
|
+
CachedModel.column_names
|
75
|
+
CachedModel.reset_column_information
|
76
|
+
expect(CachedModel.instance_variable_get(:@acts_as_taggable_on_cache_columns)).to eql(nil)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should not override a user-defined columns method' do
|
80
|
+
expect(ColumnsOverrideModel.columns.map(&:name)).not_to include('ignored_column')
|
81
|
+
ColumnsOverrideModel.acts_as_taggable
|
82
|
+
expect(ColumnsOverrideModel.columns.map(&:name)).not_to include('ignored_column')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'with a custom delimiter' do
|
87
|
+
before(:each) do
|
88
|
+
@taggable = CachedModel.new(name: 'Bob Jones')
|
89
|
+
@another_taggable = OtherCachedModel.new(name: 'John Smith')
|
90
|
+
ActsAsTaggableOn.delimiter = ';'
|
91
|
+
end
|
92
|
+
|
93
|
+
after(:all) do
|
94
|
+
ActsAsTaggableOn.delimiter = ','
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should cache tags with custom delimiter' do
|
98
|
+
@taggable.update(tag_list: 'awesome; epic')
|
99
|
+
expect(@taggable.tag_list).to eq(['awesome', 'epic'])
|
100
|
+
expect(@taggable.cached_tag_list).to eq('awesome; epic')
|
101
|
+
|
102
|
+
@taggable = CachedModel.find_by_name('Bob Jones')
|
103
|
+
expect(@taggable.tag_list).to eq(['awesome', 'epic'])
|
104
|
+
expect(@taggable.cached_tag_list).to eq('awesome; epic')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'Cache methods initialization on new models' do
|
109
|
+
before(:all) do
|
110
|
+
ActiveRecord::Base.connection.execute(
|
111
|
+
'INSERT INTO cache_methods_injected_models (cached_tag_list) VALUES (\'ciao\')'
|
112
|
+
)
|
113
|
+
class CacheMethodsInjectedModel < ActiveRecord::Base
|
114
|
+
acts_as_taggable
|
115
|
+
end
|
116
|
+
end
|
117
|
+
after(:all) { Object.send(:remove_const, :CacheMethodsInjectedModel) }
|
118
|
+
|
119
|
+
it 'cached_tag_list_on? get injected correctly' do
|
120
|
+
expect do
|
121
|
+
CacheMethodsInjectedModel.first.tag_list
|
122
|
+
end.not_to raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'CachingWithArray' do
|
127
|
+
pending '#TODO'
|
128
|
+
end
|
129
|
+
end
|
@@ -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,142 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Dirty behavior of taggable objects' 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 'should show changes of freshly initialized dirty object' do
|
21
|
+
taggable = TaggableModel.find(@taggable.id)
|
22
|
+
taggable.tag_list = 'one'
|
23
|
+
expect(taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
|
24
|
+
end
|
25
|
+
|
26
|
+
if Rails.version >= "5.1"
|
27
|
+
it 'flags tag_list as changed' do
|
28
|
+
expect(@taggable.will_save_change_to_tag_list?).to be_truthy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'preserves original value' do
|
33
|
+
expect(@taggable.tag_list_was).to eq(['awesome', 'epic'])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'shows what the change was' do
|
37
|
+
expect(@taggable.tag_list_change).to eq([['awesome', 'epic'], ['one']])
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'without order' do
|
41
|
+
it 'should not mark attribute if order change ' do
|
42
|
+
taggable = TaggableModel.create(name: 'Dirty Harry', tag_list: %w(d c b a))
|
43
|
+
taggable.tag_list = %w(a b c d)
|
44
|
+
expect(taggable.tag_list_changed?).to be_falsey
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with order' do
|
49
|
+
it 'should mark attribute if order change' do
|
50
|
+
taggable = OrderedTaggableModel.create(name: 'Clean Harry', tag_list: 'd,c,b,a')
|
51
|
+
taggable.save
|
52
|
+
taggable.tag_list = %w(a b c d)
|
53
|
+
expect(taggable.tag_list_changed?).to be_truthy
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when tag_list is the same' do
|
59
|
+
before(:each) do
|
60
|
+
@taggable.tag_list = 'awesome, epic'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'is not flagged as changed' do
|
64
|
+
expect(@taggable.tag_list_changed?).to be_falsy
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'does not show any changes to the taggable item' do
|
68
|
+
expect(@taggable.changes).to be_empty
|
69
|
+
end
|
70
|
+
|
71
|
+
context "and using a delimiter different from a ','" do
|
72
|
+
before do
|
73
|
+
@old_delimiter = ActsAsTaggableOn.delimiter
|
74
|
+
ActsAsTaggableOn.delimiter = ';'
|
75
|
+
end
|
76
|
+
|
77
|
+
after do
|
78
|
+
ActsAsTaggableOn.delimiter = @old_delimiter
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'does not show any changes to the taggable item when using array assignments' do
|
82
|
+
@taggable.tag_list = %w(awesome epic)
|
83
|
+
expect(@taggable.changes).to be_empty
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'with context tags' do
|
90
|
+
before(:each) do
|
91
|
+
@taggable = TaggableModel.create('language_list' => 'awesome, epic')
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when language_list changed' do
|
95
|
+
before(:each) do
|
96
|
+
expect(@taggable.changes).to be_empty
|
97
|
+
@taggable.language_list = 'one'
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should show changes of dirty object' do
|
101
|
+
expect(@taggable.changes).to eq({'language_list' => [['awesome', 'epic'], ['one']]})
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'flags language_list as changed' do
|
105
|
+
expect(@taggable.language_list_changed?).to be_truthy
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'preserves original value' do
|
109
|
+
expect(@taggable.language_list_was).to eq(['awesome', 'epic'])
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'shows what the change was' do
|
113
|
+
expect(@taggable.language_list_change).to eq([['awesome', 'epic'], ['one']])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when language_list is the same' do
|
118
|
+
before(:each) do
|
119
|
+
@taggable.language_list = 'awesome, epic'
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'is not flagged as changed' do
|
123
|
+
expect(@taggable.language_list_changed?).to be_falsy
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'does not show any changes to the taggable item' do
|
127
|
+
expect(@taggable.changes).to be_empty
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when language_list changed by association' do
|
132
|
+
let(:tag) { ActsAsTaggableOn::Tag.new(name: 'one') }
|
133
|
+
|
134
|
+
it 'flags language_list as changed' do
|
135
|
+
expect(@taggable.changes).to be_empty
|
136
|
+
@taggable.languages << tag
|
137
|
+
expect(@taggable.language_list_changed?).to be_truthy
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
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,99 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Acts As Taggable On' do
|
5
|
+
|
6
|
+
describe 'Related Objects' do
|
7
|
+
|
8
|
+
#TODO, shared example
|
9
|
+
it 'should find related objects based on tag names on context' do
|
10
|
+
taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
|
11
|
+
taggable2 = TaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
|
12
|
+
taggable3 = TaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
|
13
|
+
|
14
|
+
expect(taggable1.find_related_tags).to include(taggable3)
|
15
|
+
expect(taggable1.find_related_tags).to_not include(taggable2)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'finds related tags for ordered taggable on' do
|
19
|
+
taggable1 = OrderedTaggableModel.create!(name: 'Taggable 1',colour_list: 'one, two')
|
20
|
+
taggable2 = OrderedTaggableModel.create!(name: 'Taggable 2',colour_list: 'three, four')
|
21
|
+
taggable3 = OrderedTaggableModel.create!(name: 'Taggable 3',colour_list: 'one, four')
|
22
|
+
|
23
|
+
expect(taggable1.find_related_colours).to include(taggable3)
|
24
|
+
expect(taggable1.find_related_colours).to_not include(taggable2)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should find related objects based on tag names on context - non standard id' do
|
28
|
+
taggable1 = NonStandardIdTaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
|
29
|
+
taggable2 = NonStandardIdTaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
|
30
|
+
taggable3 = NonStandardIdTaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
|
31
|
+
|
32
|
+
expect(taggable1.find_related_tags).to include(taggable3)
|
33
|
+
expect(taggable1.find_related_tags).to_not include(taggable2)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should find other related objects based on tag names on context' do
|
37
|
+
taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
|
38
|
+
taggable2 = OtherTaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four')
|
39
|
+
taggable3 = OtherTaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
|
40
|
+
|
41
|
+
expect(taggable1.find_related_tags_for(OtherTaggableModel)).to include(taggable3)
|
42
|
+
expect(taggable1.find_related_tags_for(OtherTaggableModel)).to_not include(taggable2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should find other related objects based on tags only from particular context' do
|
46
|
+
taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two')
|
47
|
+
taggable2 = TaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four', skill_list: 'one, two')
|
48
|
+
taggable3 = TaggableModel.create!(name: 'Taggable 3',tag_list: 'one, four')
|
49
|
+
|
50
|
+
expect(taggable1.find_related_tags).to include(taggable3)
|
51
|
+
expect(taggable1.find_related_tags).to_not include(taggable2)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
shared_examples "a collection" do
|
56
|
+
it do
|
57
|
+
taggable1 = described_class.create!(name: 'Taggable 1', tag_list: 'one')
|
58
|
+
taggable2 = described_class.create!(name: 'Taggable 2', tag_list: 'one, two')
|
59
|
+
|
60
|
+
expect(taggable1.find_related_tags).to include(taggable2)
|
61
|
+
expect(taggable1.find_related_tags).to_not include(taggable1)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# it 'should not include the object itself in the list of related objects' do
|
66
|
+
describe TaggableModel do
|
67
|
+
it_behaves_like "a collection"
|
68
|
+
end
|
69
|
+
|
70
|
+
# it 'should not include the object itself in the list of related objects - non standard id' do
|
71
|
+
describe NonStandardIdTaggableModel do
|
72
|
+
it_behaves_like "a collection"
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'Ignored Tags' do
|
76
|
+
let(:taggable1) { TaggableModel.create!(name: 'Taggable 1', tag_list: 'one, two, four') }
|
77
|
+
let(:taggable2) { TaggableModel.create!(name: 'Taggable 2', tag_list: 'two, three') }
|
78
|
+
let(:taggable3) { TaggableModel.create!(name: 'Taggable 3', tag_list: 'one, three') }
|
79
|
+
|
80
|
+
it 'should not include ignored tags in related search' do
|
81
|
+
expect(taggable1.find_related_tags(ignore: 'two')).to_not include(taggable2)
|
82
|
+
expect(taggable1.find_related_tags(ignore: 'two')).to include(taggable3)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should accept array of ignored tags' do
|
86
|
+
taggable4 = TaggableModel.create!(name: 'Taggable 4', tag_list: 'four')
|
87
|
+
|
88
|
+
|
89
|
+
expect(taggable1.find_related_tags(ignore: ['two', 'four'])).to_not include(taggable2)
|
90
|
+
expect(taggable1.find_related_tags(ignore: ['two', 'four'])).to_not include(taggable4)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should accept symbols as ignored tags' do
|
94
|
+
expect(taggable1.find_related_tags(ignore: :two)).to_not include(taggable2)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|