acts-as-taggable-on 3.5.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +14 -18
  4. data/Appraisals +9 -8
  5. data/CHANGELOG.md +3 -1
  6. data/Gemfile +1 -1
  7. data/README.md +56 -19
  8. data/acts-as-taggable-on.gemspec +3 -3
  9. data/db/migrate/2_add_missing_unique_indices.rb +3 -2
  10. data/db/migrate/6_add_missing_indexes.rb +12 -0
  11. data/gemfiles/activerecord_4.0.gemfile +3 -2
  12. data/gemfiles/activerecord_4.1.gemfile +3 -2
  13. data/gemfiles/activerecord_4.2.gemfile +2 -3
  14. data/gemfiles/{activerecord_3.2.gemfile → activerecord_5.0.gemfile} +2 -2
  15. data/lib/acts-as-taggable-on.rb +16 -12
  16. data/lib/acts_as_taggable_on/engine.rb +0 -1
  17. data/lib/acts_as_taggable_on/tag.rb +6 -2
  18. data/lib/acts_as_taggable_on/tag_list.rb +2 -13
  19. data/lib/acts_as_taggable_on/taggable/cache.rb +1 -1
  20. data/lib/acts_as_taggable_on/taggable/collection.rb +6 -3
  21. data/lib/acts_as_taggable_on/taggable/core.rb +21 -16
  22. data/lib/acts_as_taggable_on/taggable/ownership.rb +3 -3
  23. data/lib/acts_as_taggable_on/tagger.rb +12 -11
  24. data/lib/acts_as_taggable_on/tagging.rb +4 -14
  25. data/lib/acts_as_taggable_on/utils.rb +2 -3
  26. data/lib/acts_as_taggable_on/version.rb +1 -1
  27. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +10 -1
  28. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +1 -1
  29. data/spec/acts_as_taggable_on/caching_spec.rb +22 -0
  30. data/spec/acts_as_taggable_on/tag_list_spec.rb +27 -1
  31. data/spec/acts_as_taggable_on/tag_spec.rb +15 -0
  32. data/spec/acts_as_taggable_on/taggable_spec.rb +19 -5
  33. data/spec/acts_as_taggable_on/tagging_spec.rb +64 -10
  34. data/spec/internal/db/schema.rb +7 -3
  35. data/spec/support/database.rb +1 -7
  36. metadata +10 -19
  37. data/lib/acts_as_taggable_on/compatibility.rb +0 -35
  38. data/lib/acts_as_taggable_on/tag_list_parser.rb +0 -21
  39. data/spec/acts_as_taggable_on/tag_list_parser_spec.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92222646174fc38e87d9972cea2022c78e9ba337
4
- data.tar.gz: 62d819d54ea8d538ce67d1f30c4c640e63333328
3
+ metadata.gz: 8ab1dc9bc4d03cd7fb2396284190f76719bc4a40
4
+ data.tar.gz: 8bbb5a13b5a1cc54aea59cb1ab6e524c31ea530c
5
5
  SHA512:
6
- metadata.gz: 6a17ce74f9d91e98037faa3348449813632f2f1ba2a4ca92a297beaafa8e544b650c2e12586c03a9aab8c2c6b0b5c1c1de21571d860be49aed971b0d20b8338e
7
- data.tar.gz: d50ea8e8200c3eaef6f1d80b53412637604e74de62dd3a2e6385e22d1fbf579bbb372f2bbd9b6c026f3f062e4959a288a5a890360d5f98cde6df222ebc72947f
6
+ metadata.gz: 901d4fb2dd642138c9d8b918d49eee90a86a0ea78596c37753197583b8c4068c08068077e8917bacc0b43ff0272613002aab6670a437ef9ac98a90910f11e522
7
+ data.tar.gz: 6c0f2e8dc6157b6ea854f63456c4eaa9fc0c754d46dd419ad0a184dd76eb69c3f7486591dfe156d3a224918fcd8d81a13a90661503e216ff21730d98a5d59e52
data/.gitignore CHANGED
@@ -9,3 +9,5 @@ tmp*.sw?
9
9
  tmp
10
10
  *.gem
11
11
  *.lock
12
+
13
+ /.idea
data/.travis.yml CHANGED
@@ -1,11 +1,11 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
 
3
4
  rvm:
