diff -pruN 5.0.0-2/acts-as-taggable-on.gemspec 6.0.0-3/acts-as-taggable-on.gemspec
--- 5.0.0-2/acts-as-taggable-on.gemspec	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/acts-as-taggable-on.gemspec	2018-06-19 04:38:27.000000000 +0000
@@ -22,11 +22,7 @@ Gem::Specification.new do |gem|
     gem.post_install_message = File.read('UPGRADING.md')
   end
 
-  gem.add_runtime_dependency 'activerecord', ['>= 4.2.8']
-
-  gem.add_development_dependency 'sqlite3'
-  gem.add_development_dependency 'mysql2', '~> 0.3'
-  gem.add_development_dependency 'pg'
+  gem.add_runtime_dependency 'activerecord', ['~> 5.0']
 
   gem.add_development_dependency 'rspec-rails'
   gem.add_development_dependency 'rspec-its'
diff -pruN 5.0.0-2/Appraisals 6.0.0-3/Appraisals
--- 5.0.0-2/Appraisals	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/Appraisals	2018-06-19 04:38:27.000000000 +0000
@@ -1,3 +1,7 @@
+appraise 'activerecord-5.2' do
+  gem 'activerecord', '~> 5.2.0'
+end
+
 appraise 'activerecord-5.1' do
   gem 'activerecord', "~> 5.1.1"
 end
@@ -5,7 +9,3 @@ end
 appraise 'activerecord-5.0' do
   gem 'activerecord', "~> 5.0.3"
 end
