acts-as-taggable-on 7.0.0 → 9.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/spec.yml +76 -0
  3. data/Appraisals +13 -13
  4. data/CHANGELOG.md +27 -2
  5. data/Gemfile +1 -0
  6. data/README.md +32 -7
  7. data/acts-as-taggable-on.gemspec +2 -2
  8. data/db/migrate/1_acts_as_taggable_on_migration.rb +5 -8
  9. data/db/migrate/2_add_missing_unique_indices.rb +6 -8
  10. data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +3 -6
  11. data/db/migrate/4_add_missing_taggable_index.rb +5 -7
  12. data/db/migrate/5_change_collation_for_tag_names.rb +4 -6
  13. data/db/migrate/6_add_missing_indexes_on_taggings.rb +15 -13
  14. data/db/migrate/7_add_tenant_to_taggings.rb +13 -0
  15. data/docker-compose.yml +15 -0
  16. data/gemfiles/activerecord_6.0.gemfile +5 -8
  17. data/gemfiles/activerecord_6.1.gemfile +3 -8
  18. data/gemfiles/{activerecord_5.2.gemfile → activerecord_7.0.gemfile} +6 -9
  19. data/lib/acts_as_taggable_on/default_parser.rb +8 -10
  20. data/lib/acts_as_taggable_on/engine.rb +2 -0
  21. data/lib/acts_as_taggable_on/generic_parser.rb +2 -0
  22. data/lib/acts_as_taggable_on/tag.rb +33 -27
  23. data/lib/acts_as_taggable_on/tag_list.rb +8 -11
  24. data/lib/acts_as_taggable_on/taggable/cache.rb +64 -62
  25. data/lib/acts_as_taggable_on/taggable/collection.rb +178 -142
  26. data/lib/acts_as_taggable_on/taggable/core.rb +250 -236
  27. data/lib/acts_as_taggable_on/taggable/ownership.rb +110 -98
  28. data/lib/acts_as_taggable_on/taggable/related.rb +60 -47
  29. data/lib/acts_as_taggable_on/taggable/tag_list_type.rb +6 -2
  30. data/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb +110 -106
  31. data/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb +57 -53
  32. data/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb +63 -60
  33. data/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb +54 -46
  34. data/lib/acts_as_taggable_on/taggable/tagged_with_query.rb +14 -8
  35. data/lib/acts_as_taggable_on/taggable.rb +30 -12
  36. data/lib/acts_as_taggable_on/tagger.rb +9 -5
  37. data/lib/acts_as_taggable_on/tagging.rb +8 -4
  38. data/lib/acts_as_taggable_on/tags_helper.rb +3 -1
  39. data/lib/acts_as_taggable_on/utils.rb +4 -2
  40. data/lib/acts_as_taggable_on/version.rb +3 -1
  41. data/spec/acts_as_taggable_on/tag_spec.rb +16 -1
  42. data/spec/acts_as_taggable_on/taggable_spec.rb +6 -2
  43. data/spec/acts_as_taggable_on/tagging_spec.rb +26 -0
  44. data/spec/internal/app/models/taggable_model.rb +2 -0
  45. data/spec/internal/config/database.yml.sample +4 -8
  46. data/spec/internal/db/schema.rb +3 -0
  47. data/spec/support/database.rb +36 -26
  48. metadata +13 -22
  49. data/.travis.yml +0 -49
  50. data/UPGRADING.md +0 -8
  51. data/gemfiles/activerecord_5.0.gemfile +0 -21
  52. data/gemfiles/activerecord_5.1.gemfile +0 -21
@@ -49,6 +49,22 @@ describe ActsAsTaggableOn::Tagging do
49
49
  ActsAsTaggableOn.remove_unused_tags = previous_setting
50
50
  end
51
51
 
52
+ it 'should destroy unused tags after tagging destroyed when not using tags_counter' do
53
+ remove_unused_tags_previous_setting = ActsAsTaggableOn.remove_unused_tags
54
+ tags_counter_previous_setting = ActsAsTaggableOn.tags_counter
55
+ ActsAsTaggableOn.remove_unused_tags = true
56
+ ActsAsTaggableOn.tags_counter = false
57
+
58
+ ActsAsTaggableOn::Tag.destroy_all
59
+ @taggable = TaggableModel.create(name: 'Bob Jones')
60
+ @taggable.update_attribute :tag_list, 'aaa,bbb,ccc'
61
+ @taggable.update_attribute :tag_list, ''
62
+ expect(ActsAsTaggableOn::Tag.count).to eql(0)
63
+
64
+ ActsAsTaggableOn.remove_unused_tags = remove_unused_tags_previous_setting
65
+ ActsAsTaggableOn.tags_counter = tags_counter_previous_setting
66
+ end
67
+
52
68
  describe 'context scopes' do
