Skip to content

Commit

Permalink
Release 6.5 (#968)
Browse files Browse the repository at this point in the history
close #951
fixes #953 
files #961
  • Loading branch information
seuros committed Oct 29, 2019
1 parent fbf2b60 commit 950c010
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 64 deletions.
22 changes: 10 additions & 12 deletions .travis.yml
Expand Up @@ -2,14 +2,17 @@ language: ruby
cache: bundler

addons:
postgresql: '9.4'
postgresql: '10'

services:
- mysql
- postgresql

rvm:
- ruby-head
- 2.5.1
- 2.4.4
- 2.6.5
- 2.5.5
- 2.4.6
- 2.3.7
- 2.2.7

env:
- DB=sqlite3
Expand All @@ -22,13 +25,10 @@ gemfile:
- gemfiles/activerecord_5.0.gemfile
- gemfiles/activerecord_6.0.gemfile

sudo: false

bundler_args: '--without local_development --jobs 3 --retry 3'

before_install:
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
- gem install bundler -v '< 2'
- gem install bundler

script: bundle exec rake

Expand All @@ -37,9 +37,7 @@ matrix:
- rvm: ruby-head
fast_finish: true
exclude:
- rvm: 2.2.7
gemfile: gemfiles/activerecord_6.0.gemfile
- rvm: 2.3.7
gemfile: gemfiles/activerecord_6.0.gemfile
- rvm: 2.4.4
- rvm: 2.4.6
gemfile: gemfiles/activerecord_6.0.gemfile
2 changes: 1 addition & 1 deletion acts-as-taggable-on.gemspec
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.files = `git ls-files`.split($/)
gem.test_files = gem.files.grep(%r{^spec/})
gem.require_paths = ['lib']
gem.required_ruby_version = '>= 2.2.7'
gem.required_ruby_version = '>= 2.3.7'

if File.exist?('UPGRADING.md')
gem.post_install_message = File.read('UPGRADING.md')
Expand Down
6 changes: 2 additions & 4 deletions gemfiles/activerecord_5.0.gemfile
@@ -1,5 +1,3 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 5.0.3"
Expand All @@ -9,15 +7,15 @@ when "postgresql"
when "mysql"
gem 'mysql2', '~> 0.3'
else
gem 'sqlite3'
gem "sqlite3", "~> 1.3", "< 1.4"
end

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

gemspec path: "../"
6 changes: 2 additions & 4 deletions gemfiles/activerecord_5.1.gemfile
@@ -1,5 +1,3 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 5.1.1"
Expand All @@ -9,15 +7,15 @@ when "postgresql"
when "mysql"
gem 'mysql2', '~> 0.3'
else
gem 'sqlite3'
gem "sqlite3", "~> 1.3", "< 1.4"
end

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

gemspec path: "../"
6 changes: 2 additions & 4 deletions gemfiles/activerecord_5.2.gemfile
@@ -1,5 +1,3 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 5.2.0"
Expand All @@ -9,15 +7,15 @@ when "postgresql"
when "mysql"
gem 'mysql2', '~> 0.3'
else
gem 'sqlite3'
gem "sqlite3", "~> 1.3", "< 1.4"
end

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

gemspec path: "../"
6 changes: 2 additions & 4 deletions gemfiles/activerecord_6.0.gemfile
@@ -1,8 +1,6 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 6.0.0.beta1"
gem "activerecord", "~> 6.0.0"
case ENV["DB"]
when "postgresql"
gem 'pg'
Expand All @@ -17,7 +15,7 @@ group :local_development do
gem "guard-rspec"
gem "appraisal"
gem "rake"
gem "byebug", platforms: [:mri_21, :mri_22, :mri_23]
gem "byebug", platforms: [:mri]
end

gemspec path: "../"
1 change: 1 addition & 0 deletions lib/acts-as-taggable-on.rb
Expand Up @@ -31,6 +31,7 @@ module ActsAsTaggableOn
autoload :Dirty
autoload :Ownership
autoload :Related
autoload :TagListType
end

autoload :Utils
Expand Down
18 changes: 4 additions & 14 deletions lib/acts_as_taggable_on/tag.rb
Expand Up @@ -105,8 +105,6 @@ def count

class << self



private

def comparable_name(str)
Expand All @@ -121,20 +119,12 @@ def binary
ActsAsTaggableOn::Utils.using_mysql? ? 'BINARY ' : nil
end

def unicode_downcase(string)
if ActiveSupport::Multibyte::Unicode.respond_to?(:downcase)
ActiveSupport::Multibyte::Unicode.downcase(string)
else
ActiveSupport::Multibyte::Chars.new(string).downcase.to_s
end
def as_8bit_ascii(string)
string.to_s.mb_chars
end

def as_8bit_ascii(string)
if defined?(Encoding)
string.to_s.dup.force_encoding('BINARY')
else
string.to_s.mb_chars
end
def unicode_downcase(string)
as_8bit_ascii(string).downcase
end

def sanitize_sql_for_named_any(tag)
Expand Down
13 changes: 10 additions & 3 deletions lib/acts_as_taggable_on/taggable/core.rb
@@ -1,4 +1,5 @@
require_relative 'tagged_with_query'
require_relative 'tag_list_type'

module ActsAsTaggableOn::Taggable
module Core
Expand Down Expand Up @@ -38,7 +39,7 @@ def initialize_acts_as_taggable_on_core
through: context_taggings,
source: :tag

attribute "#{tags_type.singularize}_list".to_sym, ActiveModel::Type::Value.new
attribute "#{tags_type.singularize}_list".to_sym, ActsAsTaggableOn::Taggable::TagListType.new
end

taggable_mixin.class_eval <<-RUBY, __FILE__, __LINE__ + 1
Expand All @@ -49,8 +50,14 @@ def #{tag_type}_list
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)
if self.class.preserve_tag_order? || (parsed_new_list.sort != #{tag_type}_list.sort)
if ActsAsTaggableOn::Utils.legacy_activerecord?
set_attribute_was("#{tag_type}_list", #{tag_type}_list)
else
unless #{tag_type}_list_changed?
@attributes["#{tag_type}_list"] = ActiveModel::Attribute.from_user("#{tag_type}_list", #{tag_type}_list, ActsAsTaggableOn::Taggable::TagListType.new)
end
end
write_attribute("#{tag_type}_list", parsed_new_list)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/acts_as_taggable_on/taggable/tag_list_type.rb
@@ -0,0 +1,4 @@
module ActsAsTaggableOn::Taggable
class TagListType < ActiveModel::Type::Value
end
end
4 changes: 4 additions & 0 deletions lib/acts_as_taggable_on/utils.rb
Expand Up @@ -24,6 +24,10 @@ def like_operator
using_postgresql? ? 'ILIKE' : 'LIKE'
end

def legacy_activerecord?
ActiveRecord.version <= Gem::Version.new('5.3.0')
end

# escape _ and % characters in strings, since these are wildcards in SQL.
def escape_like(str)
str.gsub(/[!%_]/) { |x| '!' + x }
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_taggable_on/version.rb
@@ -1,3 +1,3 @@
module ActsAsTaggableOn
VERSION = '6.0.1'
VERSION = '6.5.0'
end
6 changes: 3 additions & 3 deletions spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
Expand Up @@ -200,7 +200,7 @@
its(:cached_glass_list) { should be_blank }

context 'language taggings cache after update' do
before { @taggable.update_attributes(language_list: 'ruby, .net') }
before { @taggable.update(language_list: 'ruby, .net') }
subject { @taggable }

its(:language_list) { should == ['ruby', '.net']}
Expand All @@ -209,7 +209,7 @@
end

context 'status taggings cache after update' do
before { @taggable.update_attributes(status_list: 'happy, married') }
before { @taggable.update(status_list: 'happy, married') }
subject { @taggable }

its(:status_list) { should == ['happy', 'married'] }
Expand All @@ -222,7 +222,7 @@

context 'glass taggings cache after update' do
before do
@taggable.update_attributes(glass_list: 'rectangle, aviator')
@taggable.update(glass_list: 'rectangle, aviator')
end

subject { @taggable }
Expand Down
20 changes: 10 additions & 10 deletions spec/acts_as_taggable_on/caching_spec.rb
Expand Up @@ -31,40 +31,40 @@
end

it 'should cache tags' do
@taggable.update_attributes(tag_list: 'awesome, epic')
@taggable.update(tag_list: 'awesome, epic')
expect(@taggable.cached_tag_list).to eq('awesome, epic')

@another_taggable.update_attributes(language_list: 'ruby, .net')
@another_taggable.update(language_list: 'ruby, .net')
expect(@another_taggable.cached_language_list).to eq('ruby, .net')
end

it 'should keep the cache' do
@taggable.update_attributes(tag_list: 'awesome, epic')
@taggable.update(tag_list: 'awesome, epic')
@taggable = CachedModel.find(@taggable.id)
@taggable.save!
expect(@taggable.cached_tag_list).to eq('awesome, epic')
end

it 'should update the cache' do
@taggable.update_attributes(tag_list: 'awesome, epic')
@taggable.update_attributes(tag_list: 'awesome')
@taggable.update(tag_list: 'awesome, epic')
@taggable.update(tag_list: 'awesome')
expect(@taggable.cached_tag_list).to eq('awesome')
end

it 'should remove the cache' do
@taggable.update_attributes(tag_list: 'awesome, epic')
@taggable.update_attributes(tag_list: '')
@taggable.update(tag_list: 'awesome, epic')
@taggable.update(tag_list: '')
expect(@taggable.cached_tag_list).to be_blank
end

it 'should have a tag list' do
@taggable.update_attributes(tag_list: 'awesome, epic')
@taggable.update(tag_list: 'awesome, epic')
@taggable = CachedModel.find(@taggable.id)
expect(@taggable.tag_list.sort).to eq(%w(awesome epic).sort)
end

it 'should keep the tag list' do
@taggable.update_attributes(tag_list: 'awesome, epic')
@taggable.update(tag_list: 'awesome, epic')
@taggable = CachedModel.find(@taggable.id)
@taggable.save!
expect(@taggable.tag_list.sort).to eq(%w(awesome epic).sort)
Expand Down Expand Up @@ -95,7 +95,7 @@
end

it 'should cache tags with custom delimiter' do
@taggable.update_attributes(tag_list: 'awesome; epic')
@taggable.update(tag_list: 'awesome; epic')
expect(@taggable.tag_list).to eq(['awesome', 'epic'])
expect(@taggable.cached_tag_list).to eq('awesome; epic')

Expand Down
2 changes: 1 addition & 1 deletion spec/acts_as_taggable_on/single_table_inheritance_spec.rb
Expand Up @@ -150,7 +150,7 @@
inheriting_model.tag_list = 'one'
inheriting_model.save!

inheriting_model.update_attributes! name: 'foo'
inheriting_model.update! name: 'foo'
end

it "should only join with taggable's table to check type for inherited models" do
Expand Down
2 changes: 1 addition & 1 deletion spec/acts_as_taggable_on/taggable_spec.rb
Expand Up @@ -541,7 +541,7 @@

it 'should not delete tags if not updated' do
model = TaggableModel.create(name: 'foo', tag_list: 'ruby, rails, programming')
model.update_attributes(name: 'bar')
model.update(name: 'bar')
model.reload
expect(model.tag_list.sort).to eq(%w(ruby rails programming).sort)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/acts_as_taggable_on/tagger_spec.rb
Expand Up @@ -112,15 +112,15 @@
end

it 'should not lose tags' do
@taggable.update_attributes(tag_list: 'ruby')
@taggable.update(tag_list: 'ruby')
@user.tag(@taggable, with: 'ruby, scheme', on: :tags)

[@taggable, @user].each(&:reload)
expect(@taggable.tag_list).to eq(%w(ruby))
expect(@taggable.all_tags_list.sort).to eq(%w(ruby scheme).sort)

expect(-> {
@taggable.update_attributes(tag_list: '')
@taggable.update(tag_list: '')
}).to change(ActsAsTaggableOn::Tagging, :count).by(-1)

expect(@taggable.tag_list).to be_empty
Expand Down

0 comments on commit 950c010

Please sign in to comment.