diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..e6134e6 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +#@IgnoreInspection BashAddShebang +# Configuration for direnv (see https://github.com/direnv/direnv) + +PATH_add bin diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..b8cb495 --- /dev/null +++ b/Appraisals @@ -0,0 +1,34 @@ +appraise "rails-4-1" do + ruby ">= 2.1.6" + gem "activerecord", "~> 4.1.0" + gem "pg", "~> 0.17.0" + gem "activerecord-import", "~> 0.10.0" +end + +appraise "rails-4-2" do + ruby ">= 2.1.6" + gem "activerecord", "~> 4.2.0" + gem "pg", "~> 0.17.0" + gem "activerecord-import", "~> 0.10.0" +end + +appraise "rails-5-0" do + ruby ">= 2.2.2" + gem "activerecord", "~> 5.0.0" + gem "pg", "~> 0.18.0" + gem "activerecord-import", "= 0.13.0" +end + +appraise "rails-5-1" do + ruby ">= 2.2.2" + gem "activerecord", "~> 5.1.0" + gem "pg", "~> 0.18.0" + gem "activerecord-import", "= 0.13.0" +end + +appraise "rails-5-2" do + ruby ">= 2.2.2" + gem "activerecord", "~> 5.2.0" + gem "pg", "~> 0.18.0" + gem "activerecord-import", "= 0.13.0" +end diff --git a/README.md b/README.md index 7e0074d..1dc840f 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,26 @@ For example: **A.** You can use [ActiveModel::Serialization](http://api.rubyonrails.org/classes/ActiveModel/Serialization.html) or [ActiveModel::Serializers](https://github.com/rails-api/active_model_serializers) but they are not heartily recommended. The former is too coupled to the model and the latter is too coupled to Rails controllers. Vorpal uses [SimpleSerializer](https://github.com/nulogy/simple_serializer) for this purpose. -## Running Tests +## Contributing + +1. Fork it ( https://github.com/nulogy/vorpal/fork ) +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create a new Pull Request + +### Setup DirEnv + +Using this gem's bin stubs (contained in the `bin` dir) is much easier if [DirEnv](https://github.com/direnv/direnv) is installed. + +On OSX using ZSH DirEnv can be installed like so: + +1. `brew install direnv` +2. `echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc` + +Please see the [DirEnv docs](https://direnv.net/) if your environment is different. + +### Running Tests 1. Start a PostgreSQL server. 2. Either: @@ -239,16 +258,17 @@ For example: * Modify `spec/helpers/db_helpers.rb`. 3. Run `rake` from the terminal. -## Contributors +### Running Tests for the non-default versions of Rails -* [Sean Kirby](https://github.com/sskirby) -* [Paul Sobocinski](https://github.com/psobocinski) -* [Jason Cheong-Kee-You](https://github.com/jchunky) +1. Start a PostgreSQL server. +2. Either: + * Create a DB user called `vorpal` with password `pass`. OR: + * Modify `spec/helpers/db_helpers.rb`. +3. Run `appraisal rake` from the terminal. + * Where `` is one of the options defined in the `./Appraisal` file. -## Contributing +Please see the [Appraisal gem docs](https://github.com/thoughtbot/appraisal) for more information. -1. Fork it ( https://github.com/nulogy/vorpal/fork ) -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Add some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create a new Pull Request +## Contributors + +See who's [contributed](https://github.com/nulogy/vorpal/graphs/contributors)! diff --git a/bin/appraisal b/bin/appraisal new file mode 100755 index 0000000..0e7ba65 --- /dev/null +++ b/bin/appraisal @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'appraisal' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("appraisal", "appraisal") diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..9275675 --- /dev/null +++ b/bin/rake @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..a6c7852 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/gemfiles/rails_4_1.gemfile b/gemfiles/rails_4_1.gemfile new file mode 100644 index 0000000..7f760f1 --- /dev/null +++ b/gemfiles/rails_4_1.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +ruby ">= 2.1.6" + +gem "activerecord", "~> 4.1.0" +gem "pg", "~> 0.17.0" +gem "activerecord-import", "~> 0.10.0" + +gemspec path: "../" diff --git a/gemfiles/rails_4_1.gemfile.lock b/gemfiles/rails_4_1.gemfile.lock new file mode 100644 index 0000000..9cf63f3 --- /dev/null +++ b/gemfiles/rails_4_1.gemfile.lock @@ -0,0 +1,92 @@ +PATH + remote: .. + specs: + vorpal (1.0.0) + activesupport + equalizer + simple_serializer (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + activerecord (4.1.16) + activemodel (= 4.1.16) + activesupport (= 4.1.16) + arel (~> 5.0.0) + activerecord-import (0.10.0) + activerecord (>= 3.0) + activesupport (4.1.16) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (5.0.1.20140414130214) + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + builder (3.2.3) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + concurrent-ruby (1.0.5) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + diff-lcs (1.3) + equalizer (0.0.11) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + json (1.8.6) + minitest (5.11.3) + pg (0.17.1) + rake (10.5.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + simple_serializer (1.0.2) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord (~> 4.1.0) + activerecord-import (~> 0.10.0) + appraisal (~> 2.2) + pg (~> 0.17.0) + rake (~> 10.0) + rspec (~> 3.0) + virtus (~> 1.0) + vorpal! + +RUBY VERSION + ruby 2.3.3p222 + +BUNDLED WITH + 1.16.2 diff --git a/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile new file mode 100644 index 0000000..e756511 --- /dev/null +++ b/gemfiles/rails_4_2.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +ruby ">= 2.1.6" + +gem "activerecord", "~> 4.2.0" +gem "pg", "~> 0.17.0" +gem "activerecord-import", "~> 0.10.0" + +gemspec path: "../" diff --git a/gemfiles/rails_4_2.gemfile.lock b/gemfiles/rails_4_2.gemfile.lock new file mode 100644 index 0000000..a86a62a --- /dev/null +++ b/gemfiles/rails_4_2.gemfile.lock @@ -0,0 +1,90 @@ +PATH + remote: .. + specs: + vorpal (1.0.0) + activesupport + equalizer + simple_serializer (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (4.2.10) + activesupport (= 4.2.10) + builder (~> 3.1) + activerecord (4.2.10) + activemodel (= 4.2.10) + activesupport (= 4.2.10) + arel (~> 6.0) + activerecord-import (0.10.0) + activerecord (>= 3.0) + activesupport (4.2.10) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (6.0.4) + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + builder (3.2.3) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + concurrent-ruby (1.0.5) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + diff-lcs (1.3) + equalizer (0.0.11) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + minitest (5.11.3) + pg (0.17.1) + rake (10.5.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + simple_serializer (1.0.2) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord (~> 4.2.0) + activerecord-import (~> 0.10.0) + appraisal (~> 2.2) + pg (~> 0.17.0) + rake (~> 10.0) + rspec (~> 3.0) + virtus (~> 1.0) + vorpal! + +RUBY VERSION + ruby 2.3.3p222 + +BUNDLED WITH + 1.16.2 diff --git a/gemfiles/rails_5_0.gemfile b/gemfiles/rails_5_0.gemfile new file mode 100644 index 0000000..2c2b579 --- /dev/null +++ b/gemfiles/rails_5_0.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +ruby ">= 2.2.2" + +gem "activerecord", "~> 5.0.0" +gem "pg", "~> 0.18.0" +gem "activerecord-import", "= 0.13.0" + +gemspec path: "../" diff --git a/gemfiles/rails_5_0.gemfile.lock b/gemfiles/rails_5_0.gemfile.lock new file mode 100644 index 0000000..521c6c4 --- /dev/null +++ b/gemfiles/rails_5_0.gemfile.lock @@ -0,0 +1,88 @@ +PATH + remote: .. + specs: + vorpal (1.0.0) + activesupport + equalizer + simple_serializer (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (5.0.7) + activesupport (= 5.0.7) + activerecord (5.0.7) + activemodel (= 5.0.7) + activesupport (= 5.0.7) + arel (~> 7.0) + activerecord-import (0.13.0) + activerecord (>= 3.0) + activesupport (5.0.7) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (7.1.4) + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + concurrent-ruby (1.0.5) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + diff-lcs (1.3) + equalizer (0.0.11) + i18n (1.1.0) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + minitest (5.11.3) + pg (0.18.4) + rake (10.5.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + simple_serializer (1.0.2) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord (~> 5.0.0) + activerecord-import (= 0.13.0) + appraisal (~> 2.2) + pg (~> 0.18.0) + rake (~> 10.0) + rspec (~> 3.0) + virtus (~> 1.0) + vorpal! + +RUBY VERSION + ruby 2.3.3p222 + +BUNDLED WITH + 1.16.2 diff --git a/gemfiles/rails_5_1.gemfile b/gemfiles/rails_5_1.gemfile new file mode 100644 index 0000000..83abff1 --- /dev/null +++ b/gemfiles/rails_5_1.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +ruby ">= 2.2.2" + +gem "activerecord", "~> 5.1.0" +gem "pg", "~> 0.18.0" +gem "activerecord-import", "= 0.13.0" + +gemspec path: "../" diff --git a/gemfiles/rails_5_1.gemfile.lock b/gemfiles/rails_5_1.gemfile.lock new file mode 100644 index 0000000..048cbdb --- /dev/null +++ b/gemfiles/rails_5_1.gemfile.lock @@ -0,0 +1,88 @@ +PATH + remote: .. + specs: + vorpal (1.0.0) + activesupport + equalizer + simple_serializer (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (5.1.6) + activesupport (= 5.1.6) + activerecord (5.1.6) + activemodel (= 5.1.6) + activesupport (= 5.1.6) + arel (~> 8.0) + activerecord-import (0.13.0) + activerecord (>= 3.0) + activesupport (5.1.6) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (8.0.0) + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + concurrent-ruby (1.0.5) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + diff-lcs (1.3) + equalizer (0.0.11) + i18n (1.1.0) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + minitest (5.11.3) + pg (0.18.4) + rake (10.5.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + simple_serializer (1.0.2) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord (~> 5.1.0) + activerecord-import (= 0.13.0) + appraisal (~> 2.2) + pg (~> 0.18.0) + rake (~> 10.0) + rspec (~> 3.0) + virtus (~> 1.0) + vorpal! + +RUBY VERSION + ruby 2.3.3p222 + +BUNDLED WITH + 1.16.2 diff --git a/gemfiles/rails_5_2.gemfile b/gemfiles/rails_5_2.gemfile new file mode 100644 index 0000000..8ea537c --- /dev/null +++ b/gemfiles/rails_5_2.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +ruby ">= 2.2.2" + +gem "activerecord", "~> 5.2.0" +gem "pg", "~> 0.18.0" +gem "activerecord-import", "= 0.13.0" + +gemspec path: "../" diff --git a/gemfiles/rails_5_2.gemfile.lock b/gemfiles/rails_5_2.gemfile.lock new file mode 100644 index 0000000..c777a96 --- /dev/null +++ b/gemfiles/rails_5_2.gemfile.lock @@ -0,0 +1,88 @@ +PATH + remote: .. + specs: + vorpal (1.0.0) + activesupport + equalizer + simple_serializer (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (5.2.1) + activesupport (= 5.2.1) + activerecord (5.2.1) + activemodel (= 5.2.1) + activesupport (= 5.2.1) + arel (>= 9.0) + activerecord-import (0.13.0) + activerecord (>= 3.0) + activesupport (5.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (9.0.0) + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + concurrent-ruby (1.0.5) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + diff-lcs (1.3) + equalizer (0.0.11) + i18n (1.1.0) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + minitest (5.11.3) + pg (0.18.4) + rake (10.5.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + simple_serializer (1.0.2) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord (~> 5.2.0) + activerecord-import (= 0.13.0) + appraisal (~> 2.2) + pg (~> 0.18.0) + rake (~> 10.0) + rspec (~> 3.0) + virtus (~> 1.0) + vorpal! + +RUBY VERSION + ruby 2.3.3p222 + +BUNDLED WITH + 1.16.2 diff --git a/lib/vorpal/driver/postgresql.rb b/lib/vorpal/driver/postgresql.rb index 7bbde5c..7d6543e 100644 --- a/lib/vorpal/driver/postgresql.rb +++ b/lib/vorpal/driver/postgresql.rb @@ -25,7 +25,7 @@ def update(db_class, db_objects) end def destroy(db_class, ids) - db_class.delete_all(id: ids) + db_class.where(id: ids).delete_all end # Loads instances of the given class by primary key. diff --git a/spec/helpers/db_helpers.rb b/spec/helpers/db_helpers.rb index 4c012c2..c864de5 100644 --- a/spec/helpers/db_helpers.rb +++ b/spec/helpers/db_helpers.rb @@ -34,7 +34,7 @@ def establish_connection # when you change a table's columns, set force to true to re-generate the table in the DB def define_table(table_name, columns, force) - if !db_connection.table_exists?(table_name) || force + if table_name_is_free?(table_name) || force db_connection.create_table(table_name, force: true) do |t| columns.each do |name, type| t.send(type, name) @@ -48,4 +48,19 @@ def defineAr(table_name) self.table_name = table_name end end -end \ No newline at end of file + + private + + def table_name_is_free?(table_name) + if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 1 + !db_connection.table_exists?(table_name) + elsif (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2) || + (ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 0) || + (ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 1) || + (ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 2) + !db_connection.data_source_exists?(table_name) + else + raise "ActiveRecord Version #{ActiveRecord::VERSION::STRING} is not supported!" + end + end +end diff --git a/spec/vorpal/performance/performance_spec.rb b/spec/vorpal/performance/performance_spec.rb index 34822e9..39b0e1d 100644 --- a/spec/vorpal/performance/performance_spec.rb +++ b/spec/vorpal/performance/performance_spec.rb @@ -90,6 +90,46 @@ def add_branch(branch_options) # update 1.820000 0.210000 2.030000 ( 2.351518) # load 1.310000 0.010000 1.320000 ( 1.394192) # destroy 0.930000 0.010000 0.940000 ( 1.030910) + # + # Vorpal 1.0.0, Ruby 2.1.6, ActiveRecord 4.1.16, AR:Import 0.10.0 + # user system total real + # create 0.980000 0.140000 1.120000 ( 1.671115) + # update 2.030000 0.250000 2.280000 ( 2.748697) + # load 1.230000 0.010000 1.240000 ( 1.395219) + # destroy 0.830000 0.010000 0.840000 ( 1.042960) + # + # Vorpal 1.0.0, Ruby 2.3.3, ActiveRecord 4.1.16, AR:Import 0.10.0 + # user system total real + # create 0.940000 0.120000 1.060000 ( 1.579334) + # update 1.880000 0.250000 2.130000 ( 2.601979) + # load 1.130000 0.010000 1.140000 ( 1.292817) + # destroy 0.730000 0.000000 0.730000 ( 0.930980) + # + # Vorpal 1.0.0, Ruby 2.3.3, ActiveRecord 4.2.10, AR:Import 0.10.0 + # user system total real + # create 1.230000 0.130000 1.360000 ( 1.864400) + # update 2.660000 0.260000 2.920000 ( 3.416604) + # load 1.310000 0.010000 1.320000 ( 1.479030) + # destroy 0.840000 0.010000 0.850000 ( 1.037512) + # + # Vorpal 1.0.0, Ruby 2.3.3, ActiveRecord 5.0.7, AR:Import 0.13.0 + # user system total real + # create 0.960000 0.120000 1.080000 ( 1.631415) + # update 2.810000 0.270000 3.080000 ( 3.633569) + # load 1.340000 0.010000 1.350000 ( 1.510898) + # destroy 0.900000 0.010000 0.910000 ( 1.085288) + # + # Vorpal 1.0.0, Ruby 2.3.3, ActiveRecord 5.1.6, AR:Import 0.13.0 + # create 0.960000 0.120000 1.080000 ( 1.588142) + # update 3.030000 0.290000 3.320000 ( 3.839557) + # load 1.340000 0.010000 1.350000 ( 1.509182) + # destroy 0.950000 0.010000 0.960000 ( 1.155866) + # + # Vorpal 1.0.0, Ruby 2.3.3, ActiveRecord 5.1.6, AR:Import 0.13.0 + # create 0.920000 0.120000 1.040000 ( 1.534410) + # update 3.010000 0.290000 3.300000 ( 3.850101) + # load 1.380000 0.010000 1.390000 ( 1.561047) + # destroy 1.050000 0.010000 1.060000 ( 1.260379) it 'benchmarks all operations' do trees = build_trees(1000) Benchmark.bm(7) do |x| diff --git a/vorpal.gemspec b/vorpal.gemspec index 0da86fd..3bc30a2 100644 --- a/vorpal.gemspec +++ b/vorpal.gemspec @@ -18,16 +18,17 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 2.1.6" - spec.add_runtime_dependency "simple_serializer", "~> 1.0" spec.add_runtime_dependency "equalizer" spec.add_runtime_dependency "activesupport" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "activerecord", "~> 4.0" - spec.add_development_dependency "pg", "~> 0.17.0" spec.add_development_dependency "virtus", "~> 1.0" + spec.add_development_dependency "appraisal", "~> 2.2" + + spec.required_ruby_version = ">= 2.1.6" + spec.add_development_dependency "activerecord", "~> 4.1.0" + spec.add_development_dependency "pg", "~> 0.17.0" spec.add_development_dependency "activerecord-import", "~> 0.10.0" end