acts-as-taggable-on 5.0.0 → 6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f768ffeb2be31c4e8e131a9b89f796a325aba09f
4
- data.tar.gz: d4528a4f594547d31f508300b8188b17fe507295
2
+ SHA256:
3
+ metadata.gz: fe5fa5ea1924bedec74d51412d0c11dbde1ef9338cd62990105c9e67ad46366b
4
+ data.tar.gz: 3a969a26de5b8c9d96e776db6d7597558385c98a0c174062f98c6df1ee86868d
5
5
  SHA512:
6
- metadata.gz: 4246008aa86bb98b30fcb23787e5ddc94af40d8b677701a202ea6db8be2fe30cbab2117bc8b4eb2e2803f02605e392d5bd271ce77155a45d631f9ae6a3f83451
7
- data.tar.gz: 6df3714193f6004ff5d69e4bd54f54b866804dcfcb6b6d08721302c22f7da442005b19200a43628b0e5e734dcbf3a5e892435fcda2652c24ea62635c3bff5d4b
6
+ metadata.gz: f6c71ae58961f24310da59aaba97995f17170e454c66f22f34f86b7aedb85a9d5a8ddc1adb05f439c05b9adde51695a42e86a1a7552de862b80c2367caecac21
7
+ data.tar.gz: a4b6c33320bfb0d35177bc8997292ce033ea3fd1f87ccc04dd3c579d3ab7023087e189b488a2fcbcce6ba1848fbca8e4b8e47bc7f8e9d0ae5ad4fcff53a48a90
data/.gitignore CHANGED
@@ -9,5 +9,5 @@ tmp*.sw?
9
9
  tmp
10
10
  *.gem
11
11
  *.lock
12
-
12
+ *.iml
13
13
  /.idea
@@ -2,8 +2,10 @@ language: ruby
2
2
  cache: bundler
3
3
 
4
4
  rvm:
5
- - 2.4.1
6
- - 2.3.3
5
+ - ruby-head
6
+ - 2.5.1
7
+ - 2.4.4
8
+ - 2.3.7
7
9
  - 2.2.7
8
10
 
9
11
  env:
@@ -12,9 +14,9 @@ env:
12
14
  - DB=postgresql
13
15
 
14
16
  gemfile:
17
+ - gemfiles/activerecord_5.2.gemfile
15
18
  - gemfiles/activerecord_5.1.gemfile
16
19
  - gemfiles/activerecord_5.0.gemfile
17
- - gemfiles/activerecord_4.2.gemfile
18
20
 
19
21
  sudo: false
20
22
 
@@ -26,4 +28,6 @@ before_install:
26
28
  script: bundle exec rake
27
29
 
28
30
  matrix:
31
+ allow_failures:
32
+ - rvm: ruby-head
29
33
  fast_finish: true
data/Appraisals CHANGED
@@ -1,3 +1,7 @@
1
+ appraise 'activerecord-5.2' do
2
+ gem 'activerecord', '~> 5.2.0'
3
+ end
4
+
1
5
  appraise 'activerecord-5.1' do
2
6
  gem 'activerecord', "~> 5.1.1"
3
7
  end
@@ -5,7 +9,3 @@ end
5
9
  appraise 'activerecord-5.0' do
6
10
  gem 'activerecord', "~> 5.0.3"
7
11
  end
