acts-as-taggable-on 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -11
  3. data/Appraisals +7 -13
  4. data/CHANGELOG.md +82 -0
  5. data/CONTRIBUTING.md +13 -0
  6. data/Gemfile +1 -1
  7. data/README.md +42 -10
  8. data/acts-as-taggable-on.gemspec +2 -2
  9. data/db/migrate/1_acts_as_taggable_on_migration.rb +6 -1
  10. data/db/migrate/2_add_missing_unique_indices.rb +6 -1
  11. data/db/migrate/3_add_taggings_counter_cache_to_tags.rb +6 -1
  12. data/db/migrate/4_add_missing_taggable_index.rb +6 -1
  13. data/db/migrate/5_change_collation_for_tag_names.rb +6 -1
  14. data/db/migrate/6_add_missing_indexes_on_taggings.rb +22 -0
  15. data/gemfiles/activerecord_4.2.gemfile +3 -3
  16. data/gemfiles/activerecord_5.0.gemfile +3 -3
  17. data/gemfiles/{activerecord_4.0.gemfile → activerecord_5.1.gemfile} +3 -4
  18. data/lib/acts_as_taggable_on/tag.rb +10 -7
  19. data/lib/acts_as_taggable_on/tag_list.rb +1 -0
  20. data/lib/acts_as_taggable_on/taggable/core.rb +10 -157
  21. data/lib/acts_as_taggable_on/taggable/ownership.rb +16 -5
  22. data/lib/acts_as_taggable_on/taggable/tagged_with_query.rb +16 -0
  23. data/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb +113 -0
  24. data/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb +75 -0
  25. data/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb +82 -0
  26. data/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb +61 -0
  27. data/lib/acts_as_taggable_on/tagger.rb +2 -2
  28. data/lib/acts_as_taggable_on/tagging.rb +3 -2
  29. data/lib/acts_as_taggable_on/version.rb +1 -1
  30. data/spec/acts_as_taggable_on/caching_spec.rb +18 -0
  31. data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +16 -1
  32. data/spec/acts_as_taggable_on/taggable_spec.rb +1 -1
  33. data/spec/internal/db/schema.rb +3 -0
  34. metadata +13 -9
  35. data/db/migrate/6_add_missing_indexes.rb +0 -12
  36. data/gemfiles/activerecord_4.1.gemfile +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ab1dc9bc4d03cd7fb2396284190f76719bc4a40
4
- data.tar.gz: 8bbb5a13b5a1cc54aea59cb1ab6e524c31ea530c
3
+ metadata.gz: f768ffeb2be31c4e8e131a9b89f796a325aba09f
4
+ data.tar.gz: d4528a4f594547d31f508300b8188b17fe507295
5
5
  SHA512:
6
- metadata.gz: 901d4fb2dd642138c9d8b918d49eee90a86a0ea78596c37753197583b8c4068c08068077e8917bacc0b43ff0272613002aab6670a437ef9ac98a90910f11e522
7
- data.tar.gz: 6c0f2e8dc6157b6ea854f63456c4eaa9fc0c754d46dd419ad0a184dd76eb69c3f7486591dfe156d3a224918fcd8d81a13a90661503e216ff21730d98a5d59e52
6
+ metadata.gz: 4246008aa86bb98b30fcb23787e5ddc94af40d8b677701a202ea6db8be2fe30cbab2117bc8b4eb2e2803f02605e392d5bd271ce77155a45d631f9ae6a3f83451
7
+ data.tar.gz: 6df3714193f6004ff5d69e4bd54f54b866804dcfcb6b6d08721302c22f7da442005b19200a43628b0e5e734dcbf3a5e892435fcda2652c24ea62635c3bff5d4b
@@ -2,10 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
 
4
4
  rvm:
5
- - 2.3.1
6
- - 2.2.5
7
- - 2.1
8
- - 2.0.0
5
+ - 2.4.1
6
+ - 2.3.3
7
+ - 2.2.7
9
8
 
10
9
  env:
11
10
  - DB=sqlite3
@@ -13,10 +12,9 @@ env:
13
12
  - DB=postgresql
14
13
 
15
14
  gemfile:
15
+ - gemfiles/activerecord_5.1.gemfile
16
16
  - gemfiles/activerecord_5.0.gemfile
17
17
  - gemfiles/activerecord_4.2.gemfile
