acts-as-taggable-on 3.4.2 → 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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +22 -29
  4. data/Appraisals +8 -13
  5. data/CHANGELOG.md +16 -10
  6. data/Gemfile +2 -2
  7. data/README.md +88 -20
  8. data/Rakefile +2 -0
  9. data/UPGRADING.md +2 -7
  10. data/acts-as-taggable-on.gemspec +3 -3
  11. data/db/migrate/2_add_missing_unique_indices.rb +3 -2
  12. data/db/migrate/5_change_collation_for_tag_names.rb +9 -0
  13. data/db/migrate/6_add_missing_indexes.rb +12 -0
  14. data/gemfiles/activerecord_4.0.gemfile +2 -0
  15. data/gemfiles/activerecord_4.1.gemfile +2 -0
  16. data/gemfiles/activerecord_4.2.gemfile +2 -3
  17. data/gemfiles/{activerecord_3.2.gemfile → activerecord_5.0.gemfile} +2 -1
  18. data/lib/acts-as-taggable-on.rb +40 -5
  19. data/lib/acts_as_taggable_on/engine.rb +0 -1
  20. data/lib/acts_as_taggable_on/tag.rb +7 -3
  21. data/lib/acts_as_taggable_on/tag_list.rb +2 -13
  22. data/lib/acts_as_taggable_on/taggable/cache.rb +5 -1
  23. data/lib/acts_as_taggable_on/taggable/collection.rb +6 -3
  24. data/lib/acts_as_taggable_on/taggable/core.rb +21 -16
  25. data/lib/acts_as_taggable_on/taggable/ownership.rb +3 -3
  26. data/lib/acts_as_taggable_on/taggable/related.rb +1 -1
  27. data/lib/acts_as_taggable_on/taggable.rb +2 -2
  28. data/lib/acts_as_taggable_on/tagger.rb +12 -11
  29. data/lib/acts_as_taggable_on/tagging.rb +5 -15
  30. data/lib/acts_as_taggable_on/utils.rb +3 -4
  31. data/lib/acts_as_taggable_on/version.rb +1 -1
  32. data/lib/tasks/tags_collate_utf8.rake +21 -0
  33. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +10 -1
  34. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +1 -1
  35. data/spec/acts_as_taggable_on/caching_spec.rb +28 -0
  36. data/spec/acts_as_taggable_on/related_spec.rb +9 -0
  37. data/spec/acts_as_taggable_on/tag_list_spec.rb +27 -1
  38. data/spec/acts_as_taggable_on/tag_spec.rb +18 -1
  39. data/spec/acts_as_taggable_on/taggable_spec.rb +19 -5
  40. data/spec/acts_as_taggable_on/tagging_spec.rb +64 -10
  41. data/spec/acts_as_taggable_on/utils_spec.rb +7 -0
  42. data/spec/internal/db/schema.rb +7 -3
  43. data/spec/support/database.rb +1 -7
  44. metadata +14 -28
  45. data/gemfiles/activerecord_edge.gemfile +0 -15
  46. data/lib/acts_as_taggable_on/compatibility.rb +0 -35
  47. data/lib/acts_as_taggable_on/tag_list_parser.rb +0 -21
  48. 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: ee9d316a00b3742d99175e8535a48fc94bf32f7c
4
- data.tar.gz: 0a2890ba670d7df947c9e3a271d81284abc9ef42
3
+ metadata.gz: 8ab1dc9bc4d03cd7fb2396284190f76719bc4a40
4
+ data.tar.gz: 8bbb5a13b5a1cc54aea59cb1ab6e524c31ea530c
5
5
  SHA512:
6
- metadata.gz: 3da825d4c0393da92b3eef9b8f94a140c7335ed6d810476bf3ba6ef7ccfa75409b9445713bebf8b13d4890be1b1c4aa3312197eaa57b9aedae713329c6203877
7
- data.tar.gz: 0fb39c27169059d20607f33bc649655474a73003e5a210f4f5706ff73416f558cbb7ca4c94b9268c72a89501e3a6003ea9f9593a3678e09efecf953da3c0a4e6
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,9 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+
1
4
  rvm:
2
- - 1.9.3
5
+ - 2.3.1
6
+ - 2.2.5
7
+ - 2.1
3
8
  - 2.0.0
4
- - 2.1.1
5
- - rbx-2
6
- - ruby-head
7
9
 
8
10
  env:
9
11
  - DB=sqlite3
@@ -11,33 +13,24 @@ env:
11
13
  - DB=postgresql
12
14
 
13
15
  gemfile:
