acts-as-taggable-on 4.0.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/spec.yml +95 -0
  3. data/.gitignore +1 -1
  4. data/Appraisals +12 -10
  5. data/CHANGELOG.md +206 -71
  6. data/CONTRIBUTING.md +13 -0
  7. data/Gemfile +1 -1
  8. data/README.md +79 -13
  9. data/acts-as-taggable-on.gemspec +2 -6
  10. data/db/migrate/1_acts_as_taggable_on_migration.rb +14 -8
  11. data/db/migrate/2_add_missing_unique_indices.rb +14 -9
  12. data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +9 -4
  13. data/db/migrate/4_add_missing_taggable_index.rb +8 -3
  14. data/db/migrate/5_change_collation_for_tag_names.rb +7 -2
  15. data/db/migrate/6_add_missing_indexes_on_taggings.rb +22 -0
  16. data/db/migrate/7_add_tenant_to_taggings.rb +16 -0
  17. data/gemfiles/activerecord_5.0.gemfile +11 -5
  18. data/gemfiles/activerecord_5.1.gemfile +21 -0
  19. data/gemfiles/activerecord_5.2.gemfile +21 -0
  20. data/gemfiles/activerecord_6.0.gemfile +21 -0
  21. data/gemfiles/activerecord_6.1.gemfile +23 -0
  22. data/lib/acts-as-taggable-on.rb +6 -2
  23. data/lib/acts_as_taggable_on/tag.rb +23 -23
  24. data/lib/acts_as_taggable_on/tag_list.rb +1 -0
  25. data/lib/acts_as_taggable_on/taggable.rb +18 -1
  26. data/lib/acts_as_taggable_on/taggable/cache.rb +38 -34
  27. data/lib/acts_as_taggable_on/taggable/collection.rb +9 -7
  28. data/lib/acts_as_taggable_on/taggable/core.rb +49 -179
  29. data/lib/acts_as_taggable_on/taggable/ownership.rb +16 -5
  30. data/lib/acts_as_taggable_on/taggable/related.rb +1 -1
  31. data/lib/acts_as_taggable_on/taggable/tag_list_type.rb +4 -0
  32. data/lib/acts_as_taggable_on/taggable/tagged_with_query.rb +16 -0
  33. data/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb +111 -0
  34. data/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb +70 -0
  35. data/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb +82 -0
  36. data/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb +61 -0
  37. data/lib/acts_as_taggable_on/tagger.rb +3 -3
  38. data/lib/acts_as_taggable_on/tagging.rb +9 -4
  39. data/lib/acts_as_taggable_on/utils.rb +4 -4
  40. data/lib/acts_as_taggable_on/version.rb +1 -2
  41. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +4 -12
  42. data/spec/acts_as_taggable_on/caching_spec.rb +34 -10
  43. data/spec/acts_as_taggable_on/{taggable/dirty_spec.rb → dirty_spec.rb} +28 -13
  44. data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +28 -8
  45. data/spec/acts_as_taggable_on/tag_spec.rb +16 -1
  46. data/spec/acts_as_taggable_on/taggable_spec.rb +22 -15
  47. data/spec/acts_as_taggable_on/tagger_spec.rb +2 -2
  48. data/spec/acts_as_taggable_on/tagging_spec.rb +26 -0
  49. data/spec/internal/app/models/altered_inheriting_taggable_model.rb +2 -0
  50. data/spec/internal/app/models/cached_model_with_array.rb +6 -0
  51. data/spec/internal/app/models/columns_override_model.rb +5 -0
  52. data/spec/internal/app/models/company.rb +1 -1
  53. data/spec/internal/app/models/inheriting_taggable_model.rb +2 -0
  54. data/spec/internal/app/models/market.rb +1 -1
  55. data/spec/internal/app/models/non_standard_id_taggable_model.rb +1 -1
  56. data/spec/internal/app/models/student.rb +2 -0
  57. data/spec/internal/app/models/taggable_model.rb +3 -0
  58. data/spec/internal/app/models/user.rb +1 -1
  59. data/spec/internal/config/database.yml.sample +4 -8
  60. data/spec/internal/db/schema.rb +17 -5
  61. data/spec/spec_helper.rb +0 -1
  62. data/spec/support/database.rb +4 -4
  63. metadata +29 -68
  64. data/.travis.yml +0 -36
  65. data/UPGRADING.md +0 -8
  66. data/db/migrate/6_add_missing_indexes.rb +0 -12
  67. data/gemfiles/activerecord_4.0.gemfile +0 -16
  68. data/gemfiles/activerecord_4.1.gemfile +0 -16
  69. data/gemfiles/activerecord_4.2.gemfile +0 -15
  70. data/lib/acts_as_taggable_on/taggable/dirty.rb +0 -36
  71. data/spec/internal/app/models/models.rb +0 -90
