Skip to content

Commit

Permalink
Merge pull request #384 from kbrock/deprecations
Browse files Browse the repository at this point in the history
Fix 'dangerous errors' when using in Rails 5.2
  • Loading branch information
kbrock authored Apr 18, 2018
2 parents 8111e08 + 4fd4b7c commit 8b84070
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ gemfile:
- gemfiles/mysql_ar_42.gemfile
- gemfiles/mysql2_ar_50.gemfile
- gemfiles/mysql2_ar_51.gemfile
- gemfiles/mysql2_ar_52.gemfile
- gemfiles/pg_ar_42.gemfile
- gemfiles/pg_ar_50.gemfile
- gemfiles/pg_ar_51.gemfile
- gemfiles/pg_ar_52.gemfile
- gemfiles/sqlite3_ar_42.gemfile
- gemfiles/sqlite3_ar_50.gemfile
- gemfiles/sqlite3_ar_51.gemfile
- gemfiles/sqlite3_ar_52.gemfile

matrix:
include:
Expand Down
2 changes: 1 addition & 1 deletion Appraisals
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%w(mysql pg sqlite3).each do |db_type|
%w(3.2.22.5 4.2.10 5.0.7 5.1.6).each do |ar_version|
%w(3.2.22.5 4.2.10 5.0.7 5.1.6 5.2.0).each do |ar_version|
# rails 5.0 only supports 'mysql2' driver
# rails 4.2 supports both
db_gem = db_type
Expand Down
17 changes: 17 additions & 0 deletions gemfiles/mysql2_ar_52.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "coveralls", require: false
gem "activerecord", "5.2.0"
if RUBY_VERSION < "2.0"
gem "json", "~> 1.8.3"
else
gem "json"
end
gem "term-ansicolor", "~> 1.3.2"
gem "tins", "~> 1.6.0"
gem "mysql2"

gemspec path: "../"
17 changes: 17 additions & 0 deletions gemfiles/pg_ar_52.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "coveralls", require: false
gem "activerecord", "5.2.0"
if RUBY_VERSION < "2.0"
gem "json", "~> 1.8.3"
else
gem "json"
end
gem "term-ansicolor", "~> 1.3.2"
gem "tins", "~> 1.6.0"
gem "pg", "0.18.4"

gemspec path: "../"
16 changes: 16 additions & 0 deletions gemfiles/sqlite3_ar_52.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "coveralls", require: false
gem "activerecord", "5.2.0"
if RUBY_VERSION < "2.0"
gem "json", "~> 1.8.3"
else
gem "json"
end
gem "term-ansicolor", "~> 1.3.2"
gem "tins", "~> 1.6.0"

gemspec path: "../"
4 changes: 2 additions & 2 deletions lib/ancestry/has_ancestry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def has_ancestry options = {}
scope :siblings_of, lambda { |object| where(sibling_conditions(object)) }
scope :ordered_by_ancestry, Proc.new { |order|
if %w(mysql mysql2 sqlite sqlite3 postgresql).include?(connection.adapter_name.downcase) && ActiveRecord::VERSION::MAJOR >= 5
reorder("coalesce(#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)}, '')", order)
reorder(Arel.sql("coalesce(#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)}, '')"), order)
else
reorder("(CASE WHEN #{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)} IS NULL THEN 0 ELSE 1 END), #{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)}", order)
reorder(Arel.sql("(CASE WHEN #{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)} IS NULL THEN 0 ELSE 1 END), #{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)}"), order)
end
}
scope :ordered_by_ancestry_and, Proc.new { |order| ordered_by_ancestry(order) }
Expand Down
8 changes: 1 addition & 7 deletions lib/ancestry/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,7 @@ def ancestor_was_conditions
end

def ancestor_ids_was
relevant_attributes = if ActiveRecord::VERSION::STRING >= '5.1.0'
saved_changes.transform_values(&:first)
else
changed_attributes
end

parse_ancestry_column(relevant_attributes[self.ancestry_base_class.ancestry_column.to_s])
parse_ancestry_column(send("#{self.ancestry_base_class.ancestry_column}_was"))
end

def path_ids
Expand Down

0 comments on commit 8b84070

Please sign in to comment.