14
- - gemfiles/activerecord_3.2.gemfile
15
- - gemfiles/activerecord_4.0.gemfile
16
+ - gemfiles/activerecord_5.0.gemfile
17
+ - gemfiles/activerecord_4.2.gemfile
16
18
  - gemfiles/activerecord_4.1.gemfile
17
- - gemfiles/activerecord_edge.gemfile
19
+ - gemfiles/activerecord_4.0.gemfile
20
+
21
+ sudo: false
22
+
23
+ bundler_args: '--without local_development --jobs 3 --retry 3'
24
+
25
+ before_install:
26
+ - gem install bundler
18
27
 
19
- cache: bundler
20
28
  script: bundle exec rake
21
- before_install: gem install bundler
22
- bundler_args: '--without local_development'
29
+
23
30
  matrix:
24
- fast_finish: true
25
- allow_failures:
26
- - gemfile: gemfiles/activerecord_edge.gemfile
27
- - rvm: rbx-2
28
- - rvm: ruby-head
29
31
  exclude:
30
- - rvm: 1.9.3
31
- gemfile: gemfiles/activerecord_4.0.gemfile
32
- - rvm: 1.9.3
33
- gemfile: gemfiles/activerecord_4.1.gemfile
34
- - rvm: 1.9.3
35
- gemfile: gemfiles/activerecord_edge.gemfile
36
- - rvm: rbx-2
37
- gemfile: gemfiles/activerecord_3.2.gemfile
38
- - rvm: ruby-head
39
- gemfile: gemfiles/activerecord_3.2.gemfile
40
- - rvm: ruby-head
41
- gemfile: gemfiles/activerecord_4.0.gemfile
42
- - rvm: ruby-head
43
- gemfile: gemfiles/activerecord_4.1.gemfile
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,22 +1,17 @@
1
- appraise "activerecord-3.2" do
2
- gem "activerecord", "~> 3.2"
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", "~> 4.0.0"
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
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", ">= 4.2.0.beta1"
15
- gem "activerecord", ">= 4.2.0.beta1"
16
- gem "rack", ">= 1.6.0.beta"
17
- end
18
-
19
- appraise "activerecord-edge" do
20
- gem "activerecord", github: "rails/rails"
21
- gem 'arel', github: 'rails/arel'
14
+ appraise "activerecord-4.0" do
15
+ gem "activerecord", "~> 4.0.0"
16
+ gem 'mysql2', '~> 0.3.21'
22
17
  end
data/CHANGELOG.md CHANGED
@@ -4,28 +4,34 @@ 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
- ### Master [changes](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.2...master)
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
- * Breaking Changes
10
- * Features
11
9
  * Fixes