5
+ - 2.3.1
6
+ - 2.2.5
4
7
  - 2.1
5
- - 2.2
6
8
  - 2.0.0
7
- - 1.9.3
8
- - rbx-2
9
9
 
10
10
  env:
11
11
  - DB=sqlite3
@@ -13,28 +13,24 @@ env:
13
13
  - DB=postgresql
14
14
 
15
15
  gemfile:
16
- - gemfiles/activerecord_3.2.gemfile
17
- - gemfiles/activerecord_4.0.gemfile
16
+ - gemfiles/activerecord_5.0.gemfile
17
+ - gemfiles/activerecord_4.2.gemfile
18
18
  - gemfiles/activerecord_4.1.gemfile
19
+ - gemfiles/activerecord_4.0.gemfile
19
20
 
20
21
  sudo: false
21
22
 
22
23
  bundler_args: '--without local_development --jobs 3 --retry 3'
23
24
 
25
+ before_install:
26
+ - gem install bundler
27
+
24
28
  script: bundle exec rake
25
29
 
26
30
  matrix:
27
- fast_finish: true
28
- allow_failures:
29
- - gemfile: gemfiles/activerecord_edge.gemfile
30
- - rvm: rbx-2
31
31
  exclude:
32
- - rvm: 2.2
33
- gemfile: gemfiles/activerecord_3.2.gemfile
34
- - rvm: 1.9.3
35
- gemfile: gemfiles/activerecord_4.0.gemfile
36
- - rvm: 1.9.3
37
- gemfile: gemfiles/activerecord_4.1.gemfile
38
- - rvm: rbx-2
39
- gemfile: gemfiles/activerecord_3.2.gemfile
40
-
32
+ - rvm: 2.0.0
33
+ gemfile: gemfiles/activerecord_5.0.gemfile
34
+ - rvm: 2.1
35
+ gemfile: gemfiles/activerecord_5.0.gemfile
36
+ fast_finish: true
data/Appraisals CHANGED
@@ -1,16 +1,17 @@
1
- appraise "activerecord-3.2" do
2
- gem "activerecord", github: "rails/rails" , branch: '3-2-stable'
1
+ appraise 'activerecord-5.0' do
2
+ gem 'activerecord', "~> 5.0.0"
3
3
  end
4
4
 
5
- appraise "activerecord-4.0" do
6
- gem "activerecord", github: "rails/rails" , branch: '4-0-stable'
5
+ appraise "activerecord-4.2" do
6
+ gem "activerecord", "~> 4.2.0"
7
7
  end
8
8
 
9
9
  appraise "activerecord-4.1" do
10
- gem "activerecord", github: "rails/rails" , branch: '4-1-stable'
10
+ gem "activerecord", "~> 4.1.0"
11
+ gem 'mysql2', '~> 0.3.21'
11
12
  end
12
13
 
13
- appraise "activerecord-4.2" do
14
- gem "railties", github: "rails/rails" , branch: '4-2-stable'
15
- gem "activerecord", github: "rails/rails" , branch: '4-2-stable'
14
+ appraise "activerecord-4.0" do
15
+ gem "activerecord", "~> 4.0.0"
16
+ gem 'mysql2', '~> 0.3.21'
16
17
  end
data/CHANGELOG.md CHANGED
@@ -4,10 +4,12 @@ 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
- ### [3.5.0 / 2015-02-11](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.4...v3.5.0)
7
+ ### [3.5.0 / 2015-03-03](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.4...v3.5.0)
8
8
 
9
9
  * Fixes
