acts-as-taggable-on 6.5.0 → 8.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4120fe17937a900a8bbe921880f0e3e8c83a4355483bfbbb6eba6e99738b7fda
4
- data.tar.gz: 1b8924e2cb3a360e6be90986e5be0460652aac74225869f570200bde2a734cf2
3
+ metadata.gz: 86ed71e7fcf66346a4afcaac85e33d318aafb9d6dcf58a787511161f57908be9
4
+ data.tar.gz: add5ececd0bd17f3942ee5cbd102e9de65a46ed74e1382c87cb7ba0e3a071d87
5
5
  SHA512:
6
- metadata.gz: 28ea6660e352e3e025311ed9a3d470b941d3b4bca6108b3ce7eaadc0fd0aac3d8ba7508baf002ab2a8ac09ecd7bf2795e1b0a26158e1d636c305722e2bff9ad7
7
- data.tar.gz: 2ddf924977f9bdb6c0e6665186ce3de7d2624abb00b933b06194f64866bb39d3b98c0bb7a0f2de635c046a0b655ad084392120fbd12afb5ed06057579b38961d
6
+ metadata.gz: afdaa14e7584c82b022c0f763528eb09dbfb9e928fcefee8810649b7fc55d4d0035fb273d413d378404575aa7a49fa0d927042c170c86ae1af138674c752aa08
7
+ data.tar.gz: 79d100efe8a7f140f73058cb54ef365251642e9668fc492923ff09348a3f42e0c66ba011afcbe494393778b598d1fb2fc804727239d046491b66bb9d5d7d80aa
@@ -0,0 +1,95 @@
1
+ name: spec
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ continue-on-error: ${{ matrix.ruby == 'head' }}
9
+ env:
10
+ DB: ${{ matrix.db }}
11
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
12
+ strategy:
13
+ matrix:
14
+ ruby:
15
+ - 2.3
16
+ - 2.4
17
+ - 2.5
18
+ - 2.6
19
+ - 2.7
20
+ - 3.0
21
+ - head
22
+ gemfile:
23
+ - gemfiles/activerecord_5.0.gemfile
24
+ - gemfiles/activerecord_5.2.gemfile
25
+ - gemfiles/activerecord_5.1.gemfile
26
+ - gemfiles/activerecord_6.0.gemfile
27
+ - gemfiles/activerecord_6.1.gemfile
28
+ db:
29
+ - mysql
30
+ - postgresql
31
+ - sqlite3
32
+ exclude:
33
+ # Unfortunately, the mysql2 gem encounters a segfault in the ruby 2.3 environment:
34
+ - ruby: 2.3
35
+ db: mysql
36
+ # Exclude ActiveRecord 6.x for Ruby < 2.5
37
+ - ruby: 2.3
38
+ gemfile: gemfiles/activerecord_6.0.gemfile
39
+ - ruby: 2.3
40
+ gemfile: gemfiles/activerecord_6.1.gemfile
41
+ - ruby: 2.4
42
+ gemfile: gemfiles/activerecord_6.0.gemfile
43
+ - ruby: 2.4
44
+ gemfile: gemfiles/activerecord_6.1.gemfile
45
+ # Exclude ActiveRecord 5.x for Ruby >= 3.0
46
+ - ruby: 3.0
47
+ gemfile: gemfiles/activerecord_5.0.gemfile
48
+ - ruby: 3.0
49
+ gemfile: gemfiles/activerecord_5.1.gemfile
50
+ - ruby: 3.0
51
+ gemfile: gemfiles/activerecord_5.2.gemfile
52
+ - ruby: head
53
+ gemfile: gemfiles/activerecord_5.0.gemfile
54
+ - ruby: head
55
+ gemfile: gemfiles/activerecord_5.1.gemfile
56
+ - ruby: head
57
+ gemfile: gemfiles/activerecord_5.2.gemfile
58
+
59
+ services:
60
+ postgres:
61
+ image: postgres:10
62
+ env:
63
+ POSTGRES_USER: postgres
64
+ POSTGRES_DB: acts_as_taggable_on
65
+ POSTGRES_PASSWORD: postgres
66
+ ports: ['5432:5432']
67
+ options: >-
68
+ --health-cmd pg_isready
69
+ --health-interval 10s
70
+ --health-timeout 5s
71
+ --health-retries 5
72
+ mysql:
73
+ image: mysql:8
74
+ env:
75
+ MYSQL_ALLOW_EMPTY_PASSWORD: true
76
+ ports: ['3306:3306']
77
+ options: >-
78
+ --health-cmd "mysqladmin ping"
79
+ --health-interval 10s
80
+ --health-timeout 5s
81
+ --health-retries 5
82
+ steps:
83
+ - uses: actions/checkout@v2
84
+ - name: Set up Ruby
85
+ uses: ruby/setup-ruby@v1
86
+ with:
87
+ ruby-version: ${{ matrix.ruby }}
88
+ bundler-cache: true
89
+ - name: Create MySQL test database with utf8mb4 charset
90
+ if: ${{ matrix.db == 'mysql' }}
91
+ run: |
92
+ mysql -uroot --host=127.0.0.1 -e "CREATE DATABASE acts_as_taggable_on CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"
93
+ - name: Build and test with Rake
94
+ run: |
95
+ bundle exec rake
data/Appraisals CHANGED
@@ -11,5 +11,9 @@ appraise 'activerecord-5.0' do
11
11
  end
