acts-as-taggable-on 3.4.4 → 3.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3150df9e4bb27c039d1bf451b14848f05867cd1
4
- data.tar.gz: 9451664d7c39a2bae61c254f8852b7c65101658c
3
+ metadata.gz: 92222646174fc38e87d9972cea2022c78e9ba337
4
+ data.tar.gz: 62d819d54ea8d538ce67d1f30c4c640e63333328
5
5
  SHA512:
6
- metadata.gz: 33408ad30bec8845467d740606689fff474a35ff5440ed15a5320ff2b3a56f2076d557f111409c788c2431f6dfb732a2713b0847880895ed6d5abf7aa86d4bc9
7
- data.tar.gz: 402c76125e5b27adbf531c9aeccf971af256b2b4545d92daa31b98a25beb3381820055075b6ae73e03efb7dd1c22495ae737655623b536c4703e7929002b624b
6
+ metadata.gz: 6a17ce74f9d91e98037faa3348449813632f2f1ba2a4ca92a297beaafa8e544b650c2e12586c03a9aab8c2c6b0b5c1c1de21571d860be49aed971b0d20b8338e
7
+ data.tar.gz: d50ea8e8200c3eaef6f1d80b53412637604e74de62dd3a2e6385e22d1fbf579bbb372f2bbd9b6c026f3f062e4959a288a5a890360d5f98cde6df222ebc72947f
@@ -4,13 +4,10 @@ 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.4...master)
7
+ ### [3.5.0 / 2015-02-11](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)
14
11
 
15
12
  ### [3.4.4 / 2015-02-11](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.3...v3.4.4)
16
13
 
data/Gemfile CHANGED
@@ -8,4 +8,4 @@ group :local_development do
8
8
  gem 'appraisal'
9
9
  gem 'rake'
10
10
  gem 'byebug' , platform: :mri_21
11
- end
11
+ end
data/README.md CHANGED
@@ -57,6 +57,22 @@ Review the generated migrations then migrate :
57
57
  rake db:migrate
58
58
  ```
59
59
 
60
+ #### For MySql users
61
+ 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:
62
+
63
+ ```ruby
64
+ ActsAsTaggableOn.force_binary_collation = true
65
+ ```
66
+
67
+ Or by running this rake task:
68
+
69
+ ```shell
70
+ rake acts_as_taggable_on_engine:tag_names:collate_bin
71
+ ```
72
+
73
+ See the Configuration section for more details, and a general note valid for older
74
+ version of the gem.
75
+
60
76
  #### Upgrading
61
77
 
62
78
  see [UPGRADING](UPGRADING.md)
@@ -407,13 +423,28 @@ If you would like tags to be case-sensitive and not use LIKE queries for creatio
407
423
  ActsAsTaggableOn.strict_case_match = true
408
424
  ```
409
425
 
426
+ If you would like to have an exact match covering special characters with MySql:
427
+
428
+ ```ruby
429
+ ActsAsTaggableOn.force_binary_collation = true
430
+ ```
431
+
410
432
  If you want to change the default delimiter (it defaults to ','). You can also pass in an array of delimiters such as ([',', '|']):
411
433
 
412
434
  ```ruby
413
435
  ActsAsTaggableOn.delimiter = ','
414
436
  ```
415
437
 
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)*
438
+ *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)*
439
+
440
+ *NOTE 2: the option `force_binary_collation` is strongest than `strict_case_match` and when
441
+ set to true, the `strict_case_match` is ignored.
442
+ 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:*
443
+
444
+ ```shell
445
+ USE my_wonderful_app_db;
446
+ ALTER TABLE tags MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin;
447
+ ```
417
448
 
418
449
  ## Contributors
419
450
 
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
 
@@ -4,4 +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
7
+ This will create any new migrations and skip existing ones
8
+ Version 3.5.0 has a migration for mysql adapter
@@ -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
@@ -69,6 +69,13 @@ module ActsAsTaggableOn
69
69
  @remove_unused_tags = false
70
70
  @tags_counter = true
71
71
  @default_parser = DefaultParser
72
+ @force_binary_collation = false
73
+ end
74
+
75
+ def strict_case_match=(force_cs)
76
+ if @force_binary_collation == false
77
+ @strict_case_match = force_cs
78
+ end
72
79
  end
73
80
 
74
81
  def delimiter=(string)
@@ -79,6 +86,30 @@ a ActsAsTaggableOn.default_parser instead
79
86
  WARNING
80
87
  @delimiter = string
81
88
  end
89
+
90
+ def force_binary_collation=(force_bin)
91
+ if Utils.using_mysql?
92
+ if force_bin == true
93
+ Configuration.apply_binary_collation(true)
94
+ @force_binary_collation = true
95
+ @strict_case_match = true
96
+ else
97
+ Configuration.apply_binary_collation(false)
98
+ @force_binary_collation = false
99
+ end
100
+ end
101
+ end
102
+
103
+ def self.apply_binary_collation(bincoll)
104
+ if Utils.using_mysql?
105
+ coll = 'utf8_general_ci'
106
+ if bincoll == true
107
+ coll = 'utf8_bin'
108
+ end
109
+ ActiveRecord::Migration.execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE #{coll};")
110
+ end
111
+ end
112
+
82
113
  end
83
114
 
84
115
  setup
@@ -6,7 +6,7 @@ module ActsAsTaggableOn
6
6
 
7
7
  ### ASSOCIATIONS:
8
8
 
9
- has_many :taggings, dependent: :destroy, class_name: 'ActsAsTaggableOn::Tagging'
9
+ has_many :taggings, dependent: :destroy, class_name: '::ActsAsTaggableOn::Tagging'
10
10
 
