Skip to content

Commit

Permalink
Rails 5 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
minimul committed May 25, 2017
1 parent 7688d3a commit 0f38709
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
.config
.yardoc
Gemfile.lock
gemfiles/*.lock
vendor/
InstalledFiles
_yardoc
coverage
Expand Down
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
rvm:
- 2.0.0
- 2.1.0
- 2.2.2

before_install:
- gem install bundler -v '= 1.5.1'

gemfile:
- gemfiles/Gemfile.4.2
- gemfiles/Gemfile.5.0

matrix:
exclude:
- rvm: 2.1.0
gemfile: gemfiles/Gemfile.5.0

notifications:
hipchat:
rooms:
Expand Down
4 changes: 2 additions & 2 deletions destroyed_at.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '~> 2.0'

spec.add_runtime_dependency "activerecord", '~> 4.1'
spec.add_runtime_dependency 'actionpack', '~> 4.1'
spec.add_runtime_dependency "activerecord", '>= 4.1'
spec.add_runtime_dependency 'actionpack', '>= 4.1'

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
Expand Down
6 changes: 6 additions & 0 deletions gemfiles/Gemfile.4.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in destroyed_at.gemspec
gemspec :path => "../"
gem 'm', github: 'unmanbearpig/m'
gem "activerecord", "~> 4.2.0"
6 changes: 6 additions & 0 deletions gemfiles/Gemfile.5.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in destroyed_at.gemspec
gemspec :path => "../"
gem 'm', github: 'unmanbearpig/m'
gem "activerecord", "~> 5.0.0"
3 changes: 2 additions & 1 deletion lib/destroyed_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def self.has_destroy_at?(object)
module ClassMethods
def destroyed(time = nil)
query = where.not(destroyed_at: nil)
query.where_values.reject! do |node|
values = query.respond_to?(:where_clause) ? query.where_clause.send(:predicates) : query.where_values
values.reject! do |node|
Arel::Nodes::Equality === node && node.left.name == 'destroyed_at' && node.right.nil?
end
time ? query.where(destroyed_at: time) : query.where.not(destroyed_at: nil)
Expand Down
3 changes: 2 additions & 1 deletion lib/destroyed_at/has_many_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def delete_records(records, method)
r.destroy
end
end
update_counter(-records.length) unless inverse_updates_counter_cache?
iucc = ActiveRecord::VERSION::MAJOR >= 5 ? reflection.inverse_updates_counter_cache? : inverse_updates_counter_cache?
update_counter(-records.length) unless iucc
else
super
end
Expand Down

0 comments on commit 0f38709

Please sign in to comment.