18
- - gemfiles/activerecord_4.1.gemfile
19
- - gemfiles/activerecord_4.0.gemfile
20
18
 
21
19
  sudo: false
22
20
 
@@ -28,9 +26,4 @@ before_install:
28
26
  script: bundle exec rake
29
27
 
30
28
  matrix:
31
- exclude:
32
- - rvm: 2.0.0
33
- gemfile: gemfiles/activerecord_5.0.gemfile
34
- - rvm: 2.1
35
- gemfile: gemfiles/activerecord_5.0.gemfile
36
29
  fast_finish: true
data/Appraisals CHANGED
@@ -1,17 +1,11 @@
1
- appraise 'activerecord-5.0' do
2
- gem 'activerecord', "~> 5.0.0"
3
- end
4
-
5
- appraise "activerecord-4.2" do
6
- gem "activerecord", "~> 4.2.0"
1
+ appraise 'activerecord-5.1' do
2
+ gem 'activerecord', "~> 5.1.1"
7
3
  end
8
4
 
9
- appraise "activerecord-4.1" do
10
- gem "activerecord", "~> 4.1.0"
11
- gem 'mysql2', '~> 0.3.21'
5
+ appraise 'activerecord-5.0' do
6
+ gem 'activerecord', "~> 5.0.3"
12
7
  end
13
8
 
14
- appraise "activerecord-4.0" do
15
- gem "activerecord", "~> 4.0.0"
16
- gem 'mysql2', '~> 0.3.21'
17
- end
9
+ appraise "activerecord-4.2" do
10
+ gem "activerecord", "~> 4.2.8"
11
+ end
@@ -4,6 +4,88 @@ Each change should fall into categories that would affect whether the release is
4
4
 
5
5
  As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch. And _misc_ is either minor or patch, the difference being kind of fuzzy for the purposes of history. Adding tests would be patch level.
6
6
 