53
69
  before do
54
70
  @tagging_2 = ActsAsTaggableOn::Tagging.new
@@ -61,12 +77,14 @@ describe ActsAsTaggableOn::Tagging do
61
77
  @tagging.tag = ActsAsTaggableOn::Tag.create(name: "Physics")
62
78
  @tagging.tagger = @tagger
63
79
  @tagging.context = 'Science'
80
+ @tagging.tenant = 'account1'
64
81
  @tagging.save
65
82
 
66
83
  @tagging_2.taggable = TaggableModel.create(name: "Satellites")
67
84
  @tagging_2.tag = ActsAsTaggableOn::Tag.create(name: "Technology")
68
85
  @tagging_2.tagger = @tagger_2
69
86
  @tagging_2.context = 'Science'
87
+ @tagging_2.tenant = 'account1'
70
88
  @tagging_2.save
71
89
 
72
90
  @tagging_3.taggable = TaggableModel.create(name: "Satellites")
@@ -98,6 +116,14 @@ describe ActsAsTaggableOn::Tagging do
98
116
  end
99
117
  end
100
118
 
119
+ describe '.by_tenant' do
120
+ it "should find taggings by tenant" do
121
+ expect(ActsAsTaggableOn::Tagging.by_tenant('account1').length).to eq(2);
122
+ expect(ActsAsTaggableOn::Tagging.by_tenant('account1').first).to eq(@tagging);
123
+ expect(ActsAsTaggableOn::Tagging.by_tenant('account1').second).to eq(@tagging_2);
124
+ end
125
+ end
126
+
101
127
  describe '.not_owned' do
102
128
  before do
103
129
  @tagging_4 = ActsAsTaggableOn::Tagging.new
@@ -3,6 +3,8 @@ class TaggableModel < ActiveRecord::Base
3
3
  acts_as_taggable_on :languages
4
4
  acts_as_taggable_on :skills
5
5
  acts_as_taggable_on :needs, :offerings
6
+ acts_as_taggable_tenant :tenant_id
7
+
6
8
  has_many :untaggable_models
7
9
 
8
10
  attr_reader :tag_list_submethod_called
@@ -4,16 +4,12 @@ sqlite3:
4
4
 
5
5
  mysql:
6
6
  adapter: mysql2
7
- host: localhost
7
+ host: 127.0.0.1
8
8
  username: root
9
9
  password:
10
10
  database: acts_as_taggable_on
11
- charset: utf8
11
+ encoding: utf8
12
12
 
13
13
  postgresql:
14
- adapter: postgresql
15
- hostname: localhost
16
- username: postgres
17
- password:
18
- database: acts_as_taggable_on
19
- encoding: utf8
14
+ # Needs to be given as a URL to force connection via TCP
15
+ url: postgresql://postgres:postgres@127.0.0.1:5432/acts_as_taggable_on?encoding=utf8
@@ -21,6 +21,8 @@ ActiveRecord::Schema.define version: 0 do
21
21
  # length for MyISAM table type: http://bit.ly/vgW2Ql
22
22
  t.string :context, limit: 128
23
23
 
24
+ t.string :tenant , limit: 128
25
+
24
26
  t.datetime :created_at
25
27
  end
26
28
  add_index ActsAsTaggableOn.taggings_table,
@@ -34,6 +36,7 @@ ActiveRecord::Schema.define version: 0 do
34
36
  create_table :taggable_models, force: true do |t|
35
37
  t.column :name, :string
36
38
  t.column :type, :string
39
+ t.column :tenant_id, :integer
37
40
  end
38
41
 
39
42
  create_table :columns_override_models, force: true do |t|
@@ -1,36 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # set adapter to use, default is sqlite3
2
4
  # to use an alternative adapter run => rake spec DB='postgresql'
3
5
  db_name = ENV['DB'] || 'sqlite3'
4
- database_yml = File.expand_path('../../internal/config/database.yml', __FILE__)
6
+ database_yml = File.expand_path('../internal/config/database.yml', __dir__)
5
7
 
6
- if File.exist?(database_yml)
8
+ unless File.exist?(database_yml)
9
+ raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
10
+ end
7
11
 