10
10
  * [@rikettsie Fixed collation for MySql via rake rule or config parameter](https://github.com/mbleigh/acts-as-taggable-on/pull/634)
11
+ *Misc
12
+ * [@pcupueran Add rspec test for tagging_spec completeness]()
11
13
 
12
14
  ### [3.4.4 / 2015-02-11](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.3...v3.4.4)
13
15
 
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' , platform: :mri_21
10
+ gem 'byebug' , platforms: [:mri_21, :mri_22, :mri_23]
11
11
  end
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # ActsAsTaggableOn
2
+
3
+ [![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)
2
4
  [![Gem Version](https://badge.fury.io/rb/acts-as-taggable-on.svg)](http://badge.fury.io/rb/acts-as-taggable-on)
3
5
  [![Build Status](https://secure.travis-ci.org/mbleigh/acts-as-taggable-on.png)](http://travis-ci.org/mbleigh/acts-as-taggable-on)
4
6
  [![Code Climate](https://codeclimate.com/github/mbleigh/acts-as-taggable-on.png)](https://codeclimate.com/github/mbleigh/acts-as-taggable-on)
@@ -17,22 +19,14 @@ Enter Acts as Taggable On. Rather than tying functionality to a specific keyword
17
19
  tag "contexts" that can be used locally or in combination in the same way steroids
18
20
  was used.
19
21
 
20
- ## Compatibility
21
-
22
- Versions 2.x are compatible with Ruby 1.8.7+ and Rails 3.
23
-
24
- Versions 2.4.1 and up are compatible with Rails 4 too (thanks to arabonradar and cwoodcox).
25
22
 
26
- Versions >= 3.x are compatible with Ruby 1.9.3+ and Rails 3 and 4.
27
-
28
- For an up-to-date roadmap, see https://github.com/mbleigh/acts-as-taggable-on/milestones
29
23
 
30
24
  ## Installation
31
25
 
32
26
  To use it, add it to your Gemfile:
33
27
 
34
28
  ```ruby
35
- gem 'acts-as-taggable-on', '~> 3.4'
29
+ gem 'acts-as-taggable-on', '~> 4.0'
36
30
  ```
37
31
 
38
32
  and bundle:
@@ -48,8 +42,6 @@ Install migrations
48
42
  ```shell
49
43
  # For the latest versions :
50
44
  rake acts_as_taggable_on_engine:install:migrations
51
- # For versions 2.4.1 and earlier :
52
- rails generate acts_as_taggable_on:migration
53
45
  ```
54
46
 
55
47
  Review the generated migrations then migrate :
@@ -73,9 +65,6 @@ rake acts_as_taggable_on_engine:tag_names:collate_bin
73
65
  See the Configuration section for more details, and a general note valid for older
74
66
  version of the gem.
75
67
 
76
- #### Upgrading
77
-
78
- see [UPGRADING](UPGRADING.md)
79
68
 
80
69
  ## Usage
81
70
 
@@ -89,7 +78,7 @@ end
89
78
 
90
79
  class UsersController < ApplicationController
91
80
  def user_params
92
- params.require(:user).permit(:name, :tag_list => []) ## Rails 4 strong params usage
81
+ params.require(:user).permit(:name, :tag_list) ## Rails 4 strong params usage
93
82
  end
94
83
  end
95
84
 
@@ -273,7 +262,7 @@ User.tagged_with("same", :on => :customs) # => [@user]
273
262
 
274
263
  ### Tag Parsers
275
264
 
276
- If you want to change how tags are parsed, you can define a your own implementation:
265
+ If you want to change how tags are parsed, you can define your own implementation:
277
266
 
278
267
  ```ruby
279
268
  class MyParser < ActsAsTaggableOn::GenericParser
@@ -302,7 +291,7 @@ Now you can use this parser, passing it as parameter:
302
291
  Or change it globally:
303
292
 
304
293
  ```ruby
305
- ActsAsTaggable.default_parser = MyParser
294
+ ActsAsTaggableOn.default_parser = MyParser
306
295
  @user = User.new(:name => "Bobby")
307
296
  @user.tag_list = "east|south"
308
297
  @user.tag_list # => ["east", "south"]
@@ -331,6 +320,42 @@ Photo.tagged_with("paris", :on => :locations, :owned_by => @some_user)
331
320
  @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object
332
321
  ```
333
322
 
323
+ #### Working with Owned Tags
324
+ Note that `tag_list` only returns tags whose taggings do not have an owner. Continuing from the above example:
325
+ ```ruby
326
+ @some_photo.tag_list # => []
327
+ ```
328
+ To retrieve all tags of an object (regardless of ownership) or if only one owner can tag the object, use `all_tags_list`.
329
+
330
+ ##### Adding owned tags
331
+ Note that **owned tags** are added all at once, in the form of ***comma seperated tags*** in string.
332
+ Also, when you try to add **owned tags** again, it simply overwrites the previous set of **owned tags**.
333
+ So to append tags in previously existing **owned tags** list, go as follows:
334
+ ```ruby
335
+ def add_owned_tag
336
+ @some_item = Item.find(params[:id])
337
+ owned_tag_list = @some_item.all_tag_list - @some_item.tag_list
338
+ owned_tag_list += [(params[:tag])]
339
+ @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
340
+ @some_item.save
341
+ end
342
+
343
+ def stringify(tag_list)
344
+ tag_list.inject('') { |memo, tag| memo += (tag + ',') }[0..-1]
345
+ end
346
+ ```
347
+ ##### Removing owned tags
348
+ Similarly as above, removing will be as follows:
349
+ ```ruby
350
+ def remove_owned_tag
351
+ @some_item = Item.find(params[:id])
352
+ owned_tag_list = @some_item.all_tag_list - @some_item.tag_list
353
+ owned_tag_list -= [(params[:tag])]
354
+ @tag_owner.tag(@some_item, :with => stringify(owned_tag_list), :on => :tags)
355
+ @some_item.save
356
+ end
357
+ ```
358
+
334
359
  ### Dirty objects
335
360
 
336
361
  ```ruby
@@ -446,13 +471,25 @@ USE my_wonderful_app_db;
446
471
  ALTER TABLE tags MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin;
447
472
  ```
448
473
 
474
+ #### Upgrading
475
+
476
+ see [UPGRADING](UPGRADING.md)
477
+
449
478
  ## Contributors
450
479
 
451
480
  We have a long list of valued contributors. [Check them all](https://github.com/mbleigh/acts-as-taggable-on/contributors)
452
481
 
453
- ## Maintainer
482
+ ## Compatibility
483
+
484
+ Versions 2.x are compatible with Ruby 1.8.7+ and Rails 3.
485
+
486
+ Versions 2.4.1 and up are compatible with Rails 4 too (thanks to arabonradar and cwoodcox).
454
487
 
455
- * [Joost Baaij](https://github.com/tilsammans)
488
+ Versions >= 3.x are compatible with Ruby 1.9.3+ and Rails 3 and 4.
489
+
490
+ Versions >= 4.x are compatible with Ruby 2.0.0+ and Rails 4 and 5.
491
+
492
+ For an up-to-date roadmap, see https://github.com/mbleigh/acts-as-taggable-on/milestones
456
493
 
457
494
  ## TODO
458
495
 
@@ -16,16 +16,16 @@ 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 = '>= 1.9.3'
19
+ gem.required_ruby_version = '>= 2.0.0'
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', ['>= 3.2', '< 5']
25
+ gem.add_runtime_dependency 'activerecord', ['>= 4.0']
26
26
 
27
27
  gem.add_development_dependency 'sqlite3'
28
- gem.add_development_dependency 'mysql2', '~> 0.3.7'
28
+ gem.add_development_dependency 'mysql2', '~> 0.3'
29
29
  gem.add_development_dependency 'pg'
30
30
 
31
31
  gem.add_development_dependency 'rspec-rails'
@@ -2,7 +2,7 @@ class AddMissingUniqueIndices < ActiveRecord::Migration
2
2
  def self.up
3
3
  add_index :tags, :name, unique: true
4
4
 
5
- remove_index :taggings, :tag_id
5
+ remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id)
6
6
  remove_index :taggings, [:taggable_id, :taggable_type, :context]
7
7
  add_index :taggings,
8
8
  [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
@@ -13,7 +13,8 @@ class AddMissingUniqueIndices < ActiveRecord::Migration
13
13
  remove_index :tags, :name
14
14
 
15
15
  remove_index :taggings, name: 'taggings_idx'
16
- add_index :taggings, :tag_id
16
+
17
+ add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)
17
18
  add_index :taggings, [:taggable_id, :taggable_type, :context]
18
19
  end
19
20
  end
@@ -0,0 +1,12 @@
1
+ class AddMissingIndexes < ActiveRecord::Migration
2
+ def change
3
+ add_index :taggings, :tag_id
4
+ add_index :taggings, :taggable_id
5
+ add_index :taggings, :taggable_type
6
+ add_index :taggings, :tagger_id
7
+ add_index :taggings, :context
8
+
9
+ add_index :taggings, [:tagger_id, :tagger_type]
10
+ add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
11
+ end
12
+ end
@@ -2,14 +2,15 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", :github => "rails/rails", :branch => "4-0-stable"
5
+ gem "activerecord", "~> 4.0.0"
6
+ gem "mysql2", "~> 0.3.21"
6
7
 
7
8
  group :local_development do
8
9
  gem "guard"
9
10
  gem "guard-rspec"
10
11
  gem "appraisal"
11
12
  gem "rake"
12
- gem "byebug", :platform => :mri_21
13
+ gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
13
14
  end
14
15
 
15
16
  gemspec :path => "../"
@@ -2,14 +2,15 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", :github => "rails/rails", :branch => "4-1-stable"
5
+ gem "activerecord", "~> 4.1.0"
6
+ gem "mysql2", "~> 0.3.21"
6
7
 
7
8
  group :local_development do
8
9
  gem "guard"
9
10
  gem "guard-rspec"
10
11
  gem "appraisal"
11
12
  gem "rake"
12
- gem "byebug", :platform => :mri_21
13
+ gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
13
14
  end
14
15
 
15
16
  gemspec :path => "../"
@@ -2,15 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "railties", :github => "rails/rails", :branch => "4-2-stable"
6
- gem "activerecord", :github => "rails/rails", :branch => "4-2-stable"
5
+ gem "activerecord", "~> 4.2.0"
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", :platform => :mri_21
12
+ gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
14
13
  end
15
14
 
16
15
  gemspec :path => "../"
@@ -2,14 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", :github => "rails/rails", :branch => "3-2-stable"
5
+ gem "activerecord", "~> 5.0.0"
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", :platform => :mri_21
12
+ gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
13
13
  end
14
14
 
15
15
  gemspec :path => "../"
@@ -2,7 +2,12 @@ require 'active_record'
2
2
  require 'active_record/version'
3
3
  require 'active_support/core_ext/module'
4
4
 
5
- require_relative 'acts_as_taggable_on/engine' if defined?(Rails)
5
+ begin
6
+ require 'rails/engine'
7
+ require 'acts_as_taggable_on/engine'
8
+ rescue LoadError
9
+
10
+ end
6
11
 
7
12
  require 'digest/sha1'
8
13
 
@@ -13,7 +18,6 @@ module ActsAsTaggableOn
13
18
  autoload :TagList
14
19
  autoload :GenericParser
15
20
  autoload :DefaultParser
16
- autoload :TagListParser
17
21
  autoload :Taggable
18
22
  autoload :Tagger
19
23
  autoload :Tagging
@@ -57,9 +61,10 @@ module ActsAsTaggableOn
57
61
  end
58
62
 
59
63
  class Configuration
60
- attr_accessor :delimiter, :force_lowercase, :force_parameterize,
61
- :strict_case_match, :remove_unused_tags, :default_parser,
64
+ attr_accessor :force_lowercase, :force_parameterize,
65
+ :remove_unused_tags, :default_parser,
62
66
  :tags_counter
67
+ attr_reader :delimiter, :strict_case_match
63
68
 
64
69
  def initialize
65
70
  @delimiter = ','
@@ -73,9 +78,7 @@ module ActsAsTaggableOn
73
78
  end
74
79
 
75
80
  def strict_case_match=(force_cs)
76
- if @force_binary_collation == false
77
- @strict_case_match = force_cs
78
- end
81
+ @strict_case_match = force_cs unless @force_binary_collation
79
82
  end
80
83
 
81
84
  def delimiter=(string)
@@ -89,7 +92,7 @@ WARNING
89
92
 
90
93
  def force_binary_collation=(force_bin)
91
94
  if Utils.using_mysql?
92
- if force_bin == true
95
+ if force_bin
93
96
  Configuration.apply_binary_collation(true)
94
97
  @force_binary_collation = true
95
98
  @strict_case_match = true
@@ -103,10 +106,12 @@ WARNING
103
106
  def self.apply_binary_collation(bincoll)
104
107
  if Utils.using_mysql?
105
108
  coll = 'utf8_general_ci'
106
- if bincoll == true
107
- coll = 'utf8_bin'
109
+ coll = 'utf8_bin' if bincoll
110
+ begin
111
+ ActiveRecord::Migration.execute("ALTER TABLE #{Tag.table_name} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE #{coll};")
112
+ rescue Exception => e
113
+ puts "Trapping #{e.class}: collation parameter ignored while migrating for the first time."
108
114
  end
109
- ActiveRecord::Migration.execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE #{coll};")
110
115
  end
111
116
  end
112
117
 
@@ -116,7 +121,6 @@ WARNING
116
121
  end
117
122
 
118
123
  ActiveSupport.on_load(:active_record) do
119
- extend ActsAsTaggableOn::Compatibility
120
124
  extend ActsAsTaggableOn::Taggable
121
125
  include ActsAsTaggableOn::Tagger
122
126
  end
@@ -1,4 +1,3 @@
1
- require 'rails/engine'
2
1
  module ActsAsTaggableOn
3
2
  class Engine < Rails::Engine
4
3
  end
@@ -2,8 +2,6 @@
2
2
  module ActsAsTaggableOn
3
3
  class Tag < ::ActiveRecord::Base
4
4
 
5
- attr_accessible :name if defined?(ActiveModel::MassAssignmentSecurity)
6
-
7
5
  ### ASSOCIATIONS:
8
6
 
9
7
  has_many :taggings, dependent: :destroy, class_name: '::ActsAsTaggableOn::Tagging'
@@ -50,6 +48,12 @@ module ActsAsTaggableOn
50
48
  where(clause)
51
49
  end
52
50
 
51
+ def self.for_context(context)
52
+ joins(:taggings).
53
+ where(["taggings.context = ?", context]).
54
+ select("DISTINCT tags.*")
55
+ end
56
+
53
57
  ### CLASS METHODS:
54
58
 
55
59
  def self.find_or_create_with_like_by_name(name)
@@ -84,7 +84,8 @@ module ActsAsTaggableOn
84
84
  map! { |tag| tag.mb_chars.downcase.to_s } if ActsAsTaggableOn.force_lowercase
85
85
  map!(&:parameterize) if ActsAsTaggableOn.force_parameterize
86
86
 
87
- uniq!
87
+ ActsAsTaggableOn.strict_case_match ? uniq! : uniq!{ |tag| tag.downcase }
88
+ self
88
89
  end
89
90
 
90
91
 
@@ -99,18 +100,6 @@ module ActsAsTaggableOn
99
100
  args.flatten!
100
101
  end
101
102
 
102
-
103
- ## DEPRECATED
104
- def self.from(string)
105
- ActiveRecord::Base.logger.warn <<WARNING
106
- ActsAsTaggableOn::TagList.from is deprecated \
107
- and will be removed from v4.0+, use \
108
- ActsAsTaggableOn::DefaultParser.new instead
109
- WARNING
110
- @parser.new(string).parse
111
- end
112
-
113
-
114
103
  end
115
104
  end
116
105
 
@@ -73,7 +73,7 @@ module ActsAsTaggableOn::Taggable
73
73
  tag_types.map(&:to_s).each do |tag_type|
74
74
  if self.class.send("caching_#{tag_type.singularize}_list?")
75
75
  if tag_list_cache_set_on(tag_type)
76
- list = tag_list_cache_on(tag_type).to_a.flatten.compact.join(', ')
76
+ list = tag_list_cache_on(tag_type).to_a.flatten.compact.join("#{ActsAsTaggableOn.delimiter} ")
77
77
  self["cached_#{tag_type.singularize}_list"] = list
78
78
  end
79
79
  end
@@ -138,7 +138,7 @@ module ActsAsTaggableOn::Taggable
138
138
  scoped_ids = pluck(table_name_pkey)
139
139
  tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)", scoped_ids)
140
140
  else
141
- tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{safe_to_sql(select(table_name_pkey))})")
141
+ tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{safe_to_sql(except(:select).select(table_name_pkey))})")
142
142
  end
143
143
 
144
144
  tagging_scope
@@ -169,9 +169,12 @@ module ActsAsTaggableOn::Taggable
169
169
  end
170
170
 
171
171
  module CalculationMethods
172
- def count(column_name=:all, options = {})
172
+ # Rails 5 TODO: Remove options argument as soon we remove support to
173
+ # activerecord-deprecated_finders.
174
+ # See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb#L38
175
+ def count(column_name = :all, options = {})
173
176
  # https://github.com/rails/rails/commit/da9b5d4a8435b744fcf278fffd6d7f1e36d4a4f2
174
- super
177
+ ActsAsTaggableOn::Utils.active_record5? ? super(column_name) : super(column_name, options)
175
178
  end
176
179
  end
177
180
  end
@@ -23,18 +23,15 @@ module ActsAsTaggableOn::Taggable
23
23
  class_eval do
24
24
  # when preserving tag order, include order option so that for a 'tags' context
25
25
  # the associations tag_taggings & tags are always returned in created order
26
- has_many_with_taggable_compatibility context_taggings, as: :taggable,
27
- dependent: :destroy,
28
- class_name: 'ActsAsTaggableOn::Tagging',
29
- order: taggings_order,
30
- conditions: {context: tags_type},
31
- include: :tag
32
-
33
- has_many_with_taggable_compatibility context_tags, through: context_taggings,
34
- source: :tag,
35
- class_name: 'ActsAsTaggableOn::Tag',
36
- order: taggings_order
37
-
26
+ has_many context_taggings, -> { includes(:tag).order(taggings_order).where(context: tags_type) },
27
+ as: :taggable,
28
+ class_name: ActsAsTaggableOn::Tagging,
29
+ dependent: :destroy
30
+
31
+ has_many context_tags, -> { order(taggings_order) },
32
+ class_name: ActsAsTaggableOn::Tag,
33
+ through: context_taggings,
34
+ source: :tag
38
35
  end
39
36
 
40
37
  taggable_mixin.class_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -246,6 +243,14 @@ module ActsAsTaggableOn::Taggable
246
243
  def taggable_mixin
247
244
  @taggable_mixin ||= Module.new
248
245
  end
246
+
247
+ private
248
+
249
+ # Rails 5 has merged sanitize and quote_value
250
+ # See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/sanitization.rb#L10
251
+ def quote_value(value, column = nil)
252
+ ActsAsTaggableOn::Utils.active_record5? ? super(value) : super(value, column)
253
+ end
249
254
  end
250
255
 
251
256
  # all column names are necessary for PostgreSQL group clause
@@ -254,7 +259,7 @@ module ActsAsTaggableOn::Taggable
254
259
  end
255
260
 
256
261
  def custom_contexts
257
- @custom_contexts ||= []
262
+ @custom_contexts ||= taggings.map(&:context).uniq
258
263
  end
259
264
 
260
265
  def is_taggable?
@@ -333,7 +338,7 @@ module ActsAsTaggableOn::Taggable
333
338
  end
334
339
 
335
340
  def tagging_contexts
336
- custom_contexts + self.class.tag_types.map(&:to_s)
341
+ self.class.tag_types.map(&:to_s) + custom_contexts
337
342
  end
338
343
 
339
344
  def process_dirty_object(context, new_list)
@@ -407,7 +412,7 @@ module ActsAsTaggableOn::Taggable
407
412
 
408
413
  # Destroy old taggings:
409
414
  if old_tags.present?
410
- taggings.not_owned.by_context(context).destroy_all(tag_id: old_tags)
415
+ taggings.not_owned.by_context(context).where(tag_id: old_tags).destroy_all
411
416
  end
412
417
 
413
418
  # Create new taggings:
@@ -432,7 +437,7 @@ module ActsAsTaggableOn::Taggable
432
437
  tag_lists = tag_types.map {|tags_type| "#{tags_type.to_s.singularize}_list"}
433
438
  super.delete_if {|attr| tag_lists.include? attr }
434
439
  end
435
-
440
+
436
441
  ##
437
442
  # Override this hook if you wish to subclass {ActsAsTaggableOn::Tag} --
438
443
  # context is provided so that you may conditionally use a Tag subclass
@@ -108,9 +108,9 @@ module ActsAsTaggableOn::Taggable
108
108
 
109
109
  # Find all taggings that belong to the taggable (self), are owned by the owner,
110
110
  # have the correct context, and are removed from the list.
111
- ActsAsTaggableOn::Tagging.destroy_all(taggable_id: id, taggable_type: self.class.base_class.to_s,
112
- tagger_type: owner.class.base_class.to_s, tagger_id: owner.id,
113
- tag_id: old_tags, context: context) if old_tags.present?
111
+ ActsAsTaggableOn::Tagging.where(taggable_id: id, taggable_type: self.class.base_class.to_s,
112
+ tagger_type: owner.class.base_class.to_s, tagger_id: owner.id,
113
+ tag_id: old_tags, context: context).destroy_all if old_tags.present?
114
114
 
115
115
  # Create new taggings:
116
116
  new_tags.each do |tag|