From 1b849123f977a34056d92652fd36777caddcc5b7 Mon Sep 17 00:00:00 2001 From: Hamed Asghari Date: Tue, 16 May 2017 22:58:26 -0700 Subject: [PATCH] Support Rails 5.1 --- .travis.yml | 10 +- Appraisals | 12 +- README.md | 8 +- gemfiles/activerecord_4.0.gemfile.lock | 101 --------------- gemfiles/activerecord_4.1.gemfile | 8 -- gemfiles/activerecord_4.1.gemfile.lock | 103 --------------- gemfiles/activerecord_4.2.gemfile | 8 -- gemfiles/activerecord_4.2.gemfile.lock | 120 ------------------ ...d_4.0.gemfile => activerecord_5.1.gemfile} | 2 +- gemfiles/activerecord_5.1.gemfile.lock | 116 +++++++++++++++++ lib/parentry.rb | 2 +- lib/parentry/instance_methods.rb | 4 +- .../strategy/array/instance_methods.rb | 2 +- .../strategy/ltree/instance_methods.rb | 2 +- parentry.gemspec | 4 +- 15 files changed, 131 insertions(+), 371 deletions(-) delete mode 100644 gemfiles/activerecord_4.0.gemfile.lock delete mode 100644 gemfiles/activerecord_4.1.gemfile delete mode 100644 gemfiles/activerecord_4.1.gemfile.lock delete mode 100644 gemfiles/activerecord_4.2.gemfile delete mode 100644 gemfiles/activerecord_4.2.gemfile.lock rename gemfiles/{activerecord_4.0.gemfile => activerecord_5.1.gemfile} (78%) create mode 100644 gemfiles/activerecord_5.1.gemfile.lock diff --git a/.travis.yml b/.travis.yml index b5525b9..8fe7e61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,11 @@ language: ruby rvm: - - 2.0.0 - - 2.1.0 - - 2.2.0 + - 2.2.5 + - 2.3.4 + - 2.4.1 env: - STRATEGY=array - STRATEGY=ltree gemfile: - - gemfiles/activerecord_4.0.gemfile - - gemfiles/activerecord_4.1.gemfile - - gemfiles/activerecord_4.2.gemfile + - gemfiles/activerecord_5.1.gemfile before_install: gem install bundler -v 1.10.6 diff --git a/Appraisals b/Appraisals index fecc7ed..d23fcfa 100644 --- a/Appraisals +++ b/Appraisals @@ -1,11 +1,3 @@ -appraise 'activerecord-4.0' do - gem 'activerecord', '~> 4.0.0' -end - -appraise 'activerecord-4.1' do - gem 'activerecord', '~> 4.1.0' -end - -appraise 'activerecord-4.2' do - gem 'activerecord', '~> 4.2.0' +appraise 'activerecord-5.1' do + gem 'activerecord', '~> 5.1.0' end diff --git a/README.md b/README.md index ab1fbea..69d600f 100644 --- a/README.md +++ b/README.md @@ -31,15 +31,9 @@ add_column :my_table, :parentry, :ltree add_column :my_table, :parent_id, :integer ``` -## Development - -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. - -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). - ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/hasghari/parentry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct. +Bug reports and pull requests are welcome on GitHub at https://github.com/hasghari/parentry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/) code of conduct. ## License diff --git a/gemfiles/activerecord_4.0.gemfile.lock b/gemfiles/activerecord_4.0.gemfile.lock deleted file mode 100644 index 49b9e06..0000000 --- a/gemfiles/activerecord_4.0.gemfile.lock +++ /dev/null @@ -1,101 +0,0 @@ -PATH - remote: ../ - specs: - parentry (0.4.0) - activerecord (>= 4.0.0) - -GEM - remote: https://rubygems.org/ - specs: - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - appraisal (2.1.0) - bundler - rake - thor (>= 0.14.0) - arel (4.0.2) - builder (3.1.4) - coderay (1.1.0) - combustion (0.5.3) - activesupport (>= 3.0.0) - railties (>= 3.0.0) - thor (>= 0.14.6) - database_cleaner (1.5.1) - diff-lcs (1.2.5) - erubis (2.7.0) - i18n (0.7.0) - method_source (0.8.2) - minitest (4.7.5) - multi_json (1.11.2) - pg (0.18.3) - pry (0.10.3) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - rack (1.5.5) - rack-test (0.6.3) - rack (>= 1.0) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rspec-core (3.3.2) - rspec-support (~> 3.3.0) - rspec-expectations (3.3.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-mocks (3.3.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-rails (3.3.3) - actionpack (>= 3.0, < 4.3) - activesupport (>= 3.0, < 4.3) - railties (>= 3.0, < 4.3) - rspec-core (~> 3.3.0) - rspec-expectations (~> 3.3.0) - rspec-mocks (~> 3.3.0) - rspec-support (~> 3.3.0) - rspec-support (3.3.0) - slop (3.6.0) - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (0.3.45) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord (~> 4.0.0) - appraisal - bundler (~> 1.10) - combustion (>= 0.5.2) - database_cleaner - parentry! - pg - pry - rake (~> 10.0) - rspec-rails - -BUNDLED WITH - 1.10.6 diff --git a/gemfiles/activerecord_4.1.gemfile b/gemfiles/activerecord_4.1.gemfile deleted file mode 100644 index e00f621..0000000 --- a/gemfiles/activerecord_4.1.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal" -gem "activerecord", "~> 4.1.0" - -gemspec :path => "../" diff --git a/gemfiles/activerecord_4.1.gemfile.lock b/gemfiles/activerecord_4.1.gemfile.lock deleted file mode 100644 index 4af8325..0000000 --- a/gemfiles/activerecord_4.1.gemfile.lock +++ /dev/null @@ -1,103 +0,0 @@ -PATH - remote: ../ - specs: - parentry (0.4.0) - activerecord (>= 4.0.0) - -GEM - remote: https://rubygems.org/ - specs: - actionpack (4.1.13) - actionview (= 4.1.13) - activesupport (= 4.1.13) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - actionview (4.1.13) - activesupport (= 4.1.13) - builder (~> 3.1) - erubis (~> 2.7.0) - activemodel (4.1.13) - activesupport (= 4.1.13) - builder (~> 3.1) - activerecord (4.1.13) - activemodel (= 4.1.13) - activesupport (= 4.1.13) - arel (~> 5.0.0) - activesupport (4.1.13) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - appraisal (2.1.0) - bundler - rake - thor (>= 0.14.0) - arel (5.0.1.20140414130214) - builder (3.2.2) - coderay (1.1.0) - combustion (0.5.3) - activesupport (>= 3.0.0) - railties (>= 3.0.0) - thor (>= 0.14.6) - database_cleaner (1.5.1) - diff-lcs (1.2.5) - erubis (2.7.0) - i18n (0.7.0) - json (1.8.3) - method_source (0.8.2) - minitest (5.8.1) - pg (0.18.3) - pry (0.10.3) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - rack (1.5.5) - rack-test (0.6.3) - rack (>= 1.0) - railties (4.1.13) - actionpack (= 4.1.13) - activesupport (= 4.1.13) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rspec-core (3.3.2) - rspec-support (~> 3.3.0) - rspec-expectations (3.3.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-mocks (3.3.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-rails (3.3.3) - actionpack (>= 3.0, < 4.3) - activesupport (>= 3.0, < 4.3) - railties (>= 3.0, < 4.3) - rspec-core (~> 3.3.0) - rspec-expectations (~> 3.3.0) - rspec-mocks (~> 3.3.0) - rspec-support (~> 3.3.0) - rspec-support (3.3.0) - slop (3.6.0) - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord (~> 4.1.0) - appraisal - bundler (~> 1.10) - combustion (>= 0.5.2) - database_cleaner - parentry! - pg - pry - rake (~> 10.0) - rspec-rails - -BUNDLED WITH - 1.10.6 diff --git a/gemfiles/activerecord_4.2.gemfile b/gemfiles/activerecord_4.2.gemfile deleted file mode 100644 index 98eca9b..0000000 --- a/gemfiles/activerecord_4.2.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal" -gem "activerecord", "~> 4.2.0" - -gemspec :path => "../" diff --git a/gemfiles/activerecord_4.2.gemfile.lock b/gemfiles/activerecord_4.2.gemfile.lock deleted file mode 100644 index 2f27da0..0000000 --- a/gemfiles/activerecord_4.2.gemfile.lock +++ /dev/null @@ -1,120 +0,0 @@ -PATH - remote: ../ - specs: - parentry (0.4.0) - activerecord (>= 4.0.0) - -GEM - remote: https://rubygems.org/ - specs: - actionpack (4.2.4) - actionview (= 4.2.4) - activesupport (= 4.2.4) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.4) - activesupport (= 4.2.4) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activemodel (4.2.4) - activesupport (= 4.2.4) - builder (~> 3.1) - activerecord (4.2.4) - activemodel (= 4.2.4) - activesupport (= 4.2.4) - arel (~> 6.0) - activesupport (4.2.4) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - appraisal (2.1.0) - bundler - rake - thor (>= 0.14.0) - arel (6.0.3) - builder (3.2.2) - coderay (1.1.0) - combustion (0.5.3) - activesupport (>= 3.0.0) - railties (>= 3.0.0) - thor (>= 0.14.6) - database_cleaner (1.5.1) - diff-lcs (1.2.5) - erubis (2.7.0) - i18n (0.7.0) - json (1.8.3) - loofah (2.0.3) - nokogiri (>= 1.5.9) - method_source (0.8.2) - mini_portile (0.6.2) - minitest (5.8.1) - nokogiri (1.6.6.2) - mini_portile (~> 0.6.0) - pg (0.18.3) - pry (0.10.3) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - rack (1.6.4) - rack-test (0.6.3) - rack (>= 1.0) - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.2) - loofah (~> 2.0) - railties (4.2.4) - actionpack (= 4.2.4) - activesupport (= 4.2.4) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rspec-core (3.3.2) - rspec-support (~> 3.3.0) - rspec-expectations (3.3.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-mocks (3.3.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-rails (3.3.3) - actionpack (>= 3.0, < 4.3) - activesupport (>= 3.0, < 4.3) - railties (>= 3.0, < 4.3) - rspec-core (~> 3.3.0) - rspec-expectations (~> 3.3.0) - rspec-mocks (~> 3.3.0) - rspec-support (~> 3.3.0) - rspec-support (3.3.0) - slop (3.6.0) - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord (~> 4.2.0) - appraisal - bundler (~> 1.10) - combustion (>= 0.5.2) - database_cleaner - parentry! - pg - pry - rake (~> 10.0) - rspec-rails - -BUNDLED WITH - 1.10.6 diff --git a/gemfiles/activerecord_4.0.gemfile b/gemfiles/activerecord_5.1.gemfile similarity index 78% rename from gemfiles/activerecord_4.0.gemfile rename to gemfiles/activerecord_5.1.gemfile index 849ca92..a4b9b13 100644 --- a/gemfiles/activerecord_4.0.gemfile +++ b/gemfiles/activerecord_5.1.gemfile @@ -3,6 +3,6 @@ source "https://rubygems.org" gem "appraisal" -gem "activerecord", "~> 4.0.0" +gem "activerecord", "~> 5.1.0" gemspec :path => "../" diff --git a/gemfiles/activerecord_5.1.gemfile.lock b/gemfiles/activerecord_5.1.gemfile.lock new file mode 100644 index 0000000..d9f178e --- /dev/null +++ b/gemfiles/activerecord_5.1.gemfile.lock @@ -0,0 +1,116 @@ +PATH + remote: .. + specs: + parentry (0.4.0) + activerecord (~> 5.1.0) + +GEM + remote: https://rubygems.org/ + specs: + actionpack (5.1.1) + actionview (= 5.1.1) + activesupport (= 5.1.1) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.1) + activesupport (= 5.1.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activemodel (5.1.1) + activesupport (= 5.1.1) + activerecord (5.1.1) + activemodel (= 5.1.1) + activesupport (= 5.1.1) + arel (~> 8.0) + activesupport (5.1.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (8.0.0) + builder (3.2.3) + coderay (1.1.1) + combustion (0.5.3) + activesupport (>= 3.0.0) + railties (>= 3.0.0) + thor (>= 0.14.6) + concurrent-ruby (1.0.5) + database_cleaner (1.6.1) + diff-lcs (1.3) + erubi (1.6.0) + i18n (0.8.1) + loofah (2.0.3) + nokogiri (>= 1.5.9) + method_source (0.8.2) + mini_portile2 (2.1.0) + minitest (5.10.2) + nokogiri (1.7.2) + mini_portile2 (~> 2.1.0) + pg (0.20.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rack (2.0.3) + rack-test (0.6.3) + rack (>= 1.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.1.1) + actionpack (= 5.1.1) + activesupport (= 5.1.1) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.5.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-rails (3.6.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) + slop (3.6.0) + thor (0.19.4) + thread_safe (0.3.6) + tzinfo (1.2.3) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord (~> 5.1.0) + appraisal + bundler (~> 1.10) + combustion (= 0.5.3) + database_cleaner + parentry! + pg + pry + rake (~> 10.0) + rspec-rails + +BUNDLED WITH + 1.14.6 diff --git a/lib/parentry.rb b/lib/parentry.rb index 988326f..bd4d083 100644 --- a/lib/parentry.rb +++ b/lib/parentry.rb @@ -23,7 +23,7 @@ def self.included(base) after_create :commit_parentry before_update :assign_parentry, if: proc { changes[:parent_id].present? } - after_update :cascade_parentry, if: proc { changes[parentry_column].present? } + after_update :cascade_parentry, if: proc { saved_changes[parentry_column].present? } before_validation :cache_parentry_depth, if: proc { cache_depth } before_save :cache_parentry_depth, if: proc { cache_depth } diff --git a/lib/parentry/instance_methods.rb b/lib/parentry/instance_methods.rb index 7756b45..9b34f3d 100644 --- a/lib/parentry/instance_methods.rb +++ b/lib/parentry/instance_methods.rb @@ -45,8 +45,8 @@ def touch_callbacks_disabled? end def ancestor_ids_was - return [] unless changes[parentry_column] - parse_parentry(changes[parentry_column][0]).tap(&:pop) + return [] unless saved_changes[parentry_column] + parse_parentry(saved_changes[parentry_column][0]).tap(&:pop) end end end diff --git a/lib/parentry/strategy/array/instance_methods.rb b/lib/parentry/strategy/array/instance_methods.rb index e57bb98..b7e924b 100644 --- a/lib/parentry/strategy/array/instance_methods.rb +++ b/lib/parentry/strategy/array/instance_methods.rb @@ -12,7 +12,7 @@ def compute_parentry end def cascade_parentry - old_path, new_path = changes[parentry_column] + old_path, new_path = saved_changes[parentry_column] parentry_scope.where( ["#{parentry_column} @> ARRAY[:tree] AND id != :id", tree: old_path, id: id] ).update_all( diff --git a/lib/parentry/strategy/ltree/instance_methods.rb b/lib/parentry/strategy/ltree/instance_methods.rb index d9097ae..795aad5 100644 --- a/lib/parentry/strategy/ltree/instance_methods.rb +++ b/lib/parentry/strategy/ltree/instance_methods.rb @@ -11,7 +11,7 @@ def compute_parentry end def cascade_parentry - old_path, new_path = changes[parentry_column] + old_path, new_path = saved_changes[parentry_column] parentry_scope.where( ["#{parentry_column} <@ :tree AND id != :id", tree: old_path, id: id] ).update_all( diff --git a/parentry.gemspec b/parentry.gemspec index 59081f2..09146fc 100644 --- a/parentry.gemspec +++ b/parentry.gemspec @@ -16,13 +16,13 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.require_paths = ['lib'] - spec.add_dependency 'activerecord', '>= 4.0.0' + spec.add_dependency 'activerecord', '~> 5.1.0' spec.add_development_dependency 'bundler', '~> 1.10' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rspec-rails' spec.add_development_dependency 'pg' - spec.add_development_dependency 'combustion', '>= 0.5.2' + spec.add_development_dependency 'combustion', '0.5.3' spec.add_development_dependency 'database_cleaner' spec.add_development_dependency 'pry' end