7
+ ### [5.0.0 / 2017-05-18](https://github.com/mbleigh/acts-as-taggable-on/compare/v4.0.0...v5.0.0)
8
+ * Breaking Changes
9
+ * [@seuros Drop support for old version of ActiveRecord and Ruby and prepare rel](https://github.com/mbleigh/acts-as-taggable-on/pull/828)
10
+ * Added
11
+ * [@rbritom Tagged with rewrite](https://github.com/mbleigh/acts-as-taggable-on/pull/829)
12
+ * [@fearenales Due to database collisions, retry finding or creating a tag](https://github.com/mbleigh/acts-as-taggable-on/pull/809)
13
+ * [@brilyuhns Add owner_tags method to taggable](https://github.com/mbleigh/acts-as-taggable-on/pull/771)
14
+ * [@brilyuhns upport array of contexts in owner_tags_on method](https://github.com/mbleigh/acts-as-taggable-on/pull/771)
15
+ * [@brilyuhns Add specs for owner_tags_on and owner_tags methods](https://github.com/mbleigh/acts-as-taggable-on/pull/771)
16
+ * Fixes
17
+ * [@rbritom bump ruby versions for travis](https://github.com/mbleigh/acts-as-taggable-on/pull/825)
18
+ * [@mnrk Fixed Rails 5.1 deprecation message, has_many needs String value for](https://github.com/mbleigh/acts-as-taggable-on/pull/813)
19
+ * [@ProGM ProGM Adding a test to demonstrate the bug](https://github.com/mbleigh/acts-as-taggable-on/pull/806)
20
+ * [@ProGM ProGM Ensure that `caching_tag_list_on?` is injected before using it](https://github.com/mbleigh/acts-as-taggable-on/pull/806)
21
+ * [@ProGM ProGM Fix insert query for postgresql. Move schema definition in schema.rb](https://github.com/mbleigh/acts-as-taggable-on/pull/806)
22
+ * [@amatsuda assigned but unused variable - any](https://github.com/mbleigh/acts-as-taggable-on/pull/787)
23
+ * [@gmcnaughton Fix incorrect call of 'self.class' on methods which are already class](https://github.com/mbleigh/acts-as-taggable-on/pull/782)
24
+ * [@gmcnaughton Fixed #712 (incompatibility with ActiveRecord::Sanitization#quoted_id)](https://github.com/mbleigh/acts-as-taggable-on/pull/782)
25
+ * [@arpitchauhan Guard against indexes already existing](https://github.com/mbleigh/acts-as-taggable-on/pull/779)
26
+ * [@arpitchauhan Rename migration to avoid conflicts](https://github.com/mbleigh/acts-as-taggable-on/pull/774)
27
+ * [@lukeasrodgers "Bugfix `TagList#concat` with non-duplicates."](https://github.com/mbleigh/acts-as-taggable-on/pull/729)
28
+ * [@fabn Revert "Added missed indexes."](https://github.com/mbleigh/acts-as-taggable-on/pull/709)
29
+ * Documentation
30
+ * [Corey Osman Adds a table of contents to the readme and contributing files](https://github.com/mbleigh/acts-as-taggable-on/pull/803)
31
+ * [@ashishg-qburst Fix typo in README](https://github.com/mbleigh/acts-as-taggable-on/pull/800)
32
+ * [@praveenangyan Update README.md](https://github.com/mbleigh/acts-as-taggable-on/pull/798)
33
+ * [@colemerrick update finding tagged objects in readme](https://github.com/mbleigh/acts-as-taggable-on/pull/794)
34
+ * [jaredbeck Help people upgrade to 4.0.0](https://github.com/mbleigh/acts-as-taggable-on/pull/784)
35
+ * [@vasinov Update README.md](https://github.com/mbleigh/acts-as-taggable-on/pull/776)
36
+
37
+ ### [4.0.0 / 2016-08-08](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.5.0...v4.0.0)
38
+ * Breaking Changes
39
+ * [@krzysiek1507 drop support for Ruby < 2 ](https://github.com/mbleigh/acts-as-taggable-on/pull/758)
40
+ * [@krzysiek1507 drop support for Rails < 4 ](https://github.com/mbleigh/acts-as-taggable-on/pull/757)
41
+ * Added
42
+ * [@jessieay Rails 5 ](https://github.com/mbleigh/acts-as-taggable-on/pull/763)
43
+ * Fixes
44
+ * [@rikettsie #623 collation parameter is ignored if it generates an exception] (https://github.com/mbleigh/acts-as-taggable-on/pull/650 )
45
+ * [@bwvoss References working parser in deprectation warning] (https://github.com/mbleigh/acts-as-taggable-on/pull/659 )
46
+ * [@jh125486 Updated tagging_contexts to include dynamic contexts ](https://github.com/mbleigh/acts-as-taggable-on/pull/660 )
47
+ * [@jh125486 Fixed wildcard test (postgres returning rows with unexpected order)] (https://github.com/mbleigh/acts-as-taggable-on/pull/660 )
48
+ * [@FlowerWrong Add rails 5.0.0 alpha support, not hack rails <5](https://github.com/mbleigh/acts-as-taggable-on/pull/673 )
49
+ * [@ryanfox1985 Added missed indexes. ](https://github.com/mbleigh/acts-as-taggable-on/pull/682 )
50
+ * [@ zapnap scope tags to specific tagging ](https://github.com/mbleigh/acts-as-taggable-on/pull/697 )
51
+ * [@ amatsuda method redefined](https://github.com/mbleigh/acts-as-taggable-on/pull/715 )
52
+ * [@ klacointe Rails 5: Tagger is optional in Tagging relation](https://github.com/mbleigh/acts-as-taggable-on/pull/720 )
53
+ * [@ mark-jacobs Update clean! method to use case insensitive uniq! when strict_case_match false] (https://github.com/mbleigh/acts-as-taggable-on/commit/90c86994b70a399b8b1cbc0ae88835e14d6aadfc )
54
+ * [@ lukeasrodgers BugFix flackey time test ] (https://github.com/mbleigh/acts-as-taggable-on/pull/727)
55
+ * [@ pcupueran Add rspec tests for context scopes for tagging_spec ]( https://github.com/mbleigh/acts-as-taggable-on/pull/740)
56
+ * [@ Emerson Huitt Remove existing selects from relation ]( https://github.com/mbleigh/acts-as-taggable-on/pull/743)
57
+ * [@keerthisiv fix issue with custom delimiter]( https://github.com/mbleigh/acts-as-taggable-on/pull/748)
58
+ * [@priyank-gupta specify tag table name for mysql collation query ](https://github.com/mbleigh/acts-as-taggable-on/pull/760)
59
+ * [@seuros Remove warning messages](https://github.com/mbleigh/acts-as-taggable-on/commit/cda08c764b07a18b8582b948d1c5b3910a3769 65)
60
+ * [@rbritom Fix migration, #references already adds index ]
61
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/95f743010954b6b738a6e8c17315112c878f7a81 )
62
+ * [@rbritom Fix deprecation warning]
63
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/62e4a6fa74ae3faed615683cd3ad5b5cdacf5c96 )
64
+ * [@rbritom fix scope array arguments ]
65
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/a415a8d6367b2e91bd7e363589135f953929b8cc )
66
+ * [@seuros Remove more deprecations ]
67
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/05794170f64f8bf250b34d2d594e368721009278)
68
+ * [@lukeasrodgers Bugfix `TagList#concat` with non-duplicates. ]
69
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/2c6214f0ddf8c6440ab81eec04d1fbf9d97c8826)
70
+ * [@seuros clean! should return self. ]
71
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/c739422f56f8ff37e3f321235e74997422a1c980)
72
+ * [@rbritom renable appraisals ]
73
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/0ca1f1c5b059699c683a28b522e86a3d5cd7639e)
74
+ * [@rbritom remove index conditionally on up method. ]
75
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
76
+ *[@rbritom add index on down method . ]
77
+ (https://github.com/mbleigh/acts-as-taggable-on/pull/767)
78
+ q* [@rbritom remove index conditionally on up method]
79
+ (https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
80
+
81
+ * Documentation
82
+ * [@logicminds Adds table of contents using doctoc utility](https://github.com/mbleigh/acts-as-taggable-on/pull/803)
83
+ * [@jamesprior Changing ActsAsTaggable to ActsAsTaggableOn ](https://github.com/mbleigh/acts-as-taggable-on/pull/637)
84
+ * [@markgandolfo Update README.md](https://github.com/mbleigh/acts-as-taggable-on/pull/645))
85
+ * [@snowblink Update release date for 3.5.0](https://github.com/mbleigh/acts-as-taggable-on/pull/647)
86
+ * [@AlexVPopov Update README.md ](https://github.com/mbleigh/acts-as-taggable-on/pull/671)
87
+ * [@schnmudgal README.md, Improve documentation for Tag Ownership](https://github.com/mbleigh/acts-as-taggable-on/pull/706)
88
+
7
89
  ### [3.5.0 / 2015-03-03](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.4...v3.5.0)
8
90
 
9
91
  * Fixes
@@ -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
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ # gemspec
4
4
 
5
5
  group :local_development do
6
6
  gem 'guard'
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://secure.travis-ci.org/mbleigh/acts-as-taggable-on.svg)](http://travis-ci.org/mbleigh/acts-as-taggable-on)
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
@@ -207,12 +238,13 @@ User.tagged_with("awesome").by_join_date
207
238
  User.tagged_with("awesome").by_join_date.paginate(:page => params[:page], :per_page => 20)
208
239
 
209
240
  # Find users that matches all given tags:
241
+ # NOTE: This only matches users that have the exact set of specified tags. If a user has additional tags, they are not returned.
210
242
  User.tagged_with(["awesome", "cool"], :match_all => true)
211
243
 
212
244
  # Find users with any of the specified tags:
213
245
  User.tagged_with(["awesome", "cool"], :any => true)
214
246
 
215
- # Find users that has not been tagged with awesome or cool:
247
+ # Find users that have not been tagged with awesome or cool:
216
248
  User.tagged_with(["awesome", "cool"], :exclude => true)
217
249
 
218
250
  # Find users with any of the tags based on context:
@@ -332,12 +364,12 @@ Note that **owned tags** are added all at once, in the form of ***comma seperate
332
364
  Also, when you try to add **owned tags** again, it simply overwrites the previous set of **owned tags**.
333
365
  So to append tags in previously existing **owned tags** list, go as follows:
334
366
  ```ruby
335
- def add_owned_tag
367
+ def add_owned_tag
336
368
  @some_item = Item.find(params[:id])
337
- owned_tag_list = @some_item.all_tag_list - @some_item.tag_list
369
+ owned_tag_list = @some_item.all_tags_list - @some_item.tag_list
338
370
  owned_tag_list += [(params[:tag])]
339
371
  @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
340
- @some_item.save
372
+ @some_item.save
341
373
  end
342
374
 
343
375
  def stringify(tag_list)
@@ -347,12 +379,12 @@ end
347
379
  ##### Removing owned tags
348
380
  Similarly as above, removing will be as follows:
349
381
  ```ruby
350
- def remove_owned_tag
382
+ def remove_owned_tag
351
383
  @some_item = Item.find(params[:id])
352
- owned_tag_list = @some_item.all_tag_list - @some_item.tag_list
384
+ owned_tag_list = @some_item.all_tags_list - @some_item.tag_list
353
385
  owned_tag_list -= [(params[:tag])]
354
386
  @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
355
- @some_item.save
387
+ @some_item.save
356
388
  end
357
389
  ```
358
390
 
@@ -16,13 +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.2.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']
25
+ gem.add_runtime_dependency 'activerecord', ['>= 4.2.8']
26
26
 
27
27
  gem.add_development_dependency 'sqlite3'
28
28
  gem.add_development_dependency 'mysql2', '~> 0.3'
@@ -1,4 +1,9 @@
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
8
  create_table :tags do |t|
4
9
  t.string :name
@@ -1,4 +1,9 @@
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
8
  add_index :tags, :name, unique: true
4
9
 
@@ -1,4 +1,9 @@
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
8
  add_column :tags, :taggings_count, :integer, default: 0
4
9
 
@@ -1,4 +1,9 @@
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
8
  add_index :taggings, [:taggable_id, :taggable_type, :context]
4
9
  end
@@ -1,6 +1,11 @@
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
11
  execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
@@ -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 :taggings, :tag_id unless index_exists? :taggings, :tag_id
9
+ add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id
10
+ add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type
11
+ add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id
12
+ add_index :taggings, :context unless index_exists? :taggings, :context
13
+
14
+ unless index_exists? :taggings, [:tagger_id, :tagger_type]
15
+ add_index :taggings, [:tagger_id, :tagger_type]
16
+ end
17
+
18
+ unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
19
+ add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
20
+ end
21
+ end
22
+ end
@@ -2,14 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.2.0"
5
+ gem "activerecord", "~> 4.2.8"
6
6
 
7
7
  group :local_development do
8
8
  gem "guard"
9
9
  gem "guard-rspec"
10
10
  gem "appraisal"
11
11
  gem "rake"
12
- gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
12
+ gem "byebug", platforms: [:mri_21, :mri_22, :mri_23]
13
13
  end
14
14
 
15
- gemspec :path => "../"
15
+ gemspec path: "../"
@@ -2,14 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 5.0.0"
5
+ gem "activerecord", "~> 5.0.3"
6
6
 
7
7
  group :local_development do
8
8
  gem "guard"
9
9
  gem "guard-rspec"
10
10
  gem "appraisal"
11
11
  gem "rake"
12
- gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
12
+ gem "byebug", platforms: [:mri_21, :mri_22, :mri_23]
13
13
  end
14
14
 
15
- gemspec :path => "../"
15
+ gemspec path: "../"
@@ -2,15 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.0.0"
6
- gem "mysql2", "~> 0.3.21"
5
+ gem "activerecord", "~> 5.1.1"
7
6
 
8
7
  group :local_development do
9
8
  gem "guard"
10
9
  gem "guard-rspec"
11
10
  gem "appraisal"
12
11
  gem "rake"
13
- gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
12
+ gem "byebug", platforms: [:mri_21, :mri_22, :mri_23]
14
13
  end
15
14
 
16
- gemspec :path => "../"
15
+ gemspec path: "../"
@@ -69,17 +69,20 @@ module ActsAsTaggableOn
69
69
 
70
70
  return [] if list.empty?
71
71
 
72
- existing_tags = named_any(list)
73
-
74
72
  list.map do |tag_name|
75
- comparable_tag_name = comparable_name(tag_name)
76
- existing_tag = existing_tags.find { |tag| comparable_name(tag.name) == comparable_tag_name }
77
73
  begin
74
+ tries ||= 3
75
+
76
+ existing_tags = named_any(list)
77
+ comparable_tag_name = comparable_name(tag_name)
78
+ existing_tag = existing_tags.find { |tag| comparable_name(tag.name) == comparable_tag_name }
78
79
  existing_tag || create(name: tag_name)
79
80
  rescue ActiveRecord::RecordNotUnique
80
- # Postgres aborts the current transaction with
81
- # PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
82
- # so we have to rollback this transaction
81
+ if (tries -= 1).positive?
82
+ ActiveRecord::Base.connection.execute 'ROLLBACK'
83
+ retry
84
+ end
85
+
83
86
  raise DuplicateTagError.new("'#{tag_name}' has already been taken")
84
87
  end
85
88
  end