-
-appraise "activerecord-4.2" do
-  gem "activerecord", "~> 4.2.8"
-end
\ No newline at end of file
diff -pruN 5.0.0-2/CHANGELOG.md 6.0.0-3/CHANGELOG.md
--- 5.0.0-2/CHANGELOG.md	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/CHANGELOG.md	2018-06-19 04:38:27.000000000 +0000
@@ -4,6 +4,15 @@ Each change should fall into categories
 
 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.0.0 / 2017-06-19](https://github.com/mbleigh/acts-as-taggable-on/compare/v5.0.0...v6.0.0)
+  * Breaking Changes
+   * [@Fodoj Drop support for Rails 4.2](https://github.com/mbleigh/acts-as-taggable-on/pull/887)
+  * Added
+   * [@CalvertYang Add support for uuid primary keys](https://github.com/mbleigh/acts-as-taggable-on/pull/898)
+   * [@Fodoj Support Rails 5.2](https://github.com/mbleigh/acts-as-taggable-on/pull/887)
+  * Fixes
+   * [@tekniklr matches_attribute was not being used in tag_match_type](https://github.com/mbleigh/acts-as-taggable-on/pull/869)  
+
 ### [5.0.0 / 2017-05-18](https://github.com/mbleigh/acts-as-taggable-on/compare/v4.0.0...v5.0.0)
   * Breaking Changes
     * [@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
   * [@jh125486 Fixed wildcard test (postgres returning rows with unexpected order)] (https://github.com/mbleigh/acts-as-taggable-on/pull/660 )
   * [@FlowerWrong Add rails 5.0.0 alpha support, not hack rails <5](https://github.com/mbleigh/acts-as-taggable-on/pull/673 )
   * [@ryanfox1985 Added missed indexes. ](https://github.com/mbleigh/acts-as-taggable-on/pull/682 )
-   * [@ zapnap scope tags to specific tagging ](https://github.com/mbleigh/acts-as-taggable-on/pull/697 )
-   * [@ amatsuda method redefined](https://github.com/mbleigh/acts-as-taggable-on/pull/715 )
-   * [@ klacointe Rails 5: Tagger is optional in Tagging relation](https://github.com/mbleigh/acts-as-taggable-on/pull/720 )
-   * [@ 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 )
-   * [@ lukeasrodgers BugFix flackey time test ] (https://github.com/mbleigh/acts-as-taggable-on/pull/727)
-   * [@ pcupueran Add rspec tests for context scopes for tagging_spec ]( https://github.com/mbleigh/acts-as-taggable-on/pull/740)
-   * [@ Emerson Huitt Remove existing selects from relation ]( https://github.com/mbleigh/acts-as-taggable-on/pull/743)
-   * [@keerthisiv fix issue with custom delimiter]( https://github.com/mbleigh/acts-as-taggable-on/pull/748)
-   * [@priyank-gupta  specify tag table name for mysql collation query ](https://github.com/mbleigh/acts-as-taggable-on/pull/760)
-   * [@seuros Remove warning messages](https://github.com/mbleigh/acts-as-taggable-on/commit/cda08c764b07a18b8582b948d1c5b3910a3769  65)
-   * [@rbritom  Fix migration, #references already adds index ]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/95f743010954b6b738a6e8c17315112c878f7a81  )
-   * [@rbritom  Fix deprecation warning]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/62e4a6fa74ae3faed615683cd3ad5b5cdacf5c96 )
-   * [@rbritom  fix scope array arguments ]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/a415a8d6367b2e91bd7e363589135f953929b8cc )
-   * [@seuros Remove more deprecations  ]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/05794170f64f8bf250b34d2d594e368721009278)
-     * [@lukeasrodgers   Bugfix `TagList#concat` with non-duplicates. ]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/2c6214f0ddf8c6440ab81eec04d1fbf9d97c8826)
-   * [@seuros  clean! should return self. ]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/c739422f56f8ff37e3f321235e74997422a1c980)
-  * [@rbritom  renable appraisals ]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/0ca1f1c5b059699c683a28b522e86a3d5cd7639e)
-  * [@rbritom  remove index conditionally on up method. ]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
-   *[@rbritom add index on down method . ]
-  (https://github.com/mbleigh/acts-as-taggable-on/pull/767)
-  q* [@rbritom remove index conditionally on up method]
-  (https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
+  * [@ zapnap scope tags to specific tagging ](https://github.com/mbleigh/acts-as-taggable-on/pull/697 )
+  * [@ amatsuda method redefined](https://github.com/mbleigh/acts-as-taggable-on/pull/715 )
+  * [@ klacointe Rails 5: Tagger is optional in Tagging relation](https://github.com/mbleigh/acts-as-taggable-on/pull/720 )
+  * [@ 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 )
+  * [@ lukeasrodgers BugFix flackey time test ](https://github.com/mbleigh/acts-as-taggable-on/pull/727)
+  * [@ pcupueran Add rspec tests for context scopes for tagging_spec ]( https://github.com/mbleigh/acts-as-taggable-on/pull/740)
+  * [@ Emerson Huitt Remove existing selects from relation ]( https://github.com/mbleigh/acts-as-taggable-on/pull/743)
+  * [@keerthisiv fix issue with custom delimiter]( https://github.com/mbleigh/acts-as-taggable-on/pull/748)
+  * [@priyank-gupta  specify tag table name for mysql collation query ](https://github.com/mbleigh/acts-as-taggable-on/pull/760)
+  * [@seuros Remove warning messages](https://github.com/mbleigh/acts-as-taggable-on/commit/cda08c764b07a18b8582b948d1c5b3910a376965)
+  * [@rbritom  Fix migration, #references already adds index ](https://github.com/mbleigh/acts-as-taggable-on/commit/95f743010954b6b738a6e8c17315112c878f7a81)
+  * [@rbritom  Fix deprecation warning](https://github.com/mbleigh/acts-as-taggable-on/commit/62e4a6fa74ae3faed615683cd3ad5b5cdacf5c96 )
+  * [@rbritom  fix scope array arguments ](https://github.com/mbleigh/acts-as-taggable-on/commit/a415a8d6367b2e91bd7e363589135f953929b8cc )
+  * [@seuros Remove more deprecations  ](https://github.com/mbleigh/acts-as-taggable-on/commit/05794170f64f8bf250b34d2d594e368721009278)
+  * [@lukeasrodgers   Bugfix `TagList#concat` with non-duplicates. ](https://github.com/mbleigh/acts-as-taggable-on/commit/2c6214f0ddf8c6440ab81eec04d1fbf9d97c8826)
+  * [@seuros  clean! should return self. ](https://github.com/mbleigh/acts-as-taggable-on/commit/c739422f56f8ff37e3f321235e74997422a1c980)
+  * [@rbritom  renable appraisals ](https://github.com/mbleigh/acts-as-taggable-on/commit/0ca1f1c5b059699c683a28b522e86a3d5cd7639e)
+  * [@rbritom  remove index conditionally on up method. ](https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
+  *[@rbritom add index on down method . ](https://github.com/mbleigh/acts-as-taggable-on/pull/767)
+  * [@rbritom remove index conditionally on up method](https://github.com/mbleigh/acts-as-taggable-on/commit/9cc580e7f88164634eb10c8826e5b30ea0e00544)
 
  * Documentation
   * [@logicminds Adds table of contents using doctoc utility](https://github.com/mbleigh/acts-as-taggable-on/pull/803)
diff -pruN 5.0.0-2/debian/changelog 6.0.0-3/debian/changelog
--- 5.0.0-2/debian/changelog	2018-02-22 15:16:56.000000000 +0000
+++ 6.0.0-3/debian/changelog	2019-02-08 10:29:38.000000000 +0000
@@ -1,3 +1,26 @@
+ruby-acts-as-taggable-on (6.0.0-3) unstable; urgency=medium
+
+  * Remove Breaks: gitlab (gitlab not in testing)
+
+ -- Pirate Praveen <praveen@debian.org>  Fri, 08 Feb 2019 15:59:38 +0530
+
+ruby-acts-as-taggable-on (6.0.0-2) unstable; urgency=medium
+
+  * Reupload to unstable
+  * Add Breaks gitlab (we don't have a fixed version yet)
+  * Bump Standards-Version to 4.3.0 (no changes needed)
+
+ -- Pirate Praveen <praveen@debian.org>  Thu, 07 Feb 2019 17:48:38 +0530
+
+ruby-acts-as-taggable-on (6.0.0-1) experimental; urgency=medium
+
+  * Team upload
+  * New upstream release
+  * Use salsa.debian.org in Vcs-* fields
+  * Bump Standards-Version to 4.2.1 (no changes needed)
+
+ -- Sruthi Chandran <srud@disroot.org>  Wed, 19 Sep 2018 21:20:30 +0530
+
 ruby-acts-as-taggable-on (5.0.0-2) unstable; urgency=medium
 
   * Reupload to unstable
diff -pruN 5.0.0-2/debian/control 6.0.0-3/debian/control
--- 5.0.0-2/debian/control	2018-02-22 15:16:56.000000000 +0000
+++ 6.0.0-3/debian/control	2019-02-08 10:04:46.000000000 +0000
@@ -4,10 +4,11 @@ Priority: optional
 Maintainer: Debian Ruby Extras Maintainers <pkg-ruby-extras-maintainers@lists.alioth.debian.org>
 Uploaders: Pirate Praveen <praveen@debian.org>
 Build-Depends: debhelper (>= 11~),
+               ruby-activerecord (>= 2:5.0),
                gem2deb
-Standards-Version: 4.1.3
-Vcs-Git: https://anonscm.debian.org/git/pkg-ruby-extras/ruby-acts-as-taggable-on.git
-Vcs-Browser: https://anonscm.debian.org/cgit/pkg-ruby-extras/ruby-acts-as-taggable-on.git
+Standards-Version: 4.3.0
+Vcs-Git: https://salsa.debian.org/ruby-team/ruby-acts-as-taggable-on.git
+Vcs-Browser: https://salsa.debian.org/ruby-team/ruby-acts-as-taggable-on
 Homepage: https://github.com/mbleigh/acts-as-taggable-on
 Testsuite: autopkgtest-pkg-ruby
 XS-Ruby-Versions: all
@@ -15,7 +16,7 @@ XS-Ruby-Versions: all
 Package: ruby-acts-as-taggable-on
 Architecture: all
 XB-Ruby-Versions: ${ruby:Versions}
-Depends: rails,
+Depends: ruby-activerecord (>= 2:5.0),
          ruby | ruby-interpreter,
          ${misc:Depends},
          ${shlibs:Depends}
diff -pruN 5.0.0-2/debian/watch 6.0.0-3/debian/watch
--- 5.0.0-2/debian/watch	2018-02-22 15:16:56.000000000 +0000
+++ 6.0.0-3/debian/watch	2019-02-07 11:36:32.000000000 +0000
@@ -1,2 +1,2 @@
 version=3
-http://pkg-ruby-extras.alioth.debian.org/cgi-bin/gemwatch/acts-as-taggable-on .*/acts-as-taggable-on-(.*).tar.gz
+https://gemwatch.debian.net/acts-as-taggable-on .*/acts-as-taggable-on-(.*).tar.gz
diff -pruN 5.0.0-2/Gemfile 6.0.0-3/Gemfile
--- 5.0.0-2/Gemfile	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/Gemfile	2018-06-19 04:38:27.000000000 +0000
@@ -1,11 +1,11 @@
 source 'https://rubygems.org'
 
-# gemspec
+gemspec
 
 group :local_development do
   gem 'guard'
   gem 'guard-rspec'
   gem 'appraisal'
   gem 'rake'
-  gem 'byebug' , platforms: [:mri_21, :mri_22, :mri_23]
+  gem 'byebug', platforms: [:mri]
 end
diff -pruN 5.0.0-2/gemfiles/activerecord_4.2.gemfile 6.0.0-3/gemfiles/activerecord_4.2.gemfile
--- 5.0.0-2/gemfiles/activerecord_4.2.gemfile	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/gemfiles/activerecord_4.2.gemfile	1970-01-01 00:00:00.000000000 +0000
@@ -1,15 +0,0 @@
-# This file was generated by Appraisal
-
-source "https://rubygems.org"
-
-gem "activerecord", "~> 4.2.8"
-
-group :local_development do
-  gem "guard"
-  gem "guard-rspec"
-  gem "appraisal"
-  gem "rake"
-  gem "byebug", platforms: [:mri_21, :mri_22, :mri_23]
-end
-
-gemspec path: "../"
diff -pruN 5.0.0-2/gemfiles/activerecord_5.0.gemfile 6.0.0-3/gemfiles/activerecord_5.0.gemfile
--- 5.0.0-2/gemfiles/activerecord_5.0.gemfile	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/gemfiles/activerecord_5.0.gemfile	2018-06-19 04:38:27.000000000 +0000
@@ -3,6 +3,14 @@
 source "https://rubygems.org"
 
 gem "activerecord", "~> 5.0.3"
+case ENV["DB"]
+when "postgresql"
+  gem 'pg'
+when "mysql"
+  gem 'mysql2', '~> 0.3'
+else
+  gem 'sqlite3'
+end
 
 group :local_development do
   gem "guard"
diff -pruN 5.0.0-2/gemfiles/activerecord_5.1.gemfile 6.0.0-3/gemfiles/activerecord_5.1.gemfile
--- 5.0.0-2/gemfiles/activerecord_5.1.gemfile	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/gemfiles/activerecord_5.1.gemfile	2018-06-19 04:38:27.000000000 +0000
@@ -3,6 +3,14 @@
 source "https://rubygems.org"
 
 gem "activerecord", "~> 5.1.1"
+case ENV["DB"]
+when "postgresql"
+  gem 'pg'
+when "mysql"
+  gem 'mysql2', '~> 0.3'
+else
+  gem 'sqlite3'
+end
 
 group :local_development do
   gem "guard"
diff -pruN 5.0.0-2/gemfiles/activerecord_5.2.gemfile 6.0.0-3/gemfiles/activerecord_5.2.gemfile
--- 5.0.0-2/gemfiles/activerecord_5.2.gemfile	1970-01-01 00:00:00.000000000 +0000
+++ 6.0.0-3/gemfiles/activerecord_5.2.gemfile	2018-06-19 04:38:27.000000000 +0000
@@ -0,0 +1,23 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "activerecord", "~> 5.2.0"
+case ENV["DB"]
+when "postgresql"
+  gem 'pg'
+when "mysql"
+  gem 'mysql2', '~> 0.3'
+else
+  gem 'sqlite3'
+end
+
+group :local_development do
+  gem "guard"
+  gem "guard-rspec"
+  gem "appraisal"
+  gem "rake"
+  gem "byebug", platforms: [:mri_21, :mri_22, :mri_23]
+end
+
+gemspec path: "../"
diff -pruN 5.0.0-2/.gitignore 6.0.0-3/.gitignore
--- 5.0.0-2/.gitignore	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/.gitignore	2018-06-19 04:38:27.000000000 +0000
@@ -9,5 +9,5 @@ tmp*.sw?
 tmp
 *.gem
 *.lock
-
+*.iml
 /.idea
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/collection.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/collection.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/collection.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/collection.rb	2018-06-19 04:38:27.000000000 +0000
@@ -174,7 +174,7 @@ module ActsAsTaggableOn::Taggable
       # See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb#L38
       def count(column_name = :all, options = {})
         # https://github.com/rails/rails/commit/da9b5d4a8435b744fcf278fffd6d7f1e36d4a4f2
-        ActsAsTaggableOn::Utils.active_record5? ? super(column_name) : super(column_name, options)
+        super(column_name)
       end
     end
   end
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/core.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/core.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/core.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/core.rb	2018-06-19 04:38:27.000000000 +0000
@@ -2,6 +2,7 @@ require_relative 'tagged_with_query'
 
 module ActsAsTaggableOn::Taggable
   module Core
+
     def self.included(base)
       base.extend ActsAsTaggableOn::Taggable::Core::ClassMethods
 
@@ -28,12 +29,16 @@ module ActsAsTaggableOn::Taggable
             has_many context_taggings, -> { includes(:tag).order(taggings_order).where(context: tags_type) },
                      as: :taggable,
                      class_name: 'ActsAsTaggableOn::Tagging',
-                     dependent: :destroy
+                     dependent: :destroy,
+                     after_add: :dirtify_tag_list,
+                     after_remove: :dirtify_tag_list
 
             has_many context_tags, -> { order(taggings_order) },
                      class_name: 'ActsAsTaggableOn::Tag',
                      through: context_taggings,
                      source: :tag
+
+            attribute "#{tags_type.singularize}_list".to_sym, ActiveModel::Type::Value.new
           end
 
           taggable_mixin.class_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -42,12 +47,24 @@ module ActsAsTaggableOn::Taggable
             end
 
             def #{tag_type}_list=(new_tags)
+              parsed_new_list = ActsAsTaggableOn.default_parser.new(new_tags).parse
+
+              if self.class.preserve_tag_order? || parsed_new_list.sort != #{tag_type}_list.sort
+                set_attribute_was('#{tag_type}_list', #{tag_type}_list)
+                write_attribute("#{tag_type}_list", parsed_new_list)
+              end
+
               set_tag_list_on('#{tags_type}', new_tags)
             end
 
             def all_#{tags_type}_list
               all_tags_list_on('#{tags_type}')
             end
+
+            private
+            def dirtify_tag_list(tagging)
+              attribute_will_change! tagging.context.singularize+"_list"
+            end
           RUBY
         end
       end
@@ -161,7 +178,7 @@ module ActsAsTaggableOn::Taggable
 
       if ActsAsTaggableOn::Utils.using_postgresql?
         group_columns = grouped_column_names_for(ActsAsTaggableOn::Tag)
-        scope.order("max(#{tagging_table_name}.created_at)").group(group_columns)
+        scope.order(Arel.sql("max(#{tagging_table_name}.created_at)")).group(group_columns)
       else
         scope.group("#{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key}")
       end.to_a
@@ -181,33 +198,16 @@ module ActsAsTaggableOn::Taggable
       add_custom_context(context)
 
       variable_name = "@#{context.to_s.singularize}_list"
-      process_dirty_object(context, new_list) unless custom_contexts.include?(context.to_s)
 
-      instance_variable_set(variable_name, ActsAsTaggableOn.default_parser.new(new_list).parse)
+      parsed_new_list = ActsAsTaggableOn.default_parser.new(new_list).parse
+
+      instance_variable_set(variable_name, parsed_new_list)
     end
 
     def tagging_contexts
       self.class.tag_types.map(&:to_s) + custom_contexts
     end
 
-    def process_dirty_object(context, new_list)
-      value = new_list.is_a?(Array) ? ActsAsTaggableOn::TagList.new(new_list) : new_list
-      attrib = "#{context.to_s.singularize}_list"
-
-      if changed_attributes.include?(attrib)
-        # The attribute already has an unsaved change.
-        old = changed_attributes[attrib]
-        @changed_attributes.delete(attrib) if old.to_s == value.to_s
-      else
-        old = tag_list_on(context)
-        if self.class.preserve_tag_order
-          @changed_attributes[attrib] = old if old.to_s != value.to_s
-        else
-          @changed_attributes[attrib] = old.to_s if old.sort != ActsAsTaggableOn.default_parser.new(value).parse.sort
-        end
-      end
-    end
-
     def reload(*args)
       self.class.tag_types.each do |context|
         instance_variable_set("@#{context.to_s.singularize}_list", nil)
@@ -315,3 +315,4 @@ module ActsAsTaggableOn::Taggable
     end
   end
 end
+
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/dirty.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/dirty.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/dirty.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/dirty.rb	1970-01-01 00:00:00.000000000 +0000
@@ -1,36 +0,0 @@
-module ActsAsTaggableOn::Taggable
-  module Dirty
-    def self.included(base)
-      base.extend ActsAsTaggableOn::Taggable::Dirty::ClassMethods
-
-      base.initialize_acts_as_taggable_on_dirty
-    end
-
-    module ClassMethods
-      def initialize_acts_as_taggable_on_dirty
-        tag_types.map(&:to_s).each do |tags_type|
-          tag_type         = tags_type.to_s.singularize
-
-          class_eval <<-RUBY, __FILE__, __LINE__ + 1
-            def #{tag_type}_list_changed?
-              changed_attributes.include?("#{tag_type}_list")
-            end
-
-            def #{tag_type}_list_was
-              changed_attributes.include?("#{tag_type}_list") ? changed_attributes["#{tag_type}_list"] : __send__("#{tag_type}_list")
-            end
-
-            def #{tag_type}_list_change
-              [changed_attributes['#{tag_type}_list'], __send__('#{tag_type}_list')] if changed_attributes.include?("#{tag_type}_list")
-            end
-
-            def #{tag_type}_list_changes
-              [changed_attributes['#{tag_type}_list'], __send__('#{tag_type}_list')] if changed_attributes.include?("#{tag_type}_list")
-            end
-          RUBY
-
-        end
-      end
-    end
-  end
-end
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/ownership.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/ownership.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/ownership.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/ownership.rb	2018-06-19 04:38:27.000000000 +0000
@@ -49,7 +49,7 @@ module ActsAsTaggableOn::Taggable
     end
 
     def owner_tags_on(owner, context)
-      scope = owner_tags(owner).where(
+      owner_tags(owner).where(
         "#{ActsAsTaggableOn::Tagging.table_name}" => {
           context: context
         }
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/related.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/related.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/related.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/related.rb	2018-06-19 04:38:27.000000000 +0000
@@ -49,7 +49,7 @@ module ActsAsTaggableOn::Taggable
     private
 
     def exclude_self(klass, id)
-      "#{klass.table_name}.#{klass.primary_key} != #{id} AND" if [self.class.base_class, self.class].include? klass
+      "#{klass.arel_table[klass.primary_key].not_eq(id).to_sql} AND" if [self.class.base_class, self.class].include? klass
     end
 
     def group_columns(klass)
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/all_tags_query.rb	2018-06-19 04:38:27.000000000 +0000
@@ -49,12 +49,10 @@ module ActsAsTaggableOn::Taggable::Tagge
       end
 
       if options[:on].present?
-        on_condition = on_condition.and(tagging_alias[:context].lteq(options[:on]))
+        on_condition = on_condition.and(tagging_alias[:context].eq(options[:on]))
       end
 
       if (owner = options[:owned_by]).present?
-        owner_table = owner.class.base_class.arel_table
-
         on_condition = on_condition.and(tagging_alias[:tagger_id].eq(owner.id))
                                    .and(tagging_alias[:tagger_type].eq(owner.class.base_class.to_s))
       end
@@ -75,7 +73,7 @@ module ActsAsTaggableOn::Taggable::Tagge
       end
 
       if options[:on].present?
-        on_condition = on_condition.and(tagging_arel_table[:context].lteq(options[:on]))
+        on_condition = on_condition.and(tagging_arel_table[:context].eq(options[:on]))
       end
 
       on_condition
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/any_tags_query.rb	2018-06-19 04:38:27.000000000 +0000
@@ -3,7 +3,7 @@ module ActsAsTaggableOn::Taggable::Tagge
     def build
       taggable_model.select(all_fields)
                     .where(model_has_at_least_one_tag)
-                    .order(order_conditions)
+                    .order(Arel.sql(order_conditions))
                     .readonly(false)
     end
 
@@ -14,9 +14,6 @@ module ActsAsTaggableOn::Taggable::Tagge
     end
 
     def model_has_at_least_one_tag
-      tagging_alias = tagging_arel_table.alias(alias_name(tag_list))
-
-
       tagging_arel_table.project(Arel.star).where(at_least_one_tag).exists
     end
 
@@ -38,12 +35,10 @@ module ActsAsTaggableOn::Taggable::Tagge
       end
 
       if options[:on].present?
-        exists_contition = exists_contition.and(tagging_arel_table[:context].lteq(options[:on]))
+        exists_contition = exists_contition.and(tagging_arel_table[:context].eq(options[:on]))
       end
 
       if (owner = options[:owned_by]).present?
-        owner_table = owner.class.base_class.arel_table
-
         exists_contition = exists_contition.and(tagging_arel_table[:tagger_id].eq(owner.id))
                                    .and(tagging_arel_table[:tagger_type].eq(owner.class.base_class.to_s))
       end
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/exclude_tags_query.rb	2018-06-19 04:38:27.000000000 +0000
@@ -63,7 +63,7 @@ module ActsAsTaggableOn::Taggable::Tagge
       end
 
       if options[:on].present?
-        on_condition = on_condition.and(tagging_arel_table[:context].lteq(options[:on]))
+        on_condition = on_condition.and(tagging_arel_table[:context].eq(options[:on]))
       end
 
       on_condition
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb	2018-06-19 04:38:27.000000000 +0000
@@ -29,9 +29,9 @@ module ActsAsTaggableOn::Taggable::Tagge
       matches_attribute = matches_attribute.lower unless ActsAsTaggableOn.strict_case_match
 
       if options[:wild].present?
-        tag_arel_table[:name].matches("%#{escaped_tag(tag)}%", "!")
+        matches_attribute.matches("%#{escaped_tag(tag)}%", "!")
       else
-        tag_arel_table[:name].matches(escaped_tag(tag), "!")
+        matches_attribute.matches(escaped_tag(tag), "!")
       end
     end
 
@@ -48,7 +48,7 @@ module ActsAsTaggableOn::Taggable::Tagge
 
     def escaped_tag(tag)
       tag = tag.downcase unless ActsAsTaggableOn.strict_case_match
-      tag.gsub(/[!%_]/) { |x| '!' + x }
+      ActsAsTaggableOn::Utils.escape_like(tag)
     end
 
     def adjust_taggings_alias(taggings_alias)
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/taggable.rb 6.0.0-3/lib/acts_as_taggable_on/taggable.rb
--- 5.0.0-2/lib/acts_as_taggable_on/taggable.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/taggable.rb	2018-06-19 04:38:27.000000000 +0000
@@ -96,7 +96,6 @@ module ActsAsTaggableOn
       include Cache
       include Ownership
       include Related
-      include Dirty
     end
   end
 end
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/tagging.rb 6.0.0-3/lib/acts_as_taggable_on/tagging.rb
--- 5.0.0-2/lib/acts_as_taggable_on/tagging.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/tagging.rb	2018-06-19 04:38:27.000000000 +0000
@@ -4,7 +4,7 @@ module ActsAsTaggableOn
     belongs_to :tag, class_name: '::ActsAsTaggableOn::Tag', counter_cache: ActsAsTaggableOn.tags_counter
     belongs_to :taggable, polymorphic: true
 
-    belongs_to :tagger, {polymorphic: true}.tap {|o| o.merge!(optional: true) if ActsAsTaggableOn::Utils.active_record5? }
+    belongs_to :tagger, {polymorphic: true}.tap {|o| o.merge!(optional: true) }
 
     scope :owned_by, ->(owner) { where(tagger: owner) }
     scope :not_owned, -> { where(tagger_id: nil, tagger_type: nil) }
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/utils.rb 6.0.0-3/lib/acts_as_taggable_on/utils.rb
--- 5.0.0-2/lib/acts_as_taggable_on/utils.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/utils.rb	2018-06-19 04:38:27.000000000 +0000
@@ -20,10 +20,6 @@ module ActsAsTaggableOn
         Digest::SHA1.hexdigest(string)[0..6]
       end
 
-      def active_record5?
-        ::ActiveRecord::VERSION::MAJOR == 5
-      end
-
       def like_operator
         using_postgresql? ? 'ILIKE' : 'LIKE'
       end
diff -pruN 5.0.0-2/lib/acts_as_taggable_on/version.rb 6.0.0-3/lib/acts_as_taggable_on/version.rb
--- 5.0.0-2/lib/acts_as_taggable_on/version.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/lib/acts_as_taggable_on/version.rb	2018-06-19 04:38:27.000000000 +0000
@@ -1,4 +1,4 @@
 module ActsAsTaggableOn
-  VERSION = '5.0.0'
+  VERSION = '6.0.0'
 end
 
diff -pruN 5.0.0-2/README.md 6.0.0-3/README.md
--- 5.0.0-2/README.md	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/README.md	2018-06-19 04:38:27.000000000 +0000
@@ -57,7 +57,7 @@ was used.
 To use it, add it to your Gemfile:
 
 ```ruby
-gem 'acts-as-taggable-on', '~> 4.0'
+gem 'acts-as-taggable-on', '~> 5.0'
 ```
 
 and bundle:
diff -pruN 5.0.0-2/spec/acts_as_taggable_on/dirty_spec.rb 6.0.0-3/spec/acts_as_taggable_on/dirty_spec.rb
--- 5.0.0-2/spec/acts_as_taggable_on/dirty_spec.rb	1970-01-01 00:00:00.000000000 +0000
+++ 6.0.0-3/spec/acts_as_taggable_on/dirty_spec.rb	2018-06-19 04:38:27.000000000 +0000
@@ -0,0 +1,142 @@
+# -*- encoding : utf-8 -*-
+require 'spec_helper'
+
+describe 'Dirty behavior of taggable objects' do
+  context 'with un-contexted tags' do
+    before(:each) do
+      @taggable = TaggableModel.create(tag_list: 'awesome, epic')
+    end
+
+    context 'when tag_list changed' do
+      before(:each) do
+        expect(@taggable.changes).to be_empty
+        @taggable.tag_list = 'one'
+      end
+
+      it 'should show changes of dirty object' do
+        expect(@taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
+      end
+
+      it 'should show changes of freshly initialized dirty object' do
+        taggable = TaggableModel.find(@taggable.id)
+        taggable.tag_list = 'one'
+        expect(taggable.changes).to eq({'tag_list' => [['awesome', 'epic'], ['one']]})
+      end
+
+      if Rails.version >= "5.1"
+        it 'flags tag_list as changed' do
+          expect(@taggable.will_save_change_to_tag_list?).to be_truthy
+        end
+      end
+
+      it 'preserves original value' do
+        expect(@taggable.tag_list_was).to eq(['awesome', 'epic'])
+      end
+
+      it 'shows what the change was' do
+        expect(@taggable.tag_list_change).to eq([['awesome', 'epic'], ['one']])
+      end
+
+      context 'without order' do
+        it 'should not mark attribute if order change ' do
+          taggable = TaggableModel.create(name: 'Dirty Harry', tag_list: %w(d c b a))
+          taggable.tag_list =  %w(a b c d)
+          expect(taggable.tag_list_changed?).to be_falsey
+        end
+      end
+
+      context 'with order' do
+        it 'should mark attribute if order change' do
+          taggable = OrderedTaggableModel.create(name: 'Clean Harry', tag_list: 'd,c,b,a')
+          taggable.save
+          taggable.tag_list =  %w(a b c d)
+          expect(taggable.tag_list_changed?).to be_truthy
+        end
+      end
+    end
+
+    context 'when tag_list is the same' do
+      before(:each) do
+        @taggable.tag_list = 'awesome, epic'
+      end
+
+      it 'is not flagged as changed' do
+        expect(@taggable.tag_list_changed?).to be_falsy
+      end
+
+      it 'does not show any changes to the taggable item' do
+        expect(@taggable.changes).to be_empty
+      end
+
+      context "and using a delimiter different from a ','" do
+        before do
+          @old_delimiter = ActsAsTaggableOn.delimiter
+          ActsAsTaggableOn.delimiter = ';'
+        end
+
+        after do
+          ActsAsTaggableOn.delimiter = @old_delimiter
+        end
+
+        it 'does not show any changes to the taggable item when using array assignments' do
+          @taggable.tag_list = %w(awesome epic)
+          expect(@taggable.changes).to be_empty
+        end
+      end
+    end
+  end
+
+  context 'with context tags' do
+    before(:each) do
+      @taggable = TaggableModel.create('language_list' => 'awesome, epic')
+    end
+
+    context 'when language_list changed' do
+      before(:each) do
+        expect(@taggable.changes).to be_empty
+        @taggable.language_list = 'one'
+      end
+
+      it 'should show changes of dirty object' do
+        expect(@taggable.changes).to eq({'language_list' => [['awesome', 'epic'], ['one']]})
+      end
+
+      it 'flags language_list as changed' do
+        expect(@taggable.language_list_changed?).to be_truthy
+      end
+
+      it 'preserves original value' do
+        expect(@taggable.language_list_was).to eq(['awesome', 'epic'])
+      end
+
+      it 'shows what the change was' do
+        expect(@taggable.language_list_change).to eq([['awesome', 'epic'], ['one']])
+      end
+    end
+
+    context 'when language_list is the same' do
+      before(:each) do
+        @taggable.language_list = 'awesome, epic'
+      end
+
+      it 'is not flagged as changed' do
+        expect(@taggable.language_list_changed?).to be_falsy
+      end
+
+      it 'does not show any changes to the taggable item' do
+        expect(@taggable.changes).to be_empty
+      end
+    end
+
+    context 'when language_list changed by association' do
+      let(:tag) { ActsAsTaggableOn::Tag.new(name: 'one') }
+
+      it 'flags language_list as changed' do
+        expect(@taggable.changes).to be_empty
+        @taggable.languages << tag
+        expect(@taggable.language_list_changed?).to be_truthy
+      end
+    end
+
+  end
+end
diff -pruN 5.0.0-2/spec/acts_as_taggable_on/taggable/dirty_spec.rb 6.0.0-3/spec/acts_as_taggable_on/taggable/dirty_spec.rb
--- 5.0.0-2/spec/acts_as_taggable_on/taggable/dirty_spec.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/spec/acts_as_taggable_on/taggable/dirty_spec.rb	1970-01-01 00:00:00.000000000 +0000
@@ -1,127 +0,0 @@
-# -*- encoding : utf-8 -*-
-require 'spec_helper'
-
-describe ActsAsTaggableOn::Taggable::Dirty do
-  context 'with un-contexted tags' do
-    before(:each) do
-      @taggable = TaggableModel.create(tag_list: 'awesome, epic')
-    end
-
-    context 'when tag_list changed' do
-      before(:each) do
-        expect(@taggable.changes).to be_empty
-        @taggable.tag_list = 'one'
-      end
-
-      it 'should show changes of dirty object' do
-        expect(@taggable.changes).to eq({'tag_list' => ['awesome, epic', ['one']]})
-      end
-
-      it 'flags tag_list as changed' do
-        expect(@taggable.tag_list_changed?).to be_truthy
-      end
-
-      it 'preserves original value' do
-        expect(@taggable.tag_list_was).to eq('awesome, epic')
-      end
-
-      it 'shows what the change was' do
-        expect(@taggable.tag_list_change).to eq(['awesome, epic', ['one']])
-      end
-
-      context 'without order' do
-        it 'should not mark attribute if order change ' do
-          taggable = TaggableModel.create(name: 'Dirty Harry', tag_list: %w(d c b a))
-          taggable.tag_list =  %w(a b c d)
-          expect(taggable.tag_list_changed?).to be_falsey
-        end
-      end
-
-      context 'with order' do
-        it 'should mark attribute if order change' do
-          taggable = OrderedTaggableModel.create(name: 'Clean Harry', tag_list: 'd,c,b,a')
-          taggable.save
-          taggable.tag_list =  %w(a b c d)
-          expect(taggable.tag_list_changed?).to be_truthy
-        end
-      end
-    end
-
-    context 'when tag_list is the same' do
-      before(:each) do
-        @taggable.tag_list = 'awesome, epic'
-      end
-
-      it 'is not flagged as changed' do
-        expect(@taggable.tag_list_changed?).to be_falsy
-      end
-
-      it 'does not show any changes to the taggable item' do
-        expect(@taggable.changes).to be_empty
-      end
-
-      context "and using a delimiter different from a ','" do
-        before do
-          @old_delimiter = ActsAsTaggableOn.delimiter
-          ActsAsTaggableOn.delimiter = ';'
-        end
-
-        after do
-          ActsAsTaggableOn.delimiter = @old_delimiter
-        end
-
-        it 'does not show any changes to the taggable item when using array assignments' do
-          @taggable.tag_list = %w(awesome epic)
-          expect(@taggable.changes).to be_empty
-        end
-      end
-    end
-  end
-
-  context 'with context tags' do
-    before(:each) do
-      @taggable = TaggableModel.create('language_list' => 'awesome, epic')
-    end
-
-    context 'when language_list changed' do
-      before(:each) do
-        expect(@taggable.changes).to be_empty
-        @taggable.language_list = 'one'
-      end
-
-      it 'should show changes of dirty object' do
-        expect(@taggable.changes).to eq({'language_list' => ['awesome, epic', ['one']]})
-      end
-
-      it 'flags language_list as changed' do
-        expect(@taggable.language_list_changed?).to be_truthy
-      end
-
-      it 'preserves original value' do
-        expect(@taggable.language_list_was).to eq('awesome, epic')
-      end
-
-      it 'shows what the change was' do
-        expect(@taggable.language_list_change).to eq(['awesome, epic', ['one']])
-      end
-
-      it 'shows what the changes were' do
-        expect(@taggable.language_list_changes).to eq(['awesome, epic', ['one']])
-      end
-    end
-
-    context 'when language_list is the same' do
-      before(:each) do
-        @taggable.language_list = 'awesome, epic'
-      end
-
-      it 'is not flagged as changed' do
-        expect(@taggable.language_list_changed?).to be_falsy
-      end
-
-      it 'does not show any changes to the taggable item' do
-        expect(@taggable.changes).to be_empty
-      end
-    end
-  end
-end
diff -pruN 5.0.0-2/spec/acts_as_taggable_on/taggable_spec.rb 6.0.0-3/spec/acts_as_taggable_on/taggable_spec.rb
--- 5.0.0-2/spec/acts_as_taggable_on/taggable_spec.rb	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/spec/acts_as_taggable_on/taggable_spec.rb	2018-06-19 04:38:27.000000000 +0000
@@ -255,14 +255,17 @@ describe 'Taggable' do
   end
 
   it 'should be able to find by tag with context' do
-    @taggable.skill_list = 'ruby, rails, css'
-    @taggable.tag_list = 'bob, charlie'
+    @taggable.skill_list = 'ruby, rails, css, julia'
+    @taggable.tag_list = 'bob, charlie, julia'
     @taggable.save
 
     expect(TaggableModel.tagged_with('ruby').first).to eq(@taggable)
     expect(TaggableModel.tagged_with('ruby, css').first).to eq(@taggable)
     expect(TaggableModel.tagged_with('bob', on: :skills).first).to_not eq(@taggable)
     expect(TaggableModel.tagged_with('bob', on: :tags).first).to eq(@taggable)
+    expect(TaggableModel.tagged_with('julia', on: :skills).size).to eq(1)
+    expect(TaggableModel.tagged_with('julia', on: :tags).size).to eq(1)
+    expect(TaggableModel.tagged_with('julia', on: nil).size).to eq(2)
   end
 
   it 'should not care about case' do
diff -pruN 5.0.0-2/.travis.yml 6.0.0-3/.travis.yml
--- 5.0.0-2/.travis.yml	2017-05-24 12:36:05.000000000 +0000
+++ 6.0.0-3/.travis.yml	2018-06-19 04:38:27.000000000 +0000
@@ -2,8 +2,10 @@ language: ruby
 cache: bundler
 
 rvm:
-  - 2.4.1
-  - 2.3.3
+  - ruby-head
+  - 2.5.1
+  - 2.4.4
+  - 2.3.7
   - 2.2.7
 
 env:
@@ -12,9 +14,9 @@ env:
   - DB=postgresql
 
 gemfile:
+  - gemfiles/activerecord_5.2.gemfile
   - gemfiles/activerecord_5.1.gemfile
   - gemfiles/activerecord_5.0.gemfile
-  - gemfiles/activerecord_4.2.gemfile
 
 sudo: false
 
@@ -26,4 +28,6 @@ before_install:
 script: bundle exec rake
 
 matrix:
+  allow_failures:
+    - rvm: ruby-head
   fast_finish: true