data/CONTRIBUTING.md CHANGED
@@ -1,3 +1,16 @@
1
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
+ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4
+
5
+ - [How to contribute:](#how-to-contribute)
6
+ - [Bug reports / Issues](#bug-reports--issues)
7
+ - [Code](#code)
8
+ - [Commit Messages](#commit-messages)
9
+ - [About Pull Requests (PR's)](#about-pull-requests-prs)
10
+ - [Documentation](#documentation)
11
+
12
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
13
+
1
14
  # How to contribute:
2
15
 
3
16
  ## Bug reports / Issues
data/Gemfile CHANGED
@@ -7,5 +7,5 @@ group :local_development do
7
7
  gem 'guard-rspec'
8
8
  gem 'appraisal'
9
9
  gem 'rake'
10
- gem 'byebug' , platforms: [:mri_21, :mri_22, :mri_23]
10
+ gem 'byebug', platforms: [:mri]
11
11
  end
data/README.md CHANGED
@@ -1,10 +1,41 @@
1
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
+ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4
+
5
+ - [ActsAsTaggableOn](#actsastaggableon)
6
+ - [Installation](#installation)
7
+ - [Post Installation](#post-installation)
8
+ - [For MySql users](#for-mysql-users)
9
+ - [Usage](#usage)
10
+ - [Finding most or least used tags](#finding-most-or-least-used-tags)
11
+ - [Finding Tagged Objects](#finding-tagged-objects)
12
+ - [Relationships](#relationships)
13
+ - [Dynamic Tag Contexts](#dynamic-tag-contexts)
14
+ - [Tag Parsers](#tag-parsers)
15
+ - [Tag Ownership](#tag-ownership)
16
+ - [Working with Owned Tags](#working-with-owned-tags)
17
+ - [Adding owned tags](#adding-owned-tags)
18
+ - [Removing owned tags](#removing-owned-tags)
19
+ - [Dirty objects](#dirty-objects)
20
+ - [Tag cloud calculations](#tag-cloud-calculations)
21
+ - [Configuration](#configuration)
22
+ - [Upgrading](#upgrading)
23
+ - [Contributors](#contributors)
24
+ - [Compatibility](#compatibility)
25
+ - [TODO](#todo)
26
+ - [Testing](#testing)
27
+ - [License](#license)
28
+
29
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
30
+
1
31
  # ActsAsTaggableOn
2
32
 
3
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)
4
34
  [![Gem Version](https://badge.fury.io/rb/acts-as-taggable-on.svg)](http://badge.fury.io/rb/acts-as-taggable-on)
5
- [![Build Status](https://secure.travis-ci.org/mbleigh/acts-as-taggable-on.png)](http://travis-ci.org/mbleigh/acts-as-taggable-on)
6
- [![Code Climate](https://codeclimate.com/github/mbleigh/acts-as-taggable-on.png)](https://codeclimate.com/github/mbleigh/acts-as-taggable-on)
7
- [![Inline docs](http://inch-ci.org/github/mbleigh/acts-as-taggable-on.png)](http://inch-ci.org/github/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
+ [![Code Climate](https://codeclimate.com/github/mbleigh/acts-as-taggable-on.svg)](https://codeclimate.com/github/mbleigh/acts-as-taggable-on)
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
+ [![Security](https://hakiri.io/github/mbleigh/acts-as-taggable-on/master.svg)](https://hakiri.io/github/mbleigh/acts-as-taggable-on/master)
8
39
 
9
40
  This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney.
10
41
  It has evolved substantially since that point, but all credit goes to him for the
@@ -26,7 +57,7 @@ was used.
26
57
  To use it, add it to your Gemfile:
27
58
 
28
59
  ```ruby
29
- gem 'acts-as-taggable-on', '~> 4.0'
60
+ gem 'acts-as-taggable-on', '~> 7.0'
30
61
  ```
31
62
 
32
63
  and bundle:
@@ -49,6 +80,8 @@ Review the generated migrations then migrate :
49
80
  rake db:migrate
50
81
  ```
51
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
+
52
85
  #### For MySql users
53
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:
54
87
 
@@ -72,8 +105,8 @@ Setup
72
105
 
73
106
  ```ruby
74
107
  class User < ActiveRecord::Base
75
- acts_as_taggable # Alias for acts_as_taggable_on :tags
76
- 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
77
110
  end
78
111
 
79
112
  class UsersController < ApplicationController
@@ -90,6 +123,7 @@ Add and remove a single tag
90
123
  ```ruby
91
124
  @user.tag_list.add("awesome") # add a single tag. alias for <<
92
125
  @user.tag_list.remove("awesome") # remove a single tag
126
+ @user.save # save to persist tag_list
93
127
  ```
94
128
 
95
129
  Add and remove multiple tags in an array
@@ -97,6 +131,7 @@ Add and remove multiple tags in an array
97
131
  ```ruby
98
132
  @user.tag_list.add("awesome", "slick")
99
133
  @user.tag_list.remove("awesome", "slick")
134
+ @user.save
100
135
  ```
101
136
 
102
137
  You can also add and remove tags in format of String. This would
@@ -207,12 +242,13 @@ User.tagged_with("awesome").by_join_date
207
242
  User.tagged_with("awesome").by_join_date.paginate(:page => params[:page], :per_page => 20)
208
243
 
209
244
  # Find users that matches all given tags:
245
+ # NOTE: This only matches users that have the exact set of specified tags. If a user has additional tags, they are not returned.
210
246
  User.tagged_with(["awesome", "cool"], :match_all => true)
211
247
 
212
248
  # Find users with any of the specified tags:
213
249
  User.tagged_with(["awesome", "cool"], :any => true)
214
250
 
215
- # Find users that has not been tagged with awesome or cool:
251
+ # Find users that have not been tagged with awesome or cool:
216
252
  User.tagged_with(["awesome", "cool"], :exclude => true)
217
253
 
218
254
  # Find users with any of the tags based on context:
@@ -332,12 +368,12 @@ Note that **owned tags** are added all at once, in the form of ***comma seperate
332
368
  Also, when you try to add **owned tags** again, it simply overwrites the previous set of **owned tags**.
333
369
  So to append tags in previously existing **owned tags** list, go as follows:
334
370
  ```ruby
335
- def add_owned_tag
371
+ def add_owned_tag
336
372
  @some_item = Item.find(params[:id])
337
- owned_tag_list = @some_item.all_tag_list - @some_item.tag_list
373
+ owned_tag_list = @some_item.all_tags_list - @some_item.tag_list
338
374
  owned_tag_list += [(params[:tag])]
339
375
  @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
340
- @some_item.save
376
+ @some_item.save
341
377
  end
342
378
 
343
379
  def stringify(tag_list)
@@ -347,15 +383,36 @@ end
347
383
  ##### Removing owned tags
348
384
  Similarly as above, removing will be as follows:
349
385
  ```ruby
350
- def remove_owned_tag
386
+ def remove_owned_tag
351
387
  @some_item = Item.find(params[:id])
352
- owned_tag_list = @some_item.all_tag_list - @some_item.tag_list
388
+ owned_tag_list = @some_item.all_tags_list - @some_item.tag_list
353
389
  owned_tag_list -= [(params[:tag])]
354
390
  @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
355
- @some_item.save
391
+ @some_item.save
356
392
  end
357
393
  ```
358
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
+
359
416
  ### Dirty objects
360
417
 
361
418
  ```ruby
@@ -454,6 +511,13 @@ If you would like to have an exact match covering special characters with MySql:
454
511
  ActsAsTaggableOn.force_binary_collation = true
455
512
  ```
456
513
 
514
+ If you would like to specify table names:
515
+
516
+ ```ruby
517
+ ActsAsTaggableOn.tags_table = 'aato_tags'
518
+ ActsAsTaggableOn.taggings_table = 'aato_taggings'
519
+ ```
520
+
457
521
  If you want to change the default delimiter (it defaults to ','). You can also pass in an array of delimiters such as ([',', '|']):
458
522
 
459
523
  ```ruby
@@ -489,6 +553,8 @@ Versions >= 3.x are compatible with Ruby 1.9.3+ and Rails 3 and 4.
489
553
 
490
554
  Versions >= 4.x are compatible with Ruby 2.0.0+ and Rails 4 and 5.
491
555
 
556
+ Versions >= 7.x are compatible with Ruby 2.3.7+ and Rails 5 and 6.
557
+
492
558
  For an up-to-date roadmap, see https://github.com/mbleigh/acts-as-taggable-on/milestones
493
559
 
494
560
  ## TODO
@@ -16,17 +16,13 @@ Gem::Specification.new do |gem|
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.test_files = gem.files.grep(%r{^spec/})
18
18
  gem.require_paths = ['lib']
19
- gem.required_ruby_version = '>= 2.0.0'
19
+ gem.required_ruby_version = '>= 2.3.7'
20
20
 
21
21
  if File.exist?('UPGRADING.md')
22
22
  gem.post_install_message = File.read('UPGRADING.md')
23
23
  end
24
24
 
25
- gem.add_runtime_dependency 'activerecord', ['>= 4.0']
26
-
27
- gem.add_development_dependency 'sqlite3'
28
- gem.add_development_dependency 'mysql2', '~> 0.3'
29
- gem.add_development_dependency 'pg'
25
+ gem.add_runtime_dependency 'activerecord', '>= 5.0', '< 6.2'
30
26
 
31
27
  gem.add_development_dependency 'rspec-rails'
32
28
  gem.add_development_dependency 'rspec-its'
@@ -1,11 +1,17 @@
1
- class ActsAsTaggableOnMigration < ActiveRecord::Migration
1
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
2
+ class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end
3
+ else
4
+ class ActsAsTaggableOnMigration < ActiveRecord::Migration; end
5
+ end
6
+ ActsAsTaggableOnMigration.class_eval do
2
7
  def self.up
3
- create_table :tags do |t|
8
+ create_table ActsAsTaggableOn.tags_table do |t|
4
9
  t.string :name
10
+ t.timestamps
5
11
  end
6
12
 
7
- create_table :taggings do |t|
8
- t.references :tag
13
+ create_table ActsAsTaggableOn.taggings_table do |t|
14
+ t.references :tag, foreign_key: { to_table: ActsAsTaggableOn.tags_table }
9
15
 
10
16
  # You should make sure that the column created is
11
17
  # long enough to store the required class names.
@@ -19,12 +25,12 @@ class ActsAsTaggableOnMigration < ActiveRecord::Migration
19
25
  t.datetime :created_at
20
26
  end
21
27
 
22
- add_index :taggings, :tag_id
23
- add_index :taggings, [:taggable_id, :taggable_type, :context]
28
+ add_index ActsAsTaggableOn.taggings_table, :tag_id
29
+ add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx'
24
30
  end
25
31
 
26
32
  def self.down
27
- drop_table :taggings
28
- drop_table :tags
33
+ drop_table ActsAsTaggableOn.taggings_table
34
+ drop_table ActsAsTaggableOn.tags_table
29
35
  end
30
36
  end
@@ -1,20 +1,25 @@
1
- class AddMissingUniqueIndices < ActiveRecord::Migration
1
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
2
+ class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end
3
+ else
4
+ class AddMissingUniqueIndices < ActiveRecord::Migration; end
5
+ end
6
+ AddMissingUniqueIndices.class_eval do
2
7
  def self.up
3
- add_index :tags, :name, unique: true
8
+ add_index ActsAsTaggableOn.tags_table, :name, unique: true
4
9
 
5
- remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id)
6
- remove_index :taggings, [:taggable_id, :taggable_type, :context]
7
- add_index :taggings,
10
+ remove_index ActsAsTaggableOn.taggings_table, :tag_id if index_exists?(ActsAsTaggableOn.taggings_table, :tag_id)
11
+ remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx'
12
+ add_index ActsAsTaggableOn.taggings_table,
8
13
  [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
9
14
  unique: true, name: 'taggings_idx'
10
15
  end
11
16
 
12
17
  def self.down
13
- remove_index :tags, :name
18
+ remove_index ActsAsTaggableOn.tags_table, :name
14
19
 
15
- remove_index :taggings, name: 'taggings_idx'
20
+ remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_idx'
16
21
 
17
- add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)
18
- add_index :taggings, [:taggable_id, :taggable_type, :context]
22
+ add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists?(ActsAsTaggableOn.taggings_table, :tag_id)
23
+ add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx'
19
24
  end
20
25
  end
@@ -1,14 +1,19 @@
1
- class AddTaggingsCounterCacheToTags < ActiveRecord::Migration
1
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
2
+ class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end
3
+ else
4
+ class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end
5
+ end
6
+ AddTaggingsCounterCacheToTags.class_eval do
2
7
  def self.up
3
- add_column :tags, :taggings_count, :integer, default: 0
8
+ add_column ActsAsTaggableOn.tags_table, :taggings_count, :integer, default: 0
4
9
 
5
10
  ActsAsTaggableOn::Tag.reset_column_information
6
11
  ActsAsTaggableOn::Tag.find_each do |tag|
7
- ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
12
+ ActsAsTaggableOn::Tag.reset_counters(tag.id, ActsAsTaggableOn.taggings_table)
8
13
  end
9
14
  end
10
15
 
11
16
  def self.down
12
- remove_column :tags, :taggings_count
17
+ remove_column ActsAsTaggableOn.tags_table, :taggings_count
13
18
  end
14
19
  end
@@ -1,9 +1,14 @@
1
- class AddMissingTaggableIndex < ActiveRecord::Migration
1
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
2
+ class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end
3
+ else
4
+ class AddMissingTaggableIndex < ActiveRecord::Migration; end
5
+ end
6
+ AddMissingTaggableIndex.class_eval do
2
7
  def self.up
3
- add_index :taggings, [:taggable_id, :taggable_type, :context]
8
+ add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx'
4
9
  end
5
10
 
6
11
  def self.down
7
- remove_index :taggings, [:taggable_id, :taggable_type, :context]
12
+ remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx'
8
13
  end
9
14
  end
@@ -1,9 +1,14 @@
1
1
  # This migration is added to circumvent issue #623 and have special characters
2
2
  # work properly
3
- class ChangeCollationForTagNames < ActiveRecord::Migration
3
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
4
+ class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end
5
+ else
6
+ class ChangeCollationForTagNames < ActiveRecord::Migration; end
7
+ end
8
+ ChangeCollationForTagNames.class_eval do
4
9
  def up
5
10
  if ActsAsTaggableOn::Utils.using_mysql?
6
- execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
11
+ execute("ALTER TABLE #{ActsAsTaggableOn.tags_table} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
7
12
  end
8
13
  end
9
14
  end
@@ -0,0 +1,22 @@
1
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
2
+ class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end
3
+ else
4
+ class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end
5
+ end
6
+ AddMissingIndexesOnTaggings.class_eval do
7
+ def change
8
+ add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id
9
+ add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_id
10
+ add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_type
11
+ add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, :tagger_id
12
+ add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context
13
+
14
+ unless index_exists? ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type]
15
+ add_index ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type]
16
+ end
17
+
18
+ unless index_exists? ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
19
+ add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
20
+ end
21
+ end
22
+ end
@@ -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_column :taggings, :tenant
14
+ remove_index :taggings, :tenant
15
+ end
16
+ end
@@ -1,15 +1,21 @@
1
- # This file was generated by Appraisal
2
-
3
1
  source "https://rubygems.org"
4
2
 
5
- gem "activerecord", "~> 5.0.0"
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
6
12
 
7
13
  group :local_development do
8
14
  gem "guard"
9
15
  gem "guard-rspec"
10
16
  gem "appraisal"
11
17
  gem "rake"
12
- gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
18
+ gem "byebug", platforms: [:mri]
13
19
  end
14
20
 
15
- gemspec :path => "../"
21
+ gemspec path: "../"
@@ -0,0 +1,21 @@
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: "../"