8
- ActiveRecord::Migration.verbose = false
12
+ ActiveRecord::Base.configurations = YAML.load_file(database_yml)
13
+ ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), '../debug.log'))
14
+ ActiveRecord::Base.logger.level = ENV['CI'] ? ::Logger::ERROR : ::Logger::DEBUG
15
+ ActiveRecord::Migration.verbose = false
16
+ if ActiveRecord.version >= Gem::Version.new('7.0.0.alpha2')
17
+ ActiveRecord.default_timezone = :utc
18
+ else
9
19
  ActiveRecord::Base.default_timezone = :utc
10
- ActiveRecord::Base.configurations = YAML.load_file(database_yml)
11
- ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), '../debug.log'))
12
- ActiveRecord::Base.logger.level = ENV['TRAVIS'] ? ::Logger::ERROR : ::Logger::DEBUG
13
- config = ActiveSupport::HashWithIndifferentAccess.new(ActiveRecord::Base.configurations[db_name])
14
-
15
- begin
16
- ActiveRecord::Base.establish_connection(db_name.to_sym)
17
- ActiveRecord::Base.connection
18
- rescue
19
- case db_name
20
- when /mysql/
21
- ActiveRecord::Base.establish_connection(config.merge('database' => nil))
22
- ActiveRecord::Base.connection.create_database(config['database'], {charset: 'utf8', collation: 'utf8_unicode_ci'})
23
- when 'postgresql'
24
- ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
25
- ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
26
- end
20
+ end
21
+ config = if ActiveRecord.version >= Gem::Version.new('6.1.0')
22
+ ActiveRecord::Base.configurations.configs_for(env_name: db_name)
23
+ else
24
+ ActiveSupport::HashWithIndifferentAccess.new(ActiveRecord::Base.configurations[db_name])
25
+ end
27
26
 
28
- ActiveRecord::Base.establish_connection(config)
27
+ begin
28
+ ActiveRecord::Base.establish_connection(db_name.to_sym)
29
+ ActiveRecord::Base.connection
30
+ rescue StandardError
31
+ case db_name
32
+ when /mysql/
33
+ ActiveRecord::Base.establish_connection(config.merge('database' => nil))
34
+ ActiveRecord::Base.connection.create_database(config['database'],
35
+ { charset: 'utf8', collation: 'utf8_unicode_ci' })
36
+ when 'postgresql'
37
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres',
38
+ 'schema_search_path' => 'public'))
39
+ ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
29
40
  end
30
41
 
31
- require File.dirname(__FILE__) + '/../internal/db/schema.rb'
32
- Dir[File.dirname(__dir__) + '/internal/app/models/*.rb'].each { |f| require f }
33
-
34
- else
35
- fail "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
42
+ ActiveRecord::Base.establish_connection(config)
36
43
  end
44
+
45
+ require "#{File.dirname(__FILE__)}/../internal/db/schema.rb"
46
+ Dir["#{File.dirname(__dir__)}/internal/app/models/*.rb"].each { |f| require f }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 9.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-31 00:00:00.000000000 Z
12
+ date: 2022-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,20 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '5.0'
20
+ version: '6.0'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '6.2'
23
+ version: '7.1'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: '5.0'
30
+ version: '6.0'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.2'
33
+ version: '7.1'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rspec-rails
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -110,9 +110,9 @@ executables: []
110
110
  extensions: []
111
111
  extra_rdoc_files: []
112
112
  files:
113
+ - ".github/workflows/spec.yml"
113
114
  - ".gitignore"
114
115
  - ".rspec"
115
- - ".travis.yml"
116
116
  - Appraisals
117
117
  - CHANGELOG.md
118
118
  - CONTRIBUTING.md
@@ -121,7 +121,6 @@ files:
121
121
  - LICENSE.md
122
122
  - README.md
123
123
  - Rakefile
124
- - UPGRADING.md
125
124
  - acts-as-taggable-on.gemspec
126
125
  - db/migrate/1_acts_as_taggable_on_migration.rb
127
126
  - db/migrate/2_add_missing_unique_indices.rb
@@ -129,11 +128,11 @@ files:
129
128
  - db/migrate/4_add_missing_taggable_index.rb
130
129
  - db/migrate/5_change_collation_for_tag_names.rb
131
130
  - db/migrate/6_add_missing_indexes_on_taggings.rb
132
- - gemfiles/activerecord_5.0.gemfile
133
- - gemfiles/activerecord_5.1.gemfile
134
- - gemfiles/activerecord_5.2.gemfile
131
+ - db/migrate/7_add_tenant_to_taggings.rb
132
+ - docker-compose.yml
135
133
  - gemfiles/activerecord_6.0.gemfile
