Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rails 5.0.0 alpha support #673

Merged
merged 1 commit into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ tmp*.sw?
tmp
*.gem
*.lock

/.idea
5 changes: 5 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ appraise "activerecord-4.2" do
gem "railties", github: "rails/rails" , branch: '4-2-stable'
gem "activerecord", github: "rails/rails" , branch: '4-2-stable'
end

appraise "activerecord-5.0" do
gem "railties", github: "rails/rails" , branch: 'master'
gem "activerecord", github: "rails/rails" , branch: 'master'
end
2 changes: 1 addition & 1 deletion acts-as-taggable-on.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
gem.post_install_message = File.read('UPGRADING.md')
end

gem.add_runtime_dependency 'activerecord', ['>= 3.2', '< 5']
gem.add_runtime_dependency 'activerecord', ['>= 3.2', '< 5']

gem.add_development_dependency 'sqlite3'
gem.add_development_dependency 'mysql2', '~> 0.3.7'
Expand Down
18 changes: 18 additions & 0 deletions gemfiles/activerecord_5.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file was generated by Appraisal

source "https://rubygems.org"

# You can change the gem to your local path with `gem 'arel', path: 'local_gem_path'`
gem 'arel', github: "rails/arel" , branch: 'master'
gem "railties", github: "rails/rails" , branch: 'master'
gem "activerecord", github: "rails/rails" , branch: 'master'

group :local_development do
gem "guard"
gem "guard-rspec"
gem "appraisal"
gem "rake"
gem "byebug", :platform => :mri_22
end

gemspec :path => "../"
10 changes: 3 additions & 7 deletions lib/acts-as-taggable-on.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def initialize
end

def strict_case_match=(force_cs)
if @force_binary_collation == false
@strict_case_match = force_cs
end
@strict_case_match = force_cs unless @force_binary_collation
end

def delimiter=(string)
Expand All @@ -89,7 +87,7 @@ def delimiter=(string)

def force_binary_collation=(force_bin)
if Utils.using_mysql?
if force_bin == true
if force_bin
Configuration.apply_binary_collation(true)
@force_binary_collation = true
@strict_case_match = true
Expand All @@ -103,9 +101,7 @@ def force_binary_collation=(force_bin)
def self.apply_binary_collation(bincoll)
if Utils.using_mysql?
coll = 'utf8_general_ci'
if bincoll == true
coll = 'utf8_bin'
end
coll = 'utf8_bin' if bincoll
begin
ActiveRecord::Migration.execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE #{coll};")
rescue Exception => e
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_taggable_on/compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ActsAsTaggableOn::Compatibility
def has_many_with_taggable_compatibility(name, options = {}, &extention)
if ActsAsTaggableOn::Utils.active_record4?
if ActsAsTaggableOn::Utils.active_record4? || ActsAsTaggableOn::Utils.active_record5?
scope, opts = build_taggable_scope_and_options(options)
has_many(name, scope, opts, &extention)
else
Expand Down
7 changes: 5 additions & 2 deletions lib/acts_as_taggable_on/taggable/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ def tag_counts_on(context, options={})
end

module CalculationMethods
def count(column_name=:all, options = {})
# Rails 5 TODO: Remove options argument as soon we remove support to
# activerecord-deprecated_finders.
# 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
super
ActsAsTaggableOn::Utils.active_record5? ? super(column_name) : super(column_name, options)
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/acts_as_taggable_on/taggable/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ def adjust_taggings_alias(taggings_alias)
def taggable_mixin
@taggable_mixin ||= Module.new
end

private

# Rails 5 has merged sanitize and quote_value
# See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/sanitization.rb#L10
def quote_value(value, column = nil)
ActsAsTaggableOn::Utils.active_record5? ? super(value) : super(value, column)
end
end

# all column names are necessary for PostgreSQL group clause
Expand Down
4 changes: 4 additions & 0 deletions lib/acts_as_taggable_on/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def active_record4?
::ActiveRecord::VERSION::MAJOR == 4
end

def active_record5?
::ActiveRecord::VERSION::MAJOR == 5
end

def like_operator
using_postgresql? ? 'ILIKE' : 'LIKE'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
begin
#activerecord 4 uses symbol
#TODO, remove when activerecord 3 support is dropped
if ActsAsTaggableOn::Utils.active_record4?
if ActsAsTaggableOn::Utils.active_record4? || ActsAsTaggableOn::Utils.active_record5?
ActiveRecord::Base.establish_connection(db_name.to_sym)
else
ActiveRecord::Base.establish_connection(db_name)
Expand Down