11
11
  ### VALIDATIONS:
12
12
 
@@ -80,8 +80,8 @@ module ActsAsTaggableOn
80
80
  self.preserve_tag_order = preserve_tag_order
81
81
 
82
82
  class_eval do
83
- has_many :taggings, as: :taggable, dependent: :destroy, class_name: 'ActsAsTaggableOn::Tagging'
84
- has_many :base_tags, through: :taggings, source: :tag, class_name: 'ActsAsTaggableOn::Tag'
83
+ has_many :taggings, as: :taggable, dependent: :destroy, class_name: '::ActsAsTaggableOn::Tagging'
84
+ has_many :base_tags, through: :taggings, source: :tag, class_name: '::ActsAsTaggableOn::Tag'
85
85
 
86
86
  def self.taggable?
87
87
  true
@@ -19,13 +19,13 @@ module ActsAsTaggableOn
19
19
  opts.merge(
20
20
  as: :tagger,
21
21
  dependent: :destroy,
22
- class_name: 'ActsAsTaggableOn::Tagging'
22
+ class_name: '::ActsAsTaggableOn::Tagging'
23
23
  )
24
24
 
25
25
  has_many_with_taggable_compatibility :owned_tags,
26
26
  through: :owned_taggings,
27
27
  source: :tag,
28
- class_name: 'ActsAsTaggableOn::Tag',
28
+ class_name: '::ActsAsTaggableOn::Tag',
29
29
  uniq: true
30
30
  end
31
31
 
@@ -11,7 +11,7 @@ module ActsAsTaggableOn
11
11
  :tagger_type,
12
12
  :tagger_id if defined?(ActiveModel::MassAssignmentSecurity)
13
13
 
14
- belongs_to :tag, class_name: 'ActsAsTaggableOn::Tag', counter_cache: ActsAsTaggableOn.tags_counter
14
+ belongs_to :tag, class_name: '::ActsAsTaggableOn::Tag', counter_cache: ActsAsTaggableOn.tags_counter
15
15
  belongs_to :taggable, polymorphic: true
16
16
  belongs_to :tagger, polymorphic: true
17
17
 
@@ -1,4 +1,4 @@
1
1
  module ActsAsTaggableOn
2
- VERSION = '3.4.4'
2
+ VERSION = '3.5.0'
3
3
  end
4
4
 
@@ -0,0 +1,21 @@
1
+ # These rake tasks are to be run by MySql users only, they fix the management of
2
+ # binary-encoded strings for tag 'names'. Issues:
3
+ # https://github.com/mbleigh/acts-as-taggable-on/issues/623
4
+
5
+ namespace :acts_as_taggable_on_engine do
6
+
7
+ namespace :tag_names do
8
+
9
+ desc "Forcing collate of tag names to utf8_bin"
10
+ task :collate_bin => [:environment] do |t, args|
11
+ ActsAsTaggableOn::Configuration.apply_binary_collation(true)
12
+ end
13
+
14
+ desc "Forcing collate of tag names to utf8_general_ci"
15
+ task :collate_ci => [:environment] do |t, args|
16
+ ActsAsTaggableOn::Configuration.apply_binary_collation(false)
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -2,6 +2,7 @@
2
2
  require 'spec_helper'
3
3
  require 'db/migrate/2_add_missing_unique_indices.rb'
4
4
 
5
+
5
6
  shared_examples_for 'without unique index' do
6
7
  prepend_before(:all) { AddMissingUniqueIndices.down }
7
8
  append_after(:all) do
@@ -309,7 +310,7 @@ describe ActsAsTaggableOn::Tag do
309
310
  tag.save!
310
311
  end
311
312
  end
312
-
313
+
313
314
  it 'should find the most popular tags' do
314
315
  expect(ActsAsTaggableOn::Tag.most_used(3).first.name).to eq("golden_syrup")
315
316
  expect(ActsAsTaggableOn::Tag.most_used(3).length).to eq(3)
@@ -320,4 +321,5 @@ describe ActsAsTaggableOn::Tag do
320
321
  expect(ActsAsTaggableOn::Tag.least_used(3).length).to eq(3)
321
322
  end
322
323
  end
324
+
323
325
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.4
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-11 00:00:00.000000000 Z
12
+ date: 2015-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -169,6 +169,7 @@ files:
169
169
  - db/migrate/2_add_missing_unique_indices.rb
170
170
  - db/migrate/3_add_taggings_counter_cache_to_tags.rb
171
171
  - db/migrate/4_add_missing_taggable_index.rb
172
+ - db/migrate/5_change_collation_for_tag_names.rb
172
173
  - gemfiles/activerecord_3.2.gemfile
173
174
  - gemfiles/activerecord_4.0.gemfile
174
175
  - gemfiles/activerecord_4.1.gemfile
@@ -194,6 +195,7 @@ files:
194
195
  - lib/acts_as_taggable_on/tags_helper.rb
195
196
  - lib/acts_as_taggable_on/utils.rb
196
197
  - lib/acts_as_taggable_on/version.rb
198
+ - lib/tasks/tags_collate_utf8.rake
197
199
  - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
198
200
  - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
199
201
  - spec/acts_as_taggable_on/caching_spec.rb
@@ -243,7 +245,8 @@ post_install_message: |-
243
245
 
244
246
  rake acts_as_taggable_on_engine:install:migrations
245
247
 
246
- It will create any new migrations and skip existing ones
248
+ This will create any new migrations and skip existing ones
249
+ Version 3.5.0 has a migration for mysql adapter
247
250
  rdoc_options: []
248
251
  require_paths:
249
252
  - lib