8
-
9
- appraise "activerecord-4.2" do
10
- gem "activerecord", "~> 4.2.8"
11
- end
@@ -4,6 +4,15 @@ 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
+ ### [6.0.0 / 2017-06-19](https://github.com/mbleigh/acts-as-taggable-on/compare/v5.0.0...v6.0.0)
8
+ * Breaking Changes
9
+ * [@Fodoj Drop support for Rails 4.2](https://github.com/mbleigh/acts-as-taggable-on/pull/887)
10
+ * Added
11
+ * [@CalvertYang Add support for uuid primary keys](https://github.com/mbleigh/acts-as-taggable-on/pull/898)
12
+ * [@Fodoj Support Rails 5.2](https://github.com/mbleigh/acts-as-taggable-on/pull/887)
13
+ * Fixes
14
+ * [@tekniklr matches_attribute was not being used in tag_match_type](https://github.com/mbleigh/acts-as-taggable-on/pull/869)
15
+
7
16
  ### [5.0.0 / 2017-05-18](https://github.com/mbleigh/acts-as-taggable-on/compare/v4.0.0...v5.0.0)
8
17
  * Breaking Changes
9
18
  * [@seuros Drop support for old version of ActiveRecord and Ruby and prepare rel](https://github.com/mbleigh/acts-as-taggable-on/pull/828)
@@ -47,36 +56,26 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch.
47
56
  * [@jh125486 Fixed wildcard test (postgres returning rows with unexpected order)] (https://github.com/mbleigh/acts-as-taggable-on/pull/660 )
48
57
  * [@FlowerWrong Add rails 5.0.0 alpha support, not hack rails <5](https://github.com/mbleigh/acts-as-taggable-on/pull/673 )
49
58
  * [@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)
59
+ * [@ zapnap scope tags to specific tagging ](https://github.com/mbleigh/acts-as-taggable-on/pull/697 )
60
+ * [@ amatsuda method redefined](https://github.com/mbleigh/acts-as-taggable-on/pull/715 )
61
+ * [@ klacointe Rails 5: Tagger is optional in Tagging relation](https://github.com/mbleigh/acts-as-taggable-on/pull/720 )
62
+ * [@ 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 )
63
+ * [@ lukeasrodgers BugFix flackey time test ](https://github.com/mbleigh/acts-as-taggable-on/pull/727)
64
+ * [@ pcupueran Add rspec tests for context scopes for tagging_spec ]( https://github.com/mbleigh/acts-as-taggable-on/pull/740)
65
+ * [@ Emerson Huitt Remove existing selects from relation ]( https://github.com/mbleigh/acts-as-taggable-on/pull/743)
66
+ * [@keerthisiv fix issue with custom delimiter]( https://github.com/mbleigh/acts-as-taggable-on/pull/748)
67
+ * [@priyank-gupta specify tag table name for mysql collation query ](https://github.com/mbleigh/acts-as-taggable-on/pull/760)
68
+ * [@seuros Remove warning messages](https://github.com/mbleigh/acts-as-taggable-on/commit/cda08c764b07a18b8582b948d1c5b3910a376965)
69
+ * [@rbritom Fix migration, #references already adds index ](https://github.com/mbleigh/acts-as-taggable-on/commit/95f743010954b6b738a6e8c17315112c878f7a81)
70
+ * [@rbritom Fix deprecation warning](https://github.com/mbleigh/acts-as-taggable-on/commit/62e4a6fa74ae3faed615683cd3ad5b5cdacf5c96 )
71
+ * [@rbritom fix scope array arguments ](https://github.com/mbleigh/acts-as-taggable-on/commit/a415a8d6367b2e91bd7e363589135f953929b8cc )
72
+ * [@seuros Remove more deprecations ](https://github.com/mbleigh/acts-as-taggable-on/commit/05794170f64f8bf250b34d2d594e368721009278)
73
+ * [@lukeasrodgers Bugfix `TagList#concat` with non-duplicates. ](https://github.com/mbleigh/acts-as-taggable-on/commit/2c6214f0ddf8c6440ab81eec04d1fbf9d97c8826)
74
+ * [@seuros clean! should return self. ](https://github.com/mbleigh/acts-as-taggable-on/commit/c739422f56f8ff37e3f321235e74997422a1c980)
75
+ * [@rbritom renable appraisals ](https://github.com/mbleigh/acts-as-taggable-on/commit/0ca1f1c5b059699c683a28b522e86a3d5cd7639e)
76
+ * [@rbritom remove index conditionally on up method. ](https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
77
+ *[@rbritom add index on down method . ](https://github.com/mbleigh/acts-as-taggable-on/pull/767)
78
+ * [@rbritom remove index conditionally on up method](https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
80
79
 
81
80
  * Documentation
82
81
  * [@logicminds Adds table of contents using doctoc utility](https://github.com/mbleigh/acts-as-taggable-on/pull/803)
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # gemspec
3
+ gemspec
4
4
 
5
5
  group :local_development do
6
6
  gem 'guard'
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
@@ -57,7 +57,7 @@ was used.
57
57
  To use it, add it to your Gemfile:
58
58
 
59
59
  ```ruby
60
- gem 'acts-as-taggable-on', '~> 4.0'
60
+ gem 'acts-as-taggable-on', '~> 5.0'
61
61
  ```
62
62
 
63
63
  and bundle:
@@ -22,11 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.post_install_message = File.read('UPGRADING.md')
23
23
  end
24
24
 
25
- gem.add_runtime_dependency 'activerecord', ['>= 4.2.8']
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']
30
26
 
31
27
  gem.add_development_dependency 'rspec-rails'
32
28
  gem.add_development_dependency 'rspec-its'
@@ -3,6 +3,14 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.0.3"
6
+ case ENV["DB"]
7
+ when "postgresql"
8
+ gem 'pg'
9
+ when "mysql"
10
+ gem 'mysql2', '~> 0.3'
11
+ else
12
+ gem 'sqlite3'
13
+ end
6
14
 
7
15
  group :local_development do
8
16
  gem "guard"
@@ -3,6 +3,14 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.1.1"
6
+ case ENV["DB"]
7
+ when "postgresql"
8
+ gem 'pg'
9
+ when "mysql"
10
+ gem 'mysql2', '~> 0.3'
11
+ else
12
+ gem 'sqlite3'
13
+ end
6
14
 
7
15
  group :local_development do
8
16
  gem "guard"
@@ -2,7 +2,15 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.2.8"
5
+ gem "activerecord", "~> 5.2.0"
6
+ case ENV["DB"]
7
+ when "postgresql"
8
+ gem 'pg'
9
+ when "mysql"
10
+ gem 'mysql2', '~> 0.3'
11
+ else
12
+ gem 'sqlite3'
13
+ end
6
14
 
7
15
  group :local_development do
8
16
  gem "guard"
@@ -96,7 +96,6 @@ module ActsAsTaggableOn
96
96
  include Cache
97
97
  include Ownership
98
98
  include Related
99
- include Dirty
100
99
  end
101
100
  end
102
101
  end
@@ -174,7 +174,7 @@ module ActsAsTaggableOn::Taggable
174
174
  # See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb#L38
175
175
  def count(column_name = :all, options = {})
176
176
  # https://github.com/rails/rails/commit/da9b5d4a8435b744fcf278fffd6d7f1e36d4a4f2
177
- ActsAsTaggableOn::Utils.active_record5? ? super(column_name) : super(column_name, options)
177
+ super(column_name)
178
178
  end
179
179
  end
180
180
  end
@@ -2,6 +2,7 @@ require_relative 'tagged_with_query'
2
2
 
3
3
  module ActsAsTaggableOn::Taggable
4
4
  module Core
5
+
5
6
  def self.included(base)
6
7
  base.extend ActsAsTaggableOn::Taggable::Core::ClassMethods
7
8
 
@@ -28,12 +29,16 @@ module ActsAsTaggableOn::Taggable
28
29
  has_many context_taggings, -> { includes(:tag).order(taggings_order).where(context: tags_type) },
29
30
  as: :taggable,
30
31
  class_name: 'ActsAsTaggableOn::Tagging',
31
- dependent: :destroy
32
+ dependent: :destroy,
33
+ after_add: :dirtify_tag_list,
34
+ after_remove: :dirtify_tag_list
32
35
 
33
36
  has_many context_tags, -> { order(taggings_order) },
34
37
  class_name: 'ActsAsTaggableOn::Tag',
35
38
  through: context_taggings,
36
39
  source: :tag
40
+
41
+ attribute "#{tags_type.singularize}_list".to_sym, ActiveModel::Type::Value.new
37
42
  end
38
43
 
39
44
  taggable_mixin.class_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -42,12 +47,24 @@ module ActsAsTaggableOn::Taggable
42
47
  end
43
48
 
44
49
  def #{tag_type}_list=(new_tags)
50
+ parsed_new_list = ActsAsTaggableOn.default_parser.new(new_tags).parse
51
+
52
+ if self.class.preserve_tag_order? || parsed_new_list.sort != #{tag_type}_list.sort
53
+ set_attribute_was('#{tag_type}_list', #{tag_type}_list)
54
+ write_attribute("#{tag_type}_list", parsed_new_list)
55
+ end
56
+
45
57
  set_tag_list_on('#{tags_type}', new_tags)
46
58
  end
47
59
 
48
60
  def all_#{tags_type}_list
49
61
  all_tags_list_on('#{tags_type}')
50
62
  end
63
+
64
+ private
65
+ def dirtify_tag_list(tagging)
66
+ attribute_will_change! tagging.context.singularize+"_list"
67
+ end
51
68
  RUBY
52
69
  end
53
70
  end
@@ -161,7 +178,7 @@ module ActsAsTaggableOn::Taggable
161
178
 
162
179
  if ActsAsTaggableOn::Utils.using_postgresql?
163
180
  group_columns = grouped_column_names_for(ActsAsTaggableOn::Tag)
164
- scope.order("max(#{tagging_table_name}.created_at)").group(group_columns)
181
+ scope.order(Arel.sql("max(#{tagging_table_name}.created_at)")).group(group_columns)
165
182
  else
166
183
  scope.group("#{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key}")
167
184
  end.to_a
@@ -181,33 +198,16 @@ module ActsAsTaggableOn::Taggable
181
198
  add_custom_context(context)
182
199
 
183
200
  variable_name = "@#{context.to_s.singularize}_list"
184
- process_dirty_object(context, new_list) unless custom_contexts.include?(context.to_s)
185
201
 
186
- instance_variable_set(variable_name, ActsAsTaggableOn.default_parser.new(new_list).parse)
202
+ parsed_new_list = ActsAsTaggableOn.default_parser.new(new_list).parse
203
+
204
+ instance_variable_set(variable_name, parsed_new_list)
187
205
  end
188
206
 
189
207
  def tagging_contexts
190
208
  self.class.tag_types.map(&:to_s) + custom_contexts
191
209
  end
192
210
 
193
- def process_dirty_object(context, new_list)
194
- value = new_list.is_a?(Array) ? ActsAsTaggableOn::TagList.new(new_list) : new_list
195
- attrib = "#{context.to_s.singularize}_list"
196
-
197
- if changed_attributes.include?(attrib)
198
- # The attribute already has an unsaved change.
199
- old = changed_attributes[attrib]
200
- @changed_attributes.delete(attrib) if old.to_s == value.to_s
201
- else
202
- old = tag_list_on(context)
203
- if self.class.preserve_tag_order
204
- @changed_attributes[attrib] = old if old.to_s != value.to_s
205
- else
206
- @changed_attributes[attrib] = old.to_s if old.sort != ActsAsTaggableOn.default_parser.new(value).parse.sort
207
- end
208
- end
209
- end
210
-
211
211
  def reload(*args)
212
212
  self.class.tag_types.each do |context|
213
213
  instance_variable_set("@#{context.to_s.singularize}_list", nil)
@@ -315,3 +315,4 @@ module ActsAsTaggableOn::Taggable
315
315
  end
316
316
  end
317
317
  end
318
+
@@ -49,7 +49,7 @@ module ActsAsTaggableOn::Taggable
49
49
  end
50
50
 
51
51
  def owner_tags_on(owner, context)
52
- scope = owner_tags(owner).where(
52
+ owner_tags(owner).where(
53
53
  "#{ActsAsTaggableOn::Tagging.table_name}" => {
54
54
  context: context
55
55
  }
@@ -49,7 +49,7 @@ module ActsAsTaggableOn::Taggable
49
49
  private
50
50
 
51
51
  def exclude_self(klass, id)
52
- "#{klass.table_name}.#{klass.primary_key} != #{id} AND" if [self.class.base_class, self.class].include? klass
52
+ "#{klass.arel_table[klass.primary_key].not_eq(id).to_sql} AND" if [self.class.base_class, self.class].include? klass
53
53
  end
54
54
 
55
55
  def group_columns(klass)
@@ -49,12 +49,10 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
49
49
  end
50
50
 
51
51
  if options[:on].present?
52
- on_condition = on_condition.and(tagging_alias[:context].lteq(options[:on]))
52
+ on_condition = on_condition.and(tagging_alias[:context].eq(options[:on]))
53
53
  end
54
54
 
55
55
  if (owner = options[:owned_by]).present?
56
- owner_table = owner.class.base_class.arel_table
57
-
58
56
  on_condition = on_condition.and(tagging_alias[:tagger_id].eq(owner.id))
59
57
  .and(tagging_alias[:tagger_type].eq(owner.class.base_class.to_s))
60
58
  end
@@ -75,7 +73,7 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
75
73
  end
76
74
 
77
75
  if options[:on].present?
78
- on_condition = on_condition.and(tagging_arel_table[:context].lteq(options[:on]))
76
+ on_condition = on_condition.and(tagging_arel_table[:context].eq(options[:on]))
79
77
  end
80
78
 
81
79
  on_condition
@@ -3,7 +3,7 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
3
3
  def build
4
4
  taggable_model.select(all_fields)
5
5
  .where(model_has_at_least_one_tag)
6
- .order(order_conditions)
6
+ .order(Arel.sql(order_conditions))
7
7
  .readonly(false)
8
8
  end
9
9
 
@@ -14,9 +14,6 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
14
14
  end
15
15
 
16
16
  def model_has_at_least_one_tag
17
- tagging_alias = tagging_arel_table.alias(alias_name(tag_list))
18
-
19
-
20
17
  tagging_arel_table.project(Arel.star).where(at_least_one_tag).exists
21
18
  end
22
19
 
@@ -38,12 +35,10 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
38
35
  end
39
36
 
40
37
  if options[:on].present?
41
- exists_contition = exists_contition.and(tagging_arel_table[:context].lteq(options[:on]))
38
+ exists_contition = exists_contition.and(tagging_arel_table[:context].eq(options[:on]))
42
39
  end
43
40
 
44
41
  if (owner = options[:owned_by]).present?
45
- owner_table = owner.class.base_class.arel_table
46
-
47
42
  exists_contition = exists_contition.and(tagging_arel_table[:tagger_id].eq(owner.id))
48
43
  .and(tagging_arel_table[:tagger_type].eq(owner.class.base_class.to_s))
49
44
  end
@@ -63,7 +63,7 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
63
63
  end
64
64
 
65
65
  if options[:on].present?
66
- on_condition = on_condition.and(tagging_arel_table[:context].lteq(options[:on]))
66
+ on_condition = on_condition.and(tagging_arel_table[:context].eq(options[:on]))
67
67
  end
68
68
 
69
69
  on_condition
@@ -29,9 +29,9 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
29
29
  matches_attribute = matches_attribute.lower unless ActsAsTaggableOn.strict_case_match
30
30
 
31
31
  if options[:wild].present?
32
- tag_arel_table[:name].matches("%#{escaped_tag(tag)}%", "!")
32
+ matches_attribute.matches("%#{escaped_tag(tag)}%", "!")
33
33
  else
34
- tag_arel_table[:name].matches(escaped_tag(tag), "!")
34
+ matches_attribute.matches(escaped_tag(tag), "!")
35
35
  end
36
36
  end
37
37
 
@@ -48,7 +48,7 @@ module ActsAsTaggableOn::Taggable::TaggedWithQuery
48
48
 
49
49
  def escaped_tag(tag)
50
50
  tag = tag.downcase unless ActsAsTaggableOn.strict_case_match
51
- tag.gsub(/[!%_]/) { |x| '!' + x }
51
+ ActsAsTaggableOn::Utils.escape_like(tag)
52
52
  end
53
53
 
54
54
  def adjust_taggings_alias(taggings_alias)
@@ -4,7 +4,7 @@ module ActsAsTaggableOn
4
4
  belongs_to :tag, class_name: '::ActsAsTaggableOn::Tag', counter_cache: ActsAsTaggableOn.tags_counter
5
5
  belongs_to :taggable, polymorphic: true
6
6
 
7
- belongs_to :tagger, {polymorphic: true}.tap {|o| o.merge!(optional: true) if ActsAsTaggableOn::Utils.active_record5? }
7
+ belongs_to :tagger, {polymorphic: true}.tap {|o| o.merge!(optional: true) }
8
8
 
9
9
  scope :owned_by, ->(owner) { where(tagger: owner) }
10
10
  scope :not_owned, -> { where(tagger_id: nil, tagger_type: nil) }
@@ -20,10 +20,6 @@ module ActsAsTaggableOn
20
20
  Digest::SHA1.hexdigest(string)[0..6]
21
21
  end
22
22
 
23
- def active_record5?
24
- ::ActiveRecord::VERSION::MAJOR == 5
25
- end
26
-
27
23
  def like_operator
28
24
  using_postgresql? ? 'ILIKE' : 'LIKE'
29
25
  end
@@ -1,4 +1,4 @@
1
1
  module ActsAsTaggableOn
2
- VERSION = '5.0.0'
2
+ VERSION = '6.0.0'
3
3
  end
4
4
 
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'spec_helper'
3
3
 
4
- describe ActsAsTaggableOn::Taggable::Dirty do
4
+ describe 'Dirty behavior of taggable objects' do
5
5
  context 'with un-contexted tags' do
6
6
  before(:each) do
7
7
  @taggable = TaggableModel.create(tag_list: 'awesome, epic')
@@ -14,19 +14,27 @@ describe ActsAsTaggableOn::Taggable::Dirty do
14
14
  end
15
15
 
16
16
  it 'should show changes of dirty object' do
17
- expect(@taggable.changes).to eq({'tag_list' => ['awesome, epic', ['one']]})
17
+ expect(@taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
18
18
  end
19
19
 
20
- it 'flags tag_list as changed' do
21
- expect(@taggable.tag_list_changed?).to be_truthy
20
+ it 'should show changes of freshly initialized dirty object' do
21
+ taggable = TaggableModel.find(@taggable.id)
22
+ taggable.tag_list = 'one'
23
+ expect(taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
24
+ end
25
+
26
+ if Rails.version >= "5.1"
27
+ it 'flags tag_list as changed' do
28
+ expect(@taggable.will_save_change_to_tag_list?).to be_truthy
29
+ end
22
30
  end
23
31
 
24
32
  it 'preserves original value' do
25
- expect(@taggable.tag_list_was).to eq('awesome, epic')
33
+ expect(@taggable.tag_list_was).to eq(['awesome', 'epic'])
26
34
  end
27
35
 
28
36
  it 'shows what the change was' do
29
- expect(@taggable.tag_list_change).to eq(['awesome, epic', ['one']])
37
+ expect(@taggable.tag_list_change).to eq([['awesome', 'epic'], ['one']])
30
38
  end
31
39
 
32
40
  context 'without order' do
@@ -90,7 +98,7 @@ describe ActsAsTaggableOn::Taggable::Dirty do
90
98
  end
91
99
 
92
100
  it 'should show changes of dirty object' do
93
- expect(@taggable.changes).to eq({'language_list' => ['awesome, epic', ['one']]})
101
+ expect(@taggable.changes).to eq({'language_list' => [['awesome', 'epic'], ['one']]})
94
102
  end
95
103
 
96
104
  it 'flags language_list as changed' do
@@ -98,15 +106,11 @@ describe ActsAsTaggableOn::Taggable::Dirty do
98
106
  end
99
107
 
100
108
  it 'preserves original value' do
101
- expect(@taggable.language_list_was).to eq('awesome, epic')
109
+ expect(@taggable.language_list_was).to eq(['awesome', 'epic'])
102
110
  end
103
111
 
104
112
  it 'shows what the change was' do
105
- expect(@taggable.language_list_change).to eq(['awesome, epic', ['one']])
106
- end
107
-
108
- it 'shows what the changes were' do
109
- expect(@taggable.language_list_changes).to eq(['awesome, epic', ['one']])
113
+ expect(@taggable.language_list_change).to eq([['awesome', 'epic'], ['one']])
110
114
  end
111
115
  end
112
116
 
@@ -123,5 +127,16 @@ describe ActsAsTaggableOn::Taggable::Dirty do
123
127
  expect(@taggable.changes).to be_empty
124
128
  end
125
129
  end
130
+
131
+ context 'when language_list changed by association' do
132
+ let(:tag) { ActsAsTaggableOn::Tag.new(name: 'one') }
133
+
134
+ it 'flags language_list as changed' do
135
+ expect(@taggable.changes).to be_empty
136
+ @taggable.languages << tag
137
+ expect(@taggable.language_list_changed?).to be_truthy
138
+ end
139
+ end
140
+
126
141
  end
127
142
  end
@@ -255,14 +255,17 @@ describe 'Taggable' do
255
255
  end
256
256
 
257
257
  it 'should be able to find by tag with context' do
258
- @taggable.skill_list = 'ruby, rails, css'
259
- @taggable.tag_list = 'bob, charlie'
258
+ @taggable.skill_list = 'ruby, rails, css, julia'
259
+ @taggable.tag_list = 'bob, charlie, julia'
260
260
  @taggable.save
261
261
 
262
262
  expect(TaggableModel.tagged_with('ruby').first).to eq(@taggable)
263
263
  expect(TaggableModel.tagged_with('ruby, css').first).to eq(@taggable)
264
264
  expect(TaggableModel.tagged_with('bob', on: :skills).first).to_not eq(@taggable)
265
265
  expect(TaggableModel.tagged_with('bob', on: :tags).first).to eq(@taggable)
266
+ expect(TaggableModel.tagged_with('julia', on: :skills).size).to eq(1)
267
+ expect(TaggableModel.tagged_with('julia', on: :tags).size).to eq(1)
268
+ expect(TaggableModel.tagged_with('julia', on: nil).size).to eq(2)
266
269
  end
267
270
 
268
271
  it 'should not care about case' do
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: 5.0.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,64 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-21 00:00:00.000000000 Z
12
+ date: 2018-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 4.2.8
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: 4.2.8
28
- - !ruby/object:Gem::Dependency
29
- name: sqlite3
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: mysql2
44
16
  requirement: !ruby/object:Gem::Requirement
45
17
  requirements:
46
18
  - - "~>"
47
19
  - !ruby/object:Gem::Version
48
- version: '0.3'
49
- type: :development
20
+ version: '5.0'
21
+ type: :runtime
50
22
  prerelease: false
51
23
  version_requirements: !ruby/object:Gem::Requirement
52
24
  requirements:
53
25
  - - "~>"
54
26
  - !ruby/object:Gem::Version
55
- version: '0.3'
56
- - !ruby/object:Gem::Dependency
57
- name: pg
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
27
+ version: '5.0'
70
28
  - !ruby/object:Gem::Dependency
71
29
  name: rspec-rails
72
30
  requirement: !ruby/object:Gem::Requirement
@@ -165,9 +123,9 @@ files:
165
123
  - db/migrate/4_add_missing_taggable_index.rb
166
124
  - db/migrate/5_change_collation_for_tag_names.rb
167
125
  - db/migrate/6_add_missing_indexes_on_taggings.rb
168
- - gemfiles/activerecord_4.2.gemfile
169
126
  - gemfiles/activerecord_5.0.gemfile
170
127
  - gemfiles/activerecord_5.1.gemfile
128
+ - gemfiles/activerecord_5.2.gemfile
171
129
  - lib/acts-as-taggable-on.rb
172
130
  - lib/acts_as_taggable_on.rb
173
131
  - lib/acts_as_taggable_on/default_parser.rb
@@ -179,7 +137,6 @@ files:
179
137
  - lib/acts_as_taggable_on/taggable/cache.rb
180
138
  - lib/acts_as_taggable_on/taggable/collection.rb
181
139
  - lib/acts_as_taggable_on/taggable/core.rb
182
- - lib/acts_as_taggable_on/taggable/dirty.rb
183
140
  - lib/acts_as_taggable_on/taggable/ownership.rb
184
141
  - lib/acts_as_taggable_on/taggable/related.rb
185
142
  - lib/acts_as_taggable_on/taggable/tagged_with_query.rb
@@ -197,12 +154,12 @@ files:
197
154
  - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
198
155
  - spec/acts_as_taggable_on/caching_spec.rb
199
156
  - spec/acts_as_taggable_on/default_parser_spec.rb
157
+ - spec/acts_as_taggable_on/dirty_spec.rb
200
158
  - spec/acts_as_taggable_on/generic_parser_spec.rb
201
159
  - spec/acts_as_taggable_on/related_spec.rb
202
160
  - spec/acts_as_taggable_on/single_table_inheritance_spec.rb
203
161
  - spec/acts_as_taggable_on/tag_list_spec.rb
204
162
  - spec/acts_as_taggable_on/tag_spec.rb
205
- - spec/acts_as_taggable_on/taggable/dirty_spec.rb
206
163
  - spec/acts_as_taggable_on/taggable_spec.rb
207
164
  - spec/acts_as_taggable_on/tagger_spec.rb
208
165
  - spec/acts_as_taggable_on/tagging_spec.rb
@@ -258,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
215
  version: '0'
259
216
  requirements: []
260
217
  rubyforge_project:
261
- rubygems_version: 2.6.8
218
+ rubygems_version: 2.7.6
262
219
  signing_key:
263
220
  specification_version: 4
264
221
  summary: Advanced tagging for Rails.
@@ -267,12 +224,12 @@ test_files:
267
224
  - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
268
225
  - spec/acts_as_taggable_on/caching_spec.rb
269
226
  - spec/acts_as_taggable_on/default_parser_spec.rb
227
+ - spec/acts_as_taggable_on/dirty_spec.rb
270
228
  - spec/acts_as_taggable_on/generic_parser_spec.rb
271
229
  - spec/acts_as_taggable_on/related_spec.rb
272
230
  - spec/acts_as_taggable_on/single_table_inheritance_spec.rb
273
231
  - spec/acts_as_taggable_on/tag_list_spec.rb
274
232
  - spec/acts_as_taggable_on/tag_spec.rb
275
- - spec/acts_as_taggable_on/taggable/dirty_spec.rb
276
233
  - spec/acts_as_taggable_on/taggable_spec.rb
277
234
  - spec/acts_as_taggable_on/tagger_spec.rb
278
235
  - spec/acts_as_taggable_on/tagging_spec.rb
@@ -1,36 +0,0 @@
1
- module ActsAsTaggableOn::Taggable
2
- module Dirty
3
- def self.included(base)
4
- base.extend ActsAsTaggableOn::Taggable::Dirty::ClassMethods
5
-
6
- base.initialize_acts_as_taggable_on_dirty
7
- end
8
-
9
- module ClassMethods
10
- def initialize_acts_as_taggable_on_dirty
11
- tag_types.map(&:to_s).each do |tags_type|
12
- tag_type = tags_type.to_s.singularize
13
-
14
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
15
- def #{tag_type}_list_changed?
16
- changed_attributes.include?("#{tag_type}_list")
17
- end
18
-
19
- def #{tag_type}_list_was
20
- changed_attributes.include?("#{tag_type}_list") ? changed_attributes["#{tag_type}_list"] : __send__("#{tag_type}_list")
21
- end
22
-
23
- def #{tag_type}_list_change
24
- [changed_attributes['#{tag_type}_list'], __send__('#{tag_type}_list')] if changed_attributes.include?("#{tag_type}_list")
25
- end
26
-
27
- def #{tag_type}_list_changes
28
- [changed_attributes['#{tag_type}_list'], __send__('#{tag_type}_list')] if changed_attributes.include?("#{tag_type}_list")
29
- end
30
- RUBY
31
-
32
- end
33
- end
34
- end
35
- end
36
- end