12
12
 
13
13
  appraise 'activerecord-6.0' do
14
- gem 'activerecord', "~> 6.0.0.beta1"
14
+ gem 'activerecord', "~> 6.0.0"
15
+ end
16
+
17
+ appraise 'activerecord-6.1' do
18
+ gem 'activerecord', "~> 6.1.0"
15
19
  end
data/CHANGELOG.md CHANGED
@@ -10,19 +10,39 @@ Each change should fall into categories that would affect whether the release is
10
10
 
11
11
  As such, _Breaking Changes_ are major. _Features_ would map to either major or minor. _Fixes_, _Performance_, and _Misc_ are either minor or patch, the difference being kind of fuzzy for the purposes of history. Adding _Documentation_ (including tests) would be patch level.
12
12
 
13
- ### [Master / Unreleased](https://github.com/mbleigh/acts-as-taggable-on/compare/v6.0.1...master)
13
+ ### [v8.1.0) / 2021-06-19](https://github.com/mbleigh/acts-as-taggable-on/compare/v8.0.0...v8.1.0)
14
+ * Fixes
15
+ * [@ngouy Fix rollbackable tenant migrations](https://github.com/mbleigh/acts-as-taggable-on/pull/1038)
16
+ * [@ngouy Fix gem conflict with already existing tenant model](https://github.com/mbleigh/acts-as-taggable-on/pull/1037)
17
+
18
+ ### [v8.0.0) / 2021-06-07](https://github.com/mbleigh/acts-as-taggable-on/compare/v7.0.0...v8.0.0)
19
+ * Features
20
+ * [@lunaru Support tenants for taggings](https://github.com/mbleigh/acts-as-taggable-on/pull/1000)
21
+ * Fixes
22
+ * [@gr-eg Use none? instead of count.zero?](https://github.com/mbleigh/acts-as-taggable-on/pull/1030)
23
+
24
+ ### [v7.0.0) / 2020-12-31](https://github.com/mbleigh/acts-as-taggable-on/compare/v6.5.0...v7.0.0)
25
+ * Features
26
+ * [@kvokka Rails 6.1 support](https://github.com/mbleigh/acts-as-taggable-on/pull/1013)
27
+ * Fixes
28
+ * [@nbulaj Add support for Ruby 2.7 and it's kwargs](https://github.com/mbleigh/acts-as-taggable-on/pull/910)
29
+ * [@Andythurlow @endorfin case sensitivity fix for tagged_with](https://github.com/mbleigh/acts-as-taggable-on/pull/965)
30
+
31
+ ### [6.5.0 / 2019-11-07](https://github.com/mbleigh/acts-as-taggable-on/compare/v6.0.0...v6.5.0)
32
+
14
33
  * Features
15
34
  * [@mizukami234 @junmoka Make table names configurable](https://github.com/mbleigh/acts-as-taggable-on/pull/910)
35
+ * [@damianlegawiec Rails 6.0.0.beta1 support](https://github.com/mbleigh/acts-as-taggable-on/pull/937)
16
36
  * Fixes
17
37
  * [@tonyta Avoid overriding user-defined columns cache methods](https://github.com/mbleigh/acts-as-taggable-on/pull/911)
38
+ * [@hengwoon tags_count only need to join on the taggable's table if using STI](https://github.com/mbleigh/acts-as-taggable-on/pull/904)
39
+ * [@bduran82 Avoid unnecessary queries when finding or creating tags](https://github.com/mbleigh/acts-as-taggable-on/pull/839)
40
+ * [@iiwo simplify relation options syntax](https://github.com/mbleigh/acts-as-taggable-on/pull/940)
18
41
  * Misc
19
42
  * [@gssbzn Remove legacy code for an empty query and replace it with ` ActiveRecord::none`](https://github.com/mbleigh/acts-as-taggable-on/pull/906)
43
+ * [@iiwo remove unneeded spec case](https://github.com/mbleigh/acts-as-taggable-on/pull/941)
20
44
  * Documentation
21
45
  * [@tonyta Cleanup CHANGELOG.md formatting and references](https://github.com/mbleigh/acts-as-taggable-on/pull/913)
22
- ### [6.0.1 / 2018-06-27](https://github.com/mbleigh/acts-as-taggable-on/compare/v6.0.0...v6.0.1)
23
-
24
- * Fixes
25
- * [@hengwoon tags_count only need to join on the taggable's table if using STI](https://github.com/mbleigh/acts-as-taggable-on/pull/904)
26
46
 
27
47
  ### [6.0.0 / 2018-06-19](https://github.com/mbleigh/acts-as-taggable-on/compare/v5.0.0...v6.0.0)
28
48
 
data/Gemfile CHANGED
@@ -7,5 +7,6 @@ group :local_development do
7
7
  gem 'guard-rspec'
8
8
  gem 'appraisal'
9
9
  gem 'rake'
10
+ gem 'sqlite3'
10
11
  gem 'byebug', platforms: [:mri]
11
12
  end
data/README.md CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  [![Join the chat at https://gitter.im/mbleigh/acts-as-taggable-on](https://badges.gitter.im/mbleigh/acts-as-taggable-on.svg)](https://gitter.im/mbleigh/acts-as-taggable-on?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
34
34
  [![Gem Version](https://badge.fury.io/rb/acts-as-taggable-on.svg)](http://badge.fury.io/rb/acts-as-taggable-on)
35
- [![Build Status](https://secure.travis-ci.org/mbleigh/acts-as-taggable-on.svg)](http://travis-ci.org/mbleigh/acts-as-taggable-on)
35
+ [![Build Status](https://github.com/mbleigh/acts-as-taggable-on/workflows/spec/badge.svg)](https://github.com/mbleigh/acts-as-taggable-on/actions)
36
36
  [![Code Climate](https://codeclimate.com/github/mbleigh/acts-as-taggable-on.svg)](https://codeclimate.com/github/mbleigh/acts-as-taggable-on)
37
37
  [![Inline docs](http://inch-ci.org/github/mbleigh/acts-as-taggable-on.svg)](http://inch-ci.org/github/mbleigh/acts-as-taggable-on)
38
38
  [![Security](https://hakiri.io/github/mbleigh/acts-as-taggable-on/master.svg)](https://hakiri.io/github/mbleigh/acts-as-taggable-on/master)
@@ -57,7 +57,7 @@ was used.
57
57
  To use it, add it to your Gemfile:
58
58
 
59
59
  ```ruby
60
- gem 'acts-as-taggable-on', '~> 6.0'
60
+ gem 'acts-as-taggable-on', '~> 7.0'
61
61
  ```
62
62
 
63
63
  and bundle:
@@ -80,6 +80,8 @@ Review the generated migrations then migrate :
80
80
  rake db:migrate
81
81
  ```
82
82
 
83
+ If you do not wish or need to support multi-tenancy, the migration for `add_tenant_to_taggings` is optional and can be discarded safely.
84
+
83
85
  #### For MySql users
84
86
  You can circumvent at any time the problem of special characters [issue 623](https://github.com/mbleigh/acts-as-taggable-on/issues/623) by setting in an initializer file:
85
87
 
@@ -103,8 +105,8 @@ Setup
103
105
 
104
106
  ```ruby
105
107
  class User < ActiveRecord::Base
106
- acts_as_taggable # Alias for acts_as_taggable_on :tags
107
- acts_as_taggable_on :skills, :interests
108
+ acts_as_taggable_on :tags
109
+ acts_as_taggable_on :skills, :interests #You can also configure multiple tag types per model
108
110
  end
109
111
 
110
112
  class UsersController < ApplicationController
@@ -390,6 +392,27 @@ def remove_owned_tag
390
392
  end
391
393
  ```
392
394
 
395
+ ### Tag Tenancy
396
+
397
+ Tags support multi-tenancy. This is useful for applications where a Tag belongs to a scoped set of models:
398
+
399
+ ```ruby
400
+ class Account < ActiveRecord::Base
401
+ has_many :photos
402
+ end
403
+
404
+ class User < ActiveRecord::Base
405
+ belongs_to :account
406
+ acts_as_taggable_on :tags
407
+ acts_as_taggable_tenant :account_id
408
+ end
409
+
410
+ @user1.tag_list = ["foo", "bar"] # these taggings will automatically have the tenant saved
411
+ @user2.tag_list = ["bar", "baz"]
412
+
413
+ ActsAsTaggableOn::Tag.for_tenant(@user1.account.id) # returns Tag models for "foo" and "bar", but not "baz"
414
+ ```
415
+
393
416
  ### Dirty objects
394
417
 
395
418
  ```ruby
@@ -530,6 +553,8 @@ Versions >= 3.x are compatible with Ruby 1.9.3+ and Rails 3 and 4.
530
553
 
531
554
  Versions >= 4.x are compatible with Ruby 2.0.0+ and Rails 4 and 5.
532
555
 
556
+ Versions >= 7.x are compatible with Ruby 2.3.7+ and Rails 5 and 6.
557
+
533
558
  For an up-to-date roadmap, see https://github.com/mbleigh/acts-as-taggable-on/milestones
534
559
 
535
560
  ## TODO
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.post_install_message = File.read('UPGRADING.md')
23
23
  end
24
24
 
25
- gem.add_runtime_dependency 'activerecord', '>= 5.0', '< 6.1'
25
+ gem.add_runtime_dependency 'activerecord', '>= 5.0', '< 6.2'
26
26
 
27
27
  gem.add_development_dependency 'rspec-rails'
28
28
  gem.add_development_dependency 'rspec-its'
@@ -0,0 +1,16 @@
1
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
2
+ class AddTenantToTaggings < ActiveRecord::Migration[4.2]; end
3
+ else
4
+ class AddTenantToTaggings < ActiveRecord::Migration; end
5
+ end
6
+ AddTenantToTaggings.class_eval do
7
+ def self.up
8
+ add_column :taggings, :tenant, :string, limit: 128
9
+ add_index :taggings, :tenant unless index_exists? :taggings, :tenant
10
+ end
11
+
12
+ def self.down
13
+ remove_index :taggings, :tenant
14
+ remove_column :taggings, :tenant
15
+ end
16
+ end
@@ -5,7 +5,7 @@ case ENV["DB"]
5
5
  when "postgresql"
6
6
  gem 'pg'
7
7
  when "mysql"
8
- gem 'mysql2', '~> 0.3'
8
+ gem 'mysql2', '~> 0.4'
9
9
  else
10
10
  gem 'sqlite3'
11
11
  end
@@ -0,0 +1,23 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+ case ENV["DB"]
7
+ when "postgresql"
8
+ gem 'pg'
9
+ when "mysql"
10
+ gem 'mysql2', '~> 0.5'
11
+ else
12
+ gem 'sqlite3'
13
+ end
14
+
15
+ group :local_development do
16
+ gem "guard"
17
+ gem "guard-rspec"
18
+ gem "appraisal"
19
+ gem "rake"
20
+ gem "byebug", platforms: [:mri]
21
+ end
22
+
23
+ gemspec path: "../"
@@ -58,7 +58,7 @@ module ActsAsTaggableOn
58
58
  def self.glue
59
59
  setting = @configuration.delimiter
60
60
  delimiter = setting.kind_of?(Array) ? setting[0] : setting
61
- delimiter.ends_with?(' ') ? delimiter : "#{delimiter} "
61
+ delimiter.end_with?(' ') ? delimiter : "#{delimiter} "
62
62
  end
63
63
 
64
64
  class Configuration
@@ -10,7 +10,7 @@ module ActsAsTaggableOn
10
10
  ### VALIDATIONS:
11
11
 
12
12
  validates_presence_of :name
13
- validates_uniqueness_of :name, if: :validates_name_uniqueness?
13
+ validates_uniqueness_of :name, if: :validates_name_uniqueness?, case_sensitive: true
14
14
  validates_length_of :name, maximum: 255
15
15
 
16
16
  # monkey patch this method if don't need name uniqueness validation
@@ -55,6 +55,12 @@ module ActsAsTaggableOn
55
55
  select("DISTINCT #{ActsAsTaggableOn.tags_table}.*")
56
56
  end
57
57
 
58
+ def self.for_tenant(tenant)
59
+ joins(:taggings).
60
+ where("#{ActsAsTaggableOn.taggings_table}.tenant = ?", tenant.to_s).
61
+ select("DISTINCT #{ActsAsTaggableOn.tags_table}.*")
62
+ end
63
+
58
64
  ### CLASS METHODS:
59
65
 
60
66
  def self.find_or_create_with_like_by_name(name)
@@ -214,6 +214,12 @@ module ActsAsTaggableOn::Taggable
214
214
  self.class.tag_types.map(&:to_s) + custom_contexts
215
215
  end
216
216
 
217
+ def taggable_tenant
218
+ if self.class.tenant_column
219
+ public_send(self.class.tenant_column)
220
+ end
221
+ end
222
+
217
223
  def reload(*args)
218
224
  self.class.tag_types.each do |context|
219
225
  instance_variable_set("@#{context.to_s.singularize}_list", nil)
@@ -272,7 +278,11 @@ module ActsAsTaggableOn::Taggable
272
278
 
273
279
  # Create new taggings:
274
280
  new_tags.each do |tag|
275
- taggings.create!(tag_id: tag.id, context: context.to_s, taggable: self)
281
+ if taggable_tenant
282
+ taggings.create!(tag_id: tag.id, context: context.to_s, taggable: self, tenant: taggable_tenant)
283
+ else
284
+ taggings.create!(tag_id: tag.id, context: context.to_s, taggable: self)
285
+ end
276
286
  end
277
287
  end
278
288
 
@@ -29,9 +29,9 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
29
29
  matches_attribute = matches_attribute.lower unless ActsAsTaggableOn.strict_case_match
30
30
 
31
31
  if options[:wild].present?
32
- matches_attribute.matches("%#{escaped_tag(tag)}%", "!")
32
+ matches_attribute.matches("%#{escaped_tag(tag)}%", "!", ActsAsTaggableOn.strict_case_match)
33
33
  else
34
- matches_attribute.matches(escaped_tag(tag), "!")
34
+ matches_attribute.matches(escaped_tag(tag), "!", ActsAsTaggableOn.strict_case_match)
35
35
  end
36
36
  end
37
37
 
@@ -40,9 +40,9 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
40
40
  matches_attribute = matches_attribute.lower unless ActsAsTaggableOn.strict_case_match
41
41
 
42
42
  if options[:wild].present?
43
- matches_attribute.matches_any(tag_list.map{|tag| "%#{escaped_tag(tag)}%"}, "!")
43
+ matches_attribute.matches_any(tag_list.map{|tag| "%#{escaped_tag(tag)}%"}, "!", ActsAsTaggableOn.strict_case_match)
44
44
  else
45
- matches_attribute.matches_any(tag_list.map{|tag| "#{escaped_tag(tag)}"}, "!")
45
+ matches_attribute.matches_any(tag_list.map{|tag| "#{escaped_tag(tag)}"}, "!", ActsAsTaggableOn.strict_case_match)
46
46
  end
47
47
  end
48
48
 
@@ -54,6 +54,23 @@ module ActsAsTaggableOn
54
54
  taggable_on(true, tag_types)
55
55
  end
56
56
 
57
+ def acts_as_taggable_tenant(tenant)
58
+ if taggable?
59
+ self.tenant_column = tenant
60
+ else
61
+ class_attribute :tenant_column
62
+ self.tenant_column = tenant
63
+ end
64
+
65
+ # each of these add context-specific methods and must be
66
+ # called on each call of taggable_on
67
+ include Core
68
+ include Collection
69
+ include Cache
70
+ include Ownership
71
+ include Related
72
+ end
73
+
57
74
  private
58
75
 
59
76
  # Make a model taggable on specified contexts
@@ -78,6 +95,7 @@ module ActsAsTaggableOn
78
95
  self.tag_types = tag_types
79
96
  class_attribute :preserve_tag_order
80
97
  self.preserve_tag_order = preserve_tag_order
98
+ class_attribute :tenant_column
81
99
 
82
100
  class_eval do
83
101
  has_many :taggings, as: :taggable, dependent: :destroy, class_name: '::ActsAsTaggableOn::Tagging'
@@ -18,7 +18,7 @@ module ActsAsTaggableOn
18
18
  owned_taggings_scope = opts.delete(:scope)
19
19
 
20
20
  has_many :owned_taggings, owned_taggings_scope,
21
- opts.merge(
21
+ **opts.merge(
22
22
  as: :tagger,
23
23
  class_name: '::ActsAsTaggableOn::Tagging',
24
24
  dependent: :destroy
@@ -6,7 +6,7 @@ module ActsAsTaggableOn
6
6
  belongs_to :tag, class_name: '::ActsAsTaggableOn::Tag', counter_cache: ActsAsTaggableOn.tags_counter
7
7
  belongs_to :taggable, polymorphic: true
8
8
 
9
- belongs_to :tagger, { polymorphic: true, optional: true }
9
+ belongs_to :tagger, polymorphic: true, optional: true
10
10
 
11
11
  scope :owned_by, ->(owner) { where(tagger: owner) }
12
12
  scope :not_owned, -> { where(tagger_id: nil, tagger_type: nil) }
@@ -14,6 +14,8 @@ module ActsAsTaggableOn
14
14
  scope :by_contexts, ->(contexts) { where(context: (contexts || DEFAULT_CONTEXT)) }
15
15
  scope :by_context, ->(context = DEFAULT_CONTEXT) { by_contexts(context.to_s) }
16
16
 
17
+ scope :by_tenant, ->(tenant) { where(tenant: tenant) }
18
+
17
19
  validates_presence_of :context
18
20
  validates_presence_of :tag_id
19
21
 
@@ -28,7 +30,7 @@ module ActsAsTaggableOn
28
30
  if ActsAsTaggableOn.tags_counter
29
31
  tag.destroy if tag.reload.taggings_count.zero?
30
32
  else
31
- tag.destroy if tag.reload.taggings.count.zero?
33
+ tag.destroy if tag.reload.taggings.none?
32
34
  end
33
35
  end
34
36
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsTaggableOn
2
- VERSION = '6.5.0'
2
+ VERSION = '8.1.0'
3
3
  end
@@ -14,7 +14,7 @@ end
14
14
  describe ActsAsTaggableOn::Tag do
15
15
  before(:each) do
16
16
  @tag = ActsAsTaggableOn::Tag.new
17
- @user = TaggableModel.create(name: 'Pablo')
17
+ @user = TaggableModel.create(name: 'Pablo', tenant_id: 100)
18
18
  end
19
19
 
20
20
 
@@ -70,6 +70,21 @@ describe ActsAsTaggableOn::Tag do
70
70
  end
71
71
  end
72
72
 
73
+ describe 'for tenant' do
74
+ before(:each) do
75
+ @user.skill_list.add('ruby')
76
+ @user.save
77
+ end
78
+
79
+ it 'should return tags for the tenant' do
80
+ expect(ActsAsTaggableOn::Tag.for_tenant('100').pluck(:name)).to include('ruby')
81
+ end
82
+
83
+ it 'should not return tags for other tenants' do
84
+ expect(ActsAsTaggableOn::Tag.for_tenant('200').pluck(:name)).to_not include('ruby')
85
+ end
86
+ end
87
+
73
88
  describe 'find or create by name' do
74
89
  before(:each) do
75
90
  @tag.name = 'awesome'
@@ -109,6 +109,10 @@ describe 'Taggable' do
109
109
  expect(@taggable.tag_types).to eq(TaggableModel.tag_types)
110
110
  end
111
111
 
112
+ it 'should have tenant column' do
113
+ expect(TaggableModel.tenant_column).to eq(:tenant_id)
114
+ end
115
+
112
116
  it 'should have tag_counts_on' do
113
117
  expect(TaggableModel.tag_counts_on(:tags)).to be_empty
114
118
 
@@ -477,7 +481,7 @@ describe 'Taggable' do
477
481
 
478
482
  expect(TaggableModel.tagged_with(%w(bob tricia), wild: true, any: true).to_a.sort_by { |o| o.id }).to eq([bob, frank, steve])
479
483
  expect(TaggableModel.tagged_with(%w(bob tricia), wild: true, exclude: true).to_a).to eq([jim])
480
- expect(TaggableModel.tagged_with('ji', wild: true, any: true).to_a =~ [frank, jim])
484
+ expect(TaggableModel.tagged_with('ji', wild: true, any: true).to_a).to match_array([frank, jim])
481
485
  end
482
486
  end
483
487
 
@@ -676,11 +680,11 @@ describe 'Taggable' do
676
680
  end
677
681
 
678
682
  it 'should return all column names joined for TaggableModel GROUP clause' do
679
- expect(@taggable.grouped_column_names_for(TaggableModel)).to eq('taggable_models.id, taggable_models.name, taggable_models.type')
683
+ expect(@taggable.grouped_column_names_for(TaggableModel)).to eq('taggable_models.id, taggable_models.name, taggable_models.type, taggable_models.tenant_id')
680
684
  end
681
685
 
682
686
  it 'should return all column names joined for NonStandardIdTaggableModel GROUP clause' do
683
- expect(@taggable.grouped_column_names_for(TaggableModel)).to eq("taggable_models.#{TaggableModel.primary_key}, taggable_models.name, taggable_models.type")
687
+ expect(@taggable.grouped_column_names_for(TaggableModel)).to eq("taggable_models.#{TaggableModel.primary_key}, taggable_models.name, taggable_models.type, taggable_models.tenant_id")
684
688
  end
685
689
  end
686
690
 
@@ -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|
@@ -10,7 +10,7 @@ if File.exist?(database_yml)
10
10
  ActiveRecord::Base.configurations = YAML.load_file(database_yml)
11
11
  ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), '../debug.log'))
12
12
  ActiveRecord::Base.logger.level = ENV['TRAVIS'] ? ::Logger::ERROR : ::Logger::DEBUG
13
- config = ActiveRecord::Base.configurations[db_name]
13
+ config = ActiveSupport::HashWithIndifferentAccess.new(ActiveRecord::Base.configurations[db_name])
14
14
 
15
15
  begin
16
16
  ActiveRecord::Base.establish_connection(db_name.to_sym)
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: 6.5.0
4
+ version: 8.1.0
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: 2019-11-07 00:00:00.000000000 Z
12
+ date: 2021-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '5.0'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '6.1'
23
+ version: '6.2'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '5.0'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.1'
33
+ version: '6.2'
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,10 +128,12 @@ 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
131
+ - db/migrate/7_add_tenant_to_taggings.rb
132
132
  - gemfiles/activerecord_5.0.gemfile
133
133
  - gemfiles/activerecord_5.1.gemfile
134
134
  - gemfiles/activerecord_5.2.gemfile
135
135
  - gemfiles/activerecord_6.0.gemfile
136
+ - gemfiles/activerecord_6.1.gemfile
136
137
  - lib/acts-as-taggable-on.rb
137
138
  - lib/acts_as_taggable_on.rb
138
139
  - lib/acts_as_taggable_on/default_parser.rb
@@ -199,15 +200,7 @@ homepage: https://github.com/mbleigh/acts-as-taggable-on
199
200
  licenses:
200
201
  - MIT
201
202
  metadata: {}
202
- post_install_message: |-
203
- When upgrading
204
-
205
- Re-run the migrations generator
206
-
207
- rake acts_as_taggable_on_engine:install:migrations
208
-
209
- This will create any new migrations and skip existing ones
210
- Version 3.5.0 has a migration for mysql adapter
203
+ post_install_message:
211
204
  rdoc_options: []
212
205
  require_paths:
213
206
  - lib
data/.travis.yml DELETED
@@ -1,43 +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.6.5
13
- - 2.5.5
14
- - 2.4.6
15
- - 2.3.7
16
-
17
- env:
18
- - DB=sqlite3
19
- - DB=mysql
20
- - DB=postgresql
21
-
22
- gemfile:
23
- - gemfiles/activerecord_5.2.gemfile
24
- - gemfiles/activerecord_5.1.gemfile
25
- - gemfiles/activerecord_5.0.gemfile
26
- - gemfiles/activerecord_6.0.gemfile
27
-
28
- bundler_args: '--without local_development --jobs 3 --retry 3'
29
-
30
- before_install:
31
- - gem install bundler
32
-
33
- script: bundle exec rake
34
-
35
- matrix:
36
- allow_failures:
37
- - rvm: ruby-head
38
- fast_finish: true
39
- exclude:
40
- - rvm: 2.3.7
41
- gemfile: gemfiles/activerecord_6.0.gemfile
42
- - rvm: 2.4.6
43
- gemfile: gemfiles/activerecord_6.0.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