12
- * Performance
13
- * Misc
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]()
13
+
14
+ ### [3.4.4 / 2015-02-11](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.3...v3.4.4)
15
+
16
+ * Fixes
17
+ * [@d4rky-pl Add context constraint to find_related_* methods](https://github.com/mbleigh/acts-as-taggable-on/pull/629)
18
+
19
+
20
+ ### [3.4.3 / 2014-09-26](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.2...v3.4.3)
21
+
22
+ * Fixes
23
+ * [@warp clears column cache on reset_column_information resolves](https://github.com/mbleigh/acts-as-taggable-on/pull/621)
14
24
 
15
25
  ### [3.4.2 / 2014-09-26](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.1...v3.4.2)
16
26
 
17
- * Breaking Changes
18
- * Features
19
27
  * Fixes
20
28
  * [@stiff fixed tagged_with :any in postgresql](https://github.com/mbleigh/acts-as-taggable-on/pull/570)
21
29
  * [@jerefrer fixed encoding in mysql](https://github.com/mbleigh/acts-as-taggable-on/pull/588)
22
30
  * [@markedmondson Ensure taggings context aliases are maintained when joining multiple taggables](https://github.com/mbleigh/acts-as-taggable-on/pull/589)
23
- * Performance
24
- * Misc
25
31
 
26
32
  ### [3.4.1 / 2014-09-01](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.0...v3.4.1)
27
33
  * Fixes
28
- * [@konukhov fix owned ordered taggable bug]((https://github.com/mbleigh/acts-as-taggable-on/pull/585)
34
+ * [@konukhov fix owned ordered taggable bug](https://github.com/mbleigh/acts-as-taggable-on/pull/585)
29
35
 
30
36
  ### [3.4.0 / 2014-08-29](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.3.0...v3.4.0)
31
37
 
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
11
- end
10
+ gem 'byebug' , platforms: [:mri_21, :mri_22, :mri_23]
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
22
 
24
- Versions 2.4.1 and up are compatible with Rails 4 too (thanks to arabonradar and cwoodcox).
25
-
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/issues/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 :
@@ -57,9 +49,22 @@ Review the generated migrations then migrate :
57
49
  rake db:migrate
58
50
  ```
59
51
 
60
- #### Upgrading
52
+ #### For MySql users
53
+ 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
+
55
+ ```ruby
56
+ ActsAsTaggableOn.force_binary_collation = true
57
+ ```
58
+
59
+ Or by running this rake task:
60
+
61
+ ```shell
62
+ rake acts_as_taggable_on_engine:tag_names:collate_bin
63
+ ```
64
+
65
+ See the Configuration section for more details, and a general note valid for older
66
+ version of the gem.
61
67
 
62
- see [UPGRADING](UPGRADING.md)
63
68
 
64
69
  ## Usage
65
70
 
@@ -180,7 +185,7 @@ ActsAsTaggableOn::Tag.most_used
180
185
  ActsAsTaggableOn::Tag.least_used
181
186
  ```
182
187
 
183
- You can also filter the results by passing the method a limit, however the default limit is 50.
188
+ You can also filter the results by passing the method a limit, however the default limit is 20.
184
189
 
185
190
  ```ruby
186
191
  ActsAsTaggableOn::Tag.most_used(10)
@@ -257,12 +262,12 @@ User.tagged_with("same", :on => :customs) # => [@user]
257
262
 
258
263
  ### Tag Parsers
259
264
 
260
- 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:
261
266
 
262
267
  ```ruby
263
268
  class MyParser < ActsAsTaggableOn::GenericParser
264
269
  def parse
265
- TagList.new.tap do |tag_list|
270
+ ActsAsTaggableOn::TagList.new.tap do |tag_list|
266
271
  tag_list.add @tag_list.split('|')
267
272
  end
268
273
  end
@@ -286,7 +291,7 @@ Now you can use this parser, passing it as parameter:
286
291
  Or change it globally:
287
292
 
288
293
  ```ruby
289
- ActsAsTaggable.default_parser = MyParser
294
+ ActsAsTaggableOn.default_parser = MyParser
290
295
  @user = User.new(:name => "Bobby")
291
296
  @user.tag_list = "east|south"
292
297
  @user.tag_list # => ["east", "south"]
@@ -315,6 +320,42 @@ Photo.tagged_with("paris", :on => :locations, :owned_by => @some_user)
315
320
  @some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object
316
321
  ```
317
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
+
318
359
  ### Dirty objects
319
360
 
320
361
  ```ruby
@@ -407,21 +448,48 @@ If you would like tags to be case-sensitive and not use LIKE queries for creatio
407
448
  ActsAsTaggableOn.strict_case_match = true
408
449
  ```
409
450
 
451
+ If you would like to have an exact match covering special characters with MySql:
452
+
453
+ ```ruby
454
+ ActsAsTaggableOn.force_binary_collation = true
455
+ ```
456
+
410
457
  If you want to change the default delimiter (it defaults to ','). You can also pass in an array of delimiters such as ([',', '|']):
411
458
 
412
459
  ```ruby
413
460
  ActsAsTaggableOn.delimiter = ','
414
461
  ```
415
462
 
416
- *NOTE: SQLite by default can't upcase or downcase multibyte characters, resulting in unwanted behavior. Load the SQLite ICU extension for proper handle of such characters. [See docs](http://www.sqlite.org/src/artifact?ci=trunk&filename=ext/icu/README.txt)*
463
+ *NOTE 1: SQLite by default can't upcase or downcase multibyte characters, resulting in unwanted behavior. Load the SQLite ICU extension for proper handle of such characters. [See docs](http://www.sqlite.org/src/artifact?ci=trunk&filename=ext/icu/README.txt)*
464
+
465
+ *NOTE 2: the option `force_binary_collation` is strongest than `strict_case_match` and when
466
+ set to true, the `strict_case_match` is ignored.
467
+ To roughly apply the `force_binary_collation` behaviour with a version of the gem <= 3.4.4, execute the following commands in the MySql console:*
468
+
469
+ ```shell
470
+ USE my_wonderful_app_db;
471
+ ALTER TABLE tags MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin;
472
+ ```
473
+
474
+ #### Upgrading
475
+
476
+ see [UPGRADING](UPGRADING.md)
417
477
 
418
478
  ## Contributors
419
479
 
420
480
  We have a long list of valued contributors. [Check them all](https://github.com/mbleigh/acts-as-taggable-on/contributors)
421
481
 
422
- ## 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).
487
+
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.
423
491
 
424
- * [Joost Baaij](https://github.com/tilsammans)
492
+ For an up-to-date roadmap, see https://github.com/mbleigh/acts-as-taggable-on/milestones
425
493
 
426
494
  ## TODO
427
495
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
+ import "./lib/tasks/tags_collate_utf8.rake"
5
+
4
6
  desc 'Default: run specs'
5
7
  task default: :spec
6
8
 
data/UPGRADING.md CHANGED
@@ -4,10 +4,5 @@ Re-run the migrations generator
4
4
 
5
5
  rake acts_as_taggable_on_engine:install:migrations
6
6
 
7
- It will create any new migrations and skip existing ones
8
-
9
-
10
- ##Breaking changes:
11
-
12
- - ActsAsTaggableOn::Tag is not extend with ActsAsTaggableOn::Utils anymore.
13
- Please use ActsAsTaggableOn::Utils instead
7
+ This will create any new migrations and skip existing ones
8
+ Version 3.5.0 has a migration for mysql adapter
@@ -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,9 @@
1
+ # This migration is added to circumvent issue #623 and have special characters
2
+ # work properly
3
+ class ChangeCollationForTagNames < ActiveRecord::Migration
4
+ def up
5
+ if ActsAsTaggableOn::Utils.using_mysql?
6
+ execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
7
+ end
8
+ end
9
+ 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
@@ -3,12 +3,14 @@
3
3
  source "https://rubygems.org"
4
4
 
5
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"
13
+ gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
12
14
  end
13
15
 
14
16
  gemspec :path => "../"
@@ -3,12 +3,14 @@
3
3
  source "https://rubygems.org"
4
4
 
5
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"
13
+ gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
12
14
  end
13
15
 
14
16
  gemspec :path => "../"
@@ -2,15 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "railties", ">= 4.2.0.beta1"
6
- gem "activerecord", ">= 4.2.0.beta1"
7
- gem "rack", ">= 1.6.0.beta"
5
+ gem "activerecord", "~> 4.2.0"
8
6
 
9
7
  group :local_development do
10
8
  gem "guard"
11
9
  gem "guard-rspec"
12
10
  gem "appraisal"
13
11
  gem "rake"
12
+ gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
14
13
  end
15
14
 
16
15
  gemspec :path => "../"
@@ -2,13 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.2"
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", :platforms => [:mri_21, :mri_22, :mri_23]
12
13
  end
13
14
 
14
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 = ','
@@ -69,6 +74,11 @@ module ActsAsTaggableOn
69
74
  @remove_unused_tags = false
70
75
  @tags_counter = true
71
76
  @default_parser = DefaultParser
77
+ @force_binary_collation = false
78
+ end
79
+
80
+ def strict_case_match=(force_cs)
81
+ @strict_case_match = force_cs unless @force_binary_collation
72
82
  end
73
83
 
74
84
  def delimiter=(string)
@@ -79,13 +89,38 @@ a ActsAsTaggableOn.default_parser instead
79
89
  WARNING
80
90
  @delimiter = string
81
91
  end
92
+
93
+ def force_binary_collation=(force_bin)
94
+ if Utils.using_mysql?
95
+ if force_bin
96
+ Configuration.apply_binary_collation(true)
97
+ @force_binary_collation = true
98
+ @strict_case_match = true
99
+ else
100
+ Configuration.apply_binary_collation(false)
101
+ @force_binary_collation = false
102
+ end
103
+ end
104
+ end
105
+
106
+ def self.apply_binary_collation(bincoll)
107
+ if Utils.using_mysql?
108
+ coll = 'utf8_general_ci'
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."
114
+ end
115
+ end
116
+ end
117
+
82
118
  end
83
119
 
84
120
  setup
85
121
  end
86
122
 
87
123
  ActiveSupport.on_load(:active_record) do
88
- extend ActsAsTaggableOn::Compatibility
89
124
  extend ActsAsTaggableOn::Taggable
90
125
  include ActsAsTaggableOn::Tagger
91
126
  end
@@ -1,4 +1,3 @@
1
- require 'rails/engine'
2
1
  module ActsAsTaggableOn
3
2
  class Engine < Rails::Engine
4
3
  end
@@ -2,11 +2,9 @@
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
- has_many :taggings, dependent: :destroy, class_name: 'ActsAsTaggableOn::Tagging'
7
+ has_many :taggings, dependent: :destroy, class_name: '::ActsAsTaggableOn::Tagging'
10
8
 
11
9
  ### VALIDATIONS:
12
10
 
@@ -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