136
134
  - gemfiles/activerecord_6.1.gemfile
135
+ - gemfiles/activerecord_7.0.gemfile
137
136
  - lib/acts-as-taggable-on.rb
138
137
  - lib/acts_as_taggable_on.rb
139
138
  - lib/acts_as_taggable_on/default_parser.rb
@@ -200,15 +199,7 @@ homepage: https://github.com/mbleigh/acts-as-taggable-on
200
199
  licenses:
201
200
  - MIT
202
201
  metadata: {}
203
- post_install_message: |-
204
- When upgrading
205
-
206
- Re-run the migrations generator
207
-
208
- rake acts_as_taggable_on_engine:install:migrations
209
-
210
- This will create any new migrations and skip existing ones
211
- Version 3.5.0 has a migration for mysql adapter
202
+ post_install_message:
212
203
  rdoc_options: []
213
204
  require_paths:
214
205
  - lib
@@ -216,14 +207,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
207
  requirements:
217
208
  - - ">="
218
209
  - !ruby/object:Gem::Version
219
- version: 2.3.7
210
+ version: 2.5.0
220
211
  required_rubygems_version: !ruby/object:Gem::Requirement
221
212
  requirements:
222
213
  - - ">="
223
214
  - !ruby/object:Gem::Version
224
215
  version: '0'
225
216
  requirements: []
226
- rubygems_version: 3.0.3
217
+ rubygems_version: 3.2.22
227
218
  signing_key:
228
219
  specification_version: 4
229
220
  summary: Advanced tagging for Rails.
data/.travis.yml DELETED
@@ -1,49 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
-
4
- addons:
5
- postgresql: '10'
6
-
7
- services:
8
- - mysql
9
- - postgresql
10
-
11
- rvm:
12
- - 2.7.0
13
- - 2.6.5
14
- - 2.5.5
15
- - 2.4.6
16
- - 2.3.7
17
-
18
- env:
19
- - DB=sqlite3
20
- - DB=mysql
21
- - DB=postgresql
22
-
23
- gemfile:
24
- - gemfiles/activerecord_5.2.gemfile
25
- - gemfiles/activerecord_5.1.gemfile
26
- - gemfiles/activerecord_5.0.gemfile
27
- - gemfiles/activerecord_6.0.gemfile
28
- - gemfiles/activerecord_6.1.gemfile
29
-
30
- bundler_args: '--without local_development --jobs 3 --retry 3'
31
-
32
- before_install:
33
- - gem install bundler
34
-
35
- script: bundle exec rake
36
-
37
- matrix:
38
- allow_failures:
39
- - rvm: ruby-head
40
- fast_finish: true
41
- exclude:
42
- - rvm: 2.3.7
43
- gemfile: gemfiles/activerecord_6.0.gemfile
44
- - rvm: 2.4.6
45
- gemfile: gemfiles/activerecord_6.0.gemfile
46
- - rvm: 2.3.7
47
- gemfile: gemfiles/activerecord_6.1.gemfile
48
- - rvm: 2.4.6
49
- gemfile: gemfiles/activerecord_6.1.gemfile
data/UPGRADING.md DELETED
@@ -1,8 +0,0 @@
1
- When upgrading
2
-
3
- Re-run the migrations generator
4
-
5
- rake acts_as_taggable_on_engine:install:migrations
6
-
7
- This will create any new migrations and skip existing ones
8
- Version 3.5.0 has a migration for mysql adapter
@@ -1,21 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "~> 5.0.3"
4
- case ENV["DB"]
5
- when "postgresql"
6
- gem 'pg'
7
- when "mysql"
8
- gem 'mysql2', '~> 0.3'
9
- else
10
- gem "sqlite3", "~> 1.3", "< 1.4"
11
- end
12
-
13
- group :local_development do
14
- gem "guard"
15
- gem "guard-rspec"
16
- gem "appraisal"
17
- gem "rake"
18
- gem "byebug", platforms: [:mri]
19
- end
20
-
21
- gemspec path: "../"
@@ -1,21 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "~> 5.1.1"
4
- case ENV["DB"]
5
- when "postgresql"
6
- gem 'pg'
7
- when "mysql"
8
- gem 'mysql2', '~> 0.3'
9
- else
10
- gem "sqlite3", "~> 1.3", "< 1.4"
11
- end
12
-
13
- group :local_development do
14
- gem "guard"
15
- gem "guard-rspec"
16
- gem "appraisal"
17
- gem "rake"
18
- gem "byebug", platforms: [:mri]
19
- end
20
-
21
- gemspec path: "../"