diff --git a/.gitignore b/.gitignore
index 8527661..ed55b1d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,15 @@
-# DATASHIFT
+.byebug_history
-dummy
-spec/.bundle
-spec/dummy
-spec/dummy/**
+log/*.log
+pkg/
+spec/dummy/db/*.sqlite3
+spec/dummy/db/*.sqlite3-journal
+spec/dummy/db/*.sqlite3-*
+spec/dummy/log/*.log
+spec/dummy/storage/
+spec/dummy/tmp/
+
+spec/.bundle*
spec/logs
spec/fixtures/results
/spec/MissingAttachmentRecords
@@ -11,6 +17,12 @@ spec/fixtures/results
/spec/rspec_spree_sandbox
/spec/rspec_spree_sandbox/*
+spec/dummy/db/*.sqlite3
+spec/dummy/db/*.sqlite3-journal
+spec/dummy/db/log/*.log
+spec/dummy/tmp/
+spec/dummy/.sass-cache
+
sandbox
sandbox/**
diff --git a/.idea/datashift_spree.iml b/.idea/datashift_spree.iml
new file mode 100644
index 0000000..b74695d
--- /dev/null
+++ b/.idea/datashift_spree.iml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..18d9fdb
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..865422c
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..62557ec
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,145 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1581507095973
+
+
+ 1581507095973
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/lib/datashift_spree/loading.rb
+ 83
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml___jb_tmp___ b/.idea/workspace.xml___jb_tmp___
new file mode 100644
index 0000000..56e6c9f
--- /dev/null
+++ b/.idea/workspace.xml___jb_tmp___
@@ -0,0 +1,249 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1581507095973
+
+
+ 1581507095973
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..c464cd6
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,17 @@
+source 'https://rubygems.org'
+git_source(:github) { |repo| "https://github.com/#{repo}.git" }
+
+# Declare your gem's dependencies in datashift_spree.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
+gemspec
+
+# Declare any dependencies that are still in development here instead of in
+# your gemspec. These might include edge Rails or gems from your path or
+# Git. Remember to move these dependencies to your gemspec before releasing
+# your gem to rubygems.org.
+
+gem 'datashift', path: '../datashift'
+
+# To use a debugger
+# gem 'byebug', group: [:development, :test]
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..829cb5a
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,424 @@
+PATH
+ remote: ../datashift
+ specs:
+ datashift (0.40.4)
+ paperclip (>= 4.3, <= 6.0.0)
+ rails (>= 4.2)
+ rubyzip (>= 1.3.0)
+ spreadsheet (~> 1.1)
+ thor (>= 0.19.0, < 2.0)
+ thread_safe (~> 0.3, >= 0.3)
+
+PATH
+ remote: .
+ specs:
+ datashift_spree (0.7.0)
+ mechanize
+ spree (~> 4.1.0.rc1)
+ spree_auth_devise (~> 4.1.0.rc1)
+ spree_gateway (~> 3.7)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actioncable (6.0.2.1)
+ actionpack (= 6.0.2.1)
+ nio4r (~> 2.0)
+ websocket-driver (>= 0.6.1)
+ actionmailbox (6.0.2.1)
+ actionpack (= 6.0.2.1)
+ activejob (= 6.0.2.1)
+ activerecord (= 6.0.2.1)
+ activestorage (= 6.0.2.1)
+ activesupport (= 6.0.2.1)
+ mail (>= 2.7.1)
+ actionmailer (6.0.2.1)
+ actionpack (= 6.0.2.1)
+ actionview (= 6.0.2.1)
+ activejob (= 6.0.2.1)
+ mail (~> 2.5, >= 2.5.4)
+ rails-dom-testing (~> 2.0)
+ actionpack (6.0.2.1)
+ actionview (= 6.0.2.1)
+ activesupport (= 6.0.2.1)
+ rack (~> 2.0, >= 2.0.8)
+ rack-test (>= 0.6.3)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
+ actiontext (6.0.2.1)
+ actionpack (= 6.0.2.1)
+ activerecord (= 6.0.2.1)
+ activestorage (= 6.0.2.1)
+ activesupport (= 6.0.2.1)
+ nokogiri (>= 1.8.5)
+ actionview (6.0.2.1)
+ activesupport (= 6.0.2.1)
+ builder (~> 3.1)
+ erubi (~> 1.4)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
+ activejob (6.0.2.1)
+ activesupport (= 6.0.2.1)
+ globalid (>= 0.3.6)
+ activemerchant (1.104.0)
+ activesupport (>= 4.2)
+ builder (>= 2.1.2, < 4.0.0)
+ i18n (>= 0.6.9)
+ nokogiri (~> 1.4)
+ activemodel (6.0.2.1)
+ activesupport (= 6.0.2.1)
+ activerecord (6.0.2.1)
+ activemodel (= 6.0.2.1)
+ activesupport (= 6.0.2.1)
+ activestorage (6.0.2.1)
+ actionpack (= 6.0.2.1)
+ activejob (= 6.0.2.1)
+ activerecord (= 6.0.2.1)
+ marcel (~> 0.3.1)
+ activesupport (6.0.2.1)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (>= 0.7, < 2)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ zeitwerk (~> 2.2)
+ acts_as_list (0.9.19)
+ activerecord (>= 3.0)
+ addressable (2.7.0)
+ public_suffix (>= 2.0.2, < 5.0)
+ autoprefixer-rails (9.7.4)
+ execjs
+ awesome_nested_set (3.2.0)
+ activerecord (>= 4.0.0, < 7.0)
+ bcrypt (3.1.13)
+ bootstrap (4.3.1)
+ autoprefixer-rails (>= 9.1.0)
+ popper_js (>= 1.14.3, < 2)
+ sassc-rails (>= 2.0.0)
+ builder (3.2.4)
+ byebug (11.1.1)
+ camertron-eprun (1.1.1)
+ cancancan (3.0.2)
+ canonical-rails (0.2.6)
+ rails (>= 4.1, < 6.1)
+ carmen (1.1.3)
+ activesupport (>= 3.0.0)
+ cldr-plurals-runtime-rb (1.0.1)
+ climate_control (0.2.0)
+ concurrent-ruby (1.1.6)
+ connection_pool (2.2.2)
+ crass (1.0.6)
+ css_parser (1.7.1)
+ addressable
+ deface (1.5.3)
+ nokogiri (>= 1.6)
+ polyglot
+ rails (>= 4.1)
+ rainbow (>= 2.1.0)
+ devise (4.7.1)
+ bcrypt (~> 3.0)
+ orm_adapter (~> 0.1)
+ railties (>= 4.1.0)
+ responders
+ warden (~> 1.2.3)
+ devise-encryptable (0.2.0)
+ devise (>= 2.1.0)
+ diff-lcs (1.3)
+ domain_name (0.5.20190701)
+ unf (>= 0.0.5, < 1.0.0)
+ doorkeeper (5.3.1)
+ railties (>= 5)
+ erubi (1.9.0)
+ execjs (2.7.0)
+ fast_jsonapi (1.5)
+ activesupport (>= 4.2)
+ ffaker (2.13.0)
+ ffi (1.12.2)
+ friendly_id (5.3.0)
+ activerecord (>= 4.0.0)
+ globalid (0.4.2)
+ activesupport (>= 4.2.0)
+ glyphicons (1.0.2)
+ highline (2.0.3)
+ htmlentities (4.3.4)
+ http-cookie (1.0.3)
+ domain_name (~> 0.5)
+ i18n (1.8.2)
+ concurrent-ruby (~> 1.0)
+ image_processing (1.10.3)
+ mini_magick (>= 4.9.5, < 5)
+ ruby-vips (>= 2.0.17, < 3)
+ inline_svg (1.7.0)
+ activesupport (>= 3.0)
+ nokogiri (>= 1.6)
+ jquery-rails (4.3.5)
+ rails-dom-testing (>= 1, < 3)
+ railties (>= 4.2.0)
+ thor (>= 0.14, < 2.0)
+ jquery-ui-rails (6.0.1)
+ railties (>= 3.2.16)
+ kaminari (1.1.1)
+ activesupport (>= 4.1.0)
+ kaminari-actionview (= 1.1.1)
+ kaminari-activerecord (= 1.1.1)
+ kaminari-core (= 1.1.1)
+ kaminari-actionview (1.1.1)
+ actionview
+ kaminari-core (= 1.1.1)
+ kaminari-activerecord (1.1.1)
+ activerecord
+ kaminari-core (= 1.1.1)
+ kaminari-core (1.1.1)
+ loofah (2.4.0)
+ crass (~> 1.0.2)
+ nokogiri (>= 1.5.9)
+ mail (2.7.1)
+ mini_mime (>= 0.1.1)
+ marcel (0.3.3)
+ mimemagic (~> 0.3.2)
+ mechanize (2.7.6)
+ domain_name (~> 0.5, >= 0.5.1)
+ http-cookie (~> 1.0)
+ mime-types (>= 1.17.2)
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
+ net-http-persistent (>= 2.5.2)
+ nokogiri (~> 1.6)
+ ntlm-http (~> 0.1, >= 0.1.1)
+ webrobots (>= 0.0.9, < 0.2)
+ method_source (0.9.2)
+ mime-types (3.3.1)
+ mime-types-data (~> 3.2015)
+ mime-types-data (3.2019.1009)
+ mimemagic (0.3.4)
+ mini_magick (4.10.1)
+ mini_mime (1.0.2)
+ mini_portile2 (2.4.0)
+ minitest (5.14.0)
+ monetize (1.9.4)
+ money (~> 6.12)
+ money (6.13.7)
+ i18n (>= 0.6.4, <= 2)
+ net-http-digest_auth (1.4.1)
+ net-http-persistent (3.1.0)
+ connection_pool (~> 2.2)
+ nio4r (2.5.2)
+ nokogiri (1.10.8)
+ mini_portile2 (~> 2.4.0)
+ ntlm-http (0.1.1)
+ orm_adapter (0.5.0)
+ paperclip (6.0.0)
+ activemodel (>= 4.2.0)
+ activesupport (>= 4.2.0)
+ mime-types
+ mimemagic (~> 0.3.0)
+ terrapin (~> 0.6.0)
+ paranoia (2.4.2)
+ activerecord (>= 4.0, < 6.1)
+ polyamorous (2.3.2)
+ activerecord (>= 5.2.1)
+ polyglot (0.3.5)
+ popper_js (1.16.0)
+ premailer (1.11.1)
+ addressable
+ css_parser (>= 1.6.0)
+ htmlentities (>= 4.0.0)
+ premailer-rails (1.10.3)
+ actionmailer (>= 3)
+ premailer (~> 1.7, >= 1.7.9)
+ public_suffix (4.0.3)
+ rabl (0.14.2)
+ activesupport (>= 2.3.14)
+ rack (2.2.2)
+ rack-test (1.1.0)
+ rack (>= 1.0, < 3)
+ rails (6.0.2.1)
+ actioncable (= 6.0.2.1)
+ actionmailbox (= 6.0.2.1)
+ actionmailer (= 6.0.2.1)
+ actionpack (= 6.0.2.1)
+ actiontext (= 6.0.2.1)
+ actionview (= 6.0.2.1)
+ activejob (= 6.0.2.1)
+ activemodel (= 6.0.2.1)
+ activerecord (= 6.0.2.1)
+ activestorage (= 6.0.2.1)
+ activesupport (= 6.0.2.1)
+ bundler (>= 1.3.0)
+ railties (= 6.0.2.1)
+ sprockets-rails (>= 2.0.0)
+ rails-dom-testing (2.0.3)
+ activesupport (>= 4.2.0)
+ nokogiri (>= 1.6)
+ rails-html-sanitizer (1.3.0)
+ loofah (~> 2.3)
+ railties (6.0.2.1)
+ actionpack (= 6.0.2.1)
+ activesupport (= 6.0.2.1)
+ method_source
+ rake (>= 0.8.7)
+ thor (>= 0.20.3, < 2.0)
+ rainbow (3.0.0)
+ rake (13.0.1)
+ ransack (2.3.2)
+ activerecord (>= 5.2.1)
+ activesupport (>= 5.2.1)
+ i18n
+ polyamorous (= 2.3.2)
+ responders (3.0.0)
+ actionpack (>= 5.0)
+ railties (>= 5.0)
+ rspec-core (3.9.1)
+ rspec-support (~> 3.9.1)
+ rspec-expectations (3.9.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.9.0)
+ rspec-mocks (3.9.1)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.9.0)
+ rspec-rails (3.9.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 3.9.0)
+ rspec-expectations (~> 3.9.0)
+ rspec-mocks (~> 3.9.0)
+ rspec-support (~> 3.9.0)
+ rspec-support (3.9.2)
+ ruby-ole (1.2.12.2)
+ ruby-vips (2.0.17)
+ ffi (~> 1.9)
+ rubyzip (2.2.0)
+ sassc (2.2.1)
+ ffi (~> 1.9)
+ sassc-rails (2.1.2)
+ railties (>= 4.0.0)
+ sassc (>= 2.0)
+ sprockets (> 3.0)
+ sprockets-rails
+ tilt
+ select2-rails (3.5.10)
+ thor (~> 0.14)
+ spreadsheet (1.2.6)
+ ruby-ole (>= 1.0)
+ spree (4.1.0.rc2)
+ spree_api (= 4.1.0.rc2)
+ spree_backend (= 4.1.0.rc2)
+ spree_cmd (= 4.1.0.rc2)
+ spree_core (= 4.1.0.rc2)
+ spree_frontend (= 4.1.0.rc2)
+ spree_sample (= 4.1.0.rc2)
+ spree_api (4.1.0.rc2)
+ doorkeeper (~> 5.2, >= 5.2.1)
+ fast_jsonapi (~> 1.5)
+ rabl (~> 0.14.2)
+ spree_core (= 4.1.0.rc2)
+ spree_auth_devise (4.1.0.rc1)
+ deface (~> 1.0)
+ devise (~> 4.7)
+ devise-encryptable (= 0.2.0)
+ spree_core (>= 4.1.0.alpha, < 5.0)
+ spree_extension
+ spree_backend (4.1.0.rc2)
+ bootstrap (~> 4.3.1)
+ glyphicons (~> 1.0.2)
+ jquery-rails (~> 4.3)
+ jquery-ui-rails (~> 6.0.1)
+ select2-rails (~> 3.5.0)
+ spree_api (= 4.1.0.rc2)
+ spree_core (= 4.1.0.rc2)
+ spree_cmd (4.1.0.rc2)
+ thor (~> 0.14)
+ spree_core (4.1.0.rc2)
+ activemerchant (~> 1.67)
+ acts_as_list (~> 0.8)
+ awesome_nested_set (>= 3.1.4, < 3.3.0)
+ cancancan (~> 3.0)
+ carmen (>= 1.0, < 1.2)
+ ffaker (~> 2.9)
+ friendly_id (>= 5.2.1, < 5.4.0)
+ highline (~> 2.0.0)
+ image_processing (~> 1.2)
+ kaminari (>= 1.0.1, < 1.2.0)
+ mini_magick (>= 4.9.4, < 4.11.0)
+ monetize (~> 1.9)
+ money (~> 6.13)
+ paranoia (~> 2.4.2)
+ premailer-rails
+ rails (~> 6.0.0)
+ ransack (~> 2.3.0)
+ responders
+ sprockets (~> 3.7)
+ sprockets-rails
+ state_machines-activemodel (~> 0.7)
+ state_machines-activerecord (~> 0.6)
+ stringex
+ twitter_cldr (>= 4.3, < 6.0)
+ spree_extension (0.0.9)
+ activerecord (>= 4.2)
+ spree_core
+ spree_frontend (4.1.0.rc2)
+ bootstrap (~> 4.3.1)
+ canonical-rails (~> 0.2.5)
+ glyphicons (~> 1.0.2)
+ inline_svg (~> 1.5)
+ jquery-rails (~> 4.3)
+ spree_api (= 4.1.0.rc2)
+ spree_core (= 4.1.0.rc2)
+ turbolinks (~> 5.2.0)
+ spree_gateway (3.7.0)
+ spree_core (>= 3.1.0, < 5.0)
+ spree_extension
+ spree_sample (4.1.0.rc2)
+ spree_core (= 4.1.0.rc2)
+ sprockets (3.7.2)
+ concurrent-ruby (~> 1.0)
+ rack (> 1, < 3)
+ sprockets-rails (3.2.1)
+ actionpack (>= 4.0)
+ activesupport (>= 4.0)
+ sprockets (>= 3.0.0)
+ sqlite3 (1.4.2)
+ state_machines (0.5.0)
+ state_machines-activemodel (0.7.1)
+ activemodel (>= 4.1)
+ state_machines (>= 0.5.0)
+ state_machines-activerecord (0.6.0)
+ activerecord (>= 4.1)
+ state_machines-activemodel (>= 0.5.0)
+ stringex (2.8.5)
+ terrapin (0.6.0)
+ climate_control (>= 0.0.3, < 1.0)
+ thor (0.20.3)
+ thread_safe (0.3.6)
+ tilt (2.0.10)
+ turbolinks (5.2.1)
+ turbolinks-source (~> 5.2)
+ turbolinks-source (5.2.0)
+ twitter_cldr (5.3.0)
+ camertron-eprun
+ cldr-plurals-runtime-rb (~> 1.0)
+ tzinfo
+ tzinfo (1.2.6)
+ thread_safe (~> 0.1)
+ unf (0.1.4)
+ unf_ext
+ unf_ext (0.0.7.6)
+ warden (1.2.8)
+ rack (>= 2.0.6)
+ webrobots (0.1.2)
+ websocket-driver (0.7.1)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.4)
+ zeitwerk (2.2.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ byebug
+ datashift!
+ datashift_spree!
+ rspec-rails
+ sqlite3
+
+BUNDLED WITH
+ 2.1.2
diff --git a/LICENSE.txt b/LICENSE.txt
index dfa14fe..db6ad04 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -2,7 +2,7 @@
## License
-Copyright:: (c) Autotelik Media Ltd 2012
+Copyright:: (c) Autotelik B.V 2012
Author :: Tom Statter
Date :: Sept 2012
diff --git a/MIT-LICENSE b/MIT-LICENSE
new file mode 100644
index 0000000..f9e9978
--- /dev/null
+++ b/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright 2020 Thomas Statter
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.markdown b/README.markdown
index 45784bb..f79ccb0 100644
--- a/README.markdown
+++ b/README.markdown
@@ -2,11 +2,11 @@
Import and Export Spree E-Commerce models through .xls or CSV files, including all associations.
-Create and assign taxons, properties, shipping, tax categories and more through single spreadsheet.
+Create and assign images, taxons, properties, shipping categories, tax categories and more through single spreadsheet.
### Versions
-This release has been tested against Spree 3.1
+This release has been tested against Spree 3.1 and Spree 4
## Installation
@@ -32,7 +32,7 @@ require 'datashift'
require 'datashift_spree'
DataShift::load_commands
-DataShift::SpreeEcom::load_commands
+DatashiftSpree::load_commands
```
To check the available tasks run thor list with a search term, for example
@@ -55,16 +55,16 @@ for example
For loading data, probably the first thing you'll want to do is create an Excel template for the model(s) you wish to import. There is a general task `datashift:generate:excel` ( or ```datashift:generate:csv ```) for generating a template for any model.
-There are some higher level tasks, specifically for producing the specific template for loading Spree Products
+There is a task available for producing the template for loading a basic Spree Product :
```ruby
thor datashift_spree:template:product -t tmp/product_template.xls
```
-To also include all possible associations
+To generate the full Product template including all possible associations :
```ruby
-thor datashift_spree:template:product -m Spree::Product --associations -t tmp/full_product_template.xls
+thor datashift_spree:template:full -t tmp/full_product_template.xls
```
A large number of example Spreadsheets with headers and comments, can be found in the **spec/fixtures** directory - including .xls and csv versions for simple Products or complex Products with multiple/nested Taxons, Variants, Properties etc
@@ -80,10 +80,11 @@ For example to understand the `promotionable` field see . https://guides.spreeco
##### Data Import/Export
-Once you have data prepared you can import it using task :
+Once you have data prepared you can import it using task `thor datashift_spree:load:products` :
-```
+Details
+```
thor datashift_spree:load:products
-i, --input=INPUT # The import file (.xls or .csv)
@@ -94,6 +95,10 @@ thor datashift_spree:load:products
-d, [--dummy], [--no-dummy] # Dummy run, do not actually save Image or Product
```
+```ruby
+thor datashift_spree:load:products -v -d -i tmp/product_template.xls
+```
+
Dummy Run is very useful to drive out any issues without actually impacting the database. All changes are rolled back.
A summary of the import is printed to the console,and incase of errors the datashift log ('log/datashift.log') will contain full details.
@@ -106,7 +111,9 @@ E, [2020-02-13T12:12:31.469757 #24410] ERROR -- : Shipping Category can't be bl
E, [2020-02-13T12:12:31.469762 #24410] ERROR -- : Price can't be blank
```
-###### Simple Product
+##### Product
+
+###### Variants and Options on a Product
**Variant Prices/SKUs**
@@ -121,16 +128,54 @@ These should contain pipe '|' delimited lists of the prices, or SKUs, to assign,
Example
- variant_price variant_sku
-
```
-171.56|260.44|171.56|260.44 TARR.SFOP424EW0|TARR.SFOP424EW3|TARR.SFOP414EW0|TARR.SFOP414EW3
+ variant_price variant_sku
+-------------------------------------------------
+171.56|260.44|171.56|260.44 ARR.SFOP424EW0|TARR.SFOP424EW3|TARR.SFOP414EW0|TARR.SFOP414EW3
119.33|208.23 MOLE.SFOP140EA0|MOLE.SFOP140EA3
110.00|198.00 TALL.SFOP140EW0|TALL.SFOP140EW3
-54.89|109.78|69.24 CHET.SFOP128EW3|CHET.SFOP140EW0|CHET.SFOP140EW3
+54.89|109.78|69.24 CHET.SFOP128EW3|CHET.SFOP140EW0|CHET.SFOP140EW3
42.22 LOST.REDL218EW0
```
+##### Stock
+
+Use a column called count_on_hand to manage initial stock levels of a product or variants on a Product
+
+> **N.B** We don't yet have smart ordering of columns - so these columns should come AFTER the Variant creation columns,
+as the Variants must exists when these columns are processed.
+
+ For a simple single Product just specify the stock level as an integer
+
+ ```
+ count_on_hand
+ -------------
+ 13
+ ```
+
+This will use the default stock location. YOu can use the ':' delimiter to also set the stock_location name in form :
+
+ ```
+ count_on_hand
+ -------------
+ stock_location_name:13
+ ```
+
+To specify different stock levels for multiple variants use the pipe '|' to delimit each stock entry.
+
+Currently expects the **same number of stock entries as variants**, that is we only support 1 stock entry per variant.
+
+However you can still specify the single stock location if non default.
+
+ ```
+ Variants count_on_hand
+ -----------------------------------------------
+ size:small, medium, large 12|shop:6|7
+ ```
+
+Three variants by option type size, with three different stock levels.
+
+
###### Creating Association data - Excel or CSV
@@ -138,40 +183,39 @@ Example
We use RSpec, so tests located in the spec subdirectory.
-To test this gem we require an actual Spree store, so when the specs are first run
-a dummy Rails app is created containing a Spree store, whose version we can control in `spec/Gemfile`
-so it's easy to change the Spree version and re-run the specs.
+This is a Rail engine so to test this gem requires an actual Spree store, so there is a dummy Rails app
+with a Gemfile pointing to a Spree store.
-It's therefor recommended that all testing be done in spec dir itself, so first cd into spec
+The versions of Rails, Spree and Datashift to test can be controlled in `spec/dummy/Gemfile`
-Edit `spec/Gemfile` and set the version of Spree you wish to test against and run bundler :
+Edit `spec/dummy/Gemfile` and set the version of Spree you wish to test against and run bundler :
```ruby
- cd spec
+ cd spec/dummy
bundle install
```
-When changing Spree versions, you should force a rebuild of a clean sandbox, and removing the Gemfile.lock will
-resolve any funny version issues, so run:
+When changing Spree versions, you might need to force a Spree reinstallm in a clean dummy area.
```ruby
- cd spec
- rm -rf dummy
- rm -rf Gemfile.lock
+ rm -rf spec/dummy/spree_sandbox_installed.txt
```
-thor datashift:spree_tasks:build_sandbox
-
+This will trigger an installation.
The next time you run rspec the sandbox will be regenerated using the latest versions of Rails/Spree specified in your Gemfile
+##### Manual Spree Install
+
```ruby
- bundle exec rspec -c .
+ cd spec/dummy
+ bundle install
+ bundle exec rails g spree:install --force --user_class=Spree::User --sample=false --seed=false --copy_storefront=false
```
## License
-Copyright:: (c) Autotelik Media Ltd 2012
+Copyright:: (c) Autotelik B.V 2012
Author :: Tom Statter
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..fc64aaf
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,22 @@
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+
+require 'rdoc/task'
+
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'DatashiftSpree'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.md')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
+load 'rails/tasks/engine.rake'
+
+load 'rails/tasks/statistics.rake'
+
+require 'bundler/gem_tasks'
diff --git a/VERSION b/VERSION
deleted file mode 100644
index a918a2a..0000000
--- a/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-0.6.0
diff --git a/app/assets/config/datashift_spree_manifest.js b/app/assets/config/datashift_spree_manifest.js
new file mode 100644
index 0000000..1978caf
--- /dev/null
+++ b/app/assets/config/datashift_spree_manifest.js
@@ -0,0 +1 @@
+//= link_directory ../stylesheets/datashift_spree .css
diff --git a/app/assets/images/datashift_spree/.keep b/app/assets/images/datashift_spree/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/app/assets/stylesheets/datashift_spree/application.css b/app/assets/stylesheets/datashift_spree/application.css
new file mode 100644
index 0000000..0ebd7fe
--- /dev/null
+++ b/app/assets/stylesheets/datashift_spree/application.css
@@ -0,0 +1,15 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
+ * files in this directory. Styles in this file should be added after the last require_* statement.
+ * It is generally better to create a new file per style scope.
+ *
+ *= require_tree .
+ *= require_self
+ */
diff --git a/app/controllers/datashift_spree/application_controller.rb b/app/controllers/datashift_spree/application_controller.rb
new file mode 100644
index 0000000..ea4aecd
--- /dev/null
+++ b/app/controllers/datashift_spree/application_controller.rb
@@ -0,0 +1,5 @@
+module DatashiftSpree
+ class ApplicationController < ActionController::Base
+ protect_from_forgery with: :exception
+ end
+end
diff --git a/app/helpers/datashift_spree/application_helper.rb b/app/helpers/datashift_spree/application_helper.rb
new file mode 100644
index 0000000..7792bd3
--- /dev/null
+++ b/app/helpers/datashift_spree/application_helper.rb
@@ -0,0 +1,4 @@
+module DatashiftSpree
+ module ApplicationHelper
+ end
+end
diff --git a/app/jobs/datashift_spree/application_job.rb b/app/jobs/datashift_spree/application_job.rb
new file mode 100644
index 0000000..8af7b70
--- /dev/null
+++ b/app/jobs/datashift_spree/application_job.rb
@@ -0,0 +1,4 @@
+module DatashiftSpree
+ class ApplicationJob < ActiveJob::Base
+ end
+end
diff --git a/app/mailers/datashift_spree/application_mailer.rb b/app/mailers/datashift_spree/application_mailer.rb
new file mode 100644
index 0000000..cb39db5
--- /dev/null
+++ b/app/mailers/datashift_spree/application_mailer.rb
@@ -0,0 +1,6 @@
+module DatashiftSpree
+ class ApplicationMailer < ActionMailer::Base
+ default from: 'from@example.com'
+ layout 'mailer'
+ end
+end
diff --git a/app/models/datashift_spree/application_record.rb b/app/models/datashift_spree/application_record.rb
new file mode 100644
index 0000000..864dd65
--- /dev/null
+++ b/app/models/datashift_spree/application_record.rb
@@ -0,0 +1,5 @@
+module DatashiftSpree
+ class ApplicationRecord < ActiveRecord::Base
+ self.abstract_class = true
+ end
+end
diff --git a/app/views/layouts/datashift_spree/application.html.erb b/app/views/layouts/datashift_spree/application.html.erb
new file mode 100644
index 0000000..03e0821
--- /dev/null
+++ b/app/views/layouts/datashift_spree/application.html.erb
@@ -0,0 +1,15 @@
+
+
+
+ Datashift spree
+ <%= csrf_meta_tags %>
+ <%= csp_meta_tag %>
+
+ <%= stylesheet_link_tag "datashift_spree/application", media: "all" %>
+
+
+
+<%= yield %>
+
+
+
diff --git a/bin/rails b/bin/rails
new file mode 100755
index 0000000..ba5a59f
--- /dev/null
+++ b/bin/rails
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails gems
+# installed from the root of your application.
+
+ENGINE_ROOT = File.expand_path('..', __dir__)
+ENGINE_PATH = File.expand_path('../lib/datashift_spree/engine', __dir__)
+APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
+
+require "rails"
+# Pick the frameworks you want:
+require "active_model/railtie"
+require "active_job/railtie"
+require "active_record/railtie"
+require "active_storage/engine"
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "action_view/railtie"
+require "action_cable/engine"
+require "sprockets/railtie"
+# require "rails/test_unit/railtie"
+require 'rails/engine/commands'
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000..d7a229c
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,2 @@
+DatashiftSpree::Engine.routes.draw do
+end
diff --git a/datashift_spree.gemspec b/datashift_spree.gemspec
index f9cc0f7..e0db3cb 100644
--- a/datashift_spree.gemspec
+++ b/datashift_spree.gemspec
@@ -1,28 +1,39 @@
-$LOAD_PATH.push File.expand_path('../lib', __FILE__)
+$:.push File.expand_path("lib", __dir__)
# Maintain your gem"s version:
require 'datashift_spree/version'
-Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = 'datashift_spree'
- s.version = DataShift::SpreeEcom::VERSION
- s.authors = ['Thomas Statter']
- s.email = 'datashift@autotelik.co.uk'
- s.homepage = "http://github.com/autotelik/datashift_spree"
- s.summary = "Product and image import/export for Spree from Excel/CSV"
- s.description = "Comprehensive Excel/CSV import/export for Spree, Products,Images, any model with full associations"
- s.license = 'MIT'
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |spec|
+ spec.name = "datashift_spree"
+ spec.version = DatashiftSpree::VERSION
+ spec.authors = ["Thomas Statter"]
+ spec.email = ["datashift@autotelik.eu"]
+ spec.homepage = "http://github.com/autotelik/datashift_spree"
+ spec.summary = "Product and image import/export for Spree from Excel/CSV"
+ spec.description = "Comprehensive Excel/CSV import/export for Spree, Products,Images, any model with full associations"
+ spec.license = "MIT"
- s.required_ruby_version = '~> 2.0'
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
+ if spec.respond_to?(:metadata)
+ spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
+ else
+ raise "RubyGems 2.0 or newer is required to protect against " \
+ "public gem pushes."
+ end
- s.files = Dir['{lib}/**/*', 'LICENSE.md', 'README.md', 'datashift_spree.thor']
- s.require_paths = ['lib']
+ spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
+ #spec.add_runtime_dependency 'datashift'
+ #
+ spec.add_runtime_dependency 'mechanize'
+ spec.add_runtime_dependency 'spree', '~> 4.1.0.rc1'
+ spec.add_runtime_dependency 'spree_auth_devise', '~> 4.1.0.rc1'
+ spec.add_runtime_dependency 'spree_gateway', '~> 3.7'
- # leave it to datashift to define Rails versions
- s.add_runtime_dependency 'datashift'
- s.add_runtime_dependency 'mechanize', '~> 2.6', '>= 2.6.0'
- s.add_runtime_dependency 'spree', '>= 2'
-end
+ spec.add_development_dependency "sqlite3"
+ spec.add_development_dependency "byebug"
+ spec.add_development_dependency "rspec-rails"
+end
diff --git a/datashift_spree.thor b/datashift_spree.thor
index 75b4934..aeae0c4 100644
--- a/datashift_spree.thor
+++ b/datashift_spree.thor
@@ -1,10 +1,9 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Aug 2010
#
# License:: MIT - Free, OpenSource
#
-# Details:: General tools related to DataShiftSpree Gem : specification, build, deploy
+# Details:: General tools related to DatashiftSpree Gem : specification, build, deploy
#
#
module Datashift
diff --git a/lib/datashift_spree.rb b/lib/datashift_spree.rb
index 2dde167..7d8f72f 100644
--- a/lib/datashift_spree.rb
+++ b/lib/datashift_spree.rb
@@ -1,128 +1,43 @@
-# Copyright:: (c) Autotelik Media Ltd 2010 - 2012 Tom Statter
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Aug 2012
-# License:: Free, Open Source.
+# License:: MIT, Free, Open Source.
#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-
# Details:: Spree Product and Image Loader from .xls or CSV
-#
-# To pull DataShift commands into your main Spree application :
-#
-# require 'datashift_spree'
-#
-# DataShift::SpreeEcom::load_commands
#
-require 'rbconfig'
require 'datashift'
-require 'spree'
-$:.unshift '.' unless $:.include?('.')
-
-module DataShift
-
- module SpreeEcom
-
- def self.gem_version
- unless(@gem_version)
- if(File.exists?(File.join(root_path, 'VERSION') ))
- File.read( File.join(root_path, 'VERSION') ).match(/.*(\d+.\d+.\d+)/)
- @gem_version = $1
- else
- @gem_version = '1.0.0'
- end
- end
- @gem_version
- end
-
- def self.gem_name
- "datashift_spree"
- end
-
- def self.root_path
- File.expand_path("#{File.dirname(__FILE__)}/..")
- end
-
- def self.library_path
- File.expand_path("#{File.dirname(__FILE__)}/../lib")
- end
-
- def self.require_libraries
-
- loader_libs = %w{ lib }
+module DatashiftSpree
- # Base search paths - these will be searched recursively
- loader_paths = []
-
- loader_libs.each {|l| loader_paths << File.join(root_path(), l) }
-
- # Define require search paths, any dir in here will be added to LOAD_PATH
+ def self.root_path
+ File.expand_path("#{File.dirname(__FILE__)}/..")
+ end
- loader_paths.each do |base|
- $:.unshift base if File.directory?(base)
- Dir[File.join(base, '**', '**')].each do |p|
- if File.directory? p
- $:.unshift p
- end
- end
- end
+ def self.library_path
+ File.expand_path("#{File.dirname(__FILE__)}/../lib")
+ end
- end
+ # Load all the datashift rake tasks and make them available throughout app
+ def self.load_tasks
+ # Long parameter lists so ensure rake -T produces nice wide output
+ ENV['RAKE_COLUMNS'] = '180'
+ base = File.join(root_path, 'tasks', '**')
+ Dir["#{base}/*.rake"].sort.each { |ext| load ext }
+ end
- def self.require_datashift_spree
-
- require_libs = %w{ loaders helpers }
- require_libs.each do |base|
- Dir[File.join(library_path, base, '**/*.rb')].each do |rb|
- unless File.directory? rb
- require rb
- end
- end
- end
+ # Load all public datashift spree Thor commands and make them available throughout app
+ def self.load_commands
+ base = File.join(library_path, 'thor')
+ Dir["#{base}/**/*.thor"].each do |f|
+ next unless File.file?(f)
+ Thor::Util.load_thorfile(f)
end
-
- # Load all the datashift rake tasks and make them available throughout app
- def self.load_tasks
- # Long parameter lists so ensure rake -T produces nice wide output
- ENV['RAKE_COLUMNS'] = '180'
- base = File.join(root_path, 'tasks', '**')
- Dir["#{base}/*.rake"].sort.each { |ext| load ext }
- end
+ end
- # Load all public datashift spree Thor commands and make them available throughout app
+ # Test and code for this saved at : http://www.rubular.com/r/1de2TZsVJz
- def self.load_commands
- base = File.join(library_path, 'thor')
- Dir["#{base}/**/*.thor"].each do |f|
- next unless File.file?(f)
- Thor::Util.load_thorfile(f)
- end
- end
+ SPREE_URI_REGEX = Regexp::new('(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?' ) unless defined? SPREE_URI_REGEX
- end
end
-DataShift::SpreeEcom::require_libraries
-DataShift::SpreeEcom::require_datashift_spree
-
-require 'datashift_spree/exceptions'
-
+Gem.find_files('datashift_spree/**/*.rb').each { |path| require path }
diff --git a/lib/datashift_spree/engine.rb b/lib/datashift_spree/engine.rb
new file mode 100644
index 0000000..34a72e0
--- /dev/null
+++ b/lib/datashift_spree/engine.rb
@@ -0,0 +1,8 @@
+require 'spree'
+require 'spree_core'
+
+module DatashiftSpree
+ class Engine < ::Rails::Engine
+ isolate_namespace DatashiftSpree
+ end
+end
diff --git a/lib/datashift_spree/exceptions.rb b/lib/datashift_spree/exceptions.rb
index b8081c9..cbacdf2 100644
--- a/lib/datashift_spree/exceptions.rb
+++ b/lib/datashift_spree/exceptions.rb
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2014
+# Copyright:: (c) Autotelik B.V 2014
# Author :: Tom Statter
# Date :: June 2014
# License:: Free, Open Source.
@@ -6,7 +6,7 @@
module DataShift
- module SpreeEcom
+ module Spree
class ProductLoadError < DataShift::DataShiftException
def initialize( msg )
diff --git a/lib/datashift_spree/image_loader.rb b/lib/datashift_spree/image_loader.rb
new file mode 100644
index 0000000..80f6fbe
--- /dev/null
+++ b/lib/datashift_spree/image_loader.rb
@@ -0,0 +1,92 @@
+# Copyright:: (c) Autotelik B.V 2020
+# Author :: Tom Statter
+# License:: MIT. Free, Open Source.
+#
+require_relative 'loader_base'
+
+module DatashiftSpree
+
+ # TODO - THIS CONCEPT NOW BELONGS AS A POPULATOR
+
+ # Very specific Image Loading for existing Products in Spree.
+ #
+ # Requirements : A CSV or Excel file which has 2+ columns
+ #
+ # 1) Identifies a Product via Name or SKU column
+ # 2+) The full path(s) to the Images to attach to Product from column 1
+ #
+ class ImageLoader < DatashiftSpree::LoaderBase
+
+ def initialize()
+
+ super()
+
+ ModelMethods::Manager.catalog_class(Spree::Image)
+ ModelMethods::Manager.catalog_class(Spree::Product)
+ ModelMethods::Manager.catalog_class(Spree::Variant)
+
+ end
+
+ # Load object not an Image - need to look it up via Name or SKU
+ def reset( object = nil)
+ super(object)
+
+ @load_object = nil
+ end
+
+ def run(file_name)
+ super(file_name, Spree::Image)
+ end
+
+ def self.acceptable_path_headers
+ @@path_headers ||= ['attachment', 'images', 'path']
+ end
+
+ # Called from associated perform_xxxx_load
+
+ # Over ride base class process with some Spree::Image specifics
+ #
+ # What process a value string from a column, assigning value(s) to correct association on Product.
+ # Method map represents a column from a file and it's correlated Product association.
+ # Value string which may contain multiple values for a collection (has_many) association.
+ #
+ def process(method_detail, value)
+
+ raise ImageLoadError.new("Cannot process #{value} NO details found to assign to") unless(method_detail)
+
+ # TODO - start supporting assigning extra data via current_attribute_hash
+ current_value, current_attribute_hash = @populator.prepare_data(method_detail, value)
+
+ operator = method_detail.operator
+
+ # TODO - current relies on correct order - i.e lookup column must come before attachment
+
+ if(current_value && ImageLoader::acceptable_path_headers.include?(operator) )
+
+ add_images( @load_object ) if(@load_object)
+
+ elsif(current_value && method_detail.operator )
+
+ # find the db record to assign our Image usually expect either SKU (Variant) or Name (product)
+ if( MethodDictionary::find_method_detail_if_column(Spree::Product, operator) )
+ @load_object = get_record_by(@@product_klass, operator, current_value)
+
+ elsif( MethodDictionary::find_method_detail_if_column(@@variant_klass, operator) )
+ puts "Find VARIANT with #{operator} == #{current_value}"
+ @load_object = get_record_by(@@variant_klass, operator, current_value)
+ else
+ raise "No Spree class can be searched for by #{operator}"
+ end
+
+ unless(@load_object)
+ puts "WARNING: Could not find a record where #{operator} == #{current_value}"
+ return
+ else
+ puts "Image Attachment on record #{@load_object.inspect}"
+ end
+
+ end
+ end
+
+ end
+end
diff --git a/lib/datashift_spree/image_populator.rb b/lib/datashift_spree/image_populator.rb
new file mode 100644
index 0000000..6639c39
--- /dev/null
+++ b/lib/datashift_spree/image_populator.rb
@@ -0,0 +1,138 @@
+# Copyright:: (c) Autotelik B.V 2020
+# Author :: Tom Statter
+# License:: MIT
+#
+# Details:: Specific support for Loading Spree data
+#
+module DatashiftSpree
+
+ class ImagePopulator < ::DataShift::Populator
+
+ include DataShift::ImageLoading
+
+ # Global path to prefix to load paths coming from import data
+ attr_accessor :image_path_prefix
+
+ def initialize(image_path_prefix: nil)
+ @image_path_prefix = image_path_prefix
+ end
+ # If no owner class specified will attach Image to Spree image Owner (varies depending on version)
+ #
+ # Special case for Images
+ #
+ # A list of entries for Images.
+ #
+ # Multiple image items can be delimited by multi_assoc_delim
+ #
+ # Each item can contain optional attributes for the Image class within {}.
+ #
+ # For example to supply the optional 'alt' text, or position for an image
+ #
+ # Example => path_1{:alt => text}|path_2{:alt => more alt blah blah,
+ # :position => 5}|path_3{:alt => the alt text for this path}
+ #
+ def call(load_data, record, owner = nil )
+
+ # Spree > 3 - Images stored on Variant (record.master if record is a Product)
+
+ owner ||= record.is_a?(Spree::Product) ? record.master : record
+
+ load_data.to_s.split(multi_assoc_delim).each do |image|
+
+ if(image.match(DatashiftSpree::SPREE_URI_REGEX))
+
+ uri, attributes = image.split(attribute_list_start)
+
+ uri.strip!
+
+ logger.info("Processing IMAGE from URI [#{uri.inspect}]")
+
+ if(attributes)
+ #TODO move to ColumnPacker unpack ?
+ attributes = attributes.split(', ').map{|h| h1,h2 = h.split('=>'); {h1.strip! => h2.strip!}}.reduce(:merge)
+ logger.debug("IMAGE has additional attributes #{attributes.inspect}")
+ else
+ attributes = {} # will blow things up later if we pass nil where {} expected
+ end
+
+ agent = Mechanize.new
+
+ image = begin
+ agent.get(uri)
+ rescue => e
+ puts "ERROR: Failed to fetch image from URL #{uri}", e.message
+ raise DataShift::BadUri.new("Failed to fetch image from URL #{uri}")
+ end
+
+ # Expected image is_a Mechanize::Image
+ # image.filename& image.extract_filename do not handle query string well e,g blah.jpg?v=1234
+ # so for now use URI
+ # extname = image.respond_to?(:filename) ? File.extname(image.filename) : File.extname(uri)
+ extname = File.extname( uri.gsub(/\?.*=.*/, ''))
+
+ base = image.respond_to?(:filename) ? File.basename(image.filename, '.*') : File.basename(uri, '.*')
+
+ logger.debug("Storing Image in TempFile #{base.inspect}.#{extname.inspect}")
+
+ @current_image_temp_file = Tempfile.new([base, extname], :encoding => 'ascii-8bit')
+
+ begin
+
+ # TODO can we handle embedded img src e.g from Mechanize::Page::Image ?
+
+ # If I call image.save(@current_image_temp_file.path) then it creates a new file with a .1 extension
+ # so the real temp file data is empty and paperclip chokes
+ # so this is a copy from the Mechanize::Image save method. don't like it much, very brittle, but what to do ...
+ until image.body_io.eof? do
+ @current_image_temp_file.write image.body_io.read 16384
+ end
+
+ @current_image_temp_file.rewind
+
+ logger.info("IMAGE downloaded from URI #{uri.inspect}")
+
+ attachment = create_attachment(Spree::Image, @current_image_temp_file.path, nil, nil, attributes)
+ rescue => e
+ logger.error(e.message)
+ logger.error("Failed to create Image from URL #{uri}")
+ raise DataShift::DataProcessingError.new("Failed to create Image from URL #{uri}")
+
+ ensure
+ @current_image_temp_file.close
+ @current_image_temp_file.unlink
+ end
+
+ else
+ path, alt_text = image.split(name_value_delim)
+
+ logger.debug("Processing IMAGE from PATH #{path.inspect} #{alt_text.inspect}")
+
+ path = File.join(image_path_prefix, path) if(image_path_prefix.present?)
+
+ begin
+ attachment = create_attachment(Spree::Image, path, nil, nil, :alt => alt_text)
+ rescue => e
+ logger.error(e.message)
+ logger.error("Failed to create Image from URL #{uri}")
+ raise DataShift::DataProcessingError.new("Failed to create Image from URL #{uri}")
+ end
+
+ end
+
+ raise DataShift::DataProcessingError.new("No errors reported but failed to create Attachment") unless attachment
+
+ begin
+ owner.images << attachment
+ logger.debug("Product assigned Image from : #{path.inspect}")
+ rescue => e
+ logger.error("Failed to assign attachment to #{owner.class} #{owner.id}")
+ logger.error(e.message)
+ end
+
+ end
+
+ record.save
+
+ end
+ end
+end
diff --git a/lib/datashift_spree/loader_base.rb b/lib/datashift_spree/loader_base.rb
new file mode 100644
index 0000000..baf3298
--- /dev/null
+++ b/lib/datashift_spree/loader_base.rb
@@ -0,0 +1,21 @@
+# Copyright:: (c) Autotelik B.V 2020
+# Author :: Tom Statter
+# License:: MIT
+#
+# Details:: Specific over-rides/additions to support Spree Products
+#
+require_relative 'loading'
+
+module DatashiftSpree
+
+ class LoaderBase
+
+ include DataShift::ImageLoading
+ include DatashiftSpree::Loading
+
+ def initialize
+ super
+ end
+
+ end
+end
diff --git a/lib/loaders/spree/spree_loading.rb b/lib/datashift_spree/loading.rb
similarity index 89%
rename from lib/loaders/spree/spree_loading.rb
rename to lib/datashift_spree/loading.rb
index ac6d7c7..8685a62 100644
--- a/lib/loaders/spree/spree_loading.rb
+++ b/lib/datashift_spree/loading.rb
@@ -1,17 +1,15 @@
-# Copyright:: (c) Autotelik Media Ltd 2016
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Aug 2010
-# License:: MIT ?
+# License:: MIT
#
# Details:: Specific support for Loading Spree data
#
-
require 'mechanize'
require 'loaders/paperclip/image_loading'
-module DataShift
+module DatashiftSpree
- module SpreeLoading
+ module Loading
include DataShift::ImageLoading
include DataShift::Delimiters
@@ -47,24 +45,17 @@ def stock_movement_klass
end
def taxonomy_klass
- @taxonomy_klass ||= DataShift::MapperUtils::class_from_string('Spree::Taxonomy')
+ ::Spree::Taxonomy ||= DataShift::MapperUtils::class_from_string('Spree::Taxonomy')
end
def taxon_klass
- @taxon_klass ||= DataShift::MapperUtils::class_from_string('Spree::Taxon')
+ ::Spree::Taxon ||= DataShift::MapperUtils::class_from_string('Spree::Taxon')
end
def variant_klass
@variant_klass ||= DataShift::MapperUtils::class_from_string('Spree::Variant')
end
- # Test and code for this saved at : http://www.rubular.com/r/1de2TZsVJz
-
- def spree_uri_regexp
- @spree_uri_regexp ||= Regexp::new(
- '(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?'
- )
- end
# If no owner class specified will attach Image to Spree image Owner (varies depending on version)
@@ -85,14 +76,12 @@ def spree_uri_regexp
def add_images( record, owner = nil )
# Spree 3 - Images stored on Variant (record.master if record is a Product)
-
+ byebug
owner ||= record.is_a?(Spree::Product) ? record.master : record
value.to_s.split(multi_assoc_delim).each do |image|
- #TODO - make this attributes_start_delim and support {alt=> 'blah, :position => 2 etc}
-
- if(image.match(spree_uri_regexp))
+ if(image.match(DatashiftSpree::SPREE_URI_REGEX))
uri, attributes = image.split(attribute_list_start)
@@ -156,7 +145,6 @@ def add_images( record, owner = nil )
end
else
-
path, alt_text = image.split(name_value_delim)
logger.debug("Processing IMAGE from PATH #{path.inspect} #{alt_text.inspect}")
diff --git a/lib/datashift_spree/product_loader.rb b/lib/datashift_spree/product_loader.rb
new file mode 100644
index 0000000..63d2774
--- /dev/null
+++ b/lib/datashift_spree/product_loader.rb
@@ -0,0 +1,62 @@
+# Copyright:: (c) Autotelik B.V 2020
+# Author :: Tom Statter
+# License:: MIT
+#
+# Details:: Specific over-rides/additions to support Spree Products
+
+require_relative 'loading'
+
+module DatashiftSpree
+
+ class ProductLoader
+
+ include DatashiftSpree::Loading
+
+ attr_accessor :file_name
+
+ attr_accessor :datashift_loader
+
+ delegate :loaded_count, :failed_count, :processed_object_count, to: :datashift_loader
+
+ delegate :configure_from, to: :datashift_loader
+
+ def initialize(file_name)
+
+ @file_name = file_name
+
+ # gets a file type specific loader e.g csv, excel
+ @datashift_loader = DataShift::Loader::Factory.get_loader(file_name)
+ end
+
+ # Non Product database fields we can still process - delegated to Variant
+ #
+ # See delegate_belongs_to :master @ https://github.com/spree/spree/blob/master/core/app/models/spree/product.rb
+ #
+ def force_inclusion_columns
+ @force_inclusion_columns ||= %w{ cost_price
+ count_on_hand
+ images
+ option_types
+ price
+ shipping_category
+ sku
+ stock_items
+ variant_sku
+ variant_cost_price
+ variant_price
+ variant_images
+ }
+ end
+
+ def run
+ logger.info "Product load from File [#{file_name}]"
+
+ DataShift::PopulatorFactory.global_populator_class = DatashiftSpree::ProductPopulator
+
+ DataShift::Configuration.call.force_inclusion_of_columns = force_inclusion_columns
+
+ datashift_loader.run(file_name, ::Spree::Product)
+ end
+
+ end
+end
diff --git a/lib/datashift_spree/product_populator.rb b/lib/datashift_spree/product_populator.rb
new file mode 100644
index 0000000..7ed8eb7
--- /dev/null
+++ b/lib/datashift_spree/product_populator.rb
@@ -0,0 +1,712 @@
+# Copyright:: (c) Autotelik B.V 2020
+# Author :: Tom Statter
+# License:: MIT
+#
+# Details:: Specific Populator for Spree Products
+#
+require 'mechanize'
+require_relative 'loading'
+
+module DatashiftSpree
+
+ class ProductPopulator < ::DataShift::Populator
+
+ include DatashiftSpree::Loading
+
+ include DataShift::Logging
+ extend DataShift::Logging
+
+ attr_reader :product_load_object
+
+ def prepare_and_assign_method_binding(method_binding, record, data)
+
+ value, attribute_hash = prepare_data(method_binding, data)
+
+ @product_load_object = record
+
+ logger.debug("Populating data via Spree ProductPopulator [#{method_binding.operator}] - [#{value}]")
+
+ puts "\n***** Populating data via Spree ProductPopulator [#{method_binding.operator}] - [#{value}]"
+
+ # Special cases for Products, generally where default processing in base won't suffice
+ #
+ # Check takes care of headers in different forms like 'Option Types' 'option types' etc
+ #
+ if(method_binding.operator?('variants') || method_binding.operator?('option_types'))
+
+ add_options_variants
+
+ elsif(method_binding.operator?('price') )
+
+ product_load_object.price = value.to_f
+
+ elsif(method_binding.operator?('taxons'))
+
+ add_taxons
+
+ elsif(method_binding.operator?('product_properties') || method_binding.operator?('properties') )
+
+ add_properties
+
+ # This loads images to Product or Product Master Variant depending on Spree version
+ elsif(method_binding.operator?('images'))
+
+ DatashiftSpree::ImagePopulator.new().call(value, product_load_object.master)
+
+ # This loads images to Product Variants
+ elsif(method_binding.operator?('variant_images'))
+
+ add_variant_images(data)
+
+ elsif(method_binding.operator?('variant_price') && product_load_object.variants.size > 0)
+
+ if(data.to_s.include?(multi_assoc_delim))
+
+ # Check if we processed Option Types and assign per option
+ values = data.to_s.split(multi_assoc_delim)
+
+ if(record.variants.size == values.size)
+ record.variants.each_with_index {|v, i| v.price = values[i].to_f }
+ record.save
+ else
+ puts "WARNING: Price entries did not match number of Variants - None Set"
+ end
+ end
+
+ elsif(method_binding.operator?('variant_cost_price') && product_load_object.variants.size > 0)
+
+ if(data.to_s.include?(multi_assoc_delim))
+
+ # Check if we processed Option Types and assign per option
+ values = data.to_s.split(multi_assoc_delim)
+
+ if(product_load_object.variants.size == values.size)
+ product_load_object.variants.each_with_index {|v, i| v.cost_price = values[i].to_f }
+ product_load_object.save
+ else
+ puts "WARNING: Cost Price entries did not match number of Variants - None Set"
+ end
+ end
+
+ elsif(method_binding.operator?('variant_sku') && product_load_object.variants.size > 0)
+
+ if(data.to_s.include?(multi_assoc_delim))
+
+ # Check if we processed Option Types and assign per option
+ values = data.to_s.split(multi_assoc_delim)
+
+ if(product_load_object.variants.size == values.size)
+ product_load_object.variants.each_with_index {|v, i| v.sku = values[i].to_s }
+ product_load_object.save
+ else
+ puts "WARNING: SKU entries did not match number of Variants - None Set"
+ end
+ end
+
+ elsif( method_binding.operator?('stock_items') || method_binding.operator?('count_on_hand'))
+ logger.info "Adding Variants Stock Items (count_on_hand)"
+
+ product_load_object.save_if_new
+
+ add_variants_stock(value)
+ else
+ super(method_binding, product_load_object, value) if(value.present?)
+ end
+
+ end
+
+ private
+
+ # Special case for OptionTypes as it's two stage process
+ # First add the possible option_types to Product, then we are able
+ # to define Variants on those options values.
+ # So to define a Variant :
+ # 1) define at least one OptionType on Product, for example Size
+ # 2) Provide a value for at least one of these OptionType
+ # 3) A composite Variant can be created by supplying a value for more than one OptionType
+ # fro example Colour : Red and Size Medium
+ #
+ # Supported Syntax :
+ # '|' seperates Variants
+ #
+ # ';' list of option values
+ # Examples :
+ #
+ # mime_type:jpeg;print_type:black_white|mime_type:jpeg|mime_type:png, PDF;print_type:colour
+ #
+ def build_option_types(option_types)
+
+ optiontype_vlist_map = {}
+
+ option_types.each do |ostr|
+
+ oname, value_str = ostr.split(name_value_delim)
+
+ option_type = option_type_klass.where(:name => oname).first
+
+ unless option_type
+ option_type = option_type_klass.create(:name => oname, :presentation => oname.humanize)
+
+ unless option_type
+ logger.warm("WARNING: OptionType #{oname} NOT found and could not create - Not set Product")
+ next
+ end
+ logger.info "Created missing OptionType #{option_type.inspect}"
+ end
+
+ # OptionTypes must be specified first on Product to enable Variants to be created
+ product_load_object.option_types << option_type unless product_load_object.option_types.include?(option_type)
+
+ # Can be simply list of OptionTypes, some or all without values
+ next unless(value_str)
+
+ optiontype_vlist_map[option_type] ||= []
+
+ # Now get the value(s) for the option e.g red,blue,green for OptType 'colour'
+ optiontype_vlist_map[option_type] += value_str.split(',').flatten
+ end
+
+
+ # A single Variant can have MULTIPLE Option Types and the Syntax supports this combining
+ #
+ # So we need the LONGEST set of OptionValues - to use as the BASE for combining with the rest
+ #
+ # mime_type:png,PDF; print_type:colour
+ #
+ # This means create 2 Variants
+ # 1 mime_type:png && print_type:colour
+ # 1 mime_type:PDF && print_type:colour
+ #
+ # And we want to identify this "mime_type:png,PDF" as the longest to combine with the smaller print_type list
+
+ sorted_map = optiontype_vlist_map.sort_by { |ot, ov| ov.size }.reverse
+
+ sorted_map
+
+ end
+
+ def add_options_variants
+
+ # TODO smart column ordering to ensure always valid by time we get to associations
+ begin
+ product_load_object.save_if_new
+ rescue => e
+ logger.error("Cannot add OptionTypes/Variants - Save Failed : #{e.inspect}")
+ raise ProductLoadError.new("Cannot add OptionTypes/Variants - Save failed on parent Product")
+ end
+
+ # Split into multiple Variants - '|' seperates
+ #
+ # So mime_type:jpeg | print_type:black_white
+ #
+ # => 2 Variants on different OpTypes, mime_type and print_type
+ #
+ variant_chain = value.to_s.split( multi_assoc_delim )
+
+ variant_chain.each do |per_variant|
+
+ option_types = per_variant.split(multi_facet_delim) # => [mime_type:jpeg, print_type:black_white]
+
+ logger.info "Building Variants based on Option Types #{option_types.inspect}"
+
+ sorted_map = build_option_types(option_types)
+
+ next if(sorted_map.empty?) # Only option types specified - no values, so no Variant to create
+
+ # {mime => ['pdf', 'jpeg', 'gif'], print_type => ['black_white']}
+
+ lead_option_type, lead_ovalues = sorted_map.shift
+
+ # TODO .. benchmarking to find most efficient way to create these but ensure Product.variants list
+ # populated .. currently need to call reload to ensure this (seems reqd for Spree 1/Rails 3, wasn't required b4
+ lead_ovalues.each do |ovname|
+
+ ov_list = []
+
+ ovname.strip!
+
+ logger.info("Adding Variant for #{ovname} on #{lead_option_type}")
+
+ # TODO - not sure why I create the OptionValues here, rather than above with the OptionTypes
+ ov = option_value_klass.where(:name => ovname,
+ :option_type_id => lead_option_type.id).first_or_create(:presentation => ovname.humanize)
+ ov_list << ov if ov
+
+ # Process rest of array of types => values
+ sorted_map.each do |ot, ovlist|
+ ovlist.each do |ov_for_composite|
+
+ ov_for_composite.strip!
+
+ ov = option_value_klass.where(
+ :name => ov_for_composite,
+ :option_type_id => ot.id).first_or_create(:presentation => ov_for_composite.humanize)
+
+ ov_list << ov if(ov)
+ end
+ end
+
+ unless(ov_list.empty?)
+
+ logger.info("Creating Variant on OptionValue(s) #{ov_list.collect(&:name).inspect}")
+
+ i = product_load_object.variants.size + 1
+
+ product_load_object.variants.create!(
+ :sku => "#{product_load_object.sku}_#{i}",
+ :price => product_load_object.price,
+ :weight => product_load_object.weight,
+ :height => product_load_object.height,
+ :width => product_load_object.width,
+ :depth => product_load_object.depth,
+ :tax_category_id => product_load_object.tax_category_id,
+ :option_values => ov_list
+ )
+
+ end
+ end
+
+ end
+
+ end # each Variant
+
+ # Special case for ProductProperties since it can have additional value applied.
+ # A list of Properties with a optional Value - supplied in form :
+ # property_name:value|property_name|property_name:value
+ # Example :
+ # test_pp_002|test_pp_003:Example free value
+
+ def add_properties
+ # TODO smart column ordering to ensure always valid by time we get to associations
+ product_load_object.save_if_new
+
+ property_list = value.to_s.split(multi_assoc_delim)
+
+ property_list.each do |property_string|
+
+ # Special case, we know we lookup on name so operator is effectively the name to lookup
+
+ # split into usable parts ; size:large or colour:red,green,blue
+ find_by_name, find_by_value = property_string.split(name_value_delim)
+
+ raise "Cannot find Property via #{find_by_name} (with value #{find_by_value})" unless(find_by_name)
+
+ property = Spree::Property.where(:name => find_by_name).first
+
+ unless property
+ property = property_klass.create( :name => find_by_name, :presentation => find_by_name.humanize)
+ logger.info "Created New Property #{property.inspect}"
+ end
+
+ if(property)
+ # Property now protected from mass assignment
+ x = product_property_klass.new( :value => find_by_value )
+ x.property = property
+ x.save
+ @product_load_object.product_properties << x
+ logger.info "Created New ProductProperty #{x.inspect}"
+ else
+ puts "WARNING: Property #{find_by_name} NOT found - Not set Product"
+ end
+
+ end
+
+ end
+
+ # Nested tree structure support ..
+ # TAXON FORMAT
+ # name|name>child>child|name
+
+ def add_taxons
+ # TODO smart column ordering to ensure always valid by time we get to associations
+ product_load_object.save_if_new
+
+ chain_list = value.to_s.split(multi_assoc_delim) # potentially multiple chains in single column (delimited by multi_assoc_delim)
+
+ chain_list.each do |chain|
+
+ # Each chain can contain either a single Taxon, or the tree like structure parent>child>child
+ name_list = chain.split(/\s*>\s*/)
+
+ parent_name = name_list.shift
+
+ parent_taxonomy = taxonomy_klass.where(:name => parent_name).first_or_create
+
+ raise DataShift::DataProcessingError.new("Could not find or create Taxonomy #{parent_name}") unless parent_taxonomy
+
+ parent = parent_taxonomy.root
+
+ # Add the Taxons to Taxonomy from tree structure parent>child>child
+ taxons = name_list.collect do |name|
+
+ begin
+ taxon = taxon_klass.where(:name => name, :parent_id => parent.id, :taxonomy_id => parent_taxonomy.id).first_or_create
+
+ # pre Rails 4 - taxon = taxon_klass.find_or_create_by_name_and_parent_id_and_taxonomy_id(name, parent && parent.id, parent_taxonomy.id)
+
+ unless(taxon)
+ logger.warn("Missing Taxon - could not find or create #{name} for parent #{parent_taxonomy.inspect}")
+ end
+ rescue => e
+ logger.error(e.inspect)
+ logger.error "Cannot assign Taxon ['#{taxon}'] to Product ['#{product_load_object.name}']"
+ next
+ end
+
+ parent = taxon # current taxon becomes next parent
+ taxon
+ end
+
+ taxons << parent_taxonomy.root
+
+ unique_list = taxons.compact.uniq - (@product_load_object.taxons || [])
+
+ logger.debug("Product assigned to Taxons : #{unique_list.collect(&:name).inspect}")
+
+ @product_load_object.taxons << unique_list unless(unique_list.empty?)
+ # puts @product_load_object.taxons.inspect
+
+ end
+
+ end
+
+ def add_variants_stock(data)
+
+ return if data.blank?
+
+ product_load_object.save_if_new
+
+ # location = Spree::StockLocation.find_or_create_by!(name: 'default')
+
+ # product_load_object.master.stock_items.find_by!(stock_location: location).update!(count_on_hand: 1)
+
+ # do we have Variants?
+ if(@product_load_object.variants.size > 0)
+
+ logger.info "[COUNT_ON_HAND] - number of variants to process #{@product_load_object.variants.size}"
+
+ if(data.to_s.include?(multi_assoc_delim))
+ # Check if we've already processed Variants and assign count per variant
+ values = data.to_s.split(multi_assoc_delim)
+ # variants and count_on_hand number match?
+ raise "WARNING: Count on hand entries did not match number of Variants - None Set" unless (@product_load_object.variants.size == values.size)
+ end
+
+ variants = @product_load_object.variants
+ logger.info "Variants: #{variants.inspect}"
+
+ byebug
+
+ stock_coh_list = value.to_s.split(multi_assoc_delim) # we expect to get corresponding stock_location:count_on_hand for every variant
+
+ stock_coh_list.each_with_index do |stock_coh, i|
+
+ # count_on_hand column MUST HAVE "stock_location_name:variant_count_on_hand" format
+ stock_location_name, variant_count_on_hand = stock_coh.split(name_value_delim)
+
+ logger.info "Setting #{variant_count_on_hand} items for stock location #{stock_location_name}..."
+
+ if not stock_location_name # No Stock Location referenced, fallback to default one...
+ logger.info "No Stock Location was referenced. Adding count_on_hand to default Stock Location. Use 'stock_location_name:variant_count_on_hand' format to specify prefered Stock Location"
+ stock_location = stock_location_klass.where(:default => true).first
+ raise "WARNING: Can't set count_on_hand as no Stock Location exists!" unless stock_location
+ else # go with the one specified...
+ stock_location = stock_location_klass.where(:name => stock_location_name).first
+ unless stock_location
+ stock_location = stock_location_klass.create( :name => stock_location_name)
+ logger.info "Created New Stock Location #{stock_location.inspect}"
+ end
+ end
+
+ if(stock_location)
+ stock_movement_klass.create(:quantity => variant_count_on_hand.to_i, :stock_item => variants[i].stock_items.find_by_stock_location_id(stock_location.id))
+ logger.info "Added #{variant_count_on_hand} count_on_hand to Stock Location #{stock_location.inspect}"
+ else
+ puts "WARNING: Stock Location #{stock_location_name} NOT found - Can't set count_on_hand"
+ end
+
+ end
+
+ # ... or just single Master Product?
+ elsif(@product_load_object.variants.size == 0)
+ if(data.to_s.include?(multi_assoc_delim))
+ # count_on_hand column MUST HAVE "stock_location_name:master_count_on_hand" format
+ stock_location_name, master_count_on_hand = (data.to_s.split(multi_assoc_delim).first).split(name_value_delim)
+ puts "WARNING: Multiple count_on_hand values specified but no Variants/OptionTypes created"
+ else
+ stock_location_name, master_count_on_hand = data.split(name_value_delim)
+ end
+ if not stock_location_name # No Stock Location referenced, fallback to default one...
+ logger.info "No Stock Location was referenced. Adding count_on_hand to default Stock Location. Use 'stock_location_name:master_count_on_hand' format to specify prefered Stock Location"
+ stock_location = stock_location_klass.where(:default => true).first
+ raise "WARNING: Can't set count_on_hand as no Stock Location exists!" unless stock_location
+ else # go with the one specified...
+ stock_location = stock_location_klass.where(:name => stock_location_name).first
+ unless stock_location
+ stock_location = stock_location_klass.create( :name => stock_location_name)
+ logger.info "Created New Stock Location #{stock_location.inspect}"
+ end
+ end
+
+ if(stock_location)
+ stock_movement_klass.create(:quantity => master_count_on_hand.to_i, :stock_item => product_load_object.master.stock_items.find_by_stock_location_id(stock_location.id))
+ logger.info "Added #{master_count_on_hand} count_on_hand to Stock Location #{stock_location.inspect}"
+ else
+ puts "WARNING: Stock Location #{stock_location_name} NOT found - Can't set count_on_hand"
+ end
+ end
+ end
+
+ def add_variant_images(data)
+
+ product_load_object.save_if_new
+
+ # do we have Variants?
+ if(@product_load_object.variants.size > 0)
+
+ logger.info "[VARIANT IMAGES] - number of variants to process #{@product_load_object.variants.size}"
+
+ if(data.to_s.include?(multi_assoc_delim))
+ # Check if we've already processed Variants and assign count per variant
+ values = data.to_s.split(multi_assoc_delim)
+ # variants and variant_images number match?
+ raise "WARNING: Variant Images entries did not match number of Variants - None Set" unless (@product_load_object.variants.size == values.size)
+ end
+
+ variants = @product_load_object.variants
+
+ logger.info "Variants: #{variants.inspect}"
+
+ # we expect to get corresponding images for every variant (might have more than one image for each variant!)
+ variants_images_list = value.to_s.split(multi_assoc_delim)
+
+ variants_images_list.each_with_index do |variant_images, i|
+
+ if(variant_images.to_s.include?(multi_value_delim))
+ # multiple images
+ images = variant_images.to_s.split(multi_value_delim)
+ else
+ # single image
+ images = []
+ images << variant_images
+ end
+
+ logger.info "Setting #{images.count} images for variant #{variants[i].name}..."
+
+ # reset variant images to attach to variant
+ var_images = []
+
+ # Image processing...
+ logger.debug "Images to process: #{images.inspect} for variant #{variants[i].name}"
+ images.each do |image|
+
+ if(image.match(DatashiftSpree::SPREE_URI_REGEX))
+
+ uri, attributes = image.split(attribute_list_start)
+
+ uri.strip!
+
+ logger.info("Processing IMAGE from URI [#{uri.inspect}]")
+
+ if(attributes)
+ #TODO move to ColumnPacker unpack ?
+ attributes = attributes.split(', ').map{|h| h1,h2 = h.split('=>'); {h1.strip! => h2.strip!}}.reduce(:merge)
+ logger.debug("IMAGE has additional attributes #{attributes.inspect}")
+ else
+ attributes = {} # will blow things up later if we pass nil where {} expected
+ end
+
+ agent = Mechanize.new
+
+ image = begin
+ agent.get(uri)
+ rescue => e
+ puts "ERROR: Failed to fetch image from URL #{uri}", e.message
+ raise DataShift::BadUri.new("Failed to fetch image from URL #{uri}")
+ end
+
+ # Expected image is_a Mechanize::Image
+ # image.filename& image.extract_filename do not handle query string well e,g blah.jpg?v=1234
+ # so for now use URI
+ # extname = image.respond_to?(:filename) ? File.extname(image.filename) : File.extname(uri)
+ extname = File.extname( uri.gsub(/\?.*=.*/, ''))
+
+ base = image.respond_to?(:filename) ? File.basename(image.filename, '.*') : File.basename(uri, '.*')
+
+ logger.debug("Storing Image in TempFile #{base.inspect}.#{extname.inspect}")
+
+ @current_image_temp_file = Tempfile.new([base, extname], :encoding => 'ascii-8bit')
+
+ begin
+
+ # TODO can we handle embedded img src e.g from Mechanize::Page::Image ?
+
+ # If I call image.save(@current_image_temp_file.path) then it creates a new file with a .1 extension
+ # so the real temp file data is empty and paperclip chokes
+ # so this is a copy from the Mechanize::Image save method. don't like it much, very brittle, but what to do ...
+ until image.body_io.eof? do
+ @current_image_temp_file.write image.body_io.read 16384
+ end
+
+ @current_image_temp_file.rewind
+
+ logger.info("IMAGE downloaded from URI #{uri.inspect}")
+
+ attachment = create_attachment(Spree::Image, @current_image_temp_file.path, nil, nil, attributes)
+
+ rescue => e
+ logger.error(e.message)
+ logger.error("Failed to create Image from URL #{uri}")
+ raise DataShift::DataProcessingError.new("Failed to create Image from URL #{uri}")
+
+ ensure
+ @current_image_temp_file.close
+ @current_image_temp_file.unlink
+ end
+
+ else
+
+ path, alt_text = image.split(name_value_delim)
+
+ alt_text = variants[i].name if !alt_text #ensure alt_text is filled
+
+ logger.debug("Processing IMAGE from PATH #{path.inspect} #{alt_text.inspect}")
+
+ path = File.join(config[:image_path_prefix], path) if(config[:image_path_prefix])
+
+ attachment = create_attachment(Spree::Image, path, nil, nil, :alt => alt_text)
+
+ end
+
+ logger.debug "#{attachment.inspect}"
+ var_images << attachment if attachment
+
+ end # images loop
+
+ # we have our variant images. Save them!
+ begin
+ # Link images to corresponding variant
+ variants[i].images << var_images
+ variants[i].save
+ logger.debug("Variant assigned Images from : #{var_images.inspect}")
+ rescue => e
+ puts "ERROR - Failed to assign attachments to #{variants[i].class} #{variants[i].id}"
+ logger.error("Failed to assign attachments to #{variants[i].class} #{variants[i].id}")
+ end
+
+ end # variants_images_list loop
+
+ # ... or just single Master Product?
+ elsif(@product_load_object.variants.size == 0)
+
+ if(data.to_s.include?(multi_value_delim))
+ # multiple images
+ images = data.to_s.split(multi_value_delim)
+ else
+ # single image
+ images << variant_images
+ end
+
+ logger.info "Setting #{images.count} images for Master variant #{@product_load_object.master.name}..."
+
+ # Image processing...
+ images.each do |image|
+
+ if(image.match(DatashiftSpree::SPREE_URI_REGEX))
+
+ uri, attributes = image.split(attribute_list_start)
+
+ uri.strip!
+
+ logger.info("Processing IMAGE from URI [#{uri.inspect}]")
+
+ if(attributes)
+ #TODO move to ColumnPacker unpack ?
+ attributes = attributes.split(', ').map{|h| h1,h2 = h.split('=>'); {h1.strip! => h2.strip!}}.reduce(:merge)
+ logger.debug("IMAGE has additional attributes #{attributes.inspect}")
+ else
+ attributes = {} # will blow things up later if we pass nil where {} expected
+ end
+
+ agent = Mechanize.new
+
+ image = begin
+ agent.get(uri)
+ rescue => e
+ puts "ERROR: Failed to fetch image from URL #{uri}", e.message
+ raise DataShift::BadUri.new("Failed to fetch image from URL #{uri}")
+ end
+
+ # Expected image is_a Mechanize::Image
+ # image.filename& image.extract_filename do not handle query string well e,g blah.jpg?v=1234
+ # so for now use URI
+ # extname = image.respond_to?(:filename) ? File.extname(image.filename) : File.extname(uri)
+ extname = File.extname( uri.gsub(/\?.*=.*/, ''))
+
+ base = image.respond_to?(:filename) ? File.basename(image.filename, '.*') : File.basename(uri, '.*')
+
+ logger.debug("Storing Image in TempFile #{base.inspect}.#{extname.inspect}")
+
+ @current_image_temp_file = Tempfile.new([base, extname], :encoding => 'ascii-8bit')
+
+ begin
+
+ # TODO can we handle embedded img src e.g from Mechanize::Page::Image ?
+
+ # If I call image.save(@current_image_temp_file.path) then it creates a new file with a .1 extension
+ # so the real temp file data is empty and paperclip chokes
+ # so this is a copy from the Mechanize::Image save method. don't like it much, very brittle, but what to do ...
+ until image.body_io.eof? do
+ @current_image_temp_file.write image.body_io.read 16384
+ end
+
+ @current_image_temp_file.rewind
+
+ logger.info("IMAGE downloaded from URI #{uri.inspect}")
+
+ attachment = create_attachment(Spree::Image, @current_image_temp_file.path, nil, nil, attributes)
+
+ rescue => e
+ logger.error(e.message)
+ logger.error("Failed to create Image from URL #{uri}")
+ raise DataShift::DataProcessingError.new("Failed to create Image from URL #{uri}")
+
+ ensure
+ @current_image_temp_file.close
+ @current_image_temp_file.unlink
+ end
+
+ else
+ path, alt_text = image.split(name_value_delim)
+
+ alt_text = @product_load_object.master.name if !alt_text #ensure alt_text is filled
+
+ logger.debug("Processing IMAGE from PATH #{path.inspect} #{alt_text.inspect}")
+
+ path = File.join(config[:image_path_prefix], path) if(config[:image_path_prefix])
+
+ # create_attachment(klass, attachment_path, product_load_object = nil, attach_to_product_load_object_field = nil, options = {})
+ attachment = create_attachment(Spree::Image, path, nil, nil, :alt => alt_text)
+
+ end
+
+ var_images << attachment if attachment
+
+ end # images loop
+
+ # we have our variant images. Save them!
+ begin
+ # Link images to corresponding variant
+ @product_load_object.master.images << var_images
+ @product_load_object.master.save
+ logger.debug("Master Variant assigned Images from : #{var_images.inspect}")
+ rescue => e
+ puts "ERROR - Failed to assign attachment to #{@product_load_object.master.class} #{@product_load_object.master.id}"
+ logger.error("Failed to assign attachment to #{@product_load_object.master.class} #{@product_load_object.master.id}")
+ end
+
+ end
+ end
+
+ end
+end
diff --git a/lib/datashift_spree/promotions_rules_actions.rb b/lib/datashift_spree/promotions_rules_actions.rb
new file mode 100644
index 0000000..ea6f914
--- /dev/null
+++ b/lib/datashift_spree/promotions_rules_actions.rb
@@ -0,0 +1,138 @@
+# Copyright:: (c) Autotelik B.V 2020
+# Author :: Tom Statter
+# License:: MIT
+#
+# Details:: Helpers to build Spree Promo Rules+ Actions
+#
+module DatashiftSpree
+
+ # Adjustment can only be applied Once per Order
+ # $36.00 off of the Picks (once per order)
+ #
+ class WithFirstOrderRuleAdjustment
+
+ include DataShift::Logging
+
+ def initialize(promo, calculator, description = nil)
+
+ # $36.00 off of the Picks (once per order)
+
+ logger.info("Creating WithOncePerOrderRuleAdjustment from [#{description}]")
+
+ Spree::Promotion::Actions::CreateItemAdjustments.create!(calculator: calculator, promotion: promo)
+ # Not sure which Action required ?
+ # Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator, promotion: promo)
+
+ Spree::Promotion::Rules::FirstOrder.create!(promotion: promo)
+ end
+
+ end
+
+ # Adjust only Specific Items examples :
+ # 10% off collections
+ # $36.00 off of the Picks
+ #
+ class WithProductRuleAdjustment
+
+ include DataShift::Logging
+
+ def initialize(promo, calculator, description)
+
+ logger.info("Creating WithProductRuleAdjustment from [#{description}]")
+
+ Spree::Promotion::Actions::CreateItemAdjustments.create!(calculator: calculator, promotion: promo)
+
+ # Examples :
+ # regexp 1 : $36.00 off of the Picks (once per order)
+ # regexp 2 : 30% off Miss Popular
+ # 10% off collections
+
+ #
+ if(description.match(/off of the (.+) \(.*/) || description.match(/off (.+)/)
+ )
+
+ product_name = $1.strip
+
+ products = if(product_name.include?('collections') && Spree::Product.column_names.include?('is_collection'))
+ logger.info("Searching for Collections")
+ Spree::Product.where(is_collection: true).all
+ else
+ logger.info("Searching for Products matching [%#{product_name}%]")
+ Spree::Product.where(Spree::Product.arel_table[:name].matches("%#{product_name}%")).all
+ end
+
+ if(products.empty?)
+ logger.error("No Matching Products found for [%#{product_name}%]")
+ else
+ logger.info("Found Matching Products : [#{products.collect(&:name)}]")
+
+ ids = products.collect(&:id)
+
+ logger.info("Creating Promo Rule for specific Products [#{ids.inspect}]")
+
+ # Can't do one step - this chokes on invalid products - maybe cos of HABTM
+ # rule = Spree::Promotion::Rules::Product.create( products: products, promotion: promo))
+
+ rule = Spree::Promotion::Rules::Product.create(promotion: promo)
+
+ rule.products << products
+
+ #promo.rules << rule
+
+ rule.save
+ end
+ else
+ logger.error("WithProductRuleAdjustment Failed to parse Description [#{description}] - No Product Rule assigned to #{promo.inspect}")
+ end
+ end
+ end
+
+
+ # Simple - just adjust whole Order, every time
+ class WithOrderAdjustment
+
+ include DataShift::Logging
+
+ def initialize(promo, calculator, description = nil)
+
+ action = Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator)
+ promo.actions << action
+ end
+ end
+
+
+ # Adjust whole Order but only if conditions met e.g Order over $25
+ class WithItemTotalRule
+
+ include DataShift::Logging
+
+ def initialize(promo, calculator, description)
+
+ @regexp1 ||= Regexp.new('.*orders (.+) \$(\d+\.\d+)')
+ @regexp2 ||= Regexp.new('.*orders (.+) \$(\d+)')
+
+ action = Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator)
+ promo.actions << action
+
+ # $10 off orders equal or above $25.00
+ # xxx off orders equal or above $25.00
+ if(description.match(@regexp1) || description.match(@regexp2))
+
+ # $1 not currently used since only ever seen "equal or above" => 'gte'
+ logger.info("Creating Promo Rule for Min Amount of [#{$2}]")
+ rule = Spree::Promotion::Rules::ItemTotal.create( preferred_amount: $2.to_f)
+
+ # 2-1 stable only supports order greater than, not these
+ #preferred_operator_min: 'gte',
+ #preferred_operator_max: 'lte',
+ #rule.preferred_amount_min = $2.to_f
+ #rule.preferred_amount_max = nil
+
+ promo.rules << rule
+ else
+ logger.error("WithItemTotalRule : Failed to parse Shopify description [#{description}]")
+ end
+ end
+
+ end
+end
diff --git a/lib/datashift_spree/shopify_order_migrator.rb b/lib/datashift_spree/shopify_order_migrator.rb
new file mode 100644
index 0000000..7a239d5
--- /dev/null
+++ b/lib/datashift_spree/shopify_order_migrator.rb
@@ -0,0 +1,399 @@
+# Copyright:: (c) Autotelik B.V 2020
+# Author :: Tom Statter
+# License:: MIT
+#
+# Details:: Supports migrating Shopify spreadsheets to Spree
+# Currently covers :
+# Orders
+#
+module DatashiftSpree
+
+ class ShopifyOrderLoader < DatashiftSpree::LoaderBase
+
+ # Options
+ #
+ # :reload : Force load of the method dictionary for object_class even if already loaded
+ # :verbose : Verbose logging and to STDOUT
+ #
+ def initialize(klass, options = {})
+ # We want the delegated methods so always include instance methods
+ opts = {:instance_methods => true }.merge( options )
+
+ super( klass, nil, opts)
+
+ raise "Failed to create a #{klass.name} for loading" unless load_object
+ end
+
+ # OVER RIDES
+
+ # Options:
+ # [:dummy] : Perform a dummy run - attempt to load everything but then roll back
+ #
+ def run( file_name, opts = {} )
+ logger.info "Shopify run for Orders from File [#{file_name}]"
+ super(file_name, opts)
+ end
+
+ def perform_excel_load( file_name, options = {} )
+
+ # Spree 2 Checkout/Order states
+
+ # go_to_state :address
+ # go_to_state :delivery
+ # go_to_state :payment, if: ->(order) { order.payment_required? }
+ # go_to_state :confirm, if: ->(order) { order.confirmation_required? }
+ # go_to_state :complete
+
+ Spree::Order.class_eval do
+
+ checkout_flow do
+ go_to_state :address
+ go_to_state :complete
+ end
+
+
+ def confirmation_required?
+ false;
+ end
+
+ def payment_required?
+ false;
+ end
+ end
+
+ line_item_rows = 0
+
+ start_excel(file_name, options)
+
+ begin
+ puts "Dummy Run - Changes will be rolled back" if options[:dummy]
+
+ load_object_class.transaction do
+
+ Spree::Config[:track_inventory_levels] = false
+
+ @sheet.each_with_index do |row, i|
+
+ current_row_idx = i
+ @current_row = row
+
+ next if(i == header_row_index)
+
+ # This required in some circumstances where each_with_index keeps going
+ # so need to manually detect when actual data ends, so quit once we hit the first completely empty row
+ if(row.nil? || row.compact.empty?)
+ puts "Finished - Last Row #{current_row_idx} : #{row}"
+ break
+ end
+
+ logger.info "Processing Row #{current_row_idx} : #{row}"
+
+ @reporter.processed_object_count += 1
+
+ # The spreadsheet contains some lines that are LineItems only for previous Order row
+ if(!row[0].nil? && !row[0].empty?) && (row[2].nil? || row[2].empty?) # Financial Status empty on LI rows
+
+ puts("START processing Line Item Only #{current_row_idx} - #{row[0]} - #{row[17]} - #{row[16]} -#{row[18]}")
+
+ line_item_rows += 1
+
+ if(load_object && load_object.id.nil?)
+ logger.warn "No parent Order for Line Item Only row"
+ next
+ end
+
+ logger.info "Line Item Only - add row to current Order : #{load_object.id} : #{load_object.number}"
+
+ begin
+ process_line_item( row, load_object )
+
+ @reporter.success_inbound_count += 1
+
+ rescue => e
+ process_excel_failure(e, false)
+ end
+
+ next # row contains NO OTHER data
+
+ else
+ finish if(load_object.id) # Ok we have added all Line Items - now complete existing order
+
+ new_load_object # Main Order row, create new Spree::Order
+ end
+
+
+ # A real Order row, not just LineItem
+
+ logger.info("Start processing new Order from row #{current_row_idx}")
+
+ puts("START processing new Order from row #{current_row_idx} - #{row[0]} - #{row[17]} - #{row[16]} -#{row[18]}")
+
+ begin
+ # We are loading/migrating data - ensure emails not sent
+ load_object.confirmation_delivered = true
+
+ @total_idx ||= excel_headers.index('total' )
+ @shipment_total_idx ||= excel_headers.index('shipment_total' )
+ @additional_tax_total_idx ||= excel_headers.index('additional_tax_total' )
+ @payment_total_idx ||= excel_headers.index('payment_total' )
+ @promo_total_idx ||= excel_headers.index('promo_total' )
+
+ @payment_state_idx ||= excel_headers.index('payment_state' )
+ @shipment_state_idx ||= excel_headers.index('shipment_state' )
+
+ @completed_at_idx ||= excel_headers.index('completed_at' )
+ @paid_at_idx ||= excel_headers.index('Paid at' )
+ @created_at_idx ||= excel_headers.index('Created at')
+
+ @item_count_idx ||= excel_headers.index('item_count' )
+
+ @shipping_method_idx ||= excel_headers.index("shipping_method:name")
+
+
+ shipment_state = @current_row[@shipment_state_idx]
+ payment_state = @current_row[@payment_state_idx]
+
+ if(payment_state == 'refunded' && shipment_state == 'pending')
+ new_load_object
+ next
+ end
+
+ load_object.shipment_state = shipment_state
+
+ load_object.payment_state = payment_state
+
+
+ #number Email payment_state Paid at shipment_state completed_at Accepts Marketing Currency
+ # Discount Code promo_total shipping_method:name Created at item_count Lineitem name Lineitem price Lineitem compare at price LineItems sku Lineitem requires shipping Lineitem taxable LineItems fulfillment status Billing Name Billing Street bill_address:address1 Billing Address2 Billing Company Billing City Billing Zip Billing Province Billing Country Billing Phone Shipping Name Shipping Street ship_address:address1 Shipping Address2 Shipping Company Shipping City Shipping Zip Shipping Province Shipping Country Shipping Phone Notes Note Attributes Cancelled at Payment Method Payment Reference Refunded Amount Vendor Id Tags Risk Level Source Lineitem discount
+
+ load_object.number = @current_row[0]
+ load_object.email = @current_row[1]
+ load_object.currency = @current_row[7]
+
+ load_object.item_count = row[@item_count_idx].to_f
+
+ load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
+
+ # We are loading/migrating data - try to ensure emails not sent
+ load_object.confirmation_delivered = true
+
+ save
+
+ puts("Saved Order #{load_object.number} [#{load_object.id}]")
+
+ logger.info("Saved Order #{load_object.number} [#{load_object.id}]")
+
+ begin
+ logger.info("Order #{load_object.number} - Assigning User with email [#{row[1]}]")
+
+ user = Spree.user_class.where( :email => @current_row[1] ).first
+
+ if(user)
+ logger.info("Found User [#{row[1]}] - assign to #{load_object.number} (#{load_object.id}) ")
+ load_object.associate_user!(user)
+
+ # The user usually has address information attached so pull it if the order has no prepopulated addresses
+ load_object.ship_address = load_object.user.ship_address unless load_object.ship_address
+ load_object.bill_address = load_object.user.bill_address unless load_object.bill_address
+ end
+
+ def warn_no_address missing_obj
+ logger.warn("No #{missing_obj} Address info for Order #{load_object.number} (#{load_object.id})")
+
+ load_object.ship_address = nil
+ load_object.bill_address = nil
+ end
+
+ if(load_object.bill_address.nil? and load_object.ship_address.nil?)
+ warn_no_address "ship and bill"
+ elsif(load_object.ship_address.nil?)
+ if(load_object.bill_address.id.nil?)
+ warn_no_address "ship and bill id"
+ else
+ load_object.clone_billing_address
+ end
+ elsif(load_object.bill_address.nil?)
+ if(load_object.ship_address.id.nil?)
+ warn_no_address "bill and ship id"
+ else
+ load_object.bill_address.attributes = load_object.ship_address.attributes.except('id', 'updated_at', 'created_at')
+ end
+ elsif(load_object.bill_address.id.nil? and load_object.ship_address.nil?)
+ warn_no_address "bill id and ship id"
+ end
+
+ rescue => e
+ logger.error("Error assigning User #{e.inspect}")
+ logger.warn("Could not assign User #{row[1]} to Order #{load_object.number}")
+ end
+
+ unless(load_object.valid?)
+ logger.info("INVALID ADDRESS - Order still Invalid #{load_object.inspect}")
+ logger.info("Valid Order #{load_object.valid?}")
+ puts "Row #{current_row_idx} invalid #{load_object.errors.full_messages.inspect}"
+ load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
+ end
+
+ begin
+ # make sure we also process the main Order rows, LineItem
+ process_line_item( row, load_object )
+ load_object.next!
+ rescue => x # logged already
+ puts "Issue assigning LineItem #{x.inspect}"
+ end
+
+
+ shipping_method = Spree::ShippingMethod.where( name: @current_row[@shipping_method_idx]).first
+
+ load_object.shipping_method_id = shipping_method.id if(shipping_method)
+
+ load_object.completed_at = @current_row[@completed_at_idx].blank? ? @current_row[@paid_at_idx] : @current_row[@completed_at_idx]
+
+ if(load_object.completed_at.blank?)
+ puts "No suitable completed_at date - using Created at #{@current_row[@created_at_idx]}"
+
+ load_object.completed_at = @current_row[@created_at_idx]
+ end
+
+ load_object.shipment_total = row[@shipment_total_idx].to_f
+ load_object.promo_total = row[@promo_total_idx].to_f
+ load_object.total = row[@total_idx].to_f
+
+ load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
+
+ save_and_report
+
+ rescue => e
+ puts "Save Failed #{e.inspect}"
+ process_excel_failure(e)
+ next
+ end
+
+ end # all rows processed
+
+ # double check the last Order
+ finish
+
+ if(options[:dummy])
+ puts "Excel loading stage complete - Dummy run so Rolling Back."
+ raise ActiveRecord::Rollback # Don't actually create/upload to DB if we are doing dummy run
+ end
+
+ end # TRANSACTION N.B ActiveRecord::Rollback does not propagate outside of the containing transaction block
+
+ rescue => e
+ puts "ERROR: Excel loading failed : #{e.inspect}"
+ raise e
+ ensure
+ report
+ end
+
+ puts "Line Item only row count : #{line_item_rows}"
+ end
+
+ def finish
+
+ return unless(load_object && load_object.id) # Ok we have added all Line Items - now complete existing order
+
+ load_object.create_proposed_shipments
+
+ # Spree::Order.shipments is a CollectionProxy (empty if no shipments)
+ # so each is safe to use
+ load_object.shipments.each do |s|
+ s.state = 'shipped'
+ s.shipped_at = load_object.completed_at
+ end
+
+ load_object.payment_state = 'paid'
+ load_object.shipment_state = 'shipped'
+ load_object.state = 'complete'
+
+ logger.info("Order #{load_object.id}(#{load_object.number}) state set to 'complete' - Final Save")
+
+ load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
+
+ begin
+ load_object.save! # ok this Order done
+ rescue => x
+ logger.error("Final Spree Order save failed : #{load_object.errors.full_messages.inspect}")
+ puts x.inspect
+ end
+
+ end
+
+ def process_line_item( row, order )
+ # for now just hard coding the columns 16 (quantity) and 17 (variant name), 20 (variant sku)
+ @quantity_header_idx ||= 16
+ @price_header_idx ||= 18
+ @sku_header_idx ||= 20 # Lineitem:sku
+
+ # if by name ...
+ # by name - product = Spree::Product.where(:name => row[17]).first
+ # variant = product.master if(product)
+
+ sku = row[@sku_header_idx]
+
+ method_detail = DataShift::MethodDictionary.find_method_detail(Spree::Order, "LineItems" )
+
+ # will perform substitutions etc
+ @populator.prepare_data(method_detail, sku)
+
+ variant = Spree::Variant.where(:sku => sku).first
+
+ unless(variant)
+ raise RecordNotFound.new("Failed to find Variant with sku [#{sku}] for LineItem")
+ end
+
+ logger.info("Processing LineItem - Found Variant [#{variant.sku}] (#{variant.name})") if(variant)
+
+ quantity = row[@quantity_header_idx].to_i
+
+ if(quantity > 0)
+
+ price = row[@price_header_idx].to_f
+
+ logger.info("Adding LineItem for #{sku} with Quantity #{quantity} to Order #{load_object.inspect}")
+
+ if(order.new_record?)
+ puts "ORDER NEEDS SAVING - #{order.number} (#{order.id})"
+ save
+ end
+
+ # idea incase we need full stock management
+ # variant.stock_items.first.adjust_count_on_hand(quantity)
+
+ begin
+ #puts("Adding LineItem for #{sku} with Quantity #{quantity} to Order #{load_object.inspect}")
+ #puts("Variant [#{variant.sku}] (#{variant.name})") if(variant)
+
+ logger.info("Attempting to add new LineItem against Order #{order.number} (#{order.id})")
+
+ order.line_items.new(quantity: quantity, variant: variant, :price => price)
+=begin
+
+ line_item = Spree::LineItem.create!(:variant => variant,
+ :quantity => quantity,
+ :price => price,
+ :pre_tax_amount => price,
+ :order => order,
+ :currency => order.currency)
+
+
+ # line_item.save
+ #order.reload
+
+ logger.info("Success - Added LineItems to Order #{order.number} (#{order.id})")
+ end
+=end
+ rescue => e
+ puts("Create LineItem failed for [#{sku}] Order #{order.number} (#{order.id}) - #{e.inspect}")
+ puts("Create LineItem failed for [#{sku}] Order #{order.number} (#{order.id}) - #{e.inspect}")
+ logger.error("Create LineItem failed for [#{sku}] Order #{order.number} (#{order.id}) - #{e.inspect}")
+ raise
+ end
+
+ end
+ end
+
+ end
+end
diff --git a/lib/loaders/spree/shopify_promotions_migrator.rb b/lib/datashift_spree/shopify_promotions_migrator.rb
similarity index 96%
rename from lib/loaders/spree/shopify_promotions_migrator.rb
rename to lib/datashift_spree/shopify_promotions_migrator.rb
index 2c4dae3..57bcd9b 100644
--- a/lib/loaders/spree/shopify_promotions_migrator.rb
+++ b/lib/datashift_spree/shopify_promotions_migrator.rb
@@ -1,20 +1,17 @@
-# Copyright:: (c) Autotelik Media Ltd 2015
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Aug 2015
# License:: MIT
#
# Details:: Supports migrating Shopify spreadsheets to Spree
# Currently covers :
# Promotions
#
-require 'spree_loader_base'
-require 'promotions_rules_actions.rb'
+require_relative 'promotions_rules_actions'
+require_relative 'loader_base'
-module DataShift
+module DatashiftSpree
- module SpreeEcom
-
- class ShopifyPromotionsMigrator < SpreeLoaderBase
+ class ShopifyPromotionsMigrator < DatashiftSpree::LoaderBase
# Options
#
@@ -200,5 +197,4 @@ def perform_excel_load( file_name, options = {} )
end
- end
end
diff --git a/lib/datashift_spree/version.rb b/lib/datashift_spree/version.rb
index 736c547..d97e3cd 100644
--- a/lib/datashift_spree/version.rb
+++ b/lib/datashift_spree/version.rb
@@ -1,5 +1,3 @@
-module DataShift
- module SpreeEcom
- VERSION = '0.40.5'.freeze unless defined?(SpreeEcom::VERSION)
- end
+module DatashiftSpree
+ VERSION = '0.7.0'
end
diff --git a/lib/loaders/spree/image_loader.rb b/lib/loaders/spree/image_loader.rb
deleted file mode 100644
index 73cae5d..0000000
--- a/lib/loaders/spree/image_loader.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
-# Author :: Tom Statter
-# Date :: Jan 2011
-# License:: MIT. Free, Open Source.
-#
-require 'loader_base'
-require 'spree_loader_base'
-
-
-module DataShift
-
- module SpreeEcom
-
- # TODO - THIS CONCEPT NOW BELONGS AS A POPULATOR
-
-
- # Very specific Image Loading for existing Products in Spree.
- #
- # Requirements : A CSV or Excel file which has 2+ columns
- #
- # 1) Identifies a Product via Name or SKU column
- # 2+) The full path(s) to the Images to attach to Product from column 1
- #
- class ImageLoader < SpreeLoaderBase
-
- def initialize()
-
- super()
-
- ModelMethods::Manager.catalog_class(Spree::Image)
- ModelMethods::Manager.catalog_class(Spree::Product)
- ModelMethods::Manager.catalog_class(Spree::Variant)
-
- end
-
- # Load object not an Image - need to look it up via Name or SKU
- def reset( object = nil)
- super(object)
-
- @load_object = nil
- end
-
- def run(file_name)
- super(file_name, Spree::Image)
- end
-
- def self.acceptable_path_headers
- @@path_headers ||= ['attachment', 'images', 'path']
- end
-
- # Called from associated perform_xxxx_load
-
- # Over ride base class process with some Spree::Image specifics
- #
- # What process a value string from a column, assigning value(s) to correct association on Product.
- # Method map represents a column from a file and it's correlated Product association.
- # Value string which may contain multiple values for a collection (has_many) association.
- #
- def process(method_detail, value)
-
- raise ImageLoadError.new("Cannot process #{value} NO details found to assign to") unless(method_detail)
-
- # TODO - start supporting assigning extra data via current_attribute_hash
- current_value, current_attribute_hash = @populator.prepare_data(method_detail, value)
-
- operator = method_detail.operator
-
- # TODO - current relies on correct order - i.e lookup column must come before attachment
-
- if(current_value && ImageLoader::acceptable_path_headers.include?(operator) )
-
- add_images( @load_object ) if(@load_object)
-
- elsif(current_value && method_detail.operator )
-
- # find the db record to assign our Image usually expect either SKU (Variant) or Name (product)
- if( MethodDictionary::find_method_detail_if_column(Spree::Product, operator) )
- @load_object = get_record_by(@@product_klass, operator, current_value)
-
- elsif( MethodDictionary::find_method_detail_if_column(@@variant_klass, operator) )
- puts "Find VARIANT with #{operator} == #{current_value}"
- @load_object = get_record_by(@@variant_klass, operator, current_value)
- else
- raise "No Spree class can be searched for by #{operator}"
- end
-
- unless(@load_object)
- puts "WARNING: Could not find a record where #{operator} == #{current_value}"
- return
- else
- puts "Image Attachment on record #{@load_object.inspect}"
- end
-
- end
-
- end
-
- end
- end
-end
diff --git a/lib/loaders/spree/product_loader.rb b/lib/loaders/spree/product_loader.rb
deleted file mode 100644
index 15ba7ce..0000000
--- a/lib/loaders/spree/product_loader.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# Copyright:: (c) Autotelik Media Ltd 2016
-# Author :: Tom Statter
-# Date :: 2016
-# License:: MIT
-#
-# Details:: Specific over-rides/additions to support Spree Products
-#
-# require 'spree_ecom'
-
-require 'loaders/spree/spree_loading'
-
-module DataShift
-
- module SpreeEcom
-
- class ProductLoader
-
- include DataShift::SpreeLoading
-
- attr_accessor :file_name
-
- attr_accessor :datashift_loader
-
- delegate :loaded_count, :failed_count, :processed_object_count, to: :datashift_loader
-
- delegate :configure_from, to: :datashift_loader
-
- def initialize(file_name)
-
- @file_name = file_name
-
- # gets a file type specific loader e.g csv, excel
- @datashift_loader = DataShift::Loader::Factory.get_loader(file_name)
- end
-
- # Non Product database fields we can still process - delegated to Variant
- #
- # See delegate_belongs_to :master @ https://github.com/spree/spree/blob/master/core/app/models/spree/product.rb
- #
- def force_inclusion_columns
- @force_inclusion_columns ||= %w{ cost_price
- images
- price
- shipping_category
- sku
- stock_items
- variant_sku
- variant_cost_price
- variant_price
- variant_images
- }
- end
-
- def run
-
- logger.info "Product load from File [#{file_name}]"
-
- DataShift::PopulatorFactory.global_populator_class = DataShift::SpreeEcom::ProductPopulator
-
- DataShift::Configuration.call.force_inclusion_of_columns = force_inclusion_columns
-
- datashift_loader.run(file_name, Spree::Product)
- end
-
- end
- end
-end
diff --git a/lib/loaders/spree/product_populator.rb b/lib/loaders/spree/product_populator.rb
deleted file mode 100644
index fbbefc5..0000000
--- a/lib/loaders/spree/product_populator.rb
+++ /dev/null
@@ -1,708 +0,0 @@
-# Copyright:: (c) Autotelik Media Ltd 2016
-# Author :: Tom Statter
-# Date :: 2016
-# License:: MIT
-#
-# Details:: Specific Populator for Spree Products
-#
-
-require 'mechanize'
-require 'loaders/spree/spree_loading'
-
-module DataShift
-
- module SpreeEcom
-
- class ProductPopulator < Populator
-
- include DataShift::SpreeLoading
-
- include DataShift::Logging
- extend DataShift::Logging
-
- attr_reader :product_load_object
-
- def prepare_and_assign_method_binding(method_binding, record, data)
-
- prepare_data(method_binding, data)
-
- @product_load_object = record
-
- logger.debug("Populating data via Spree specific ProductPopulator")
-
- logger.debug("Populating data via Spree specific ProductPopulator [#{method_binding.operator}] - [#{data}]")
-
- # Special cases for Products, generally where a simple one stage lookup won't suffice
- # otherwise simply use default processing from base class
- if(method_binding.operator?('variants') || method_binding.operator?('option_types'))
-
- add_options_variants
-
- elsif(method_binding.operator?('taxons'))
-
- add_taxons
-
- elsif(method_binding.operator?('product_properties')|| method_binding.operator?('properties') )
-
- add_properties
-
- # This loads images to Product or Product Master Variant depending on Spree version
- elsif(method_binding.operator?('images') || method_binding.operator?('Images'))
-
- add_images( product_load_object.master )
-
- # This loads images to Product Variants
- elsif(method_binding.operator?('variant_images'))
-
- add_variant_images(data)
-
- elsif(method_binding.operator?('variant_price') && product_load_object.variants.size > 0)
-
- if(data.to_s.include?(multi_assoc_delim))
-
- # Check if we processed Option Types and assign per option
- values = data.to_s.split(multi_assoc_delim)
-
- if(record.variants.size == values.size)
- record.variants.each_with_index {|v, i| v.price = values[i].to_f }
- record.save
- else
- puts "WARNING: Price entries did not match number of Variants - None Set"
- end
- end
-
- elsif(method_binding.operator?('variant_cost_price') && product_load_object.variants.size > 0)
-
- if(data.to_s.include?(multi_assoc_delim))
-
- # Check if we processed Option Types and assign per option
- values = data.to_s.split(multi_assoc_delim)
-
- if(product_load_object.variants.size == values.size)
- product_load_object.variants.each_with_index {|v, i| v.cost_price = values[i].to_f }
- product_load_object.save
- else
- puts "WARNING: Cost Price entries did not match number of Variants - None Set"
- end
- end
-
- elsif(method_binding.operator?('variant_sku') && product_load_object.variants.size > 0)
-
- if(data.to_s.include?(multi_assoc_delim))
-
- # Check if we processed Option Types and assign per option
- values = data.to_s.split(multi_assoc_delim)
-
- if(product_load_object.variants.size == values.size)
- product_load_object.variants.each_with_index {|v, i| v.sku = values[i].to_s }
- product_load_object.save
- else
- puts "WARNING: SKU entries did not match number of Variants - None Set"
- end
- end
-
- elsif(data && method_binding.operator?('stock_items'))
-
- logger.info "Adding Variants Stock Items (count_on_hand)"
-
- product_load_object.save_if_new
-
- add_variants_stock(data)
-
- else
- super(method_binding, product_load_object, data) if(data)
- end
-
- end
-
- private
-
- # Special case for OptionTypes as it's two stage process
- # First add the possible option_types to Product, then we are able
- # to define Variants on those options values.
- # So to define a Variant :
- # 1) define at least one OptionType on Product, for example Size
- # 2) Provide a value for at least one of these OptionType
- # 3) A composite Variant can be created by supplying a value for more than one OptionType
- # fro example Colour : Red and Size Medium
- #
- # Supported Syntax :
- # '|' seperates Variants
- #
- # ';' list of option values
- # Examples :
- #
- # mime_type:jpeg;print_type:black_white|mime_type:jpeg|mime_type:png, PDF;print_type:colour
- #
- def build_option_types(option_types)
-
- optiontype_vlist_map = {}
-
- option_types.each do |ostr|
-
- oname, value_str = ostr.split(name_value_delim)
-
- option_type = option_type_klass.where(:name => oname).first
-
- unless option_type
- option_type = option_type_klass.create(:name => oname, :presentation => oname.humanize)
-
- unless option_type
- logger.warm("WARNING: OptionType #{oname} NOT found and could not create - Not set Product")
- next
- end
- logger.info "Created missing OptionType #{option_type.inspect}"
- end
-
- # OptionTypes must be specified first on Product to enable Variants to be created
- product_load_object.option_types << option_type unless product_load_object.option_types.include?(option_type)
-
- # Can be simply list of OptionTypes, some or all without values
- next unless(value_str)
-
- optiontype_vlist_map[option_type] ||= []
-
- # Now get the value(s) for the option e.g red,blue,green for OptType 'colour'
- optiontype_vlist_map[option_type] += value_str.split(',').flatten
- end
-
-
- # A single Variant can have MULTIPLE Option Types and the Syntax supports this combining
- #
- # So we need the LONGEST set of OptionValues - to use as the BASE for combining with the rest
- #
- # mime_type:png,PDF; print_type:colour
- #
- # This means create 2 Variants
- # 1 mime_type:png && print_type:colour
- # 1 mime_type:PDF && print_type:colour
- #
- # And we want to identify this "mime_type:png,PDF" as the longest to combine with the smaller print_type list
-
- sorted_map = optiontype_vlist_map.sort_by { |ot, ov| ov.size }.reverse
-
- sorted_map
-
- end
-
- def add_options_variants
-
- # TODO smart column ordering to ensure always valid by time we get to associations
- begin
- product_load_object.save_if_new
- rescue => e
- logger.error("Cannot add OptionTypes/Variants - Save Failed : #{e.inspect}")
- raise ProductLoadError.new("Cannot add OptionTypes/Variants - Save failed on parent Product")
- end
-
- # Split into multiple Variants - '|' seperates
- #
- # So mime_type:jpeg | print_type:black_white
- #
- # => 2 Variants on different OpTypes, mime_type and print_type
- #
- variant_chain = value.to_s.split( multi_assoc_delim )
-
- variant_chain.each do |per_variant|
-
- option_types = per_variant.split(multi_facet_delim) # => [mime_type:jpeg, print_type:black_white]
-
- logger.info "Building Variants based on Option Types #{option_types.inspect}"
-
- sorted_map = build_option_types(option_types)
-
- next if(sorted_map.empty?) # Only option types specified - no values, so no Variant to create
-
- # {mime => ['pdf', 'jpeg', 'gif'], print_type => ['black_white']}
-
- lead_option_type, lead_ovalues = sorted_map.shift
-
- # TODO .. benchmarking to find most efficient way to create these but ensure Product.variants list
- # populated .. currently need to call reload to ensure this (seems reqd for Spree 1/Rails 3, wasn't required b4
- lead_ovalues.each do |ovname|
-
- ov_list = []
-
- ovname.strip!
-
- logger.info("Adding Variant for #{ovname} on #{lead_option_type}")
-
- # TODO - not sure why I create the OptionValues here, rather than above with the OptionTypes
- ov = option_value_klass.where(:name => ovname,
- :option_type_id => lead_option_type.id).first_or_create(:presentation => ovname.humanize)
- ov_list << ov if ov
-
- # Process rest of array of types => values
- sorted_map.each do |ot, ovlist|
- ovlist.each do |ov_for_composite|
-
- ov_for_composite.strip!
-
- ov = option_value_klass.where(
- :name => ov_for_composite,
- :option_type_id => ot.id).first_or_create(:presentation => ov_for_composite.humanize)
-
- ov_list << ov if(ov)
- end
- end
-
- unless(ov_list.empty?)
-
- logger.info("Creating Variant on OptionValue(s) #{ov_list.collect(&:name).inspect}")
-
- i = product_load_object.variants.size + 1
-
- product_load_object.variants.create!(
- :sku => "#{product_load_object.sku}_#{i}",
- :price => product_load_object.price,
- :weight => product_load_object.weight,
- :height => product_load_object.height,
- :width => product_load_object.width,
- :depth => product_load_object.depth,
- :tax_category_id => product_load_object.tax_category_id,
- :option_values => ov_list
- )
-
- end
- end
-
- end
-
- end # each Variant
-
- # Special case for ProductProperties since it can have additional value applied.
- # A list of Properties with a optional Value - supplied in form :
- # property_name:value|property_name|property_name:value
- # Example :
- # test_pp_002|test_pp_003:Example free value
-
- def add_properties
- # TODO smart column ordering to ensure always valid by time we get to associations
- product_load_object.save_if_new
-
- property_list = value.to_s.split(multi_assoc_delim)
-
- property_list.each do |property_string|
-
- # Special case, we know we lookup on name so operator is effectively the name to lookup
-
- # split into usable parts ; size:large or colour:red,green,blue
- find_by_name, find_by_value = property_string.split(name_value_delim)
-
- raise "Cannot find Property via #{find_by_name} (with value #{find_by_value})" unless(find_by_name)
-
- property = Spree::Property.where(:name => find_by_name).first
-
- unless property
- property = property_klass.create( :name => find_by_name, :presentation => find_by_name.humanize)
- logger.info "Created New Property #{property.inspect}"
- end
-
- if(property)
- # Property now protected from mass assignment
- x = product_property_klass.new( :value => find_by_value )
- x.property = property
- x.save
- @product_load_object.product_properties << x
- logger.info "Created New ProductProperty #{x.inspect}"
- else
- puts "WARNING: Property #{find_by_name} NOT found - Not set Product"
- end
-
- end
-
- end
-
- # Nested tree structure support ..
- # TAXON FORMAT
- # name|name>child>child|name
-
- def add_taxons
- # TODO smart column ordering to ensure always valid by time we get to associations
- product_load_object.save_if_new
-
- chain_list = value.to_s.split(multi_assoc_delim) # potentially multiple chains in single column (delimited by multi_assoc_delim)
-
- chain_list.each do |chain|
-
- # Each chain can contain either a single Taxon, or the tree like structure parent>child>child
- name_list = chain.split(/\s*>\s*/)
-
- parent_name = name_list.shift
-
- parent_taxonomy = taxonomy_klass.where(:name => parent_name).first_or_create
-
- raise DataShift::DataProcessingError.new("Could not find or create Taxonomy #{parent_name}") unless parent_taxonomy
-
- parent = parent_taxonomy.root
-
- # Add the Taxons to Taxonomy from tree structure parent>child>child
- taxons = name_list.collect do |name|
-
- begin
- taxon = taxon_klass.where(:name => name, :parent_id => parent.id, :taxonomy_id => parent_taxonomy.id).first_or_create
-
- # pre Rails 4 - taxon = taxon_klass.find_or_create_by_name_and_parent_id_and_taxonomy_id(name, parent && parent.id, parent_taxonomy.id)
-
- unless(taxon)
- logger.warn("Missing Taxon - could not find or create #{name} for parent #{parent_taxonomy.inspect}")
- end
- rescue => e
- logger.error(e.inspect)
- logger.error "Cannot assign Taxon ['#{taxon}'] to Product ['#{product_load_object.name}']"
- next
- end
-
- parent = taxon # current taxon becomes next parent
- taxon
- end
-
- taxons << parent_taxonomy.root
-
- unique_list = taxons.compact.uniq - (@product_load_object.taxons || [])
-
- logger.debug("Product assigned to Taxons : #{unique_list.collect(&:name).inspect}")
-
- @product_load_object.taxons << unique_list unless(unique_list.empty?)
- # puts @product_load_object.taxons.inspect
-
- end
-
- end
-
- def add_variants_stock(data)
-
- product_load_object.save_if_new
-
- # do we have Variants?
- if(@product_load_object.variants.size > 0)
-
- logger.info "[COUNT_ON_HAND] - number of variants to process #{@product_load_object.variants.size}"
-
- if(data.to_s.include?(multi_assoc_delim))
- # Check if we've already processed Variants and assign count per variant
- values = data.to_s.split(multi_assoc_delim)
- # variants and count_on_hand number match?
- raise "WARNING: Count on hand entries did not match number of Variants - None Set" unless (@product_load_object.variants.size == values.size)
- end
-
- variants = @product_load_object.variants # just for readability and logic
- logger.info "Variants: #{@product_load_object.variants.inspect}"
-
- stock_coh_list = value.to_s.split(multi_assoc_delim) # we expect to get corresponding stock_location:count_on_hand for every variant
-
- stock_coh_list.each_with_index do |stock_coh, i|
-
- # count_on_hand column MUST HAVE "stock_location_name:variant_count_on_hand" format
- stock_location_name, variant_count_on_hand = stock_coh.split(name_value_delim)
-
- logger.info "Setting #{variant_count_on_hand} items for stock location #{stock_location_name}..."
-
- if not stock_location_name # No Stock Location referenced, fallback to default one...
- logger.info "No Stock Location was referenced. Adding count_on_hand to default Stock Location. Use 'stock_location_name:variant_count_on_hand' format to specify prefered Stock Location"
- stock_location = stock_location_klass.where(:default => true).first
- raise "WARNING: Can't set count_on_hand as no Stock Location exists!" unless stock_location
- else # go with the one specified...
- stock_location = stock_location_klass.where(:name => stock_location_name).first
- unless stock_location
- stock_location = stock_location_klass.create( :name => stock_location_name)
- logger.info "Created New Stock Location #{stock_location.inspect}"
- end
- end
-
- if(stock_location)
- stock_movement_klass.create(:quantity => variant_count_on_hand.to_i, :stock_item => variants[i].stock_items.find_by_stock_location_id(stock_location.id))
- logger.info "Added #{variant_count_on_hand} count_on_hand to Stock Location #{stock_location.inspect}"
- else
- puts "WARNING: Stock Location #{stock_location_name} NOT found - Can't set count_on_hand"
- end
-
- end
-
- # ... or just single Master Product?
- elsif(@product_load_object.variants.size == 0)
- if(data.to_s.include?(multi_assoc_delim))
- # count_on_hand column MUST HAVE "stock_location_name:master_count_on_hand" format
- stock_location_name, master_count_on_hand = (data.to_s.split(multi_assoc_delim).first).split(name_value_delim)
- puts "WARNING: Multiple count_on_hand values specified but no Variants/OptionTypes created"
- else
- stock_location_name, master_count_on_hand = data.split(name_value_delim)
- end
- if not stock_location_name # No Stock Location referenced, fallback to default one...
- logger.info "No Stock Location was referenced. Adding count_on_hand to default Stock Location. Use 'stock_location_name:master_count_on_hand' format to specify prefered Stock Location"
- stock_location = stock_location_klass.where(:default => true).first
- raise "WARNING: Can't set count_on_hand as no Stock Location exists!" unless stock_location
- else # go with the one specified...
- stock_location = stock_location_klass.where(:name => stock_location_name).first
- unless stock_location
- stock_location = stock_location_klass.create( :name => stock_location_name)
- logger.info "Created New Stock Location #{stock_location.inspect}"
- end
- end
-
- if(stock_location)
- stock_movement_klass.create(:quantity => master_count_on_hand.to_i, :stock_item => product_load_object.master.stock_items.find_by_stock_location_id(stock_location.id))
- logger.info "Added #{master_count_on_hand} count_on_hand to Stock Location #{stock_location.inspect}"
- else
- puts "WARNING: Stock Location #{stock_location_name} NOT found - Can't set count_on_hand"
- end
- end
- end
-
- def add_variant_images(data)
-
- product_load_object.save_if_new
-
- # do we have Variants?
- if(@product_load_object.variants.size > 0)
-
- logger.info "[VARIANT IMAGES] - number of variants to process #{@product_load_object.variants.size}"
-
- if(data.to_s.include?(multi_assoc_delim))
- # Check if we've already processed Variants and assign count per variant
- values = data.to_s.split(multi_assoc_delim)
- # variants and variant_images number match?
- raise "WARNING: Variant Images entries did not match number of Variants - None Set" unless (@product_load_object.variants.size == values.size)
- end
-
- variants = @product_load_object.variants
-
- logger.info "Variants: #{variants.inspect}"
-
- # we expect to get corresponding images for every variant (might have more than one image for each variant!)
- variants_images_list = value.to_s.split(multi_assoc_delim)
-
- variants_images_list.each_with_index do |variant_images, i|
-
- if(variant_images.to_s.include?(multi_value_delim))
- # multiple images
- images = variant_images.to_s.split(multi_value_delim)
- else
- # single image
- images = []
- images << variant_images
- end
-
- logger.info "Setting #{images.count} images for variant #{variants[i].name}..."
-
- # reset variant images to attach to variant
- var_images = []
-
- # Image processing...
- logger.debug "Images to process: #{images.inspect} for variant #{variants[i].name}"
- images.each do |image|
- @spree_uri_regexp ||= Regexp::new('(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?' )
-
- if(image.match(@spree_uri_regexp))
-
- uri, attributes = image.split(attribute_list_start)
-
- uri.strip!
-
- logger.info("Processing IMAGE from URI [#{uri.inspect}]")
-
- if(attributes)
- #TODO move to ColumnPacker unpack ?
- attributes = attributes.split(', ').map{|h| h1,h2 = h.split('=>'); {h1.strip! => h2.strip!}}.reduce(:merge)
- logger.debug("IMAGE has additional attributes #{attributes.inspect}")
- else
- attributes = {} # will blow things up later if we pass nil where {} expected
- end
-
- agent = Mechanize.new
-
- image = begin
- agent.get(uri)
- rescue => e
- puts "ERROR: Failed to fetch image from URL #{uri}", e.message
- raise DataShift::BadUri.new("Failed to fetch image from URL #{uri}")
- end
-
- # Expected image is_a Mechanize::Image
- # image.filename& image.extract_filename do not handle query string well e,g blah.jpg?v=1234
- # so for now use URI
- # extname = image.respond_to?(:filename) ? File.extname(image.filename) : File.extname(uri)
- extname = File.extname( uri.gsub(/\?.*=.*/, ''))
-
- base = image.respond_to?(:filename) ? File.basename(image.filename, '.*') : File.basename(uri, '.*')
-
- logger.debug("Storing Image in TempFile #{base.inspect}.#{extname.inspect}")
-
- @current_image_temp_file = Tempfile.new([base, extname], :encoding => 'ascii-8bit')
-
- begin
-
- # TODO can we handle embedded img src e.g from Mechanize::Page::Image ?
-
- # If I call image.save(@current_image_temp_file.path) then it creates a new file with a .1 extension
- # so the real temp file data is empty and paperclip chokes
- # so this is a copy from the Mechanize::Image save method. don't like it much, very brittle, but what to do ...
- until image.body_io.eof? do
- @current_image_temp_file.write image.body_io.read 16384
- end
-
- @current_image_temp_file.rewind
-
- logger.info("IMAGE downloaded from URI #{uri.inspect}")
-
- attachment = create_attachment(Spree::Image, @current_image_temp_file.path, nil, nil, attributes)
-
- rescue => e
- logger.error(e.message)
- logger.error("Failed to create Image from URL #{uri}")
- raise DataShift::DataProcessingError.new("Failed to create Image from URL #{uri}")
-
- ensure
- @current_image_temp_file.close
- @current_image_temp_file.unlink
- end
-
- else
-
- path, alt_text = image.split(name_value_delim)
-
- alt_text = variants[i].name if !alt_text #ensure alt_text is filled
-
- logger.debug("Processing IMAGE from PATH #{path.inspect} #{alt_text.inspect}")
-
- path = File.join(config[:image_path_prefix], path) if(config[:image_path_prefix])
-
- attachment = create_attachment(Spree::Image, path, nil, nil, :alt => alt_text)
-
- end
-
- logger.debug "#{attachment.inspect}"
- var_images << attachment if attachment
-
- end # images loop
-
- # we have our variant images. Save them!
- begin
- # Link images to corresponding variant
- variants[i].images << var_images
- variants[i].save
- logger.debug("Variant assigned Images from : #{var_images.inspect}")
- rescue => e
- puts "ERROR - Failed to assign attachments to #{variants[i].class} #{variants[i].id}"
- logger.error("Failed to assign attachments to #{variants[i].class} #{variants[i].id}")
- end
-
- end # variants_images_list loop
-
- # ... or just single Master Product?
- elsif(@product_load_object.variants.size == 0)
-
- if(data.to_s.include?(multi_value_delim))
- # multiple images
- images = data.to_s.split(multi_value_delim)
- else
- # single image
- images << variant_images
- end
-
- logger.info "Setting #{images.count} images for Master variant #{@product_load_object.master.name}..."
-
- # Image processing...
- images.each do |image|
- @spree_uri_regexp ||= Regexp::new('(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?' )
-
- if(image.match(@spree_uri_regexp))
-
- uri, attributes = image.split(attribute_list_start)
-
- uri.strip!
-
- logger.info("Processing IMAGE from URI [#{uri.inspect}]")
-
- if(attributes)
- #TODO move to ColumnPacker unpack ?
- attributes = attributes.split(', ').map{|h| h1,h2 = h.split('=>'); {h1.strip! => h2.strip!}}.reduce(:merge)
- logger.debug("IMAGE has additional attributes #{attributes.inspect}")
- else
- attributes = {} # will blow things up later if we pass nil where {} expected
- end
-
- agent = Mechanize.new
-
- image = begin
- agent.get(uri)
- rescue => e
- puts "ERROR: Failed to fetch image from URL #{uri}", e.message
- raise DataShift::BadUri.new("Failed to fetch image from URL #{uri}")
- end
-
- # Expected image is_a Mechanize::Image
- # image.filename& image.extract_filename do not handle query string well e,g blah.jpg?v=1234
- # so for now use URI
- # extname = image.respond_to?(:filename) ? File.extname(image.filename) : File.extname(uri)
- extname = File.extname( uri.gsub(/\?.*=.*/, ''))
-
- base = image.respond_to?(:filename) ? File.basename(image.filename, '.*') : File.basename(uri, '.*')
-
- logger.debug("Storing Image in TempFile #{base.inspect}.#{extname.inspect}")
-
- @current_image_temp_file = Tempfile.new([base, extname], :encoding => 'ascii-8bit')
-
- begin
-
- # TODO can we handle embedded img src e.g from Mechanize::Page::Image ?
-
- # If I call image.save(@current_image_temp_file.path) then it creates a new file with a .1 extension
- # so the real temp file data is empty and paperclip chokes
- # so this is a copy from the Mechanize::Image save method. don't like it much, very brittle, but what to do ...
- until image.body_io.eof? do
- @current_image_temp_file.write image.body_io.read 16384
- end
-
- @current_image_temp_file.rewind
-
- logger.info("IMAGE downloaded from URI #{uri.inspect}")
-
- attachment = create_attachment(Spree::Image, @current_image_temp_file.path, nil, nil, attributes)
-
- rescue => e
- logger.error(e.message)
- logger.error("Failed to create Image from URL #{uri}")
- raise DataShift::DataProcessingError.new("Failed to create Image from URL #{uri}")
-
- ensure
- @current_image_temp_file.close
- @current_image_temp_file.unlink
- end
-
- else
-
- path, alt_text = image.split(name_value_delim)
-
- alt_text = @product_load_object.master.name if !alt_text #ensure alt_text is filled
-
- logger.debug("Processing IMAGE from PATH #{path.inspect} #{alt_text.inspect}")
-
- path = File.join(config[:image_path_prefix], path) if(config[:image_path_prefix])
-
- # create_attachment(klass, attachment_path, product_load_object = nil, attach_to_product_load_object_field = nil, options = {})
- attachment = create_attachment(Spree::Image, path, nil, nil, :alt => alt_text)
-
- end
-
- var_images << attachment if attachment
-
- end # images loop
-
- # we have our variant images. Save them!
- begin
- # Link images to corresponding variant
- @product_load_object.master.images << var_images
- @product_load_object.master.save
- logger.debug("Master Variant assigned Images from : #{var_images.inspect}")
- rescue => e
- puts "ERROR - Failed to assign attachment to #{@product_load_object.master.class} #{@product_load_object.master.id}"
- logger.error("Failed to assign attachment to #{@product_load_object.master.class} #{@product_load_object.master.id}")
- end
-
- end
- end
-
- end
- end
-end
diff --git a/lib/loaders/spree/promotions_rules_actions.rb b/lib/loaders/spree/promotions_rules_actions.rb
deleted file mode 100644
index 7f998a6..0000000
--- a/lib/loaders/spree/promotions_rules_actions.rb
+++ /dev/null
@@ -1,144 +0,0 @@
-# Copyright:: (c) Autotelik Media Ltd 2015
-# Author :: Tom Statter
-# Date :: Aug 2015
-# License:: MIT
-#
-# Details:: Helpers to build Spree Promo Rules+ Actions
-#
-
-module DataShift
-
- module SpreeEcom
-
- # Adjustment can only be applied Once per Order
- # $36.00 off of the Picks (once per order)
- #
- class WithFirstOrderRuleAdjustment
-
- include DataShift::Logging
-
- def initialize(promo, calculator, description = nil)
-
- # $36.00 off of the Picks (once per order)
-
- logger.info("Creating WithOncePerOrderRuleAdjustment from [#{description}]")
-
- Spree::Promotion::Actions::CreateItemAdjustments.create!(calculator: calculator, promotion: promo)
- # Not sure which Action required ?
- # Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator, promotion: promo)
-
- Spree::Promotion::Rules::FirstOrder.create!(promotion: promo)
- end
-
- end
-
- # Adjust only Specific Items examples :
- # 10% off collections
- # $36.00 off of the Picks
- #
- class WithProductRuleAdjustment
-
- include DataShift::Logging
-
- def initialize(promo, calculator, description)
-
- logger.info("Creating WithProductRuleAdjustment from [#{description}]")
-
- Spree::Promotion::Actions::CreateItemAdjustments.create!(calculator: calculator, promotion: promo)
-
- # Examples :
- # regexp 1 : $36.00 off of the Picks (once per order)
- # regexp 2 : 30% off Miss Popular
- # 10% off collections
-
- #
- if(description.match(/off of the (.+) \(.*/) || description.match(/off (.+)/)
- )
-
- product_name = $1.strip
-
- products = if(product_name.include?('collections') && Spree::Product.column_names.include?('is_collection'))
- logger.info("Searching for Collections")
- Spree::Product.where(is_collection: true).all
- else
- logger.info("Searching for Products matching [%#{product_name}%]")
- Spree::Product.where(Spree::Product.arel_table[:name].matches("%#{product_name}%")).all
- end
-
- if(products.empty?)
- logger.error("No Matching Products found for [%#{product_name}%]")
- else
- logger.info("Found Matching Products : [#{products.collect(&:name)}]")
-
- ids = products.collect(&:id)
-
- logger.info("Creating Promo Rule for specific Products [#{ids.inspect}]")
-
- # Can't do one step - this chokes on invalid products - maybe cos of HABTM
- # rule = Spree::Promotion::Rules::Product.create( products: products, promotion: promo))
-
- rule = Spree::Promotion::Rules::Product.create(promotion: promo)
-
- rule.products << products
-
- #promo.rules << rule
-
- rule.save
- end
- else
- logger.error("WithProductRuleAdjustment Failed to parse Description [#{description}] - No Product Rule assigned to #{promo.inspect}")
- end
- end
- end
-
-
- # Simple - just adjust whole Order, every time
- class WithOrderAdjustment
-
- include DataShift::Logging
-
- def initialize(promo, calculator, description = nil)
-
- action = Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator)
- promo.actions << action
- end
- end
-
-
- # Adjust whole Order but only if conditions met e.g Order over $25
- class WithItemTotalRule
-
- include DataShift::Logging
-
- def initialize(promo, calculator, description)
-
- @regexp1 ||= Regexp.new('.*orders (.+) \$(\d+\.\d+)')
- @regexp2 ||= Regexp.new('.*orders (.+) \$(\d+)')
-
- action = Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator)
- promo.actions << action
-
- # $10 off orders equal or above $25.00
- # xxx off orders equal or above $25.00
- if(description.match(@regexp1) || description.match(@regexp2))
-
- # $1 not currently used since only ever seen "equal or above" => 'gte'
- logger.info("Creating Promo Rule for Min Amount of [#{$2}]")
- rule = Spree::Promotion::Rules::ItemTotal.create( preferred_amount: $2.to_f)
-
- # 2-1 stable only supports order greater than, not these
- #preferred_operator_min: 'gte',
- #preferred_operator_max: 'lte',
- #rule.preferred_amount_min = $2.to_f
- #rule.preferred_amount_max = nil
-
- promo.rules << rule
- else
- logger.error("WithItemTotalRule : Failed to parse Shopify description [#{description}]")
- end
- end
-
- end
-
- end
-end
\ No newline at end of file
diff --git a/lib/loaders/spree/shopify_order_migrator.rb b/lib/loaders/spree/shopify_order_migrator.rb
deleted file mode 100644
index 845755c..0000000
--- a/lib/loaders/spree/shopify_order_migrator.rb
+++ /dev/null
@@ -1,407 +0,0 @@
-# Copyright:: (c) Autotelik Media Ltd 2015
-# Author :: Tom Statter
-# Date :: Aug 2015
-# License:: MIT
-#
-# Details:: Supports migrating Shopify spreadsheets to Spree
-# Currently covers :
-# Orders
-#
-require 'spree_loader_base'
-# require 'spree_ecom'
-
-module DataShift
-
- module SpreeEcom
-
- class ShopifyOrderLoader < SpreeLoaderBase
-
- # Options
- #
- # :reload : Force load of the method dictionary for object_class even if already loaded
- # :verbose : Verbose logging and to STDOUT
- #
- def initialize(klass, options = {})
- # We want the delegated methods so always include instance methods
- opts = {:instance_methods => true }.merge( options )
-
- super( klass, nil, opts)
-
- raise "Failed to create a #{klass.name} for loading" unless load_object
- end
-
- # OVER RIDES
-
- # Options:
- # [:dummy] : Perform a dummy run - attempt to load everything but then roll back
- #
- def run( file_name, opts = {} )
- logger.info "Shopify run for Orders from File [#{file_name}]"
- super(file_name, opts)
- end
-
- def perform_excel_load( file_name, options = {} )
-
- # Spree 2 Checkout/Order states
-
- # go_to_state :address
- # go_to_state :delivery
- # go_to_state :payment, if: ->(order) { order.payment_required? }
- # go_to_state :confirm, if: ->(order) { order.confirmation_required? }
- # go_to_state :complete
-
- Spree::Order.class_eval do
-
- checkout_flow do
- go_to_state :address
- go_to_state :complete
- end
-
-
- def confirmation_required?
- false;
- end
-
- def payment_required?
- false;
- end
- end
-
- line_item_rows = 0
-
- start_excel(file_name, options)
-
- begin
- puts "Dummy Run - Changes will be rolled back" if options[:dummy]
-
- load_object_class.transaction do
-
- Spree::Config[:track_inventory_levels] = false
-
- @sheet.each_with_index do |row, i|
-
- current_row_idx = i
- @current_row = row
-
- next if(i == header_row_index)
-
- # This required in some circumstances where each_with_index keeps going
- # so need to manually detect when actual data ends, so quit once we hit the first completely empty row
- if(row.nil? || row.compact.empty?)
- puts "Finished - Last Row #{current_row_idx} : #{row}"
- break
- end
-
- logger.info "Processing Row #{current_row_idx} : #{row}"
-
- @reporter.processed_object_count += 1
-
- # The spreadsheet contains some lines that are LineItems only for previous Order row
- if(!row[0].nil? && !row[0].empty?) && (row[2].nil? || row[2].empty?) # Financial Status empty on LI rows
-
- puts("START processing Line Item Only #{current_row_idx} - #{row[0]} - #{row[17]} - #{row[16]} -#{row[18]}")
-
- line_item_rows += 1
-
- if(load_object && load_object.id.nil?)
- logger.warn "No parent Order for Line Item Only row"
- next
- end
-
- logger.info "Line Item Only - add row to current Order : #{load_object.id} : #{load_object.number}"
-
- begin
- process_line_item( row, load_object )
-
- @reporter.success_inbound_count += 1
-
- rescue => e
- process_excel_failure(e, false)
- end
-
- next # row contains NO OTHER data
-
- else
- finish if(load_object.id) # Ok we have added all Line Items - now complete existing order
-
- new_load_object # Main Order row, create new Spree::Order
- end
-
-
- # A real Order row, not just LineItem
-
- logger.info("Start processing new Order from row #{current_row_idx}")
-
- puts("START processing new Order from row #{current_row_idx} - #{row[0]} - #{row[17]} - #{row[16]} -#{row[18]}")
-
- begin
- # We are loading/migrating data - ensure emails not sent
- load_object.confirmation_delivered = true
-
- @total_idx ||= excel_headers.index('total' )
- @shipment_total_idx ||= excel_headers.index('shipment_total' )
- @additional_tax_total_idx ||= excel_headers.index('additional_tax_total' )
- @payment_total_idx ||= excel_headers.index('payment_total' )
- @promo_total_idx ||= excel_headers.index('promo_total' )
-
- @payment_state_idx ||= excel_headers.index('payment_state' )
- @shipment_state_idx ||= excel_headers.index('shipment_state' )
-
- @completed_at_idx ||= excel_headers.index('completed_at' )
- @paid_at_idx ||= excel_headers.index('Paid at' )
- @created_at_idx ||= excel_headers.index('Created at')
-
- @item_count_idx ||= excel_headers.index('item_count' )
-
- @shipping_method_idx ||= excel_headers.index("shipping_method:name")
-
-
- shipment_state = @current_row[@shipment_state_idx]
- payment_state = @current_row[@payment_state_idx]
-
- if(payment_state == 'refunded' && shipment_state == 'pending')
- new_load_object
- next
- end
-
- load_object.shipment_state = shipment_state
-
- load_object.payment_state = payment_state
-
-
- #number Email payment_state Paid at shipment_state completed_at Accepts Marketing Currency
- # Discount Code promo_total shipping_method:name Created at item_count Lineitem name Lineitem price Lineitem compare at price LineItems sku Lineitem requires shipping Lineitem taxable LineItems fulfillment status Billing Name Billing Street bill_address:address1 Billing Address2 Billing Company Billing City Billing Zip Billing Province Billing Country Billing Phone Shipping Name Shipping Street ship_address:address1 Shipping Address2 Shipping Company Shipping City Shipping Zip Shipping Province Shipping Country Shipping Phone Notes Note Attributes Cancelled at Payment Method Payment Reference Refunded Amount Vendor Id Tags Risk Level Source Lineitem discount
-
- load_object.number = @current_row[0]
- load_object.email = @current_row[1]
- load_object.currency = @current_row[7]
-
- load_object.item_count = row[@item_count_idx].to_f
-
- load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
-
- # We are loading/migrating data - try to ensure emails not sent
- load_object.confirmation_delivered = true
-
- save
-
- puts("Saved Order #{load_object.number} [#{load_object.id}]")
-
- logger.info("Saved Order #{load_object.number} [#{load_object.id}]")
-
- begin
- logger.info("Order #{load_object.number} - Assigning User with email [#{row[1]}]")
-
- user = Spree.user_class.where( :email => @current_row[1] ).first
-
- if(user)
- logger.info("Found User [#{row[1]}] - assign to #{load_object.number} (#{load_object.id}) ")
- load_object.associate_user!(user)
-
- # The user usually has address information attached so pull it if the order has no prepopulated addresses
- load_object.ship_address = load_object.user.ship_address unless load_object.ship_address
- load_object.bill_address = load_object.user.bill_address unless load_object.bill_address
- end
-
- def warn_no_address missing_obj
- logger.warn("No #{missing_obj} Address info for Order #{load_object.number} (#{load_object.id})")
-
- load_object.ship_address = nil
- load_object.bill_address = nil
- end
-
- if(load_object.bill_address.nil? and load_object.ship_address.nil?)
- warn_no_address "ship and bill"
- elsif(load_object.ship_address.nil?)
- if(load_object.bill_address.id.nil?)
- warn_no_address "ship and bill id"
- else
- load_object.clone_billing_address
- end
- elsif(load_object.bill_address.nil?)
- if(load_object.ship_address.id.nil?)
- warn_no_address "bill and ship id"
- else
- load_object.bill_address.attributes = load_object.ship_address.attributes.except('id', 'updated_at', 'created_at')
- end
- elsif(load_object.bill_address.id.nil? and load_object.ship_address.nil?)
- warn_no_address "bill id and ship id"
- end
-
- rescue => e
- logger.error("Error assigning User #{e.inspect}")
- logger.warn("Could not assign User #{row[1]} to Order #{load_object.number}")
- end
-
- unless(load_object.valid?)
- logger.info("INVALID ADDRESS - Order still Invalid #{load_object.inspect}")
- logger.info("Valid Order #{load_object.valid?}")
- puts "Row #{current_row_idx} invalid #{load_object.errors.full_messages.inspect}"
- load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
- end
-
- begin
- # make sure we also process the main Order rows, LineItem
- process_line_item( row, load_object )
- load_object.next!
- rescue => x # logged already
- puts "Issue assigning LineItem #{x.inspect}"
- end
-
-
- shipping_method = Spree::ShippingMethod.where( name: @current_row[@shipping_method_idx]).first
-
- load_object.shipping_method_id = shipping_method.id if(shipping_method)
-
- load_object.completed_at = @current_row[@completed_at_idx].blank? ? @current_row[@paid_at_idx] : @current_row[@completed_at_idx]
-
- if(load_object.completed_at.blank?)
- puts "No suitable completed_at date - using Created at #{@current_row[@created_at_idx]}"
-
- load_object.completed_at = @current_row[@created_at_idx]
- end
-
- load_object.shipment_total = row[@shipment_total_idx].to_f
- load_object.promo_total = row[@promo_total_idx].to_f
- load_object.total = row[@total_idx].to_f
-
- load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
-
- save_and_report
-
- rescue => e
- puts "Save Failed #{e.inspect}"
- process_excel_failure(e)
- next
- end
-
- end # all rows processed
-
- # double check the last Order
- finish
-
- if(options[:dummy])
- puts "Excel loading stage complete - Dummy run so Rolling Back."
- raise ActiveRecord::Rollback # Don't actually create/upload to DB if we are doing dummy run
- end
-
- end # TRANSACTION N.B ActiveRecord::Rollback does not propagate outside of the containing transaction block
-
- rescue => e
- puts "ERROR: Excel loading failed : #{e.inspect}"
- raise e
- ensure
- report
- end
-
- puts "Line Item only row count : #{line_item_rows}"
- end
-
- def finish
-
- return unless(load_object && load_object.id) # Ok we have added all Line Items - now complete existing order
-
- load_object.create_proposed_shipments
-
- # Spree::Order.shipments is a CollectionProxy (empty if no shipments)
- # so each is safe to use
- load_object.shipments.each do |s|
- s.state = 'shipped'
- s.shipped_at = load_object.completed_at
- end
-
- load_object.payment_state = 'paid'
- load_object.shipment_state = 'shipped'
- load_object.state = 'complete'
-
- logger.info("Order #{load_object.id}(#{load_object.number}) state set to 'complete' - Final Save")
-
- load_object.id = nil if(load_object.id == 0) # why the hell is this 0 happening !?
-
- begin
- load_object.save! # ok this Order done
- rescue => x
- logger.error("Final Spree Order save failed : #{load_object.errors.full_messages.inspect}")
- puts x.inspect
- end
-
- end
-
- def process_line_item( row, order )
- # for now just hard coding the columns 16 (quantity) and 17 (variant name), 20 (variant sku)
- @quantity_header_idx ||= 16
- @price_header_idx ||= 18
- @sku_header_idx ||= 20 # Lineitem:sku
-
- # if by name ...
- # by name - product = Spree::Product.where(:name => row[17]).first
- # variant = product.master if(product)
-
- sku = row[@sku_header_idx]
-
- method_detail = DataShift::MethodDictionary.find_method_detail(Spree::Order, "LineItems" )
-
- # will perform substitutions etc
- @populator.prepare_data(method_detail, sku)
-
- variant = Spree::Variant.where(:sku => sku).first
-
- unless(variant)
- raise RecordNotFound.new("Failed to find Variant with sku [#{sku}] for LineItem")
- end
-
- logger.info("Processing LineItem - Found Variant [#{variant.sku}] (#{variant.name})") if(variant)
-
- quantity = row[@quantity_header_idx].to_i
-
- if(quantity > 0)
-
- price = row[@price_header_idx].to_f
-
- logger.info("Adding LineItem for #{sku} with Quantity #{quantity} to Order #{load_object.inspect}")
-
- if(order.new_record?)
- puts "ORDER NEEDS SAVING - #{order.number} (#{order.id})"
- save
- end
-
- # idea incase we need full stock management
- # variant.stock_items.first.adjust_count_on_hand(quantity)
-
- begin
- #puts("Adding LineItem for #{sku} with Quantity #{quantity} to Order #{load_object.inspect}")
- #puts("Variant [#{variant.sku}] (#{variant.name})") if(variant)
-
- logger.info("Attempting to add new LineItem against Order #{order.number} (#{order.id})")
-
- order.line_items.new(quantity: quantity, variant: variant, :price => price)
-=begin
-
- line_item = Spree::LineItem.create!(:variant => variant,
- :quantity => quantity,
- :price => price,
- :pre_tax_amount => price,
- :order => order,
- :currency => order.currency)
-
-
- # line_item.save
- #order.reload
-
- logger.info("Success - Added LineItems to Order #{order.number} (#{order.id})")
- end
-=end
- rescue => e
- puts("Create LineItem failed for [#{sku}] Order #{order.number} (#{order.id}) - #{e.inspect}")
- puts("Create LineItem failed for [#{sku}] Order #{order.number} (#{order.id}) - #{e.inspect}")
- logger.error("Create LineItem failed for [#{sku}] Order #{order.number} (#{order.id}) - #{e.inspect}")
- raise
- end
-
- end
- end
-
- end
-
- end
-end
diff --git a/lib/loaders/spree/spree_loader_base.rb b/lib/loaders/spree/spree_loader_base.rb
deleted file mode 100644
index 0bc7cec..0000000
--- a/lib/loaders/spree/spree_loader_base.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright:: (c) Autotelik Media Ltd 2010
-# Author :: Tom Statter
-# Date :: Aug 2010
-# License:: MIT ?
-#
-# Details:: Specific over-rides/additions to support Spree Products
-#
-
-require 'loaders/paperclip/image_loading'
-require 'loaders/spree/spree_loading'
-
-module DataShift
-
- class SpreeLoaderBase < LoaderBase
-
- include DataShift::ImageLoading
- include DataShift::SpreeLoading
-
- def initialize
- super
- end
-
- end
-end
diff --git a/lib/tasks/datashift_spree_tasks.rake b/lib/tasks/datashift_spree_tasks.rake
new file mode 100644
index 0000000..d4e7402
--- /dev/null
+++ b/lib/tasks/datashift_spree_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :datashift_spree do
+# # Task goes here
+# end
diff --git a/lib/thor/spree/digitals.thor b/lib/thor/spree/digitals.thor
index 21be06e..24bf415 100644
--- a/lib/thor/spree/digitals.thor
+++ b/lib/thor/spree/digitals.thor
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2012
+# Copyright:: (c) Autotelik B.V 2012
# Author :: Tom Statter
# Date :: March 2012
# License:: MIT. Free, Open Source.
diff --git a/lib/thor/spree/exports.thor b/lib/thor/spree/exports.thor
index aaf7d93..622b02e 100644
--- a/lib/thor/spree/exports.thor
+++ b/lib/thor/spree/exports.thor
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2012
+# Copyright:: (c) Autotelik B.V 2012
# Author :: Tom Statter
# Date :: Dec 2014
# License:: MIT. Free, Open Source.
diff --git a/lib/thor/spree/products_images.thor b/lib/thor/spree/products_images.thor
index 1091ef5..bebbab3 100644
--- a/lib/thor/spree/products_images.thor
+++ b/lib/thor/spree/products_images.thor
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2012
+# Copyright:: (c) Autotelik B.V 2012
# Author :: Tom Statter
# Date :: March 2012
# License:: MIT. Free, Open Source.
@@ -21,7 +21,7 @@ module DatashiftSpree
include DataShift::Logging
- desc "products", "Populate Spree Product/Variant data from .xls (Excel) or CSV file"
+ desc "products", 'Populate Spree Product/Variant data from .xls (Excel) or CSV file'
method_option :input, :aliases => '-i', :required => true, :desc => "The import file (.xls or .csv)"
method_option :sku_prefix, :aliases => '-s', :desc => "Prefix to add to each SKU before saving Product"
@@ -32,28 +32,24 @@ module DatashiftSpree
def products()
- # TODO - We're assuming run from a rails app/top level dir...
- # ...can we make this more robust ? e.g what about when using active record but not in Rails app,
require File.expand_path('config/environment.rb')
input = options[:input]
- require 'product_loader'
-
- loader = DataShift::SpreeEcom::ProductLoader.new(input)
+ loader = DatashiftSpree::ProductLoader.new(input)
# YAML configuration file to drive defaults etc
if(options[:config])
raise "Bad Config - Cannot find specified file #{options[:config]}" unless File.exists?(options[:config])
- puts "DataShift::Product proccssing config from: #{options[:config]}"
+ puts "DataShift::Product processing config from: #{options[:config]}"
loader.configure_from( options[:config] )
else
DataShift::Transformation.factory do |factory|
- factory.set_default_on(Spree::Product, 'available_on', Time.now.to_s(:db) )
- factory.set_default_on(Spree::Product, 'cost_price', 0.0 )
- factory.set_default_on(Spree::Product, 'price', 0.0 )
+ factory.set_default_on(::Spree::Product, 'available_on', Time.now.to_s(:db) )
+ factory.set_default_on(::Spree::Product, 'cost_price', 0.0 )
+ factory.set_default_on(::Spree::Product, 'price', 0.0 )
end
end
@@ -76,7 +72,7 @@ module DatashiftSpree
require 'image_loader'
- loader = DataShift::SpreeEcom::ImageLoader.new(nil, options)
+ loader = DatashiftSpree::ImageLoader.new(nil, options)
loader.run( options[:input], options )
end
@@ -133,7 +129,7 @@ module DatashiftSpree
loader_options[:attach_to_klass] = owner_klass # Pass in real Ruby class not string class name
# WTF ... this works in the specs but thor gives me
- # products_images.thor:131:in `images': uninitialized constant Thor::Sandbox::Datashift::Spree::Variant (NameError)
+ # products_images.thor:131:in `images': uninitialized constant Thor::Sandbox::DatashiftSpree::Variant (NameError)
# loader_options[:attach_to_find_by_field] = (owner_klass. == Spree::Variant) ? :sku : :name
# so for now just sku lookup available .... TOFIX - name wont currently work for Variant and sku won't work for Product
diff --git a/lib/thor/spree/reports.thor b/lib/thor/spree/reports.thor
index 23bb7c1..c02902f 100644
--- a/lib/thor/spree/reports.thor
+++ b/lib/thor/spree/reports.thor
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2012
+# Copyright:: (c) Autotelik B.V 2012
# Author :: Tom Statter
# Date :: March 2012
# License:: MIT. Free, Open Source.
diff --git a/lib/thor/spree/shopify.thor b/lib/thor/spree/shopify.thor
index ed86672..e08ccb3 100644
--- a/lib/thor/spree/shopify.thor
+++ b/lib/thor/spree/shopify.thor
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2015
+# Copyright:: (c) Autotelik B.V 2015
# Author :: Tom Statter
# Date :: March 2015
# License:: MIT. Free, Open Source.
@@ -59,7 +59,7 @@ module DatashiftSpree
require 'shopify_promotions_migrator'
- loader = DataShift::SpreeEcom::ShopifyPromotionsMigrator.new(:verbose => options[:verbose])
+ loader = DatashiftSpree::ShopifyPromotionsMigrator.new(:verbose => options[:verbose])
# YAML configuration file to drive defaults etc
@@ -125,7 +125,7 @@ module DatashiftSpree
require 'shopify_order_migrator'
- loader = DataShift::SpreeEcom::ShopifyOrderLoader.new( Spree::Order, {:verbose => options[:verbose]})
+ loader = DatashiftSpree::ShopifyOrderLoader.new( Spree::Order, {:verbose => options[:verbose]})
# YAML configuration file to drive defaults etc
diff --git a/lib/thor/spree/templates.thor b/lib/thor/spree/templates.thor
new file mode 100644
index 0000000..23714a2
--- /dev/null
+++ b/lib/thor/spree/templates.thor
@@ -0,0 +1,38 @@
+module DatashiftSpree
+
+ class Template < Thor
+
+ include DataShift::Logging
+
+ desc "product", "Create a template .xls (Excel) file for loading Products"
+
+ method_option :template, aliases: '-t', default: 'product_template.xls', desc: "Filename for the template"
+
+ def product()
+ invoke('datashift:generate:excel', [], defaults)
+ end
+
+ desc "full", "Create a template .xls (Excel) file for loading Products and associations"
+
+ method_option :template, aliases: '-t', default: 'product_template.xls', desc:'Filename for the template'
+
+ def full
+ pass_options = defaults.merge(associations: true)
+
+ pp pass_options
+ invoke('datashift:generate:excel', [], pass_options)
+ end
+
+ private
+
+ def defaults
+ {
+ verbose: true,
+ model: 'Spree::Product',
+ additional_headers: ['price', 'sku'],
+ result: options[:template]
+ }
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/lib/thor/spree/utils.thor b/lib/thor/spree/utils.thor
index acc4cd7..de3ffaf 100644
--- a/lib/thor/spree/utils.thor
+++ b/lib/thor/spree/utils.thor
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2012
+# Copyright:: (c) Autotelik B.V 2012
# Author :: Tom Statter
# Date :: March 2012
# License:: MIT. Free, Open Source.
diff --git a/lib/thor/spree_databank/uk_shipping.thor b/lib/thor/spree_databank/uk_shipping.thor
index b4c8e8c..45ae90e 100644
--- a/lib/thor/spree_databank/uk_shipping.thor
+++ b/lib/thor/spree_databank/uk_shipping.thor
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 201=3
+# Copyright:: (c) Autotelik B.V 201=3
# Author :: Tom Statter
# Date :: Jan 2013
# License:: MIT. Free, Open Source.
diff --git a/spec/Gemfile b/spec/Gemfile
deleted file mode 100644
index 449d5e7..0000000
--- a/spec/Gemfile
+++ /dev/null
@@ -1,56 +0,0 @@
-source 'https://rubygems.org'
-
-
-gem "datashift_spree", path: '..'
-
-gem 'datashift', :git => 'https://github.com/bhtabor/datashift.git', branch: 'spree-3-7'
-
-# This Gemfile is for TESTING really.
-
-# DEFINE VERSIONS YOU WANT TO TEST AGAINST HERE
-# THIS SHOULD BASICALLY REPLICATE WHAT IS IN THE SANDBOX GEMFILE
-
-# N.B Spree will update the sandbox Gemfile with additional Spree gems
-# e,g User model and Authorisation
-# For rspec you may need to add them in here or you'll get missing Spree constants
-# TODO - update sandbox code so it automatically adds Spree gems in here
-
-gem 'spree', '~> 3.7.0'
-gem 'spree_auth_devise', '~> 3.5'
-gem 'spree_gateway', '~> 3.4'
-gem 'spree_digital', github: 'spree-contrib/spree_digital', branch: 'master'
-
-# See https://github.com/sstephenson/execjs#readme for more supported runtimes
-gem 'therubyracer', platforms: :ruby
-gem 'mechanize'
-
-gem 'database_cleaner'
-gem 'coffee-rails'
-gem 'sass-rails'
-
-
-group :development, :test do
- # Call 'byebug' anywhere in the code to stop execution and get a debugger console
- gem 'byebug'
-end
-
-# we want to test both JRuby and non JRuby especially for Excel
-
-platform :jruby do
- gem 'jruby-openssl'
- gem 'activerecord-jdbcsqlite3-adapter'
-end
-
-platform :ruby do
- gem 'sqlite3'
-end
-
-# STATIC GEMS
-
-gem 'rspec' # Behavior Driven Development (BDD) for Ruby
-gem 'rspec-core' # RSpec runner and example groups.
-gem 'rspec-expectations' # RSpec matchers for should and should_not.
-gem 'rspec-mocks' # RSpec test double framework with stubbing and mocking.
-gem 'rspec-rails' # RSpec version 2.x for Rails version 3.x.
-
-
diff --git a/spec/datashift_spree.thor b/spec/datashift_spree.thor
index 5847907..bfb8196 100644
--- a/spec/datashift_spree.thor
+++ b/spec/datashift_spree.thor
@@ -1,10 +1,10 @@
-# Copyright:: (c) Autotelik Media Ltd 2014
+# Copyright:: (c) Autotelik B.V 2014
# Author :: Tom Statter
# Date :: June 2014
#
# License:: MIT - Free, OpenSource
#
-# Details:: Spec tools for DataShiftSpree Gem
+# Details:: Spec tools for DatashiftSpree Gem
#
#
require 'datashift'
@@ -19,7 +19,7 @@ module Datashift
def build_sandbox()
- DataShift::SpreeEcom::build_sandbox
+ DatashiftSpree::build_sandbox
original_dir = Dir.pwd
@@ -27,7 +27,7 @@ module Datashift
# TOFIX - this don't work ... but works if run straight after the task
# maybe the env not right using system ?
begin
- Dir.chdir DataShift::SpreeEcom::spree_sandbox_path
+ Dir.chdir DatashiftSpree::spree_sandbox_path
puts "Running bundle install"
system('bundle install')
diff --git a/spec/datashift_spree/spree_digitals_spec.rb b/spec/datashift_spree/spree_digitals_spec.rb
deleted file mode 100644
index b34f63d..0000000
--- a/spec/datashift_spree/spree_digitals_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
-# Author :: Tom Statter
-# Date :: Mar 2013
-#
-# License:: MIT - Free, OpenSource
-#
-# Details:: Specification for loading Spree Digitals
-
-#
-require "spec_helper"
-
-describe 'Spree Digitals Loader' do
-
- before(:all) do
- end
-
- before(:each) do
- end
-
-end
diff --git a/spec/dummy/.ruby-version b/spec/dummy/.ruby-version
new file mode 100644
index 0000000..ccfb6ef
--- /dev/null
+++ b/spec/dummy/.ruby-version
@@ -0,0 +1 @@
+ruby-2.7.0
diff --git a/spec/dummy/Gemfile b/spec/dummy/Gemfile
new file mode 100644
index 0000000..012be6e
--- /dev/null
+++ b/spec/dummy/Gemfile
@@ -0,0 +1,39 @@
+source 'https://rubygems.org'
+git_source(:github) do |repo_name|
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
+ "https://github.com/#{repo_name}.git"
+end
+
+# RAILS
+gem 'rails', '~> 6.0.2', '>= 6.0.2.1'
+
+gem 'jbuilder'
+
+gem 'sass-rails'
+gem 'sqlite3'
+gem 'turbolinks'
+gem 'uglifier'
+
+# This Gemfile is only really for TESTING - Project is a gem that sits inside a Spree Rails APP
+
+# DEFINE VERSIONS YOU WANT TO TEST AGAINST HERE
+# THIS SHOULD BASICALLY REPLICATE WHAT IS IN THE SANDBOX GEMFILE
+
+# N.B Spree will update the sandbox Gemfile with additional Spree gems
+# e,g User model and Authorisation
+# For rspec you may need to add them in here or you'll get missing Spree constants
+# TODO - update sandbox code so it automatically adds Spree gems in here
+
+gem 'spree', '~> 4.1.0.rc1'
+gem 'spree_auth_devise', '~> 4.1.0.rc1'
+gem 'spree_gateway', '~> 3.7'
+
+gem 'spree_digital', github: 'spree-contrib/spree_digital', branch: 'master'
+
+gem 'datashift', path: '../../..' #, :git => 'https://github.com/autotelik/datashift.git', branch: 'update-to-support-rails-6'
+
+gem "datashift_spree", path: '../..'
+
+gem 'byebug'
+
+
diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile
new file mode 100644
index 0000000..e85f913
--- /dev/null
+++ b/spec/dummy/Rakefile
@@ -0,0 +1,6 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require_relative 'config/application'
+
+Rails.application.load_tasks
diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js
new file mode 100644
index 0000000..4f8d806
--- /dev/null
+++ b/spec/dummy/app/assets/config/manifest.js
@@ -0,0 +1,3 @@
+//= link_tree ../images
+//= link_directory ../stylesheets .css
+//= link datashift_spree_manifest.js
diff --git a/spec/dummy/app/assets/images/.keep b/spec/dummy/app/assets/images/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/spec/dummy/app/assets/stylesheets/application.css b/spec/dummy/app/assets/stylesheets/application.css
new file mode 100644
index 0000000..0ebd7fe
--- /dev/null
+++ b/spec/dummy/app/assets/stylesheets/application.css
@@ -0,0 +1,15 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
+ * files in this directory. Styles in this file should be added after the last require_* statement.
+ * It is generally better to create a new file per style scope.
+ *
+ *= require_tree .
+ *= require_self
+ */
diff --git a/spec/dummy/app/channels/application_cable/channel.rb b/spec/dummy/app/channels/application_cable/channel.rb
new file mode 100644
index 0000000..d672697
--- /dev/null
+++ b/spec/dummy/app/channels/application_cable/channel.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Channel < ActionCable::Channel::Base
+ end
+end
diff --git a/spec/dummy/app/channels/application_cable/connection.rb b/spec/dummy/app/channels/application_cable/connection.rb
new file mode 100644
index 0000000..0ff5442
--- /dev/null
+++ b/spec/dummy/app/channels/application_cable/connection.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Connection < ActionCable::Connection::Base
+ end
+end
diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb
new file mode 100644
index 0000000..09705d1
--- /dev/null
+++ b/spec/dummy/app/controllers/application_controller.rb
@@ -0,0 +1,2 @@
+class ApplicationController < ActionController::Base
+end
diff --git a/spec/dummy/app/controllers/concerns/.keep b/spec/dummy/app/controllers/concerns/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb
new file mode 100644
index 0000000..de6be79
--- /dev/null
+++ b/spec/dummy/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
diff --git a/spec/dummy/app/javascript/packs/application.js b/spec/dummy/app/javascript/packs/application.js
new file mode 100644
index 0000000..67ce467
--- /dev/null
+++ b/spec/dummy/app/javascript/packs/application.js
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file. JavaScript code in this file should be added after the last require_* statement.
+//
+// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
+// about supported directives.
+//
+//= require rails-ujs
+//= require activestorage
+//= require_tree .
diff --git a/spec/dummy/app/jobs/application_job.rb b/spec/dummy/app/jobs/application_job.rb
new file mode 100644
index 0000000..d394c3d
--- /dev/null
+++ b/spec/dummy/app/jobs/application_job.rb
@@ -0,0 +1,7 @@
+class ApplicationJob < ActiveJob::Base
+ # Automatically retry jobs that encountered a deadlock
+ # retry_on ActiveRecord::Deadlocked
+
+ # Most jobs are safe to ignore if the underlying records are no longer available
+ # discard_on ActiveJob::DeserializationError
+end
diff --git a/spec/dummy/app/mailers/application_mailer.rb b/spec/dummy/app/mailers/application_mailer.rb
new file mode 100644
index 0000000..286b223
--- /dev/null
+++ b/spec/dummy/app/mailers/application_mailer.rb
@@ -0,0 +1,4 @@
+class ApplicationMailer < ActionMailer::Base
+ default from: 'from@example.com'
+ layout 'mailer'
+end
diff --git a/spec/dummy/app/models/application_record.rb b/spec/dummy/app/models/application_record.rb
new file mode 100644
index 0000000..10a4cba
--- /dev/null
+++ b/spec/dummy/app/models/application_record.rb
@@ -0,0 +1,3 @@
+class ApplicationRecord < ActiveRecord::Base
+ self.abstract_class = true
+end
diff --git a/spec/dummy/app/models/concerns/.keep b/spec/dummy/app/models/concerns/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb
new file mode 100644
index 0000000..24307d3
--- /dev/null
+++ b/spec/dummy/app/views/layouts/application.html.erb
@@ -0,0 +1,14 @@
+
+
+
+ Dummy
+ <%= csrf_meta_tags %>
+ <%= csp_meta_tag %>
+
+ <%= stylesheet_link_tag 'application', media: 'all' %>
+
+
+
+ <%= yield %>
+
+
diff --git a/spec/dummy/app/views/layouts/mailer.html.erb b/spec/dummy/app/views/layouts/mailer.html.erb
new file mode 100644
index 0000000..cbd34d2
--- /dev/null
+++ b/spec/dummy/app/views/layouts/mailer.html.erb
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+ <%= yield %>
+
+
diff --git a/spec/dummy/app/views/layouts/mailer.text.erb b/spec/dummy/app/views/layouts/mailer.text.erb
new file mode 100644
index 0000000..37f0bdd
--- /dev/null
+++ b/spec/dummy/app/views/layouts/mailer.text.erb
@@ -0,0 +1 @@
+<%= yield %>
diff --git a/spec/dummy/bin/rails b/spec/dummy/bin/rails
new file mode 100755
index 0000000..0739660
--- /dev/null
+++ b/spec/dummy/bin/rails
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/spec/dummy/bin/rake b/spec/dummy/bin/rake
new file mode 100755
index 0000000..1724048
--- /dev/null
+++ b/spec/dummy/bin/rake
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/spec/dummy/bin/setup b/spec/dummy/bin/setup
new file mode 100755
index 0000000..0e39e8c
--- /dev/null
+++ b/spec/dummy/bin/setup
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+require 'fileutils'
+
+# path to your application root.
+APP_ROOT = File.expand_path('..', __dir__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+FileUtils.chdir APP_ROOT do
+ # This script is a way to setup or update your development environment automatically.
+ # This script is idempotent, so that you can run it at anytime and get an expectable outcome.
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
+ # end
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:prepare'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru
new file mode 100644
index 0000000..f7ba0b5
--- /dev/null
+++ b/spec/dummy/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb
new file mode 100644
index 0000000..e3c3cd3
--- /dev/null
+++ b/spec/dummy/config/application.rb
@@ -0,0 +1,48 @@
+require_relative 'boot'
+require 'bundler/setup'
+require 'rails/all'
+
+require "active_model/railtie"
+require "active_job/railtie"
+require "active_record/railtie"
+require "active_storage/engine"
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "action_view/railtie"
+require "action_cable/engine"
+require "sprockets/railtie"
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+require "byebug"
+require "devise"
+require "spree_auth_devise"
+require "spree"
+require "datashift_spree"
+
+module Dummy
+ class Application < Rails::Application
+
+ config.to_prepare do
+ # Load application's model / class decorators
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
+ Rails.configuration.cache_classes ? require(c) : load(c)
+ end
+
+ # Load application's view overrides
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
+ Rails.configuration.cache_classes ? require(c) : load(c)
+ end
+ end
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 6.0
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration can go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded after loading
+ # the framework and any gems in your application.
+ end
+end
+
diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb
new file mode 100644
index 0000000..c9aef85
--- /dev/null
+++ b/spec/dummy/config/boot.rb
@@ -0,0 +1,5 @@
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
+
+require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
+$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
diff --git a/spec/dummy/config/cable.yml b/spec/dummy/config/cable.yml
new file mode 100644
index 0000000..98367f8
--- /dev/null
+++ b/spec/dummy/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: test
+
+production:
+ adapter: redis
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
+ channel_prefix: dummy_production
diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml
new file mode 100644
index 0000000..4a8a1b2
--- /dev/null
+++ b/spec/dummy/config/database.yml
@@ -0,0 +1,25 @@
+# SQLite. Versions 3.8.0 and up are supported.
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem 'sqlite3'
+#
+default: &default
+ adapter: sqlite3
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+ timeout: 5000
+
+development:
+ <<: *default
+ database: db/development.sqlite3
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: db/test.sqlite3
+
+production:
+ <<: *default
+ database: db/production.sqlite3
diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb
new file mode 100644
index 0000000..426333b
--- /dev/null
+++ b/spec/dummy/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative 'application'
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb
new file mode 100644
index 0000000..7e49c00
--- /dev/null
+++ b/spec/dummy/config/environments/development.rb
@@ -0,0 +1,62 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ # Run rails dev:cache to toggle caching.
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+ config.action_controller.enable_fragment_cache_logging = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
+
+ # Store uploaded files on the local file system (see config/storage.yml for options).
+ config.active_storage.service = :local
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ config.action_mailer.perform_caching = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Highlight code that triggered database queries in logs.
+ config.active_record.verbose_query_logs = true
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
+
+ # Raises error for missing translations.
+ # config.action_view.raise_on_missing_translations = true
+
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+end
diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb
new file mode 100644
index 0000000..b7ad81b
--- /dev/null
+++ b/spec/dummy/config/environments/production.rb
@@ -0,0 +1,112 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
+ # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
+ # config.require_master_key = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress CSS using a preprocessor.
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Store uploaded files on the local file system (see config/storage.yml for options).
+ config.active_storage.service = :local
+
+ # Mount Action Cable outside main process or domain.
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ config.log_tags = [ :request_id ]
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Use a real queuing backend for Active Job (and separate queues per environment).
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "dummy_production"
+
+ config.action_mailer.perform_caching = false
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+
+ # Inserts middleware to perform automatic connection switching.
+ # The `database_selector` hash is used to pass options to the DatabaseSelector
+ # middleware. The `delay` is used to determine how long to wait after a write
+ # to send a subsequent read to the primary.
+ #
+ # The `database_resolver` class is used by the middleware to determine which
+ # database is appropriate to use based on the time delay.
+ #
+ # The `database_resolver_context` class is used by the middleware to set
+ # timestamps for the last write to the primary. The resolver uses the context
+ # class timestamps to determine how long to wait before reading from the
+ # replica.
+ #
+ # By default Rails will store a last write timestamp in the session. The
+ # DatabaseSelector middleware is designed as such you can define your own
+ # strategy for connection switching and pass that into the middleware through
+ # these configuration options.
+ # config.active_record.database_selector = { delay: 2.seconds }
+ # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
+ # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
+end
diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb
new file mode 100644
index 0000000..1d62e91
--- /dev/null
+++ b/spec/dummy/config/environments/test.rb
@@ -0,0 +1,48 @@
+# The test environment is used exclusively to run your application's
+# test suite. You never need to work with it otherwise. Remember that
+# your test database is "scratch space" for the test suite and is wiped
+# and recreated between test runs. Don't rely on the data there!
+
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ config.cache_classes = false
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
+ }
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+ config.cache_store = :null_store
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+
+ # Store uploaded files on the local file system in a temporary directory.
+ config.active_storage.service = :test
+
+ config.action_mailer.perform_caching = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations.
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/spec/dummy/config/initializers/application_controller_renderer.rb b/spec/dummy/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000..89d2efa
--- /dev/null
+++ b/spec/dummy/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb
new file mode 100644
index 0000000..fe48fc3
--- /dev/null
+++ b/spec/dummy/config/initializers/assets.rb
@@ -0,0 +1,12 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000..59385cd
--- /dev/null
+++ b/spec/dummy/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/spec/dummy/config/initializers/content_security_policy.rb b/spec/dummy/config/initializers/content_security_policy.rb
new file mode 100644
index 0000000..41c4301
--- /dev/null
+++ b/spec/dummy/config/initializers/content_security_policy.rb
@@ -0,0 +1,28 @@
+# Be sure to restart your server when you modify this file.
+
+# Define an application-wide content security policy
+# For further information see the following documentation
+# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
+
+# Rails.application.config.content_security_policy do |policy|
+# policy.default_src :self, :https
+# policy.font_src :self, :https, :data
+# policy.img_src :self, :https, :data
+# policy.object_src :none
+# policy.script_src :self, :https
+# policy.style_src :self, :https
+
+# # Specify URI for violation reports
+# # policy.report_uri "/csp-violation-report-endpoint"
+# end
+
+# If you are using UJS then enable automatic nonce generation
+# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
+
+# Set the nonce only to specific directives
+# Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
+
+# Report CSP violations to a specified URI
+# For further information see the following documentation:
+# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
+# Rails.application.config.content_security_policy_report_only = true
diff --git a/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000..5a6a32d
--- /dev/null
+++ b/spec/dummy/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/spec/dummy/config/initializers/devise.rb b/spec/dummy/config/initializers/devise.rb
new file mode 100644
index 0000000..5354908
--- /dev/null
+++ b/spec/dummy/config/initializers/devise.rb
@@ -0,0 +1 @@
+Devise.secret_key = "520df1720aa6c330030074fd1d8fb5f3726e0037cbb121347ab5c6552a317d20af6d120ccff38c5ad67adc525b0b908451f3"
diff --git a/spec/dummy/config/initializers/filter_parameter_logging.rb b/spec/dummy/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000..4a994e1
--- /dev/null
+++ b/spec/dummy/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb
new file mode 100644
index 0000000..ac033bf
--- /dev/null
+++ b/spec/dummy/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb
new file mode 100644
index 0000000..dc18996
--- /dev/null
+++ b/spec/dummy/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/spec/dummy/config/initializers/spree.rb b/spec/dummy/config/initializers/spree.rb
new file mode 100644
index 0000000..2dbe62f
--- /dev/null
+++ b/spec/dummy/config/initializers/spree.rb
@@ -0,0 +1,29 @@
+# Configure Spree Preferences
+#
+# Note: Initializing preferences available within the Admin will overwrite any changes that were made through the user interface when you restart.
+# If you would like users to be able to update a setting with the Admin it should NOT be set here.
+#
+# Note: If a preference is set here it will be stored within the cache & database upon initialization.
+# Just removing an entry from this initializer will not make the preference value go away.
+# Instead you must either set a new value or remove entry, clear cache, and remove database entry.
+#
+# In order to initialize a setting do:
+# config.setting_name = 'new value'
+Spree.config do |config|
+ # Example:
+ # Uncomment to stop tracking inventory levels in the application
+ # config.track_inventory_levels = false
+end
+
+# Configure Spree Dependencies
+#
+# Note: If a dependency is set here it will NOT be stored within the cache & database upon initialization.
+# Just removing an entry from this initializer will make the dependency value go away.
+#
+Spree.dependencies do |dependencies|
+ # Example:
+ # Uncomment to change the default Service handling adding Items to Cart
+ # dependencies.cart_add_item_service = 'MyNewAwesomeService'
+end
+
+Spree.user_class = "Spree::User"
diff --git a/spec/dummy/config/initializers/spree_storefront.rb b/spec/dummy/config/initializers/spree_storefront.rb
new file mode 100644
index 0000000..2698623
--- /dev/null
+++ b/spec/dummy/config/initializers/spree_storefront.rb
@@ -0,0 +1 @@
+SpreeStorefrontConfig = YAML.load_file(Rails.root.join('config', 'spree_storefront.yml')).with_indifferent_access
diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000..bbfc396
--- /dev/null
+++ b/spec/dummy/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
diff --git a/spec/dummy/config/locales/en.yml b/spec/dummy/config/locales/en.yml
new file mode 100644
index 0000000..cf9b342
--- /dev/null
+++ b/spec/dummy/config/locales/en.yml
@@ -0,0 +1,33 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# The following keys must be escaped otherwise they will not be retrieved by
+# the default I18n backend:
+#
+# true, false, on, off, yes, no
+#
+# Instead, surround them with single quotes.
+#
+# en:
+# 'true': 'foo'
+#
+# To learn more, please read the Rails Internationalization guide
+# available at https://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/spec/dummy/config/puma.rb b/spec/dummy/config/puma.rb
new file mode 100644
index 0000000..5ed4437
--- /dev/null
+++ b/spec/dummy/config/puma.rb
@@ -0,0 +1,38 @@
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers: a minimum and maximum.
+# Any libraries that use thread pools should be configured to match
+# the maximum value specified for Puma. Default is set to 5 threads for minimum
+# and maximum; this matches the default thread size of Active Record.
+#
+max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
+threads min_threads_count, max_threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
+
+# Specifies the `pidfile` that Puma will use.
+pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
+
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked web server processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory.
+#
+# preload_app!
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb
new file mode 100644
index 0000000..8b0eba9
--- /dev/null
+++ b/spec/dummy/config/routes.rb
@@ -0,0 +1,12 @@
+Rails.application.routes.draw do
+ # This line mounts Spree's routes at the root of your application.
+ # This means, any requests to URLs such as /products, will go to
+ # Spree::ProductsController.
+ # If you would like to change where this engine is mounted, simply change the
+ # :at option to something different.
+ #
+ # We ask that you don't use the :as option here, as Spree relies on it being
+ # the default of "spree".
+ mount Spree::Core::Engine, at: '/'
+ mount DatashiftSpree::Engine => "/datashift_spree"
+end
diff --git a/spec/dummy/config/spree_storefront.yml b/spec/dummy/config/spree_storefront.yml
new file mode 100644
index 0000000..dfa4e0b
--- /dev/null
+++ b/spec/dummy/config/spree_storefront.yml
@@ -0,0 +1,67 @@
+default:
+ navigation:
+ - title: Women
+ subtitle: Categories
+ url: /t/women
+ items:
+ - :title: Skirts
+ :url: /t/women/skirts
+ - :title: Dresses
+ :url: /t/women/dresses
+ - :title: Shirts and Blouses
+ :url: /t/women/shirts-and-blouses
+ - :title: Sweaters
+ :url: /t/women/sweaters
+ - :title: Tops and T-shirts
+ :url: /t/women/tops-and-t-shirts
+ - :title: Jackets and Coats
+ :url: /t/women/jackets-and-coats
+ promo_banners:
+ - subtitle: New collection
+ title: Summer 2019
+ url: /t/new-collection/summer-2019
+ image: 'meganav/promo_banner_left-first-category.jpg'
+ - subtitle: Special Offers
+ title: Get up to 30% off
+ url: /t/special-offers/30-off
+ image: 'meganav/promo_banner_right-first-category.jpg'
+ - title: Men
+ subtitle: Categories
+ url: /t/men
+ items:
+ - :title: Shirts
+ :url: /t/men/shirts
+ - :title: T-shirts
+ :url: /t/men/t-shirts
+ - :title: Sweaters
+ :url: /t/men/sweaters
+ - :title: Jackets and Coats
+ :url: /t/men/jackets-and-coats
+ promo_banners:
+ - subtitle: New collection
+ title: Summer 2019
+ url: /t/new-collection/summer-2019
+ image: 'meganav/promo_banner_left-second-category.jpg'
+ - subtitle: Special Offers
+ title: Get up to 30% off
+ url: /t/special-offers/30-off
+ image: 'meganav/promo_banner_right-second-category.jpg'
+ - title: Sportswear
+ subtitle: Categories
+ url: /t/sportswear
+ items:
+ - :title: Tops
+ :url: /t/sportswear/tops
+ - :title: Sweatshirts
+ :url: /t/sportswear/sweatshirts
+ - :title: Pants
+ :url: /t/sportswear/pants
+ promo_banners:
+ - subtitle: New collection
+ title: Summer 2019
+ url: /t/new-collection/summer-2019
+ image: 'meganav/promo_banner_left-third-category.jpg'
+ - subtitle: Special Offers
+ title: Get up to 30% off
+ url: /t/special-offers/30-off
+ image: 'meganav/promo_banner_right-third-category.jpg'
diff --git a/spec/dummy/config/spring.rb b/spec/dummy/config/spring.rb
new file mode 100644
index 0000000..db5bf13
--- /dev/null
+++ b/spec/dummy/config/spring.rb
@@ -0,0 +1,6 @@
+Spring.watch(
+ ".ruby-version",
+ ".rbenv-vars",
+ "tmp/restart.txt",
+ "tmp/caching-dev.txt"
+)
diff --git a/spec/dummy/config/storage.yml b/spec/dummy/config/storage.yml
new file mode 100644
index 0000000..d32f76e
--- /dev/null
+++ b/spec/dummy/config/storage.yml
@@ -0,0 +1,34 @@
+test:
+ service: Disk
+ root: <%= Rails.root.join("tmp/storage") %>
+
+local:
+ service: Disk
+ root: <%= Rails.root.join("storage") %>
+
+# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
+# amazon:
+# service: S3
+# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
+# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
+# region: us-east-1
+# bucket: your_own_bucket
+
+# Remember not to checkin your GCS keyfile to a repository
+# google:
+# service: GCS
+# project: your_project
+# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
+# bucket: your_own_bucket
+
+# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
+# microsoft:
+# service: AzureStorage
+# storage_account_name: your_account_name
+# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
+# container: your_container_name
+
+# mirror:
+# service: Mirror
+# primary: local
+# mirrors: [ amazon, google, microsoft ]
diff --git a/spec/dummy/db/migrate/20200218145740_create_active_storage_tables.active_storage.rb b/spec/dummy/db/migrate/20200218145740_create_active_storage_tables.active_storage.rb
new file mode 100644
index 0000000..0b2ce25
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145740_create_active_storage_tables.active_storage.rb
@@ -0,0 +1,27 @@
+# This migration comes from active_storage (originally 20170806125915)
+class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
+ def change
+ create_table :active_storage_blobs do |t|
+ t.string :key, null: false
+ t.string :filename, null: false
+ t.string :content_type
+ t.text :metadata
+ t.bigint :byte_size, null: false
+ t.string :checksum, null: false
+ t.datetime :created_at, null: false
+
+ t.index [ :key ], unique: true
+ end
+
+ create_table :active_storage_attachments do |t|
+ t.string :name, null: false
+ t.references :record, null: false, polymorphic: true, index: false
+ t.references :blob, null: false
+
+ t.datetime :created_at, null: false
+
+ t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
+ t.foreign_key :active_storage_blobs, column: :blob_id
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145741_create_action_mailbox_tables.action_mailbox.rb b/spec/dummy/db/migrate/20200218145741_create_action_mailbox_tables.action_mailbox.rb
new file mode 100644
index 0000000..2dd4279
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145741_create_action_mailbox_tables.action_mailbox.rb
@@ -0,0 +1,14 @@
+# This migration comes from action_mailbox (originally 20180917164000)
+class CreateActionMailboxTables < ActiveRecord::Migration[6.0]
+ def change
+ create_table :action_mailbox_inbound_emails do |t|
+ t.integer :status, default: 0, null: false
+ t.string :message_id, null: false
+ t.string :message_checksum, null: false
+
+ t.timestamps
+
+ t.index [ :message_id, :message_checksum ], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145742_create_action_text_tables.action_text.rb b/spec/dummy/db/migrate/20200218145742_create_action_text_tables.action_text.rb
new file mode 100644
index 0000000..5dfbd15
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145742_create_action_text_tables.action_text.rb
@@ -0,0 +1,14 @@
+# This migration comes from action_text (originally 20180528164100)
+class CreateActionTextTables < ActiveRecord::Migration[6.0]
+ def change
+ create_table :action_text_rich_texts do |t|
+ t.string :name, null: false
+ t.text :body, size: :long
+ t.references :record, null: false, polymorphic: true, index: false
+
+ t.timestamps
+
+ t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145743_spree_one_two.spree.rb b/spec/dummy/db/migrate/20200218145743_spree_one_two.spree.rb
new file mode 100644
index 0000000..e14a8ca
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145743_spree_one_two.spree.rb
@@ -0,0 +1,482 @@
+# This migration comes from spree (originally 20120831092320)
+class SpreeOneTwo < ActiveRecord::Migration[4.2]
+ def up
+ # This migration is just a compressed version of all the previous
+ # migrations for spree_core. Do not run it if one of the core tables
+ # already exists. Assume the best.
+ return if data_source_exists?(:spree_addresses)
+
+
+ create_table :spree_activators do |t|
+ t.string :description
+ t.datetime :expires_at
+ t.datetime :starts_at
+ t.string :name
+ t.string :event_name
+ t.string :type
+ t.integer :usage_limit
+ t.string :match_policy, default: 'all'
+ t.string :code
+ t.boolean :advertise, default: false
+ t.string :path
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_addresses do |t|
+ t.string :firstname
+ t.string :lastname
+ t.string :address1
+ t.string :address2
+ t.string :city
+ t.string :zipcode
+ t.string :phone
+ t.string :state_name
+ t.string :alternative_phone
+ t.string :company
+ t.references :state
+ t.references :country
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_addresses, [:firstname], name: 'index_addresses_on_firstname'
+ add_index :spree_addresses, [:lastname], name: 'index_addresses_on_lastname'
+
+ create_table :spree_adjustments do |t|
+ t.references :source, polymorphic: true
+ t.references :adjustable, polymorphic: true
+ t.references :originator, polymorphic: true
+ t.decimal :amount, precision: 8, scale: 2
+ t.string :label
+ t.boolean :mandatory
+ t.boolean :locked
+ t.boolean :eligible, default: true
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_adjustments, [:adjustable_id], name: 'index_adjustments_on_order_id'
+
+ create_table :spree_assets do |t|
+ t.references :viewable, polymorphic: true
+ t.integer :attachment_width
+ t.integer :attachment_height
+ t.integer :attachment_file_size
+ t.integer :position
+ t.string :attachment_content_type
+ t.string :attachment_file_name
+ t.string :type, limit: 75
+ t.datetime :attachment_updated_at
+ t.text :alt
+ end
+
+ add_index :spree_assets, [:viewable_id], name: 'index_assets_on_viewable_id'
+ add_index :spree_assets, [:viewable_type, :type], name: 'index_assets_on_viewable_type_and_type'
+
+ create_table :spree_calculators do |t|
+ t.string :type
+ t.references :calculable, polymorphic: true
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_configurations do |t|
+ t.string :name
+ t.string :type, limit: 50
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_configurations, [:name, :type], name: 'index_spree_configurations_on_name_and_type'
+
+ create_table :spree_countries do |t|
+ t.string :iso_name
+ t.string :iso
+ t.string :iso3
+ t.string :name
+ t.integer :numcode
+ end
+
+ create_table :spree_credit_cards do |t|
+ t.string :month
+ t.string :year
+ t.string :cc_type
+ t.string :last_digits
+ t.string :first_name
+ t.string :last_name
+ t.string :start_month
+ t.string :start_year
+ t.string :issue_number
+ t.references :address
+ t.string :gateway_customer_profile_id
+ t.string :gateway_payment_profile_id
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_gateways do |t|
+ t.string :type
+ t.string :name
+ t.text :description
+ t.boolean :active, default: true
+ t.string :environment, default: 'development'
+ t.string :server, default: 'test'
+ t.boolean :test_mode, default: true
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_inventory_units do |t|
+ t.integer :lock_version, default: 0
+ t.string :state
+ t.references :variant
+ t.references :order
+ t.references :shipment
+ t.references :return_authorization
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_inventory_units, [:order_id], name: 'index_inventory_units_on_order_id'
+ add_index :spree_inventory_units, [:shipment_id], name: 'index_inventory_units_on_shipment_id'
+ add_index :spree_inventory_units, [:variant_id], name: 'index_inventory_units_on_variant_id'
+
+ create_table :spree_line_items do |t|
+ t.references :variant
+ t.references :order
+ t.integer :quantity, null: false
+ t.decimal :price, precision: 8, scale: 2, null: false
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_line_items, [:order_id], name: 'index_spree_line_items_on_order_id'
+ add_index :spree_line_items, [:variant_id], name: 'index_spree_line_items_on_variant_id'
+
+ create_table :spree_log_entries do |t|
+ t.references :source, polymorphic: true
+ t.text :details
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_mail_methods do |t|
+ t.string :environment
+ t.boolean :active, default: true
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_option_types do |t|
+ t.string :name, limit: 100
+ t.string :presentation, limit: 100
+ t.integer :position, default: 0, null: false
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_option_types_prototypes, id: false do |t|
+ t.references :prototype
+ t.references :option_type
+ end
+
+ create_table :spree_option_values do |t|
+ t.integer :position
+ t.string :name
+ t.string :presentation
+ t.references :option_type
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_option_values_variants, id: false do |t|
+ t.references :variant
+ t.references :option_value
+ end
+
+ add_index :spree_option_values_variants, [:variant_id, :option_value_id], name: 'index_option_values_variants_on_variant_id_and_option_value_id'
+ add_index :spree_option_values_variants, [:variant_id], name: 'index_spree_option_values_variants_on_variant_id'
+
+ create_table :spree_orders do |t|
+ t.string :number, limit: 15
+ t.decimal :item_total, precision: 8, scale: 2, default: 0.0, null: false
+ t.decimal :total, precision: 8, scale: 2, default: 0.0, null: false
+ t.string :state
+ t.decimal :adjustment_total, precision: 8, scale: 2, default: 0.0, null: false
+ t.references :user
+ t.datetime :completed_at
+ t.references :bill_address
+ t.references :ship_address
+ t.decimal :payment_total, precision: 8, scale: 2, default: 0.0
+ t.references :shipping_method
+ t.string :shipment_state
+ t.string :payment_state
+ t.string :email
+ t.text :special_instructions
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_orders, [:number], name: 'index_spree_orders_on_number'
+
+ create_table :spree_payment_methods do |t|
+ t.string :type
+ t.string :name
+ t.text :description
+ t.boolean :active, default: true
+ t.string :environment, default: 'development'
+ t.datetime :deleted_at
+ t.string :display_on
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_payments do |t|
+ t.decimal :amount, precision: 8, scale: 2, default: 0.0, null: false
+ t.references :order
+ t.references :source, polymorphic: true
+ t.references :payment_method
+ t.string :state
+ t.string :response_code
+ t.string :avs_response
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_preferences do |t|
+ t.string :name, limit: 100
+ t.references :owner, polymorphic: true
+ t.text :value
+ t.string :key
+ t.string :value_type
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_preferences, [:key], name: 'index_spree_preferences_on_key', unique: true
+
+ create_table :spree_product_option_types do |t|
+ t.integer :position
+ t.references :product
+ t.references :option_type
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_product_properties do |t|
+ t.string :value
+ t.references :product
+ t.references :property
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_product_properties, [:product_id], name: 'index_product_properties_on_product_id'
+
+ create_table :spree_products do |t|
+ t.string :name, default: '', null: false
+ t.text :description
+ t.datetime :available_on
+ t.datetime :deleted_at
+ t.string :permalink
+ t.string :meta_description
+ t.string :meta_keywords
+ t.references :tax_category
+ t.references :shipping_category
+ t.integer :count_on_hand, default: 0, null: false
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_products, [:available_on], name: 'index_spree_products_on_available_on'
+ add_index :spree_products, [:deleted_at], name: 'index_spree_products_on_deleted_at'
+ add_index :spree_products, [:name], name: 'index_spree_products_on_name'
+ add_index :spree_products, [:permalink], name: 'index_spree_products_on_permalink'
+
+ create_table :spree_products_taxons, id: false do |t|
+ t.references :product
+ t.references :taxon
+ end
+
+ add_index :spree_products_taxons, [:product_id], name: 'index_spree_products_taxons_on_product_id'
+ add_index :spree_products_taxons, [:taxon_id], name: 'index_spree_products_taxons_on_taxon_id'
+
+ create_table :spree_properties do |t|
+ t.string :name
+ t.string :presentation, null: false
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_properties_prototypes, id: false do |t|
+ t.references :prototype
+ t.references :property
+ end
+
+ create_table :spree_prototypes do |t|
+ t.string :name
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_return_authorizations do |t|
+ t.string :number
+ t.string :state
+ t.decimal :amount, precision: 8, scale: 2, default: 0.0, null: false
+ t.references :order
+ t.text :reason
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_roles do |t|
+ t.string :name
+ end
+
+ create_table :spree_roles_users, id: false do |t|
+ t.references :role
+ t.references :user
+ end
+
+ add_index :spree_roles_users, [:role_id], name: 'index_spree_roles_users_on_role_id'
+ add_index :spree_roles_users, [:user_id], name: 'index_spree_roles_users_on_user_id'
+
+ create_table :spree_shipments do |t|
+ t.string :tracking
+ t.string :number
+ t.decimal :cost, precision: 8, scale: 2
+ t.datetime :shipped_at
+ t.references :order
+ t.references :shipping_method
+ t.references :address
+ t.string :state
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_shipments, [:number], name: 'index_shipments_on_number'
+
+ create_table :spree_shipping_categories do |t|
+ t.string :name
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_shipping_methods do |t|
+ t.string :name
+ t.references :zone
+ t.string :display_on
+ t.references :shipping_category
+ t.boolean :match_none
+ t.boolean :match_all
+ t.boolean :match_one
+ t.datetime :deleted_at
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_state_changes do |t|
+ t.string :name
+ t.string :previous_state
+ t.references :stateful
+ t.references :user
+ t.string :stateful_type
+ t.string :next_state
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_states do |t|
+ t.string :name
+ t.string :abbr
+ t.references :country
+ end
+
+ create_table :spree_tax_categories do |t|
+ t.string :name
+ t.string :description
+ t.boolean :is_default, default: false
+ t.datetime :deleted_at
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_tax_rates do |t|
+ t.decimal :amount, precision: 8, scale: 5
+ t.references :zone
+ t.references :tax_category
+ t.boolean :included_in_price, default: false
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_taxonomies do |t|
+ t.string :name, null: false
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_taxons do |t|
+ t.references :parent
+ t.integer :position, default: 0
+ t.string :name, null: false
+ t.string :permalink
+ t.references :taxonomy
+ t.integer :lft
+ t.integer :rgt
+ t.string :icon_file_name
+ t.string :icon_content_type
+ t.integer :icon_file_size
+ t.datetime :icon_updated_at
+ t.text :description
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_taxons, [:parent_id], name: 'index_taxons_on_parent_id'
+ add_index :spree_taxons, [:permalink], name: 'index_taxons_on_permalink'
+ add_index :spree_taxons, [:taxonomy_id], name: 'index_taxons_on_taxonomy_id'
+
+ create_table :spree_tokenized_permissions, force: true do |t|
+ t.references :permissable, polymorphic: true
+ t.string :token
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_tokenized_permissions, [:permissable_id, :permissable_type], name: 'index_tokenized_name_and_type'
+
+ create_table :spree_trackers do |t|
+ t.string :environment
+ t.string :analytics_id
+ t.boolean :active, default: true
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_users do |t|
+ t.string :encrypted_password, limit: 128
+ t.string :password_salt, limit: 128
+ t.string :email
+ t.string :remember_token
+ t.string :persistence_token
+ t.string :reset_password_token
+ t.string :perishable_token
+ t.integer :sign_in_count, default: 0, null: false
+ t.integer :failed_attempts, default: 0, null: false
+ t.datetime :last_request_at
+ t.datetime :current_sign_in_at
+ t.datetime :last_sign_in_at
+ t.string :current_sign_in_ip
+ t.string :last_sign_in_ip
+ t.string :login
+ t.references :ship_address
+ t.references :bill_address
+ t.string :authentication_token
+ t.string :unlock_token
+ t.datetime :locked_at
+ t.datetime :remember_created_at
+ t.datetime :reset_password_sent_at
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_variants do |t|
+ t.string :sku, default: '', null: false
+ t.decimal :price, precision: 8, scale: 2, null: false
+ t.decimal :weight, precision: 8, scale: 2
+ t.decimal :height, precision: 8, scale: 2
+ t.decimal :width, precision: 8, scale: 2
+ t.decimal :depth, precision: 8, scale: 2
+ t.datetime :deleted_at
+ t.boolean :is_master, default: false
+ t.references :product
+ t.integer :count_on_hand, default: 0, null: false
+ t.decimal :cost_price, precision: 8, scale: 2
+ t.integer :position
+ end
+
+ add_index :spree_variants, [:product_id], name: 'index_spree_variants_on_product_id'
+
+ create_table :spree_zone_members do |t|
+ t.references :zoneable, polymorphic: true
+ t.references :zone
+ t.timestamps null: false, precision: 6
+ end
+
+ create_table :spree_zones do |t|
+ t.string :name
+ t.string :description
+ t.boolean :default_tax, default: false
+ t.integer :zone_members_count, default: 0
+ t.timestamps null: false, precision: 6
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145744_spree_promo_one_two.spree.rb b/spec/dummy/db/migrate/20200218145744_spree_promo_one_two.spree.rb
new file mode 100644
index 0000000..ef2dc2e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145744_spree_promo_one_two.spree.rb
@@ -0,0 +1,46 @@
+# This migration comes from spree (originally 20120831092359)
+class SpreePromoOneTwo < ActiveRecord::Migration[4.2]
+ def up
+ # This migration is just a compressed migration for all previous versions of spree_promo
+ return if data_source_exists?(:spree_products_promotion_rules)
+
+ create_table :spree_products_promotion_rules, id: false, force: true do |t|
+ t.references :product
+ t.references :promotion_rule
+ end
+
+ add_index :spree_products_promotion_rules, [:product_id], name: 'index_products_promotion_rules_on_product_id'
+ add_index :spree_products_promotion_rules, [:promotion_rule_id], name: 'index_products_promotion_rules_on_promotion_rule_id'
+
+ create_table :spree_promotion_action_line_items, force: true do |t|
+ t.references :promotion_action
+ t.references :variant
+ t.integer :quantity, default: 1
+ end
+
+ create_table :spree_promotion_actions, force: true do |t|
+ t.references :activator
+ t.integer :position
+ t.string :type
+ end
+
+ create_table :spree_promotion_rules, force: true do |t|
+ t.references :activator
+ t.references :user
+ t.references :product_group
+ t.string :type
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_promotion_rules, [:product_group_id], name: 'index_promotion_rules_on_product_group_id'
+ add_index :spree_promotion_rules, [:user_id], name: 'index_promotion_rules_on_user_id'
+
+ create_table :spree_promotion_rules_users, id: false, force: true do |t|
+ t.references :user
+ t.references :promotion_rule
+ end
+
+ add_index :spree_promotion_rules_users, [:promotion_rule_id], name: 'index_promotion_rules_users_on_promotion_rule_id'
+ add_index :spree_promotion_rules_users, [:user_id], name: 'index_promotion_rules_users_on_user_id'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145745_add_tax_rate_label.spree.rb b/spec/dummy/db/migrate/20200218145745_add_tax_rate_label.spree.rb
new file mode 100644
index 0000000..121adec
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145745_add_tax_rate_label.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20120905145253)
+class AddTaxRateLabel < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_tax_rates, :name, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145746_add_toggle_tax_rate_display.spree.rb b/spec/dummy/db/migrate/20200218145746_add_toggle_tax_rate_display.spree.rb
new file mode 100644
index 0000000..ee1dc3c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145746_add_toggle_tax_rate_display.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20120905151823)
+class AddToggleTaxRateDisplay < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_tax_rates, :show_rate_in_label, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145747_remove_unused_preference_columns.spree.rb b/spec/dummy/db/migrate/20200218145747_remove_unused_preference_columns.spree.rb
new file mode 100644
index 0000000..e29f378
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145747_remove_unused_preference_columns.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20120929093553)
+class RemoveUnusedPreferenceColumns < ActiveRecord::Migration[4.2]
+ def change
+ # Columns have already been removed if the application was upgraded from an older version, but must be removed from new apps.
+ remove_column :spree_preferences, :name if ApplicationRecord.connection.column_exists?(:spree_preferences, :name)
+ remove_column :spree_preferences, :owner_id if ApplicationRecord.connection.column_exists?(:spree_preferences, :owner_id)
+ remove_column :spree_preferences, :owner_type if ApplicationRecord.connection.column_exists?(:spree_preferences, :owner_type)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145748_add_lock_version_to_variant.spree.rb b/spec/dummy/db/migrate/20200218145748_add_lock_version_to_variant.spree.rb
new file mode 100644
index 0000000..6fc41a7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145748_add_lock_version_to_variant.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121009142519)
+class AddLockVersionToVariant < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_variants, :lock_version, :integer, default: 0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145749_add_states_required_to_countries.spree.rb b/spec/dummy/db/migrate/20200218145749_add_states_required_to_countries.spree.rb
new file mode 100644
index 0000000..a97f817
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145749_add_states_required_to_countries.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121010142909)
+class AddStatesRequiredToCountries < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_countries, :states_required, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145750_add_on_demand_to_product_and_variant.spree.rb b/spec/dummy/db/migrate/20200218145750_add_on_demand_to_product_and_variant.spree.rb
new file mode 100644
index 0000000..257a0e4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145750_add_on_demand_to_product_and_variant.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20121012071449)
+class AddOnDemandToProductAndVariant < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_products, :on_demand, :boolean, default: false
+ add_column :spree_variants, :on_demand, :boolean, default: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145751_remove_not_null_constraint_from_products_on_hand.spree.rb b/spec/dummy/db/migrate/20200218145751_remove_not_null_constraint_from_products_on_hand.spree.rb
new file mode 100644
index 0000000..53744c8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145751_remove_not_null_constraint_from_products_on_hand.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20121017010007)
+class RemoveNotNullConstraintFromProductsOnHand < ActiveRecord::Migration[4.2]
+ def up
+ change_column :spree_products, :count_on_hand, :integer, null: true
+ change_column :spree_variants, :count_on_hand, :integer, null: true
+ end
+
+ def down
+ change_column :spree_products, :count_on_hand, :integer, null: false
+ change_column :spree_variants, :count_on_hand, :integer, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145752_split_prices_from_variants.spree.rb b/spec/dummy/db/migrate/20200218145752_split_prices_from_variants.spree.rb
new file mode 100644
index 0000000..74a20f0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145752_split_prices_from_variants.spree.rb
@@ -0,0 +1,32 @@
+# This migration comes from spree (originally 20121031162139)
+class SplitPricesFromVariants < ActiveRecord::Migration[4.2]
+ def up
+ create_table :spree_prices do |t|
+ t.integer :variant_id, null: false
+ t.decimal :amount, precision: 8, scale: 2, null: false
+ t.string :currency
+ end
+
+ Spree::Variant.all.each do |variant|
+ Spree::Price.create!(
+ variant_id: variant.id,
+ amount: variant[:price],
+ currency: Spree::Config[:currency]
+ )
+ end
+
+ remove_column :spree_variants, :price
+ end
+
+ def down
+ prices = ApplicationRecord.connection.execute("select variant_id, amount from spree_prices")
+ add_column :spree_variants, :price, :decimal, after: :sku, scale: 2, precision: 8
+
+ prices.each do |price|
+ ApplicationRecord.connection.execute("update spree_variants set price = #{price['amount']} where id = #{price['variant_id']}")
+ end
+
+ change_column :spree_variants, :price, :decimal, after: :sku, scale: 2, precision: 8, null: false
+ drop_table :spree_prices
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145753_remove_not_null_from_spree_prices_amount.spree.rb b/spec/dummy/db/migrate/20200218145753_remove_not_null_from_spree_prices_amount.spree.rb
new file mode 100644
index 0000000..f323413
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145753_remove_not_null_from_spree_prices_amount.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20121107003422)
+class RemoveNotNullFromSpreePricesAmount < ActiveRecord::Migration[4.2]
+ def up
+ change_column :spree_prices, :amount, :decimal, precision: 8, scale: 2, null: true
+ end
+
+ def down
+ change_column :spree_prices, :amount, :decimal, precision: 8, scale: 2, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145754_add_currency_to_line_items.spree.rb b/spec/dummy/db/migrate/20200218145754_add_currency_to_line_items.spree.rb
new file mode 100644
index 0000000..76d4bad
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145754_add_currency_to_line_items.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121107184631)
+class AddCurrencyToLineItems < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :currency, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145755_add_currency_to_orders.spree.rb b/spec/dummy/db/migrate/20200218145755_add_currency_to_orders.spree.rb
new file mode 100644
index 0000000..cb7d51e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145755_add_currency_to_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121107194006)
+class AddCurrencyToOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :currency, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145756_add_cost_currency_to_variants.spree.rb b/spec/dummy/db/migrate/20200218145756_add_cost_currency_to_variants.spree.rb
new file mode 100644
index 0000000..6e56a00
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145756_add_cost_currency_to_variants.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121109173623)
+class AddCostCurrencyToVariants < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_variants, :cost_currency, :string, after: :cost_price
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145757_remove_display_on_from_payment_methods.spree.rb b/spec/dummy/db/migrate/20200218145757_remove_display_on_from_payment_methods.spree.rb
new file mode 100644
index 0000000..e27115e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145757_remove_display_on_from_payment_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121111231553)
+class RemoveDisplayOnFromPaymentMethods < ActiveRecord::Migration[4.2]
+ def up
+ remove_column :spree_payment_methods, :display_on
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145758_add_position_to_taxonomies.spree.rb b/spec/dummy/db/migrate/20200218145758_add_position_to_taxonomies.spree.rb
new file mode 100644
index 0000000..ceee97c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145758_add_position_to_taxonomies.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121124203911)
+class AddPositionToTaxonomies < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_taxonomies, :position, :integer, default: 0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145759_add_last_ip_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145759_add_last_ip_to_spree_orders.spree.rb
new file mode 100644
index 0000000..191a0e9
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145759_add_last_ip_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20121126040517)
+class AddLastIpToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :last_ip_address, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145760_add_state_to_spree_adjustments.spree.rb b/spec/dummy/db/migrate/20200218145760_add_state_to_spree_adjustments.spree.rb
new file mode 100644
index 0000000..493f275
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145760_add_state_to_spree_adjustments.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20121213162028)
+class AddStateToSpreeAdjustments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_adjustments, :state, :string
+ remove_column :spree_adjustments, :locked
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145761_add_display_on_to_spree_payment_methods.spree.rb b/spec/dummy/db/migrate/20200218145761_add_display_on_to_spree_payment_methods.spree.rb
new file mode 100644
index 0000000..4a4e0aa
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145761_add_display_on_to_spree_payment_methods.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130114053446)
+class AddDisplayOnToSpreePaymentMethods < ActiveRecord::Migration[4.2]
+ def self.up
+ add_column :spree_payment_methods, :display_on, :string
+ end
+
+ def self.down
+ remove_column :spree_payment_methods, :display_on
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145762_add_position_to_product_properties.spree.rb b/spec/dummy/db/migrate/20200218145762_add_position_to_product_properties.spree.rb
new file mode 100644
index 0000000..4477281
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145762_add_position_to_product_properties.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20130120201805)
+class AddPositionToProductProperties < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_product_properties, :position, :integer, default: 0
+ end
+end
+
diff --git a/spec/dummy/db/migrate/20200218145763_add_identifier_to_spree_payments.spree.rb b/spec/dummy/db/migrate/20200218145763_add_identifier_to_spree_payments.spree.rb
new file mode 100644
index 0000000..44df67a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145763_add_identifier_to_spree_payments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130203232234)
+class AddIdentifierToSpreePayments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_payments, :identifier, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145764_add_order_id_index_to_payments.spree.rb b/spec/dummy/db/migrate/20200218145764_add_order_id_index_to_payments.spree.rb
new file mode 100644
index 0000000..b5e168b
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145764_add_order_id_index_to_payments.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130207155350)
+class AddOrderIdIndexToPayments < ActiveRecord::Migration[4.2]
+ def self.up
+ add_index :spree_payments, :order_id
+ end
+
+ def self.down
+ remove_index :spree_payments, :order_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145765_add_primary_to_spree_products_taxons.spree.rb b/spec/dummy/db/migrate/20200218145765_add_primary_to_spree_products_taxons.spree.rb
new file mode 100644
index 0000000..d1b7cf5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145765_add_primary_to_spree_products_taxons.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130208032954)
+class AddPrimaryToSpreeProductsTaxons < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_products_taxons, :id, :primary_key
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145766_create_spree_stock_items.spree.rb b/spec/dummy/db/migrate/20200218145766_create_spree_stock_items.spree.rb
new file mode 100644
index 0000000..a05d6d7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145766_create_spree_stock_items.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20130211190146)
+class CreateSpreeStockItems < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_stock_items do |t|
+ t.belongs_to :stock_location
+ t.belongs_to :variant
+ t.integer :count_on_hand, null: false, default: 0
+ t.integer :lock_version
+
+ t.timestamps null: false, precision: 6
+ end
+ add_index :spree_stock_items, :stock_location_id
+ add_index :spree_stock_items, [:stock_location_id, :variant_id], name: 'stock_item_by_loc_and_var_id'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145767_create_spree_stock_locations.spree.rb b/spec/dummy/db/migrate/20200218145767_create_spree_stock_locations.spree.rb
new file mode 100644
index 0000000..0aff6ee
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145767_create_spree_stock_locations.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20130211191120)
+class CreateSpreeStockLocations < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_stock_locations do |t|
+ t.string :name
+ t.belongs_to :address
+
+ t.timestamps null: false, precision: 6
+ end
+ add_index :spree_stock_locations, :address_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145768_create_default_stock.spree.rb b/spec/dummy/db/migrate/20200218145768_create_default_stock.spree.rb
new file mode 100644
index 0000000..6397100
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145768_create_default_stock.spree.rb
@@ -0,0 +1,34 @@
+# This migration comes from spree (originally 20130213191427)
+class CreateDefaultStock < ActiveRecord::Migration[4.2]
+ def up
+ unless column_exists? :spree_stock_locations, :default
+ add_column :spree_stock_locations, :default, :boolean, null: false, default: false
+ end
+
+ Spree::StockLocation.skip_callback(:create, :after, :create_stock_items)
+ Spree::StockLocation.skip_callback(:save, :after, :ensure_one_default)
+ location = Spree::StockLocation.new(name: 'default')
+ location.save(validate: false)
+
+ Spree::Variant.find_each do |variant|
+ stock_item = Spree::StockItem.unscoped.build(stock_location: location, variant: variant)
+ stock_item.send(:count_on_hand=, variant.count_on_hand)
+ # Avoid running default_scope defined by acts_as_paranoid, related to #3805,
+ # validations would run a query with a delete_at column that might not be present yet
+ stock_item.save! validate: false
+ end
+
+ remove_column :spree_variants, :count_on_hand
+ end
+
+ def down
+ add_column :spree_variants, :count_on_hand, :integer
+
+ Spree::StockItem.find_each do |stock_item|
+ stock_item.variant.update_column :count_on_hand, stock_item.count_on_hand
+ end
+
+ Spree::StockLocation.delete_all
+ Spree::StockItem.delete_all
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145769_add_order_id_index_to_shipments.spree.rb b/spec/dummy/db/migrate/20200218145769_add_order_id_index_to_shipments.spree.rb
new file mode 100644
index 0000000..1b80d05
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145769_add_order_id_index_to_shipments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130222032153)
+class AddOrderIdIndexToShipments < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_shipments, :order_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145770_change_meta_description_on_spree_products_to_text.spree.rb b/spec/dummy/db/migrate/20200218145770_change_meta_description_on_spree_products_to_text.spree.rb
new file mode 100644
index 0000000..fa228e2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145770_change_meta_description_on_spree_products_to_text.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130226032817)
+class ChangeMetaDescriptionOnSpreeProductsToText < ActiveRecord::Migration[4.2]
+ def change
+ change_column :spree_products, :meta_description, :text, limit: nil
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145771_add_stock_location_id_to_spree_shipments.spree.rb b/spec/dummy/db/migrate/20200218145771_add_stock_location_id_to_spree_shipments.spree.rb
new file mode 100644
index 0000000..66df6e1
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145771_add_stock_location_id_to_spree_shipments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130226191231)
+class AddStockLocationIdToSpreeShipments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_shipments, :stock_location_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145772_add_pending_to_inventory_unit.spree.rb b/spec/dummy/db/migrate/20200218145772_add_pending_to_inventory_unit.spree.rb
new file mode 100644
index 0000000..d2137be
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145772_add_pending_to_inventory_unit.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20130227143905)
+class AddPendingToInventoryUnit < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_inventory_units, :pending, :boolean, default: true
+ Spree::InventoryUnit.update_all(pending: false)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145773_remove_on_demand_from_product_and_variant.spree.rb b/spec/dummy/db/migrate/20200218145773_remove_on_demand_from_product_and_variant.spree.rb
new file mode 100644
index 0000000..83c27a4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145773_remove_on_demand_from_product_and_variant.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20130228164411)
+class RemoveOnDemandFromProductAndVariant < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_products, :on_demand
+ remove_column :spree_variants, :on_demand
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145774_create_shipping_method_zone.spree.rb b/spec/dummy/db/migrate/20200218145774_create_shipping_method_zone.spree.rb
new file mode 100644
index 0000000..10ac904
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145774_create_shipping_method_zone.spree.rb
@@ -0,0 +1,22 @@
+# This migration comes from spree (originally 20130228210442)
+class CreateShippingMethodZone < ActiveRecord::Migration[4.2]
+ class ShippingMethodZone < ApplicationRecord
+ self.table_name = 'shipping_methods_zones'
+ end
+ def up
+ create_table :shipping_methods_zones, id: false do |t|
+ t.integer :shipping_method_id
+ t.integer :zone_id
+ end
+ Spree::ShippingMethod.all.each do |sm|
+ ShippingMethodZone.create!(zone_id: sm.zone_id, shipping_method_id: sm.id)
+ end
+
+ remove_column :spree_shipping_methods, :zone_id
+ end
+
+ def down
+ drop_table :shipping_methods_zones
+ add_column :spree_shipping_methods, :zone_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145775_remove_shipping_category_id_from_shipping_method.spree.rb b/spec/dummy/db/migrate/20200218145775_remove_shipping_category_id_from_shipping_method.spree.rb
new file mode 100644
index 0000000..8f6aeaf
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145775_remove_shipping_category_id_from_shipping_method.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130301162745)
+class RemoveShippingCategoryIdFromShippingMethod < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_shipping_methods, :shipping_category_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145776_create_shipping_method_categories.spree.rb b/spec/dummy/db/migrate/20200218145776_create_shipping_method_categories.spree.rb
new file mode 100644
index 0000000..bb872b5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145776_create_shipping_method_categories.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20130301162924)
+class CreateShippingMethodCategories < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_shipping_method_categories do |t|
+ t.integer :shipping_method_id, null: false
+ t.integer :shipping_category_id, null: false
+
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_shipping_method_categories, :shipping_method_id
+ add_index :spree_shipping_method_categories, :shipping_category_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145777_add_tracking_url_to_spree_shipping_methods.spree.rb b/spec/dummy/db/migrate/20200218145777_add_tracking_url_to_spree_shipping_methods.spree.rb
new file mode 100644
index 0000000..16ac6fe
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145777_add_tracking_url_to_spree_shipping_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130301205200)
+class AddTrackingUrlToSpreeShippingMethods < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_shipping_methods, :tracking_url, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145778_create_spree_shipping_rates.spree.rb b/spec/dummy/db/migrate/20200218145778_create_spree_shipping_rates.spree.rb
new file mode 100644
index 0000000..7877288
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145778_create_spree_shipping_rates.spree.rb
@@ -0,0 +1,25 @@
+# This migration comes from spree (originally 20130304162240)
+class CreateSpreeShippingRates < ActiveRecord::Migration[4.2]
+ def up
+ create_table :spree_shipping_rates do |t|
+ t.belongs_to :shipment
+ t.belongs_to :shipping_method
+ t.boolean :selected, default: false
+ t.decimal :cost, precision: 8, scale: 2
+ t.timestamps null: false, precision: 6
+ end
+ add_index(:spree_shipping_rates, [:shipment_id, :shipping_method_id],
+ name: 'spree_shipping_rates_join_index',
+ unique: true)
+
+ # Spree::Shipment.all.each do |shipment|
+ # shipping_method = Spree::ShippingMethod.find(shipment.shipment_method_id)
+ # shipment.add_shipping_method(shipping_method, true)
+ # end
+ end
+
+ def down
+ # add_column :spree_shipments, :shipping_method_id, :integer
+ drop_table :spree_shipping_rates
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145779_remove_category_match_attributes_from_shipping_method.spree.rb b/spec/dummy/db/migrate/20200218145779_remove_category_match_attributes_from_shipping_method.spree.rb
new file mode 100644
index 0000000..9c62e3d
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145779_remove_category_match_attributes_from_shipping_method.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20130304192936)
+class RemoveCategoryMatchAttributesFromShippingMethod < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_shipping_methods, :match_none
+ remove_column :spree_shipping_methods, :match_one
+ remove_column :spree_shipping_methods, :match_all
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145780_create_stock_movements.spree.rb b/spec/dummy/db/migrate/20200218145780_create_stock_movements.spree.rb
new file mode 100644
index 0000000..d8562e8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145780_create_stock_movements.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20130305143310)
+class CreateStockMovements < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_stock_movements do |t|
+ t.belongs_to :stock_item
+ t.integer :quantity
+ t.string :action
+
+ t.timestamps null: false, precision: 6
+ end
+ add_index :spree_stock_movements, :stock_item_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145781_add_address_fields_to_stock_location.spree.rb b/spec/dummy/db/migrate/20200218145781_add_address_fields_to_stock_location.spree.rb
new file mode 100644
index 0000000..927a1a4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145781_add_address_fields_to_stock_location.spree.rb
@@ -0,0 +1,23 @@
+# This migration comes from spree (originally 20130306181701)
+class AddAddressFieldsToStockLocation < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_stock_locations, :address_id
+
+ add_column :spree_stock_locations, :address1, :string
+ add_column :spree_stock_locations, :address2, :string
+ add_column :spree_stock_locations, :city, :string
+ add_column :spree_stock_locations, :state_id, :integer
+ add_column :spree_stock_locations, :state_name, :string
+ add_column :spree_stock_locations, :country_id, :integer
+ add_column :spree_stock_locations, :zipcode, :string
+ add_column :spree_stock_locations, :phone, :string
+
+
+ usa = Spree::Country.where(iso: 'US').first
+ # In case USA isn't found.
+ # See #3115
+ country = usa || Spree::Country.first
+ Spree::Country.reset_column_information
+ Spree::StockLocation.update_all(country_id: country)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145782_add_active_field_to_stock_locations.spree.rb b/spec/dummy/db/migrate/20200218145782_add_active_field_to_stock_locations.spree.rb
new file mode 100644
index 0000000..120fd33
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145782_add_active_field_to_stock_locations.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130306191917)
+class AddActiveFieldToStockLocations < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_stock_locations, :active, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145783_add_backorderable_to_stock_item.spree.rb b/spec/dummy/db/migrate/20200218145783_add_backorderable_to_stock_item.spree.rb
new file mode 100644
index 0000000..49b5324
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145783_add_backorderable_to_stock_item.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130306195650)
+class AddBackorderableToStockItem < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_stock_items, :backorderable, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145784_add_default_quantity_to_stock_movement.spree.rb b/spec/dummy/db/migrate/20200218145784_add_default_quantity_to_stock_movement.spree.rb
new file mode 100644
index 0000000..bac5896
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145784_add_default_quantity_to_stock_movement.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130307161754)
+class AddDefaultQuantityToStockMovement < ActiveRecord::Migration[4.2]
+ def change
+ change_column :spree_stock_movements, :quantity, :integer, default: 0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145785_add_source_and_destination_to_stock_movements.spree.rb b/spec/dummy/db/migrate/20200218145785_add_source_and_destination_to_stock_movements.spree.rb
new file mode 100644
index 0000000..f22f110
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145785_add_source_and_destination_to_stock_movements.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20130318151756)
+class AddSourceAndDestinationToStockMovements < ActiveRecord::Migration[4.2]
+ def change
+ change_table :spree_stock_movements do |t|
+ t.references :source, polymorphic: true
+ t.references :destination, polymorphic: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145786_change_orders_total_precision.spree.rb b/spec/dummy/db/migrate/20200218145786_change_orders_total_precision.spree.rb
new file mode 100644
index 0000000..cda5ba8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145786_change_orders_total_precision.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20130319062004)
+class ChangeOrdersTotalPrecision < ActiveRecord::Migration[4.2]
+ def change
+ change_column :spree_orders, :item_total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ change_column :spree_orders, :total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ change_column :spree_orders, :adjustment_total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ change_column :spree_orders, :payment_total, :decimal, precision: 10, scale: 2, default: 0.0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145787_change_spree_payments_amount_precision.spree.rb b/spec/dummy/db/migrate/20200218145787_change_spree_payments_amount_precision.spree.rb
new file mode 100644
index 0000000..0524ed9
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145787_change_spree_payments_amount_precision.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20130319063911)
+class ChangeSpreePaymentsAmountPrecision < ActiveRecord::Migration[4.2]
+ def change
+
+ change_column :spree_payments, :amount, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145788_change_spree_return_authorization_amount_precision.spree.rb b/spec/dummy/db/migrate/20200218145788_change_spree_return_authorization_amount_precision.spree.rb
new file mode 100644
index 0000000..60923c2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145788_change_spree_return_authorization_amount_precision.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20130319064308)
+class ChangeSpreeReturnAuthorizationAmountPrecision < ActiveRecord::Migration[4.2]
+ def change
+
+ change_column :spree_return_authorizations, :amount, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145789_change_adjustments_amount_precision.spree.rb b/spec/dummy/db/migrate/20200218145789_change_adjustments_amount_precision.spree.rb
new file mode 100644
index 0000000..064a578
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145789_change_adjustments_amount_precision.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20130319082943)
+class ChangeAdjustmentsAmountPrecision < ActiveRecord::Migration[4.2]
+ def change
+
+ change_column :spree_adjustments, :amount, :decimal, precision: 10, scale: 2
+
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145790_add_originator_to_stock_movement.spree.rb b/spec/dummy/db/migrate/20200218145790_add_originator_to_stock_movement.spree.rb
new file mode 100644
index 0000000..ab33f8c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145790_add_originator_to_stock_movement.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20130319183250)
+class AddOriginatorToStockMovement < ActiveRecord::Migration[4.2]
+ def change
+ change_table :spree_stock_movements do |t|
+ t.references :originator, polymorphic: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145791_drop_source_and_destination_from_stock_movement.spree.rb b/spec/dummy/db/migrate/20200218145791_drop_source_and_destination_from_stock_movement.spree.rb
new file mode 100644
index 0000000..0a79d47
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145791_drop_source_and_destination_from_stock_movement.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20130319190507)
+class DropSourceAndDestinationFromStockMovement < ActiveRecord::Migration[4.2]
+ def up
+ change_table :spree_stock_movements do |t|
+ t.remove_references :source, polymorphic: true
+ t.remove_references :destination, polymorphic: true
+ end
+ end
+
+ def down
+ change_table :spree_stock_movements do |t|
+ t.references :source, polymorphic: true
+ t.references :destination, polymorphic: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145792_migrate_inventory_unit_sold_to_on_hand.spree.rb b/spec/dummy/db/migrate/20200218145792_migrate_inventory_unit_sold_to_on_hand.spree.rb
new file mode 100644
index 0000000..095a0d1
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145792_migrate_inventory_unit_sold_to_on_hand.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130325163316)
+class MigrateInventoryUnitSoldToOnHand < ActiveRecord::Migration[4.2]
+ def up
+ Spree::InventoryUnit.where(state: 'sold').update_all(state: 'on_hand')
+ end
+
+ def down
+ Spree::InventoryUnit.where(state: 'on_hand').update_all(state: 'sold')
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145793_add_stock_location_to_rma.spree.rb b/spec/dummy/db/migrate/20200218145793_add_stock_location_to_rma.spree.rb
new file mode 100644
index 0000000..d9c85d8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145793_add_stock_location_to_rma.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130326175857)
+class AddStockLocationToRma < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_return_authorizations, :stock_location_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145794_update_shipment_state_for_canceled_orders.spree.rb b/spec/dummy/db/migrate/20200218145794_update_shipment_state_for_canceled_orders.spree.rb
new file mode 100644
index 0000000..8d9e5ba
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145794_update_shipment_state_for_canceled_orders.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20130328130308)
+class UpdateShipmentStateForCanceledOrders < ActiveRecord::Migration[4.2]
+ def up
+ shipments = Spree::Shipment.joins(:order).
+ where("spree_orders.state = 'canceled'")
+ case Spree::Shipment.connection.adapter_name
+ when "SQLite3"
+ shipments.update_all("state = 'cancelled'")
+ when "MySQL" || "PostgreSQL"
+ shipments.update_all("spree_shipments.state = 'cancelled'")
+ end
+ end
+
+ def down
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145795_add_seo_metas_to_taxons.spree.rb b/spec/dummy/db/migrate/20200218145795_add_seo_metas_to_taxons.spree.rb
new file mode 100644
index 0000000..bbcb8b5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145795_add_seo_metas_to_taxons.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130328195253)
+class AddSeoMetasToTaxons < ActiveRecord::Migration[4.2]
+ def change
+ change_table :spree_taxons do |t|
+ t.string :meta_title
+ t.string :meta_description
+ t.string :meta_keywords
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145796_remove_stock_item_and_variant_lock.spree.rb b/spec/dummy/db/migrate/20200218145796_remove_stock_item_and_variant_lock.spree.rb
new file mode 100644
index 0000000..c9ba659
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145796_remove_stock_item_and_variant_lock.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20130329134939)
+class RemoveStockItemAndVariantLock < ActiveRecord::Migration[4.2]
+ def up
+ # we are moving to pessimistic locking on stock_items
+ remove_column :spree_stock_items, :lock_version
+
+ # variants no longer manage their count_on_hand so we are removing their lock
+ remove_column :spree_variants, :lock_version
+ end
+
+ def down
+ add_column :spree_stock_items, :lock_version, :integer
+ add_column :spree_variants, :lock_version, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145797_add_name_to_spree_credit_cards.spree.rb b/spec/dummy/db/migrate/20200218145797_add_name_to_spree_credit_cards.spree.rb
new file mode 100644
index 0000000..70f5ec7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145797_add_name_to_spree_credit_cards.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130413230529)
+class AddNameToSpreeCreditCards < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_credit_cards, :name, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145798_update_name_fields_on_spree_credit_cards.spree.rb b/spec/dummy/db/migrate/20200218145798_update_name_fields_on_spree_credit_cards.spree.rb
new file mode 100644
index 0000000..2e1a41a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145798_update_name_fields_on_spree_credit_cards.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20130414000512)
+class UpdateNameFieldsOnSpreeCreditCards < ActiveRecord::Migration[4.2]
+ def up
+ if ApplicationRecord.connection.adapter_name.downcase.include? "mysql"
+ execute "UPDATE spree_credit_cards SET name = CONCAT(first_name, ' ', last_name)"
+ else
+ execute "UPDATE spree_credit_cards SET name = first_name || ' ' || last_name"
+ end
+ end
+
+ def down
+ execute "UPDATE spree_credit_cards SET name = NULL"
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145799_add_index_to_source_columns_on_adjustments.spree.rb b/spec/dummy/db/migrate/20200218145799_add_index_to_source_columns_on_adjustments.spree.rb
new file mode 100644
index 0000000..f8d7fec
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145799_add_index_to_source_columns_on_adjustments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130417120034)
+class AddIndexToSourceColumnsOnAdjustments < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_adjustments, [:source_type, :source_id]
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145800_update_adjustment_states.spree.rb b/spec/dummy/db/migrate/20200218145800_update_adjustment_states.spree.rb
new file mode 100644
index 0000000..0e40ac5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145800_update_adjustment_states.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20130417120035)
+class UpdateAdjustmentStates < ActiveRecord::Migration[4.2]
+ def up
+ Spree::Order.complete.find_each do |order|
+ order.adjustments.update_all(state: 'closed')
+ end
+
+ Spree::Shipment.shipped.includes(:adjustment).find_each do |shipment|
+ shipment.adjustment.update_column(:state, 'finalized') if shipment.adjustment
+ end
+
+ Spree::Adjustment.where(state: nil).update_all(state: 'open')
+ end
+
+ def down
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145801_add_shipping_rates_to_shipments.spree.rb b/spec/dummy/db/migrate/20200218145801_add_shipping_rates_to_shipments.spree.rb
new file mode 100644
index 0000000..8e1a12e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145801_add_shipping_rates_to_shipments.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20130417123427)
+class AddShippingRatesToShipments < ActiveRecord::Migration[4.2]
+ def up
+ Spree::Shipment.find_each do |shipment|
+ shipment.shipping_rates.create(shipping_method_id: shipment.shipping_method_id,
+ cost: shipment.cost,
+ selected: true)
+ end
+
+ remove_column :spree_shipments, :shipping_method_id
+ end
+
+ def down
+ add_column :spree_shipments, :shipping_method_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145802_create_spree_stock_transfers.spree.rb b/spec/dummy/db/migrate/20200218145802_create_spree_stock_transfers.spree.rb
new file mode 100644
index 0000000..24c1156
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145802_create_spree_stock_transfers.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20130418125341)
+class CreateSpreeStockTransfers < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_stock_transfers do |t|
+ t.string :type
+ t.string :reference_number
+ t.integer :source_location_id
+ t.integer :destination_location_id
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_stock_transfers, :source_location_id
+ add_index :spree_stock_transfers, :destination_location_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145803_drop_products_count_on_hand.spree.rb b/spec/dummy/db/migrate/20200218145803_drop_products_count_on_hand.spree.rb
new file mode 100644
index 0000000..a5fdc46
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145803_drop_products_count_on_hand.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130423110707)
+class DropProductsCountOnHand < ActiveRecord::Migration[4.2]
+ def up
+ remove_column :spree_products, :count_on_hand
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145804_set_default_shipping_rate_cost.spree.rb b/spec/dummy/db/migrate/20200218145804_set_default_shipping_rate_cost.spree.rb
new file mode 100644
index 0000000..141b395
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145804_set_default_shipping_rate_cost.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130423223847)
+class SetDefaultShippingRateCost < ActiveRecord::Migration[4.2]
+ def change
+ change_column :spree_shipping_rates, :cost, :decimal, default: 0, precision: 8, scale: 2
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145805_add_number_to_stock_transfer.spree.rb b/spec/dummy/db/migrate/20200218145805_add_number_to_stock_transfer.spree.rb
new file mode 100644
index 0000000..1fb83e2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145805_add_number_to_stock_transfer.spree.rb
@@ -0,0 +1,24 @@
+# This migration comes from spree (originally 20130509115210)
+class AddNumberToStockTransfer < ActiveRecord::Migration[4.2]
+ def up
+ remove_index :spree_stock_transfers, :source_location_id
+ remove_index :spree_stock_transfers, :destination_location_id
+
+ rename_column :spree_stock_transfers, :reference_number, :reference
+ add_column :spree_stock_transfers, :number, :string
+
+ Spree::StockTransfer.find_each do |transfer|
+ transfer.send(:generate_stock_transfer_number)
+ transfer.save!
+ end
+
+ add_index :spree_stock_transfers, :number
+ add_index :spree_stock_transfers, :source_location_id
+ add_index :spree_stock_transfers, :destination_location_id
+ end
+
+ def down
+ rename_column :spree_stock_transfers, :reference, :reference_number
+ remove_column :spree_stock_transfers, :number, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145806_add_sku_index_to_spree_variants.spree.rb b/spec/dummy/db/migrate/20200218145806_add_sku_index_to_spree_variants.spree.rb
new file mode 100644
index 0000000..1d5b78a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145806_add_sku_index_to_spree_variants.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130514151929)
+class AddSkuIndexToSpreeVariants < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_variants, :sku
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145807_add_backorderable_default_to_spree_stock_location.spree.rb b/spec/dummy/db/migrate/20200218145807_add_backorderable_default_to_spree_stock_location.spree.rb
new file mode 100644
index 0000000..5408ef1
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145807_add_backorderable_default_to_spree_stock_location.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130515180736)
+class AddBackorderableDefaultToSpreeStockLocation < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_stock_locations, :backorderable_default, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145808_add_propage_all_variants_to_spree_stock_location.spree.rb b/spec/dummy/db/migrate/20200218145808_add_propage_all_variants_to_spree_stock_location.spree.rb
new file mode 100644
index 0000000..7211952
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145808_add_propage_all_variants_to_spree_stock_location.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130516151222)
+class AddPropageAllVariantsToSpreeStockLocation < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_stock_locations, :propagate_all_variants, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145809_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb b/spec/dummy/db/migrate/20200218145809_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb
new file mode 100644
index 0000000..243375f
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145809_rename_shipping_methods_zones_to_spree_shipping_methods_zones.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130611054351)
+class RenameShippingMethodsZonesToSpreeShippingMethodsZones < ActiveRecord::Migration[4.2]
+ def change
+ rename_table :shipping_methods_zones, :spree_shipping_methods_zones
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145810_add_user_id_index_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145810_add_user_id_index_to_spree_orders.spree.rb
new file mode 100644
index 0000000..0993e96
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145810_add_user_id_index_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130611185927)
+class AddUserIdIndexToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_orders, :user_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145811_add_updated_at_to_spree_countries.spree.rb b/spec/dummy/db/migrate/20200218145811_add_updated_at_to_spree_countries.spree.rb
new file mode 100644
index 0000000..fdc7c20
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145811_add_updated_at_to_spree_countries.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130618041418)
+class AddUpdatedAtToSpreeCountries < ActiveRecord::Migration[4.2]
+ def up
+ add_column :spree_countries, :updated_at, :datetime
+ end
+
+ def down
+ remove_column :spree_countries, :updated_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145812_add_updated_at_to_spree_states.spree.rb b/spec/dummy/db/migrate/20200218145812_add_updated_at_to_spree_states.spree.rb
new file mode 100644
index 0000000..d9eaa65
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145812_add_updated_at_to_spree_states.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130619012236)
+class AddUpdatedAtToSpreeStates < ActiveRecord::Migration[4.2]
+ def up
+ add_column :spree_states, :updated_at, :datetime
+ end
+
+ def down
+ remove_column :spree_states, :updated_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145813_add_cvv_result_code_and_cvv_result_message_to_spree_payments.spree.rb b/spec/dummy/db/migrate/20200218145813_add_cvv_result_code_and_cvv_result_message_to_spree_payments.spree.rb
new file mode 100644
index 0000000..5bdea3d
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145813_add_cvv_result_code_and_cvv_result_message_to_spree_payments.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20130626232741)
+class AddCvvResultCodeAndCvvResultMessageToSpreePayments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_payments, :cvv_response_code, :string
+ add_column :spree_payments, :cvv_response_message, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145814_add_unique_index_to_permalink_on_spree_products.spree.rb b/spec/dummy/db/migrate/20200218145814_add_unique_index_to_permalink_on_spree_products.spree.rb
new file mode 100644
index 0000000..43bd037
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145814_add_unique_index_to_permalink_on_spree_products.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130628021056)
+class AddUniqueIndexToPermalinkOnSpreeProducts < ActiveRecord::Migration[4.2]
+ def change
+ add_index "spree_products", ["permalink"], name: "permalink_idx_unique", unique: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145815_add_unique_index_to_orders_shipments_and_stock_transfers.spree.rb b/spec/dummy/db/migrate/20200218145815_add_unique_index_to_orders_shipments_and_stock_transfers.spree.rb
new file mode 100644
index 0000000..18955f9
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145815_add_unique_index_to_orders_shipments_and_stock_transfers.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20130628022817)
+class AddUniqueIndexToOrdersShipmentsAndStockTransfers < ActiveRecord::Migration[4.2]
+ def add
+ add_index "spree_orders", ["number"], name: "number_idx_unique", unique: true
+ add_index "spree_shipments", ["number"], name: "number_idx_unique", unique: true
+ add_index "spree_stock_transfers", ["number"], name: "number_idx_unique", unique: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145816_add_deleted_at_to_spree_tax_rates.spree.rb b/spec/dummy/db/migrate/20200218145816_add_deleted_at_to_spree_tax_rates.spree.rb
new file mode 100644
index 0000000..e742f76
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145816_add_deleted_at_to_spree_tax_rates.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130708052307)
+class AddDeletedAtToSpreeTaxRates < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_tax_rates, :deleted_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145817_remove_lock_version_from_inventory_units.spree.rb b/spec/dummy/db/migrate/20200218145817_remove_lock_version_from_inventory_units.spree.rb
new file mode 100644
index 0000000..cac6f7a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145817_remove_lock_version_from_inventory_units.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20130711200933)
+class RemoveLockVersionFromInventoryUnits < ActiveRecord::Migration[4.2]
+ def change
+ # we are moving to pessimistic locking on stock_items
+ remove_column :spree_inventory_units, :lock_version
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145818_add_cost_price_to_line_item.spree.rb b/spec/dummy/db/migrate/20200218145818_add_cost_price_to_line_item.spree.rb
new file mode 100644
index 0000000..ff33d37
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145818_add_cost_price_to_line_item.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130718042445)
+class AddCostPriceToLineItem < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :cost_price, :decimal, precision: 8, scale: 2
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145819_set_backorderable_to_default_to_false.spree.rb b/spec/dummy/db/migrate/20200218145819_set_backorderable_to_default_to_false.spree.rb
new file mode 100644
index 0000000..6e1edea
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145819_set_backorderable_to_default_to_false.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20130718233855)
+class SetBackorderableToDefaultToFalse < ActiveRecord::Migration[4.2]
+ def change
+ change_column :spree_stock_items, :backorderable, :boolean, default: false
+ change_column :spree_stock_locations, :backorderable_default, :boolean, default: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145820_add_created_by_id_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145820_add_created_by_id_to_spree_orders.spree.rb
new file mode 100644
index 0000000..287ed57
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145820_add_created_by_id_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130725031716)
+class AddCreatedByIdToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :created_by_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145821_index_completed_at_on_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145821_index_completed_at_on_spree_orders.spree.rb
new file mode 100644
index 0000000..ac0ba38
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145821_index_completed_at_on_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130729214043)
+class IndexCompletedAtOnSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_orders, :completed_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145822_add_tax_category_id_to_spree_line_items.spree.rb b/spec/dummy/db/migrate/20200218145822_add_tax_category_id_to_spree_line_items.spree.rb
new file mode 100644
index 0000000..fded241
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145822_add_tax_category_id_to_spree_line_items.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130802014537)
+class AddTaxCategoryIdToSpreeLineItems < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :tax_category_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145823_migrate_tax_categories_to_line_items.spree.rb b/spec/dummy/db/migrate/20200218145823_migrate_tax_categories_to_line_items.spree.rb
new file mode 100644
index 0000000..38b3c0c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145823_migrate_tax_categories_to_line_items.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20130802022321)
+class MigrateTaxCategoriesToLineItems < ActiveRecord::Migration[4.2]
+ def change
+ Spree::LineItem.find_each do |line_item|
+ next if line_item.variant.nil?
+ next if line_item.variant.product.nil?
+ next if line_item.product.nil?
+ line_item.update_column(:tax_category_id, line_item.product.tax_category_id)
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145824_drop_spree_mail_methods.spree.rb b/spec/dummy/db/migrate/20200218145824_drop_spree_mail_methods.spree.rb
new file mode 100644
index 0000000..3fdc655
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145824_drop_spree_mail_methods.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20130806022521)
+class DropSpreeMailMethods < ActiveRecord::Migration[4.2]
+ def up
+ drop_table :spree_mail_methods
+ end
+
+ def down
+ create_table(:spree_mail_methods) do |t|
+ t.string :environment
+ t.boolean :active
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145825_set_default_stock_location_on_shipments.spree.rb b/spec/dummy/db/migrate/20200218145825_set_default_stock_location_on_shipments.spree.rb
new file mode 100644
index 0000000..6a4d6d6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145825_set_default_stock_location_on_shipments.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20130806145853)
+class SetDefaultStockLocationOnShipments < ActiveRecord::Migration[4.2]
+ def change
+ if Spree::Shipment.where('stock_location_id IS NULL').count > 0
+ location = Spree::StockLocation.find_by(name: 'default') || Spree::StockLocation.first
+ Spree::Shipment.where('stock_location_id IS NULL').update_all(stock_location_id: location.id)
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145826_upgrade_adjustments.spree.rb b/spec/dummy/db/migrate/20200218145826_upgrade_adjustments.spree.rb
new file mode 100644
index 0000000..895ed65
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145826_upgrade_adjustments.spree.rb
@@ -0,0 +1,47 @@
+# This migration comes from spree (originally 20130807024301)
+class UpgradeAdjustments < ActiveRecord::Migration[4.2]
+ def up
+ # Add Temporary index
+ add_index :spree_adjustments, :originator_type unless index_exists?(:spree_adjustments, :originator_type)
+
+ # Temporarily make originator association available
+ Spree::Adjustment.class_eval do
+ belongs_to :originator, polymorphic: true
+ end
+ # Shipping adjustments are now tracked as fields on the object
+ Spree::Adjustment.where(source_type: "Spree::Shipment").find_each do |adjustment|
+ # Account for possible invalid data
+ next if adjustment.source.nil?
+ adjustment.source.update_column(:cost, adjustment.amount)
+ adjustment.destroy!
+ end
+
+ # Tax adjustments have their sources altered
+ Spree::Adjustment.where(originator_type: "Spree::TaxRate").find_each do |adjustment|
+ adjustment.source_id = adjustment.originator_id
+ adjustment.source_type = "Spree::TaxRate"
+ adjustment.save!
+ end
+
+ # Promotion adjustments have their source altered also
+ Spree::Adjustment.where(originator_type: "Spree::PromotionAction").find_each do |adjustment|
+ next if adjustment.originator.nil?
+ adjustment.source = adjustment.originator
+ begin
+ if adjustment.source.calculator_type == "Spree::Calculator::FreeShipping"
+ # Previously this was a Spree::Promotion::Actions::CreateAdjustment
+ # And it had a calculator to work out FreeShipping
+ # In Spree 2.2, the "calculator" is now the action itself.
+ adjustment.source.becomes(Spree::Promotion::Actions::FreeShipping)
+ end
+ rescue
+ # Fail silently. This is primarily in instances where the calculator no longer exists
+ end
+
+ adjustment.save!
+ end
+
+ # Remove Temporary index
+ remove_index :spree_adjustments, :originator_type if index_exists?(:spree_adjustments, :originator_type)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145827_rename_adjustment_fields.spree.rb b/spec/dummy/db/migrate/20200218145827_rename_adjustment_fields.spree.rb
new file mode 100644
index 0000000..885810f
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145827_rename_adjustment_fields.spree.rb
@@ -0,0 +1,21 @@
+# This migration comes from spree (originally 20130807024302)
+class RenameAdjustmentFields < ActiveRecord::Migration[4.2]
+ def up
+ # Add Temporary index
+ add_index :spree_adjustments, :adjustable_type unless index_exists?(:spree_adjustments, :adjustable_type)
+
+ remove_column :spree_adjustments, :originator_id
+ remove_column :spree_adjustments, :originator_type
+
+ add_column :spree_adjustments, :order_id, :integer unless column_exists?(:spree_adjustments, :order_id)
+
+ # This enables the Spree::Order#all_adjustments association to work correctly
+ Spree::Adjustment.reset_column_information
+ Spree::Adjustment.where(adjustable_type: "Spree::Order").find_each do |adjustment|
+ adjustment.update_column(:order_id, adjustment.adjustable_id)
+ end
+
+ # Remove Temporary index
+ remove_index :spree_adjustments, :adjustable_type if index_exists?(:spree_adjustments, :adjustable_type)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145828_add_admin_name_column_to_spree_shipping_methods.spree.rb b/spec/dummy/db/migrate/20200218145828_add_admin_name_column_to_spree_shipping_methods.spree.rb
new file mode 100644
index 0000000..bbf68a0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145828_add_admin_name_column_to_spree_shipping_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130809164245)
+class AddAdminNameColumnToSpreeShippingMethods < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_shipping_methods, :admin_name, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145829_add_admin_name_column_to_spree_stock_locations.spree.rb b/spec/dummy/db/migrate/20200218145829_add_admin_name_column_to_spree_stock_locations.spree.rb
new file mode 100644
index 0000000..aeba3be
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145829_add_admin_name_column_to_spree_stock_locations.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130809164330)
+class AddAdminNameColumnToSpreeStockLocations < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_stock_locations, :admin_name, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145830_add_shipment_total_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145830_add_shipment_total_to_spree_orders.spree.rb
new file mode 100644
index 0000000..4c9fa88
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145830_add_shipment_total_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130813004002)
+class AddShipmentTotalToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :shipment_total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145831_expand_order_number_size.spree.rb b/spec/dummy/db/migrate/20200218145831_expand_order_number_size.spree.rb
new file mode 100644
index 0000000..56640de
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145831_expand_order_number_size.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130813140619)
+class ExpandOrderNumberSize < ActiveRecord::Migration[4.2]
+ def up
+ change_column :spree_orders, :number, :string, limit: 32
+ end
+
+ def down
+ change_column :spree_orders, :number, :string, limit: 15
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145832_rename_activators_to_promotions.spree.rb b/spec/dummy/db/migrate/20200218145832_rename_activators_to_promotions.spree.rb
new file mode 100644
index 0000000..92c7ac8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145832_rename_activators_to_promotions.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130813232134)
+class RenameActivatorsToPromotions < ActiveRecord::Migration[4.2]
+ def change
+ rename_table :spree_activators, :spree_promotions
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145833_add_adjustment_total_to_line_items.spree.rb b/spec/dummy/db/migrate/20200218145833_add_adjustment_total_to_line_items.spree.rb
new file mode 100644
index 0000000..ae500e2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145833_add_adjustment_total_to_line_items.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130815000406)
+class AddAdjustmentTotalToLineItems < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :adjustment_total, :decimal, precision: 10, scale: 2, default: 0.0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145834_add_adjustment_total_to_shipments.spree.rb b/spec/dummy/db/migrate/20200218145834_add_adjustment_total_to_shipments.spree.rb
new file mode 100644
index 0000000..1d753f0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145834_add_adjustment_total_to_shipments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130815024413)
+class AddAdjustmentTotalToShipments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_shipments, :adjustment_total, :decimal, precision: 10, scale: 2, default: 0.0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145835_add_depth_to_spree_taxons.spree.rb b/spec/dummy/db/migrate/20200218145835_add_depth_to_spree_taxons.spree.rb
new file mode 100644
index 0000000..edabe29
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145835_add_depth_to_spree_taxons.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20130826062534)
+class AddDepthToSpreeTaxons < ActiveRecord::Migration[4.2]
+ def up
+ if !Spree::Taxon.column_names.include?('depth')
+ add_column :spree_taxons, :depth, :integer
+
+ say_with_time 'Update depth on all taxons' do
+ Spree::Taxon.reset_column_information
+ Spree::Taxon.all.each { |t| t.save }
+ end
+ end
+ end
+
+ def down
+ remove_column :spree_taxons, :depth
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145836_add_tax_total_to_line_items_shipments_and_orders.spree.rb b/spec/dummy/db/migrate/20200218145836_add_tax_total_to_line_items_shipments_and_orders.spree.rb
new file mode 100644
index 0000000..2518bd2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145836_add_tax_total_to_line_items_shipments_and_orders.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20130828234942)
+class AddTaxTotalToLineItemsShipmentsAndOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :tax_total, :decimal, precision: 10, scale: 2, default: 0.0
+ add_column :spree_shipments, :tax_total, :decimal, precision: 10, scale: 2, default: 0.0
+ # This column may already be here from a 2.1.x migration
+ add_column :spree_orders, :tax_total, :decimal, precision: 10, scale: 2, default: 0.0 unless column_exists? :spree_orders, :tax_total, :decimal
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145837_add_shipping_category_to_shipping_methods_and_products.spree.rb b/spec/dummy/db/migrate/20200218145837_add_shipping_category_to_shipping_methods_and_products.spree.rb
new file mode 100644
index 0000000..050bb5c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145837_add_shipping_category_to_shipping_methods_and_products.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20130830001033)
+class AddShippingCategoryToShippingMethodsAndProducts < ActiveRecord::Migration[4.2]
+ def up
+ default_category = Spree::ShippingCategory.first
+ default_category ||= Spree::ShippingCategory.create!(name: "Default")
+
+ Spree::ShippingMethod.all.each do |method|
+ method.shipping_categories << default_category if method.shipping_categories.blank?
+ end
+
+ Spree::Product.where(shipping_category_id: nil).update_all(shipping_category_id: default_category.id)
+ end
+
+ def down
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145838_migrate_old_shipping_calculators.spree.rb b/spec/dummy/db/migrate/20200218145838_migrate_old_shipping_calculators.spree.rb
new file mode 100644
index 0000000..4037cb7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145838_migrate_old_shipping_calculators.spree.rb
@@ -0,0 +1,20 @@
+# This migration comes from spree (originally 20130830001159)
+class MigrateOldShippingCalculators < ActiveRecord::Migration[4.2]
+ def up
+ Spree::ShippingMethod.all.each do |shipping_method|
+ old_calculator = shipping_method.calculator
+ next if old_calculator.class < Spree::ShippingCalculator # We don't want to mess with new shipping calculators
+ new_calculator = eval(old_calculator.class.name.sub("::Calculator::", "::Calculator::Shipping::")).new
+ new_calculator.preferences.keys.each do |pref|
+ # Preferences can't be read/set by name, you have to prefix preferred_
+ pref_method = "preferred_#{pref}"
+ new_calculator.send("#{pref_method}=", old_calculator.send(pref_method))
+ end
+ new_calculator.calculable = old_calculator.calculable
+ new_calculator.save
+ end
+ end
+
+ def down
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145839_add_code_to_spree_promotion_rules.spree.rb b/spec/dummy/db/migrate/20200218145839_add_code_to_spree_promotion_rules.spree.rb
new file mode 100644
index 0000000..b9ff423
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145839_add_code_to_spree_promotion_rules.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130903183026)
+class AddCodeToSpreePromotionRules < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_promotion_rules, :code, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145840_change_states_required_for_countries.spree.rb b/spec/dummy/db/migrate/20200218145840_change_states_required_for_countries.spree.rb
new file mode 100644
index 0000000..4f74d35
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145840_change_states_required_for_countries.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20130909115621)
+class ChangeStatesRequiredForCountries < ActiveRecord::Migration[4.2]
+ def up
+ change_column_default :spree_countries, :states_required, false
+ end
+
+ def down
+ change_column_default :spree_countries, :states_required, true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145841_add_deleted_at_to_spree_stock_items.spree.rb b/spec/dummy/db/migrate/20200218145841_add_deleted_at_to_spree_stock_items.spree.rb
new file mode 100644
index 0000000..57bdb41
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145841_add_deleted_at_to_spree_stock_items.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130915032339)
+class AddDeletedAtToSpreeStockItems < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_stock_items, :deleted_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145842_remove_promotions_event_name_field.spree.rb b/spec/dummy/db/migrate/20200218145842_remove_promotions_event_name_field.spree.rb
new file mode 100644
index 0000000..7013858
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145842_remove_promotions_event_name_field.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20130917024658)
+class RemovePromotionsEventNameField < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_promotions, :event_name, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145843_add_promo_total_to_line_items_and_shipments_and_orders.spree.rb b/spec/dummy/db/migrate/20200218145843_add_promo_total_to_line_items_and_shipments_and_orders.spree.rb
new file mode 100644
index 0000000..18ba89d
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145843_add_promo_total_to_line_items_and_shipments_and_orders.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20130924040529)
+class AddPromoTotalToLineItemsAndShipmentsAndOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :promo_total, :decimal, precision: 10, scale: 2, default: 0.0
+ add_column :spree_shipments, :promo_total, :decimal, precision: 10, scale: 2, default: 0.0
+ add_column :spree_orders, :promo_total, :decimal, precision: 10, scale: 2, default: 0.0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145844_remove_unused_credit_card_fields.spree.rb b/spec/dummy/db/migrate/20200218145844_remove_unused_credit_card_fields.spree.rb
new file mode 100644
index 0000000..ecac20a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145844_remove_unused_credit_card_fields.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20131001013410)
+class RemoveUnusedCreditCardFields < ActiveRecord::Migration[4.2]
+ def up
+ remove_column :spree_credit_cards, :start_month if column_exists?(:spree_credit_cards, :start_month)
+ remove_column :spree_credit_cards, :start_year if column_exists?(:spree_credit_cards, :start_year)
+ remove_column :spree_credit_cards, :issue_number if column_exists?(:spree_credit_cards, :issue_number)
+ end
+ def down
+ add_column :spree_credit_cards, :start_month, :string
+ add_column :spree_credit_cards, :start_year, :string
+ add_column :spree_credit_cards, :issue_number, :string
+ end
+
+ def column_exists?(table, column)
+ ApplicationRecord.connection.column_exists?(table, column)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145845_add_track_inventory_to_variant.spree.rb b/spec/dummy/db/migrate/20200218145845_add_track_inventory_to_variant.spree.rb
new file mode 100644
index 0000000..8ec5187
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145845_add_track_inventory_to_variant.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20131026154747)
+class AddTrackInventoryToVariant < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_variants, :track_inventory, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145846_add_tax_category_to_variants.spree.rb b/spec/dummy/db/migrate/20200218145846_add_tax_category_to_variants.spree.rb
new file mode 100644
index 0000000..deb415c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145846_add_tax_category_to_variants.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20131107132123)
+class AddTaxCategoryToVariants < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_variants, :tax_category_id, :integer
+ add_index :spree_variants, :tax_category_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145847_add_channel_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145847_add_channel_to_spree_orders.spree.rb
new file mode 100644
index 0000000..af11d70
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145847_add_channel_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20131113035136)
+class AddChannelToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :channel, :string, default: "spree"
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145848_add_included_to_adjustments.spree.rb b/spec/dummy/db/migrate/20200218145848_add_included_to_adjustments.spree.rb
new file mode 100644
index 0000000..cbcbc5b
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145848_add_included_to_adjustments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20131118043959)
+class AddIncludedToAdjustments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_adjustments, :included, :boolean, default: false unless Spree::Adjustment.column_names.include?("included")
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145849_rename_tax_total_fields.spree.rb b/spec/dummy/db/migrate/20200218145849_rename_tax_total_fields.spree.rb
new file mode 100644
index 0000000..50287a7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145849_rename_tax_total_fields.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20131118050234)
+class RenameTaxTotalFields < ActiveRecord::Migration[4.2]
+ def change
+ rename_column :spree_line_items, :tax_total, :additional_tax_total
+ rename_column :spree_shipments, :tax_total, :additional_tax_total
+ rename_column :spree_orders, :tax_total, :additional_tax_total
+
+ add_column :spree_line_items, :included_tax_total, :decimal, precision: 10, scale: 2, null: false, default: 0.0
+ add_column :spree_shipments, :included_tax_total, :decimal, precision: 10, scale: 2, null: false, default: 0.0
+ add_column :spree_orders, :included_tax_total, :decimal, precision: 10, scale: 2, null: false, default: 0.0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145850_add_line_item_id_to_spree_inventory_units.spree.rb b/spec/dummy/db/migrate/20200218145850_add_line_item_id_to_spree_inventory_units.spree.rb
new file mode 100644
index 0000000..a1db268
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145850_add_line_item_id_to_spree_inventory_units.spree.rb
@@ -0,0 +1,22 @@
+# This migration comes from spree (originally 20131118183431)
+class AddLineItemIdToSpreeInventoryUnits < ActiveRecord::Migration[4.2]
+ def change
+ # Stores running the product-assembly extension already have a line_item_id column
+ unless column_exists? Spree::InventoryUnit.table_name, :line_item_id
+ add_column :spree_inventory_units, :line_item_id, :integer
+ add_index :spree_inventory_units, :line_item_id
+
+ shipments = Spree::Shipment.includes(:inventory_units, :order)
+
+ shipments.find_each do |shipment|
+ shipment.inventory_units.group_by(&:variant_id).each do |variant_id, units|
+
+ line_item = shipment.order.line_items.find_by(variant_id: variant_id)
+ next unless line_item
+
+ Spree::InventoryUnit.where(id: units.map(&:id)).update_all(line_item_id: line_item.id)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145851_add_updated_at_to_variants.spree.rb b/spec/dummy/db/migrate/20200218145851_add_updated_at_to_variants.spree.rb
new file mode 100644
index 0000000..b636468
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145851_add_updated_at_to_variants.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20131120234456)
+class AddUpdatedAtToVariants < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_variants, :updated_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145852_add_position_to_classifications.spree.rb b/spec/dummy/db/migrate/20200218145852_add_position_to_classifications.spree.rb
new file mode 100644
index 0000000..071adb0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145852_add_position_to_classifications.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20131127001002)
+class AddPositionToClassifications < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_products_taxons, :position, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145853_create_spree_orders_promotions.spree.rb b/spec/dummy/db/migrate/20200218145853_create_spree_orders_promotions.spree.rb
new file mode 100644
index 0000000..5ec87b6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145853_create_spree_orders_promotions.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20131211112807)
+class CreateSpreeOrdersPromotions < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_orders_promotions, id: false do |t|
+ t.references :order
+ t.references :promotion
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145854_unique_shipping_method_categories.spree.rb b/spec/dummy/db/migrate/20200218145854_unique_shipping_method_categories.spree.rb
new file mode 100644
index 0000000..9cb0011
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145854_unique_shipping_method_categories.spree.rb
@@ -0,0 +1,25 @@
+# This migration comes from spree (originally 20131211192741)
+class UniqueShippingMethodCategories < ActiveRecord::Migration[4.2]
+ def change
+ klass = Spree::ShippingMethodCategory
+ columns = %w[shipping_category_id shipping_method_id]
+
+ say "Find duplicate #{klass} records"
+ duplicates = klass.
+ select((columns + %w[COUNT(*)]).join(',')).
+ group(columns.join(',')).
+ having('COUNT(*) > 1').
+ map { |row| row.attributes.slice(*columns) }
+
+ say "Delete all but the oldest duplicate #{klass} record"
+ duplicates.each do |conditions|
+ klass.where(conditions).order(:created_at).drop(1).each(&:destroy)
+ end
+
+ say "Add unique index to #{klass.table_name} for #{columns.inspect}"
+ add_index klass.table_name, columns, unique: true, name: 'unique_spree_shipping_method_categories'
+
+ say "Remove redundant simple index on #{klass.table_name}"
+ remove_index klass.table_name, name: 'index_spree_shipping_method_categories_on_shipping_category_id'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145855_add_item_count_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145855_add_item_count_to_spree_orders.spree.rb
new file mode 100644
index 0000000..10bfb29
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145855_add_item_count_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20131218054603)
+class AddItemCountToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :item_count, :integer, default: 0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145856_remove_value_type_from_spree_preferences.spree.rb b/spec/dummy/db/migrate/20200218145856_remove_value_type_from_spree_preferences.spree.rb
new file mode 100644
index 0000000..be6ccc5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145856_remove_value_type_from_spree_preferences.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20140106065820)
+class RemoveValueTypeFromSpreePreferences < ActiveRecord::Migration[4.2]
+ def up
+ remove_column :spree_preferences, :value_type
+ end
+ def down
+ raise ActiveRecord::IrreversableMigration
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145857_rename_permalink_to_slug_for_products.spree.rb b/spec/dummy/db/migrate/20200218145857_rename_permalink_to_slug_for_products.spree.rb
new file mode 100644
index 0000000..c94c754
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145857_rename_permalink_to_slug_for_products.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140106224208)
+class RenamePermalinkToSlugForProducts < ActiveRecord::Migration[4.2]
+ def change
+ rename_column :spree_products, :permalink, :slug
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145858_add_index_to_variant_id_and_currency_on_prices.spree.rb b/spec/dummy/db/migrate/20200218145858_add_index_to_variant_id_and_currency_on_prices.spree.rb
new file mode 100644
index 0000000..bcaeb19
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145858_add_index_to_variant_id_and_currency_on_prices.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140120160805)
+class AddIndexToVariantIdAndCurrencyOnPrices < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_prices, [:variant_id, :currency]
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145859_rename_activator_id_in_rules_and_actions_to_promotion_id.spree.rb b/spec/dummy/db/migrate/20200218145859_rename_activator_id_in_rules_and_actions_to_promotion_id.spree.rb
new file mode 100644
index 0000000..1622c21
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145859_rename_activator_id_in_rules_and_actions_to_promotion_id.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140124023232)
+class RenameActivatorIdInRulesAndActionsToPromotionId < ActiveRecord::Migration[4.2]
+ def change
+ rename_column :spree_promotion_rules, :activator_id, :promotion_id
+ rename_column :spree_promotion_actions, :activator_id, :promotion_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145860_add_deleted_at_to_spree_prices.spree.rb b/spec/dummy/db/migrate/20200218145860_add_deleted_at_to_spree_prices.spree.rb
new file mode 100644
index 0000000..5e27097
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145860_add_deleted_at_to_spree_prices.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140129024326)
+class AddDeletedAtToSpreePrices < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_prices, :deleted_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145861_add_approver_id_and_approved_at_to_orders.spree.rb b/spec/dummy/db/migrate/20200218145861_add_approver_id_and_approved_at_to_orders.spree.rb
new file mode 100644
index 0000000..17a6d74
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145861_add_approver_id_and_approved_at_to_orders.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140203161722)
+class AddApproverIdAndApprovedAtToOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :approver_id, :integer
+ add_column :spree_orders, :approved_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145862_add_confirmation_delivered_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145862_add_confirmation_delivered_to_spree_orders.spree.rb
new file mode 100644
index 0000000..7cc83de
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145862_add_confirmation_delivered_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140204115338)
+class AddConfirmationDeliveredToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :confirmation_delivered, :boolean, default: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145863_add_auto_capture_to_payment_methods.spree.rb b/spec/dummy/db/migrate/20200218145863_add_auto_capture_to_payment_methods.spree.rb
new file mode 100644
index 0000000..9a158df
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145863_add_auto_capture_to_payment_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140204192230)
+class AddAutoCaptureToPaymentMethods < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_payment_methods, :auto_capture, :boolean
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145864_create_spree_payment_capture_events.spree.rb b/spec/dummy/db/migrate/20200218145864_create_spree_payment_capture_events.spree.rb
new file mode 100644
index 0000000..66aa891
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145864_create_spree_payment_capture_events.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20140205120320)
+class CreateSpreePaymentCaptureEvents < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_payment_capture_events do |t|
+ t.decimal :amount, precision: 10, scale: 2, default: 0.0
+ t.integer :payment_id
+
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_payment_capture_events, :payment_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145865_add_uncaptured_amount_to_payments.spree.rb b/spec/dummy/db/migrate/20200218145865_add_uncaptured_amount_to_payments.spree.rb
new file mode 100644
index 0000000..35ab2f0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145865_add_uncaptured_amount_to_payments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140205144710)
+class AddUncapturedAmountToPayments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_payments, :uncaptured_amount, :decimal, precision: 10, scale: 2, default: 0.0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145866_default_variant_weight_to_zero.spree.rb b/spec/dummy/db/migrate/20200218145866_default_variant_weight_to_zero.spree.rb
new file mode 100644
index 0000000..4abecc3
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145866_default_variant_weight_to_zero.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20140205181631)
+class DefaultVariantWeightToZero < ActiveRecord::Migration[4.2]
+ def up
+ Spree::Variant.unscoped.where(weight: nil).update_all("weight = 0.0")
+
+ change_column :spree_variants, :weight, :decimal, precision: 8, scale: 2, default: 0.0
+ end
+
+ def down
+ change_column :spree_variants, :weight, :decimal, precision: 8, scale: 2
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145867_add_tax_category_id_to_shipping_methods.spree.rb b/spec/dummy/db/migrate/20200218145867_add_tax_category_id_to_shipping_methods.spree.rb
new file mode 100644
index 0000000..38a74b2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145867_add_tax_category_id_to_shipping_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140207085910)
+class AddTaxCategoryIdToShippingMethods < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_shipping_methods, :tax_category_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145868_add_tax_rate_id_to_shipping_rates.spree.rb b/spec/dummy/db/migrate/20200218145868_add_tax_rate_id_to_shipping_rates.spree.rb
new file mode 100644
index 0000000..caaabbe
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145868_add_tax_rate_id_to_shipping_rates.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140207093021)
+class AddTaxRateIdToShippingRates < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_shipping_rates, :tax_rate_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145869_add_pre_tax_amount_to_line_items_and_shipments.spree.rb b/spec/dummy/db/migrate/20200218145869_add_pre_tax_amount_to_line_items_and_shipments.spree.rb
new file mode 100644
index 0000000..47334ba
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145869_add_pre_tax_amount_to_line_items_and_shipments.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140211040159)
+class AddPreTaxAmountToLineItemsAndShipments < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :pre_tax_amount, :decimal, precision: 8, scale: 2
+ add_column :spree_shipments, :pre_tax_amount, :decimal, precision: 8, scale: 2
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145870_add_more_indexes.spree.rb b/spec/dummy/db/migrate/20200218145870_add_more_indexes.spree.rb
new file mode 100644
index 0000000..e201e09
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145870_add_more_indexes.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20140213184916)
+class AddMoreIndexes < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_payment_methods, [:id, :type]
+ add_index :spree_calculators, [:id, :type]
+ add_index :spree_calculators, [:calculable_id, :calculable_type]
+ add_index :spree_payments, :payment_method_id
+ add_index :spree_promotion_actions, [:id, :type]
+ add_index :spree_promotion_actions, :promotion_id
+ add_index :spree_promotions, [:id, :type]
+ add_index :spree_option_values, :option_type_id
+ add_index :spree_shipments, :stock_location_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145871_add_considered_risky_to_orders.spree.rb b/spec/dummy/db/migrate/20200218145871_add_considered_risky_to_orders.spree.rb
new file mode 100644
index 0000000..f4266fc
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145871_add_considered_risky_to_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140219060952)
+class AddConsideredRiskyToOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :considered_risky, :boolean, default: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145872_add_preference_store_to_everything.spree.rb b/spec/dummy/db/migrate/20200218145872_add_preference_store_to_everything.spree.rb
new file mode 100644
index 0000000..4ee2793
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145872_add_preference_store_to_everything.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20140227112348)
+class AddPreferenceStoreToEverything < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_calculators, :preferences, :text
+ add_column :spree_gateways, :preferences, :text
+ add_column :spree_payment_methods, :preferences, :text
+ add_column :spree_promotion_rules, :preferences, :text
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145873_add_user_id_to_spree_credit_cards.spree.rb b/spec/dummy/db/migrate/20200218145873_add_user_id_to_spree_credit_cards.spree.rb
new file mode 100644
index 0000000..e31c76a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145873_add_user_id_to_spree_credit_cards.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20140307235515)
+class AddUserIdToSpreeCreditCards < ActiveRecord::Migration[4.2]
+ def change
+ unless Spree::CreditCard.column_names.include? "user_id"
+ add_column :spree_credit_cards, :user_id, :integer
+ add_index :spree_credit_cards, :user_id
+ end
+
+ unless Spree::CreditCard.column_names.include? "payment_method_id"
+ add_column :spree_credit_cards, :payment_method_id, :integer
+ add_index :spree_credit_cards, :payment_method_id
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145874_migrate_old_preferences.spree.rb b/spec/dummy/db/migrate/20200218145874_migrate_old_preferences.spree.rb
new file mode 100644
index 0000000..f1248f6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145874_migrate_old_preferences.spree.rb
@@ -0,0 +1,28 @@
+# This migration comes from spree (originally 20140309023735)
+class MigrateOldPreferences < ActiveRecord::Migration[4.2]
+ def up
+ if Spree::Calculator.respond_to?(:with_deleted)
+ migrate_preferences(Spree::Calculator.with_deleted)
+ else
+ migrate_preferences(Spree::Calculator)
+ end
+ migrate_preferences(Spree::PaymentMethod)
+ migrate_preferences(Spree::PromotionRule)
+ end
+
+ def down
+ end
+
+ private
+ def migrate_preferences klass
+ klass.reset_column_information
+ klass.find_each do |record|
+ store = Spree::Preferences::ScopedStore.new(record.class.name.underscore, record.id)
+ record.defined_preferences.each do |key|
+ value = store.fetch(key){}
+ record.preferences[key] = value unless value.nil?
+ end
+ record.save!
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145875_create_spree_stores.spree.rb b/spec/dummy/db/migrate/20200218145875_create_spree_stores.spree.rb
new file mode 100644
index 0000000..079e856
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145875_create_spree_stores.spree.rb
@@ -0,0 +1,26 @@
+# This migration comes from spree (originally 20140309024355)
+class CreateSpreeStores < ActiveRecord::Migration[4.2]
+ def change
+ if data_source_exists?(:spree_stores)
+ rename_column :spree_stores, :domains, :url
+ rename_column :spree_stores, :email, :mail_from_address
+ add_column :spree_stores, :meta_description, :text
+ add_column :spree_stores, :meta_keywords, :text
+ add_column :spree_stores, :seo_title, :string
+ else
+ create_table :spree_stores do |t|
+ t.string :name
+ t.string :url
+ t.text :meta_description
+ t.text :meta_keywords
+ t.string :seo_title
+ t.string :mail_from_address
+ t.string :default_currency
+ t.string :code
+ t.boolean :default, default: false, null: false
+
+ t.timestamps null: false, precision: 6
+ end
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145876_create_store_from_preferences.spree.rb b/spec/dummy/db/migrate/20200218145876_create_store_from_preferences.spree.rb
new file mode 100644
index 0000000..c15ee44
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145876_create_store_from_preferences.spree.rb
@@ -0,0 +1,43 @@
+# This migration comes from spree (originally 20140309033438)
+class CreateStoreFromPreferences < ActiveRecord::Migration[4.2]
+ def change
+ # workaround for spree_i18n and Store translations
+ Spree::Store.class_eval do
+ def self.translated?(name)
+ false
+ end
+ end
+
+ preference_store = Spree::Preferences::Store.instance
+ if store = Spree::Store.where(default: true).first
+ store.meta_description = preference_store.get('spree/app_configuration/default_meta_description') {}
+ store.meta_keywords = preference_store.get('spree/app_configuration/default_meta_keywords') {}
+ store.seo_title = preference_store.get('spree/app_configuration/default_seo_title') {}
+ store.default_currency = preference_store.get('spree/app_configuration/currency') { 'USD' }
+ store.save!
+ else
+ # we set defaults for the things we now require
+ Spree::Store.new do |s|
+ s.name = preference_store.get 'spree/app_configuration/site_name' do
+ 'Spree Demo Site'
+ end
+ s.url = preference_store.get 'spree/app_configuration/site_url' do
+ 'demo.spreecommerce.org'
+ end
+ s.mail_from_address = preference_store.get 'spree/app_configuration/mails_from' do
+ 'spree@example.com'
+ end
+
+ s.meta_description = preference_store.get('spree/app_configuration/default_meta_description') do
+ 'Spree Commerce is an open source Ecommerce framework decision makers want, developers enjoy.'
+ end
+ s.meta_keywords = preference_store.get('spree/app_configuration/default_meta_keywords') {}
+ s.seo_title = preference_store.get('spree/app_configuration/default_seo_title') do
+ 'Spree Commerce Demo Shop'
+ end
+ s.default_currency = preference_store.get('spree/app_configuration/currency') { 'USD' }
+ s.code = 'spree'
+ end.save!
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145877_add_timestamps_to_spree_assets.spree.rb b/spec/dummy/db/migrate/20200218145877_add_timestamps_to_spree_assets.spree.rb
new file mode 100644
index 0000000..5b4a411
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145877_add_timestamps_to_spree_assets.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140315053743)
+class AddTimestampsToSpreeAssets < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_assets, :created_at, :datetime
+ add_column :spree_assets, :updated_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145878_create_spree_taxons_promotion_rules.spree.rb b/spec/dummy/db/migrate/20200218145878_create_spree_taxons_promotion_rules.spree.rb
new file mode 100644
index 0000000..bddc695
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145878_create_spree_taxons_promotion_rules.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20140318191500)
+class CreateSpreeTaxonsPromotionRules < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_taxons_promotion_rules do |t|
+ t.references :taxon, index: true
+ t.references :promotion_rule, index: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145879_add_additional_store_fields.spree.rb b/spec/dummy/db/migrate/20200218145879_add_additional_store_fields.spree.rb
new file mode 100644
index 0000000..df3e9c8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145879_add_additional_store_fields.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20140331100557)
+class AddAdditionalStoreFields < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_stores, :code, :string unless column_exists?(:spree_stores, :code)
+ add_column :spree_stores, :default, :boolean, default: false, null: false unless column_exists?(:spree_stores, :default)
+ add_index :spree_stores, :code
+ add_index :spree_stores, :default
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145880_add_many_missing_indexes.spree.rb b/spec/dummy/db/migrate/20200218145880_add_many_missing_indexes.spree.rb
new file mode 100644
index 0000000..9359674
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145880_add_many_missing_indexes.spree.rb
@@ -0,0 +1,19 @@
+# This migration comes from spree (originally 20140410141842)
+class AddManyMissingIndexes < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_adjustments, [:adjustable_id, :adjustable_type]
+ add_index :spree_adjustments, :eligible
+ add_index :spree_adjustments, :order_id
+ add_index :spree_promotions, :code
+ add_index :spree_promotions, :expires_at
+ add_index :spree_states, :country_id
+ add_index :spree_stock_items, :deleted_at
+ add_index :spree_option_types, :position
+ add_index :spree_option_values, :position
+ add_index :spree_product_option_types, :option_type_id
+ add_index :spree_product_option_types, :product_id
+ add_index :spree_products_taxons, :position
+ add_index :spree_promotions, :starts_at
+ add_index :spree_stores, :url
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145881_correct_some_polymorphic_index_and_add_more_missing.spree.rb b/spec/dummy/db/migrate/20200218145881_correct_some_polymorphic_index_and_add_more_missing.spree.rb
new file mode 100644
index 0000000..0a0564e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145881_correct_some_polymorphic_index_and_add_more_missing.spree.rb
@@ -0,0 +1,67 @@
+# This migration comes from spree (originally 20140410150358)
+class CorrectSomePolymorphicIndexAndAddMoreMissing < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_addresses, :country_id
+ add_index :spree_addresses, :state_id
+ remove_index :spree_adjustments, [:source_type, :source_id]
+ add_index :spree_adjustments, [:source_id, :source_type]
+ add_index :spree_credit_cards, :address_id
+ add_index :spree_gateways, :active
+ add_index :spree_gateways, :test_mode
+ add_index :spree_inventory_units, :return_authorization_id
+ add_index :spree_line_items, :tax_category_id
+ add_index :spree_log_entries, [:source_id, :source_type]
+ add_index :spree_orders, :approver_id
+ add_index :spree_orders, :bill_address_id
+ add_index :spree_orders, :confirmation_delivered
+ add_index :spree_orders, :considered_risky
+ add_index :spree_orders, :created_by_id
+ add_index :spree_orders, :ship_address_id
+ add_index :spree_orders, :shipping_method_id
+ add_index :spree_orders_promotions, [:order_id, :promotion_id]
+ add_index :spree_payments, [:source_id, :source_type]
+ add_index :spree_prices, :deleted_at
+ add_index :spree_product_option_types, :position
+ add_index :spree_product_properties, :position
+ add_index :spree_product_properties, :property_id
+ add_index :spree_products, :shipping_category_id
+ add_index :spree_products, :tax_category_id
+ add_index :spree_promotion_action_line_items, :promotion_action_id
+ add_index :spree_promotion_action_line_items, :variant_id
+ add_index :spree_promotion_rules, :promotion_id
+ add_index :spree_promotions, :advertise
+ add_index :spree_return_authorizations, :number
+ add_index :spree_return_authorizations, :order_id
+ add_index :spree_return_authorizations, :stock_location_id
+ add_index :spree_shipments, :address_id
+ add_index :spree_shipping_methods, :deleted_at
+ add_index :spree_shipping_methods, :tax_category_id
+ add_index :spree_shipping_rates, :selected
+ add_index :spree_shipping_rates, :tax_rate_id
+ add_index :spree_state_changes, [:stateful_id, :stateful_type]
+ add_index :spree_state_changes, :user_id
+ add_index :spree_stock_items, :backorderable
+ add_index :spree_stock_locations, :active
+ add_index :spree_stock_locations, :backorderable_default
+ add_index :spree_stock_locations, :country_id
+ add_index :spree_stock_locations, :propagate_all_variants
+ add_index :spree_stock_locations, :state_id
+ add_index :spree_tax_categories, :deleted_at
+ add_index :spree_tax_categories, :is_default
+ add_index :spree_tax_rates, :deleted_at
+ add_index :spree_tax_rates, :included_in_price
+ add_index :spree_tax_rates, :show_rate_in_label
+ add_index :spree_tax_rates, :tax_category_id
+ add_index :spree_tax_rates, :zone_id
+ add_index :spree_taxonomies, :position
+ add_index :spree_taxons, :position
+ add_index :spree_trackers, :active
+ add_index :spree_variants, :deleted_at
+ add_index :spree_variants, :is_master
+ add_index :spree_variants, :position
+ add_index :spree_variants, :track_inventory
+ add_index :spree_zone_members, :zone_id
+ add_index :spree_zone_members, [:zoneable_id, :zoneable_type]
+ add_index :spree_zones, :default_tax
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145882_add_user_id_created_by_id_index_to_order.spree.rb b/spec/dummy/db/migrate/20200218145882_add_user_id_created_by_id_index_to_order.spree.rb
new file mode 100644
index 0000000..21a53f4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145882_add_user_id_created_by_id_index_to_order.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140415041315)
+class AddUserIdCreatedByIdIndexToOrder < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_orders, [:user_id, :created_by_id]
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145883_change_spree_price_amount_precision.spree.rb b/spec/dummy/db/migrate/20200218145883_change_spree_price_amount_precision.spree.rb
new file mode 100644
index 0000000..9efb43a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145883_change_spree_price_amount_precision.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20140508151342)
+class ChangeSpreePriceAmountPrecision < ActiveRecord::Migration[4.2]
+ def change
+ change_column :spree_prices, :amount, :decimal, precision: 10, scale: 2
+ change_column :spree_line_items, :price, :decimal, precision: 10, scale: 2
+ change_column :spree_line_items, :cost_price, :decimal, precision: 10, scale: 2
+ change_column :spree_variants, :cost_price, :decimal, precision: 10, scale: 2
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145884_add_token_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145884_add_token_to_spree_orders.spree.rb
new file mode 100644
index 0000000..ab6066c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145884_add_token_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140518174634)
+class AddTokenToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :guest_token, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145885_move_order_token_from_tokenized_permission.spree.rb b/spec/dummy/db/migrate/20200218145885_move_order_token_from_tokenized_permission.spree.rb
new file mode 100644
index 0000000..67f1b9f
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145885_move_order_token_from_tokenized_permission.spree.rb
@@ -0,0 +1,30 @@
+# This migration comes from spree (originally 20140530024945)
+class MoveOrderTokenFromTokenizedPermission < ActiveRecord::Migration[4.2]
+ class Spree::TokenizedPermission < Spree::Base
+ belongs_to :permissable, polymorphic: true
+ end
+
+ def up
+ case Spree::Order.connection.adapter_name
+ when 'SQLite'
+ Spree::Order.has_one :tokenized_permission, as: :permissable
+ Spree::Order.includes(:tokenized_permission).each do |o|
+ o.update_column :guest_token, o.tokenized_permission.token
+ end
+ when 'Mysql2', 'MySQL'
+ execute "UPDATE spree_orders, spree_tokenized_permissions
+ SET spree_orders.guest_token = spree_tokenized_permissions.token
+ WHERE spree_tokenized_permissions.permissable_id = spree_orders.id
+ AND spree_tokenized_permissions.permissable_type = 'Spree::Order'"
+ else
+ execute "UPDATE spree_orders
+ SET guest_token = spree_tokenized_permissions.token
+ FROM spree_tokenized_permissions
+ WHERE spree_tokenized_permissions.permissable_id = spree_orders.id
+ AND spree_tokenized_permissions.permissable_type = 'Spree::Order'"
+ end
+ end
+
+ def down
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145886_set_shipment_total_for_users_upgrading.spree.rb b/spec/dummy/db/migrate/20200218145886_set_shipment_total_for_users_upgrading.spree.rb
new file mode 100644
index 0000000..00cc72c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145886_set_shipment_total_for_users_upgrading.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20140601011216)
+class SetShipmentTotalForUsersUpgrading < ActiveRecord::Migration[4.2]
+ def up
+ # NOTE You might not need this at all unless you're upgrading from Spree 2.1.x
+ # or below. For those upgrading this should populate the Order#shipment_total
+ # for legacy orders
+ Spree::Order.complete.where('shipment_total = ?', 0).includes(:shipments).find_each do |order|
+ order.update_column(:shipment_total, order.shipments.sum(:cost))
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145887_drop_credit_card_first_name_and_last_name.spree.rb b/spec/dummy/db/migrate/20200218145887_drop_credit_card_first_name_and_last_name.spree.rb
new file mode 100644
index 0000000..5185ba2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145887_drop_credit_card_first_name_and_last_name.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140604135309)
+class DropCreditCardFirstNameAndLastName < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_credit_cards, :first_name, :string
+ remove_column :spree_credit_cards, :last_name, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145888_add_deleted_at_to_spree_promotion_actions.spree.rb b/spec/dummy/db/migrate/20200218145888_add_deleted_at_to_spree_promotion_actions.spree.rb
new file mode 100644
index 0000000..c282023
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145888_add_deleted_at_to_spree_promotion_actions.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140609201656)
+class AddDeletedAtToSpreePromotionActions < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_promotion_actions, :deleted_at, :datetime
+ add_index :spree_promotion_actions, :deleted_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145889_remove_uncaptured_amount_from_spree_payments.spree.rb b/spec/dummy/db/migrate/20200218145889_remove_uncaptured_amount_from_spree_payments.spree.rb
new file mode 100644
index 0000000..d8dab95
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145889_remove_uncaptured_amount_from_spree_payments.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140616202624)
+class RemoveUncapturedAmountFromSpreePayments < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_payments, :uncaptured_amount
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145890_create_spree_refunds.spree.rb b/spec/dummy/db/migrate/20200218145890_create_spree_refunds.spree.rb
new file mode 100644
index 0000000..a4e1648
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145890_create_spree_refunds.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20140625214618)
+class CreateSpreeRefunds < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_refunds do |t|
+ t.integer :payment_id
+ t.integer :return_authorization_id
+ t.decimal :amount, precision: 10, scale: 2, default: 0.0, null: false
+ t.string :transaction_id
+
+ t.timestamps null: false, precision: 6
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145891_create_spree_return_authorization_inventory_unit.spree.rb b/spec/dummy/db/migrate/20200218145891_create_spree_return_authorization_inventory_unit.spree.rb
new file mode 100644
index 0000000..911e175
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145891_create_spree_return_authorization_inventory_unit.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20140702140656)
+class CreateSpreeReturnAuthorizationInventoryUnit < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_return_authorization_inventory_units do |t|
+ t.integer :return_authorization_id
+ t.integer :inventory_unit_id
+ t.integer :exchange_variant_id
+ t.datetime :received_at
+
+ t.timestamps null: false, precision: 6
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145892_rename_return_authorization_inventory_unit_to_return_items.spree.rb b/spec/dummy/db/migrate/20200218145892_rename_return_authorization_inventory_unit_to_return_items.spree.rb
new file mode 100644
index 0000000..e4e4c04
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145892_rename_return_authorization_inventory_unit_to_return_items.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140707125621)
+class RenameReturnAuthorizationInventoryUnitToReturnItems < ActiveRecord::Migration[4.2]
+ def change
+ rename_table :spree_return_authorization_inventory_units, :spree_return_items
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145893_backfill_line_item_pre_tax_amount.spree.rb b/spec/dummy/db/migrate/20200218145893_backfill_line_item_pre_tax_amount.spree.rb
new file mode 100644
index 0000000..57165c9
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145893_backfill_line_item_pre_tax_amount.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20140709160534)
+class BackfillLineItemPreTaxAmount < ActiveRecord::Migration[4.2]
+ def change
+ # set pre_tax_amount to discounted_amount - included_tax_total
+ execute(<<-SQL)
+ UPDATE spree_line_items
+ SET pre_tax_amount = ((price * quantity) + promo_total) - included_tax_total
+ WHERE pre_tax_amount IS NULL;
+ SQL
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145894_recreate_spree_return_authorizations.spree.rb b/spec/dummy/db/migrate/20200218145894_recreate_spree_return_authorizations.spree.rb
new file mode 100644
index 0000000..d5325d6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145894_recreate_spree_return_authorizations.spree.rb
@@ -0,0 +1,56 @@
+# This migration comes from spree (originally 20140710041921)
+class RecreateSpreeReturnAuthorizations < ActiveRecord::Migration[4.2]
+ def up
+ # If the app has any legacy return authorizations then rename the table & columns and leave them there
+ # for the spree_legacy_return_authorizations extension to pick up with.
+ # Otherwise just drop the tables/columns as they are no longer used in stock spree. The spree_legacy_return_authorizations
+ # extension will recreate these tables for dev environments & etc as needed.
+ if Spree::ReturnAuthorization.exists?
+ rename_table :spree_return_authorizations, :spree_legacy_return_authorizations
+ rename_column :spree_inventory_units, :return_authorization_id, :legacy_return_authorization_id
+ else
+ drop_table :spree_return_authorizations
+ remove_column :spree_inventory_units, :return_authorization_id
+ end
+
+ Spree::Adjustment.where(source_type: 'Spree::ReturnAuthorization').update_all(source_type: 'Spree::LegacyReturnAuthorization')
+
+ # For now just recreate the table as it was. Future changes to the schema (including dropping "amount") will be coming in a
+ # separate commit.
+ create_table :spree_return_authorizations do |t|
+ t.string "number"
+ t.string "state"
+ t.decimal "amount", precision: 10, scale: 2, default: 0.0, null: false
+ t.integer "order_id"
+ t.text "reason"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "stock_location_id"
+ end
+
+ end
+
+ def down
+ drop_table :spree_return_authorizations
+
+ Spree::Adjustment.where(source_type: 'Spree::LegacyReturnAuthorization').update_all(source_type: 'Spree::ReturnAuthorization')
+
+ if data_source_exists?(:spree_legacy_return_authorizations)
+ rename_table :spree_legacy_return_authorizations, :spree_return_authorizations
+ rename_column :spree_inventory_units, :legacy_return_authorization_id, :return_authorization_id
+ else
+ create_table :spree_return_authorizations do |t|
+ t.string "number"
+ t.string "state"
+ t.decimal "amount", precision: 10, scale: 2, default: 0.0, null: false
+ t.integer "order_id"
+ t.text "reason"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "stock_location_id"
+ end
+ add_column :spree_inventory_units, :return_authorization_id, :integer, after: :shipment_id
+ add_index :spree_inventory_units, :return_authorization_id
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145895_add_amount_fields_to_return_items.spree.rb b/spec/dummy/db/migrate/20200218145895_add_amount_fields_to_return_items.spree.rb
new file mode 100644
index 0000000..4de3e51
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145895_add_amount_fields_to_return_items.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20140710181204)
+class AddAmountFieldsToReturnItems < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_return_items, :pre_tax_amount, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ add_column :spree_return_items, :included_tax_total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ add_column :spree_return_items, :additional_tax_total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145896_drop_return_authorization_amount.spree.rb b/spec/dummy/db/migrate/20200218145896_drop_return_authorization_amount.spree.rb
new file mode 100644
index 0000000..ed64ea2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145896_drop_return_authorization_amount.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140710190048)
+class DropReturnAuthorizationAmount < ActiveRecord::Migration[4.2]
+ def change
+ remove_column :spree_return_authorizations, :amount
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145897_create_spree_return_authorization_reasons.spree.rb b/spec/dummy/db/migrate/20200218145897_create_spree_return_authorization_reasons.spree.rb
new file mode 100644
index 0000000..a145919
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145897_create_spree_return_authorization_reasons.spree.rb
@@ -0,0 +1,29 @@
+# This migration comes from spree (originally 20140713140455)
+class CreateSpreeReturnAuthorizationReasons < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_return_authorization_reasons do |t|
+ t.string :name
+ t.boolean :active, default: true
+ t.boolean :mutable, default: true
+
+ t.timestamps null: false, precision: 6
+ end
+
+ reversible do |direction|
+ direction.up do
+ Spree::ReturnAuthorizationReason.create!(name: 'Better price available')
+ Spree::ReturnAuthorizationReason.create!(name: 'Missed estimated delivery date')
+ Spree::ReturnAuthorizationReason.create!(name: 'Missing parts or accessories')
+ Spree::ReturnAuthorizationReason.create!(name: 'Damaged/Defective')
+ Spree::ReturnAuthorizationReason.create!(name: 'Different from what was ordered')
+ Spree::ReturnAuthorizationReason.create!(name: 'Different from description')
+ Spree::ReturnAuthorizationReason.create!(name: 'No longer needed/wanted')
+ Spree::ReturnAuthorizationReason.create!(name: 'Accidental order')
+ Spree::ReturnAuthorizationReason.create!(name: 'Unauthorized purchase')
+ end
+ end
+
+ add_column :spree_return_authorizations, :return_authorization_reason_id, :integer
+ add_index :spree_return_authorizations, :return_authorization_reason_id, name: 'index_return_authorizations_on_return_authorization_reason_id'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145898_create_spree_refund_reasons.spree.rb b/spec/dummy/db/migrate/20200218145898_create_spree_refund_reasons.spree.rb
new file mode 100644
index 0000000..7c5df80
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145898_create_spree_refund_reasons.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20140713140527)
+class CreateSpreeRefundReasons < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_refund_reasons do |t|
+ t.string :name
+ t.boolean :active, default: true
+ t.boolean :mutable, default: true
+
+ t.timestamps null: false, precision: 6
+ end
+
+ add_column :spree_refunds, :refund_reason_id, :integer
+ add_index :spree_refunds, :refund_reason_id, name: 'index_refunds_on_refund_reason_id'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145899_rename_return_authorization_reason.spree.rb b/spec/dummy/db/migrate/20200218145899_rename_return_authorization_reason.spree.rb
new file mode 100644
index 0000000..58219b6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145899_rename_return_authorization_reason.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140713142214)
+class RenameReturnAuthorizationReason < ActiveRecord::Migration[4.2]
+ def change
+ rename_column :spree_return_authorizations, :reason, :memo
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145900_create_spree_promotion_categories.spree.rb b/spec/dummy/db/migrate/20200218145900_create_spree_promotion_categories.spree.rb
new file mode 100644
index 0000000..cf68890
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145900_create_spree_promotion_categories.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20140715182625)
+class CreateSpreePromotionCategories < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_promotion_categories do |t|
+ t.string :name
+ t.timestamps null: false, precision: 6
+ end
+
+ add_column :spree_promotions, :promotion_category_id, :integer
+ add_index :spree_promotions, :promotion_category_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145901_drop_received_at_on_return_items.spree.rb b/spec/dummy/db/migrate/20200218145901_drop_received_at_on_return_items.spree.rb
new file mode 100644
index 0000000..fbb5466
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145901_drop_received_at_on_return_items.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20140716204111)
+class DropReceivedAtOnReturnItems < ActiveRecord::Migration[4.2]
+ def up
+ remove_column :spree_return_items, :received_at
+ end
+
+ def down
+ add_column :spree_return_items, :received_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145902_add_reception_and_acceptance_status_to_return_items.spree.rb b/spec/dummy/db/migrate/20200218145902_add_reception_and_acceptance_status_to_return_items.spree.rb
new file mode 100644
index 0000000..491399d
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145902_add_reception_and_acceptance_status_to_return_items.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140716212330)
+class AddReceptionAndAcceptanceStatusToReturnItems < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_return_items, :reception_status, :string
+ add_column :spree_return_items, :acceptance_status, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145903_create_default_refund_reason.spree.rb b/spec/dummy/db/migrate/20200218145903_create_default_refund_reason.spree.rb
new file mode 100644
index 0000000..0a01f7f
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145903_create_default_refund_reason.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20140717155155)
+class CreateDefaultRefundReason < ActiveRecord::Migration[4.2]
+ def up
+ Spree::RefundReason.create!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false)
+ end
+
+ def down
+ Spree::RefundReason.find_by(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false).destroy
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145904_add_default_to_spree_stock_locations.spree.rb b/spec/dummy/db/migrate/20200218145904_add_default_to_spree_stock_locations.spree.rb
new file mode 100644
index 0000000..7e5093d
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145904_add_default_to_spree_stock_locations.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20140717185932)
+class AddDefaultToSpreeStockLocations < ActiveRecord::Migration[4.2]
+ def change
+ unless column_exists? :spree_stock_locations, :default
+ add_column :spree_stock_locations, :default, :boolean, null: false, default: false
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145905_create_spree_customer_returns.spree.rb b/spec/dummy/db/migrate/20200218145905_create_spree_customer_returns.spree.rb
new file mode 100644
index 0000000..0f8b994
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145905_create_spree_customer_returns.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20140718133010)
+class CreateSpreeCustomerReturns < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_customer_returns do |t|
+ t.string :number
+ t.integer :stock_location_id
+ t.timestamps null: false, precision: 6
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145906_add_customer_return_id_to_return_item.spree.rb b/spec/dummy/db/migrate/20200218145906_add_customer_return_id_to_return_item.spree.rb
new file mode 100644
index 0000000..dfa720c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145906_add_customer_return_id_to_return_item.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140718133349)
+class AddCustomerReturnIdToReturnItem < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_return_items, :customer_return_id, :integer
+ add_index :spree_return_items, :customer_return_id, name: 'index_return_items_on_customer_return_id'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145907_create_friendly_id_slugs.spree.rb b/spec/dummy/db/migrate/20200218145907_create_friendly_id_slugs.spree.rb
new file mode 100644
index 0000000..8464fe0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145907_create_friendly_id_slugs.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20140718195325)
+class CreateFriendlyIdSlugs < ActiveRecord::Migration[4.2]
+ def change
+ create_table :friendly_id_slugs do |t|
+ t.string :slug, null: false
+ t.integer :sluggable_id, null: false
+ t.string :sluggable_type, limit: 50
+ t.string :scope
+ t.datetime :created_at
+ end
+ add_index :friendly_id_slugs, :sluggable_id
+ add_index :friendly_id_slugs, [:slug, :sluggable_type]
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
+ add_index :friendly_id_slugs, :sluggable_type
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145908_rename_spree_refund_return_authorization_id.spree.rb b/spec/dummy/db/migrate/20200218145908_rename_spree_refund_return_authorization_id.spree.rb
new file mode 100644
index 0000000..1b8b4b1
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145908_rename_spree_refund_return_authorization_id.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140723004419)
+class RenameSpreeRefundReturnAuthorizationId < ActiveRecord::Migration[4.2]
+ def change
+ rename_column :spree_refunds, :return_authorization_id, :customer_return_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145909_increase_return_item_pre_tax_amount_precision.spree.rb b/spec/dummy/db/migrate/20200218145909_increase_return_item_pre_tax_amount_precision.spree.rb
new file mode 100644
index 0000000..204bf29
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145909_increase_return_item_pre_tax_amount_precision.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20140723152808)
+class IncreaseReturnItemPreTaxAmountPrecision < ActiveRecord::Migration[4.2]
+ def up
+ change_column :spree_return_items, :pre_tax_amount, :decimal, precision: 12, scale: 4, default: 0.0, null: false
+ change_column :spree_return_items, :included_tax_total, :decimal, precision: 12, scale: 4, default: 0.0, null: false
+ change_column :spree_return_items, :additional_tax_total, :decimal, precision: 12, scale: 4, default: 0.0, null: false
+ end
+
+ def down
+ change_column :spree_return_items, :pre_tax_amount, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ change_column :spree_return_items, :included_tax_total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ change_column :spree_return_items, :additional_tax_total, :decimal, precision: 10, scale: 2, default: 0.0, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145910_copy_product_slugs_to_slug_history.spree.rb b/spec/dummy/db/migrate/20200218145910_copy_product_slugs_to_slug_history.spree.rb
new file mode 100644
index 0000000..c65a9fe
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145910_copy_product_slugs_to_slug_history.spree.rb
@@ -0,0 +1,16 @@
+# This migration comes from spree (originally 20140723214541)
+class CopyProductSlugsToSlugHistory < ActiveRecord::Migration[4.2]
+ def change
+
+ # do what sql does best: copy all slugs into history table in a single query
+ # rather than load potentially millions of products into memory
+ Spree::Product.connection.execute <<-SQL
+INSERT INTO #{FriendlyId::Slug.table_name} (slug, sluggable_id, sluggable_type, created_at)
+ SELECT slug, id, '#{Spree::Product.to_s}', #{ApplicationRecord.send(:sanitize_sql_array, ['?', Time.current])}
+ FROM #{Spree::Product.table_name}
+ WHERE slug IS NOT NULL
+ ORDER BY id
+SQL
+
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145911_create_spree_reimbursements.spree.rb b/spec/dummy/db/migrate/20200218145911_create_spree_reimbursements.spree.rb
new file mode 100644
index 0000000..20373ab
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145911_create_spree_reimbursements.spree.rb
@@ -0,0 +1,22 @@
+# This migration comes from spree (originally 20140725131539)
+class CreateSpreeReimbursements < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_reimbursements do |t|
+ t.string :number
+ t.string :reimbursement_status
+ t.integer :customer_return_id
+ t.integer :order_id
+ t.decimal :total, precision: 10, scale: 2
+
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_reimbursements, :customer_return_id
+ add_index :spree_reimbursements, :order_id
+
+ remove_column :spree_refunds, :customer_return_id, :integer
+ add_column :spree_refunds, :reimbursement_id, :integer
+
+ add_column :spree_return_items, :reimbursement_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145912_add_promotionable_to_spree_products.spree.rb b/spec/dummy/db/migrate/20200218145912_add_promotionable_to_spree_products.spree.rb
new file mode 100644
index 0000000..5b97921
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145912_add_promotionable_to_spree_products.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140728225422)
+class AddPromotionableToSpreeProducts < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_products, :promotionable, :boolean, default: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145913_add_exchange_inventory_unit_foreign_keys.spree.rb b/spec/dummy/db/migrate/20200218145913_add_exchange_inventory_unit_foreign_keys.spree.rb
new file mode 100644
index 0000000..beb5fa9
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145913_add_exchange_inventory_unit_foreign_keys.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20140729133613)
+class AddExchangeInventoryUnitForeignKeys < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_return_items, :exchange_inventory_unit_id, :integer
+
+ add_index :spree_return_items, :exchange_inventory_unit_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145914_add_acceptance_status_errors_to_return_item.spree.rb b/spec/dummy/db/migrate/20200218145914_add_acceptance_status_errors_to_return_item.spree.rb
new file mode 100644
index 0000000..07b92eb
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145914_add_acceptance_status_errors_to_return_item.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140730155938)
+class AddAcceptanceStatusErrorsToReturnItem < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_return_items, :acceptance_status_errors, :text
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145915_create_spree_reimbursement_types.spree.rb b/spec/dummy/db/migrate/20200218145915_create_spree_reimbursement_types.spree.rb
new file mode 100644
index 0000000..b9b7dca
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145915_create_spree_reimbursement_types.spree.rb
@@ -0,0 +1,21 @@
+# This migration comes from spree (originally 20140731150017)
+class CreateSpreeReimbursementTypes < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_reimbursement_types do |t|
+ t.string :name
+ t.boolean :active, default: true
+ t.boolean :mutable, default: true
+
+ t.timestamps null: false, precision: 6
+ end
+
+ reversible do |direction|
+ direction.up do
+ Spree::ReimbursementType.create!(name: Spree::ReimbursementType::ORIGINAL)
+ end
+ end
+
+ add_column :spree_return_items, :preferred_reimbursement_type_id, :integer
+ add_column :spree_return_items, :override_reimbursement_type_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145916_add_default_to_shipment_cost.spree.rb b/spec/dummy/db/migrate/20200218145916_add_default_to_shipment_cost.spree.rb
new file mode 100644
index 0000000..6f4c6a3
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145916_add_default_to_shipment_cost.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20140804185157)
+class AddDefaultToShipmentCost < ActiveRecord::Migration[4.2]
+ def up
+ change_column :spree_shipments, :cost, :decimal, precision: 10, scale: 2, default: 0.0
+ Spree::Shipment.where(cost: nil).update_all(cost: 0)
+ end
+
+ def down
+ change_column :spree_shipments, :cost, :decimal, precision: 10, scale: 2
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145917_add_default_to_spree_credit_cards.spree.rb b/spec/dummy/db/migrate/20200218145917_add_default_to_spree_credit_cards.spree.rb
new file mode 100644
index 0000000..17e9f91
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145917_add_default_to_spree_credit_cards.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140805171035)
+class AddDefaultToSpreeCreditCards < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_credit_cards, :default, :boolean, null: false, default: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145918_make_existing_credit_cards_default.spree.rb b/spec/dummy/db/migrate/20200218145918_make_existing_credit_cards_default.spree.rb
new file mode 100644
index 0000000..4ce7f70
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145918_make_existing_credit_cards_default.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20140805171219)
+class MakeExistingCreditCardsDefault < ActiveRecord::Migration[4.2]
+ def up
+ # set the newest credit card for every user to be the default; SQL technique from
+ # http://stackoverflow.com/questions/121387/fetch-the-row-which-has-the-max-value-for-a-column
+ Spree::CreditCard.where.not(user_id: nil).joins("LEFT OUTER JOIN spree_credit_cards cc2 ON cc2.user_id = spree_credit_cards.user_id AND spree_credit_cards.created_at < cc2.created_at").where("cc2.user_id IS NULL").update_all(default: true)
+ end
+ def down
+ # do nothing
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145919_add_type_to_reimbursement_type.spree.rb b/spec/dummy/db/migrate/20200218145919_add_type_to_reimbursement_type.spree.rb
new file mode 100644
index 0000000..14b50cc
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145919_add_type_to_reimbursement_type.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20140806144901)
+class AddTypeToReimbursementType < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_reimbursement_types, :type, :string
+ add_index :spree_reimbursement_types, :type
+
+ Spree::ReimbursementType.reset_column_information
+ Spree::ReimbursementType.find_by(name: Spree::ReimbursementType::ORIGINAL).update!(type: 'Spree::ReimbursementType::OriginalPayment')
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145920_create_spree_reimbursement_credits.spree.rb b/spec/dummy/db/migrate/20200218145920_create_spree_reimbursement_credits.spree.rb
new file mode 100644
index 0000000..c49cfac
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145920_create_spree_reimbursement_credits.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20140808184039)
+class CreateSpreeReimbursementCredits < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_reimbursement_credits do |t|
+ t.decimal :amount, precision: 10, scale: 2, default: 0.0, null: false
+ t.integer :reimbursement_id
+ t.integer :creditable_id
+ t.string :creditable_type
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145921_add_meta_title_to_spree_products.spree.rb b/spec/dummy/db/migrate/20200218145921_add_meta_title_to_spree_products.spree.rb
new file mode 100644
index 0000000..1719f72
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145921_add_meta_title_to_spree_products.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20140827170513)
+class AddMetaTitleToSpreeProducts < ActiveRecord::Migration[4.2]
+ def change
+ change_table :spree_products do |t|
+ t.string :meta_title
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145922_add_kind_to_zone.spree.rb b/spec/dummy/db/migrate/20200218145922_add_kind_to_zone.spree.rb
new file mode 100644
index 0000000..9252cf4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145922_add_kind_to_zone.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20140911173301)
+class AddKindToZone < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_zones, :kind, :string
+ add_index :spree_zones, :kind
+
+ Spree::Zone.find_each do |zone|
+ last_type = zone.members.where.not(zoneable_type: nil).pluck(:zoneable_type).last
+ zone.update_column :kind, last_type.demodulize.underscore if last_type
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145923_add_code_to_spree_tax_categories.spree.rb b/spec/dummy/db/migrate/20200218145923_add_code_to_spree_tax_categories.spree.rb
new file mode 100644
index 0000000..2348b93
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145923_add_code_to_spree_tax_categories.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20140924164824)
+class AddCodeToSpreeTaxCategories < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_tax_categories, :tax_code, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145924_default_pre_tax_amount_should_be_zero.spree.rb b/spec/dummy/db/migrate/20200218145924_default_pre_tax_amount_should_be_zero.spree.rb
new file mode 100644
index 0000000..247062b
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145924_default_pre_tax_amount_should_be_zero.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20140927193717)
+class DefaultPreTaxAmountShouldBeZero < ActiveRecord::Migration[4.2]
+ def change
+ change_column :spree_line_items, :pre_tax_amount, :decimal, precision: 8, scale: 2, default: 0
+ change_column :spree_shipments, :pre_tax_amount, :decimal, precision: 8, scale: 2, default: 0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145925_add_code_to_spree_shipping_methods.spree.rb b/spec/dummy/db/migrate/20200218145925_add_code_to_spree_shipping_methods.spree.rb
new file mode 100644
index 0000000..1a85980
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145925_add_code_to_spree_shipping_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20141002191113)
+class AddCodeToSpreeShippingMethods < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_shipping_methods, :code, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145926_add_cancel_audit_fields_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145926_add_cancel_audit_fields_to_spree_orders.spree.rb
new file mode 100644
index 0000000..b40092a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145926_add_cancel_audit_fields_to_spree_orders.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20141007230328)
+class AddCancelAuditFieldsToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :canceled_at, :datetime
+ add_column :spree_orders, :canceler_id, :integer
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145927_add_store_id_to_orders.spree.rb b/spec/dummy/db/migrate/20200218145927_add_store_id_to_orders.spree.rb
new file mode 100644
index 0000000..c3ddd8d
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145927_add_store_id_to_orders.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20141009204607)
+class AddStoreIdToOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :store_id, :integer
+ if Spree::Store.default.persisted?
+ Spree::Order.where(store_id: nil).update_all(store_id: Spree::Store.default.id)
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145928_create_spree_taxons_prototypes.spree.rb b/spec/dummy/db/migrate/20200218145928_create_spree_taxons_prototypes.spree.rb
new file mode 100644
index 0000000..3111302
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145928_create_spree_taxons_prototypes.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20141012083513)
+class CreateSpreeTaxonsPrototypes < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_taxons_prototypes do |t|
+ t.belongs_to :taxon, index: true
+ t.belongs_to :prototype, index: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145929_add_state_lock_version_to_order.spree.rb b/spec/dummy/db/migrate/20200218145929_add_state_lock_version_to_order.spree.rb
new file mode 100644
index 0000000..c739fbe
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145929_add_state_lock_version_to_order.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20141021194502)
+class AddStateLockVersionToOrder < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_orders, :state_lock_version, :integer, default: 0, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145930_add_counter_cache_from_spree_variants_to_spree_stock_items.spree.rb b/spec/dummy/db/migrate/20200218145930_add_counter_cache_from_spree_variants_to_spree_stock_items.spree.rb
new file mode 100644
index 0000000..bf3d2c8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145930_add_counter_cache_from_spree_variants_to_spree_stock_items.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20141023005240)
+class AddCounterCacheFromSpreeVariantsToSpreeStockItems < ActiveRecord::Migration[4.2]
+ # This was unnecessary and was removed
+ def up
+ end
+
+ def down
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145931_fix_adjustment_order_presence.spree.rb b/spec/dummy/db/migrate/20200218145931_fix_adjustment_order_presence.spree.rb
new file mode 100644
index 0000000..fa04dc7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145931_fix_adjustment_order_presence.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20141101231208)
+class FixAdjustmentOrderPresence < ActiveRecord::Migration[4.2]
+ def change
+ say 'Fixing adjustments without direct order reference'
+ Spree::Adjustment.where(order: nil).find_each do |adjustment|
+ adjustable = adjustment.adjustable
+ if adjustable.is_a? Spree::Order
+ adjustment.update!(order_id: adjustable.id)
+ else
+ adjustment.update!(adjustable: adjustable.order)
+ end
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145932_update_classifications_positions.spree.rb b/spec/dummy/db/migrate/20200218145932_update_classifications_positions.spree.rb
new file mode 100644
index 0000000..7c18c51
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145932_update_classifications_positions.spree.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree (originally 20141105213646)
+class UpdateClassificationsPositions < ActiveRecord::Migration[4.2]
+ def up
+ Spree::Taxon.all.each do |taxon|
+ taxon.classifications.each_with_index do |c12n, i|
+ c12n.set_list_position(i + 1)
+ end
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145933_add_guest_token_index_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145933_add_guest_token_index_to_spree_orders.spree.rb
new file mode 100644
index 0000000..f7cb22f
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145933_add_guest_token_index_to_spree_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20141120135441)
+class AddGuestTokenIndexToSpreeOrders < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_orders, :guest_token
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145934_remove_token_permissions_table.spree.rb b/spec/dummy/db/migrate/20200218145934_remove_token_permissions_table.spree.rb
new file mode 100644
index 0000000..9f51ceb
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145934_remove_token_permissions_table.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20141215232040)
+class RemoveTokenPermissionsTable < ActiveRecord::Migration[4.2]
+ def change
+ # The MoveOrderTokenFromTokenizedPermission migration never dropped this.
+ drop_table :spree_tokenized_permissions
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145935_remove_extra_products_slug_index.spree.rb b/spec/dummy/db/migrate/20200218145935_remove_extra_products_slug_index.spree.rb
new file mode 100644
index 0000000..f68a313
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145935_remove_extra_products_slug_index.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20141215235502)
+class RemoveExtraProductsSlugIndex < ActiveRecord::Migration[4.2]
+ def change
+ remove_index :spree_products, name: :permalink_idx_unique
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145936_update_product_slug_index.spree.rb b/spec/dummy/db/migrate/20200218145936_update_product_slug_index.spree.rb
new file mode 100644
index 0000000..4329fc5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145936_update_product_slug_index.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20141217215630)
+class UpdateProductSlugIndex < ActiveRecord::Migration[4.2]
+ def change
+ remove_index :spree_products, :slug if index_exists?(:spree_products, :slug)
+ add_index :spree_products, :slug, unique: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145937_rename_identifier_to_number_for_payment.spree.rb b/spec/dummy/db/migrate/20200218145937_rename_identifier_to_number_for_payment.spree.rb
new file mode 100644
index 0000000..1c8bc97
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145937_rename_identifier_to_number_for_payment.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20141218025915)
+class RenameIdentifierToNumberForPayment < ActiveRecord::Migration[4.2]
+ def change
+ rename_column :spree_payments, :identifier, :number
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145938_create_spree_store_credits.spree.rb b/spec/dummy/db/migrate/20200218145938_create_spree_store_credits.spree.rb
new file mode 100644
index 0000000..9a606d8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145938_create_spree_store_credits.spree.rb
@@ -0,0 +1,25 @@
+# This migration comes from spree (originally 20150118210639)
+class CreateSpreeStoreCredits < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_store_credits do |t|
+ t.references :user
+ t.references :category
+ t.references :created_by
+ t.decimal :amount, precision: 8, scale: 2, default: 0.0, null: false
+ t.decimal :amount_used, precision: 8, scale: 2, default: 0.0, null: false
+ t.text :memo
+ t.datetime :deleted_at
+ t.string :currency
+ t.decimal :amount_authorized, precision: 8, scale: 2, default: 0.0, null: false
+ t.integer :originator_id
+ t.string :originator_type
+ t.integer :type_id
+ t.timestamps null: false, precision: 6
+ end
+
+ add_index :spree_store_credits, :deleted_at
+ add_index :spree_store_credits, :user_id
+ add_index :spree_store_credits, :type_id
+ add_index :spree_store_credits, [:originator_id, :originator_type], name: :spree_store_credits_originator
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145939_create_spree_store_credit_categories.spree.rb b/spec/dummy/db/migrate/20200218145939_create_spree_store_credit_categories.spree.rb
new file mode 100644
index 0000000..56c3069
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145939_create_spree_store_credit_categories.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20150118211500)
+class CreateSpreeStoreCreditCategories < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_store_credit_categories do |t|
+ t.string :name
+ t.timestamps null: false, precision: 6
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145940_create_spree_store_credit_events.spree.rb b/spec/dummy/db/migrate/20200218145940_create_spree_store_credit_events.spree.rb
new file mode 100644
index 0000000..c232340
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145940_create_spree_store_credit_events.spree.rb
@@ -0,0 +1,18 @@
+# This migration comes from spree (originally 20150118212051)
+class CreateSpreeStoreCreditEvents < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_store_credit_events do |t|
+ t.integer :store_credit_id, null: false
+ t.string :action, null: false
+ t.decimal :amount, precision: 8, scale: 2
+ t.string :authorization_code, null: false
+ t.decimal :user_total_amount, precision: 8, scale: 2, default: 0.0, null: false
+ t.integer :originator_id
+ t.string :originator_type
+ t.datetime :deleted_at
+ t.timestamps null: false, precision: 6
+ end
+ add_index :spree_store_credit_events, :store_credit_id
+ add_index :spree_store_credit_events, [:originator_id, :originator_type], name: :spree_store_credit_events_originator
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145941_create_spree_store_credit_types.spree.rb b/spec/dummy/db/migrate/20200218145941_create_spree_store_credit_types.spree.rb
new file mode 100644
index 0000000..09cc0c6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145941_create_spree_store_credit_types.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20150118212101)
+class CreateSpreeStoreCreditTypes < ActiveRecord::Migration[4.2]
+ def change
+ create_table :spree_store_credit_types do |t|
+ t.string :name
+ t.integer :priority
+ t.timestamps null: false, precision: 6
+ end
+ add_index :spree_store_credit_types, :priority
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145942_remove_environment_from_payment_method.spree.rb b/spec/dummy/db/migrate/20200218145942_remove_environment_from_payment_method.spree.rb
new file mode 100644
index 0000000..5f634e2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145942_remove_environment_from_payment_method.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20150121022521)
+class RemoveEnvironmentFromPaymentMethod < ActiveRecord::Migration[4.2]
+ def up
+ Spree::PaymentMethod.where('environment != ?', Rails.env).update_all(active: false)
+ remove_column :spree_payment_methods, :environment
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145943_add_resellable_to_return_items.spree.rb b/spec/dummy/db/migrate/20200218145943_add_resellable_to_return_items.spree.rb
new file mode 100644
index 0000000..78e029b
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145943_add_resellable_to_return_items.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20150122145607)
+class AddResellableToReturnItems < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_return_items, :resellable, :boolean, default: true, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145944_add_code_to_spree_promotion_categories.spree.rb b/spec/dummy/db/migrate/20200218145944_add_code_to_spree_promotion_categories.spree.rb
new file mode 100644
index 0000000..d813251
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145944_add_code_to_spree_promotion_categories.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20150122202432)
+class AddCodeToSpreePromotionCategories < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_promotion_categories, :code, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145945_remove_environment_from_tracker.spree.rb b/spec/dummy/db/migrate/20200218145945_remove_environment_from_tracker.spree.rb
new file mode 100644
index 0000000..c5dd5e4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145945_remove_environment_from_tracker.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20150128032538)
+class RemoveEnvironmentFromTracker < ActiveRecord::Migration[4.2]
+ class Spree::Tracker < Spree::Base; end
+
+ def up
+ Spree::Tracker.where('environment != ?', Rails.env).update_all(active: false)
+ remove_column :spree_trackers, :environment
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145946_remove_spree_configurations.spree.rb b/spec/dummy/db/migrate/20200218145946_remove_spree_configurations.spree.rb
new file mode 100644
index 0000000..5ce2df7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145946_remove_spree_configurations.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20150128060325)
+class RemoveSpreeConfigurations < ActiveRecord::Migration[4.2]
+ def up
+ drop_table "spree_configurations"
+ end
+
+ def down
+ create_table "spree_configurations", force: true do |t|
+ t.string "name"
+ t.string "type", limit: 50
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "spree_configurations", ["name", "type"], name: "index_spree_configurations_on_name_and_type"
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145947_add_index_to_spree_stock_items_variant_id.spree.rb b/spec/dummy/db/migrate/20200218145947_add_index_to_spree_stock_items_variant_id.spree.rb
new file mode 100644
index 0000000..f629919
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145947_add_index_to_spree_stock_items_variant_id.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20150216173445)
+class AddIndexToSpreeStockItemsVariantId < ActiveRecord::Migration[4.2]
+ def up
+ unless index_exists? :spree_stock_items, :variant_id
+ add_index :spree_stock_items, :variant_id
+ end
+ end
+
+ def down
+ if index_exists? :spree_stock_items, :variant_id
+ remove_index :spree_stock_items, :variant_id
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145948_ensure_payments_have_numbers.spree.rb b/spec/dummy/db/migrate/20200218145948_ensure_payments_have_numbers.spree.rb
new file mode 100644
index 0000000..8a994e9
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145948_ensure_payments_have_numbers.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20150309161154)
+class EnsurePaymentsHaveNumbers < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_payments, :number unless index_exists?(:spree_payments, :number)
+ Spree::Payment.where(number: nil).find_each do |payment|
+ begin
+ payment.save! # to generate a new number we need to save the record
+ rescue ActiveRecord::RecordNotSaved
+ Rails.logger.error("Payment with ID = #{payment.id} couldn't be saved")
+ Rails.logger.error(payment.errors.full_messages.to_sentence)
+ end
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145949_add_missing_indexes_on_spree_tables.spree.rb b/spec/dummy/db/migrate/20200218145949_add_missing_indexes_on_spree_tables.spree.rb
new file mode 100644
index 0000000..b86e526
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145949_add_missing_indexes_on_spree_tables.spree.rb
@@ -0,0 +1,68 @@
+# This migration comes from spree (originally 20150314013438)
+class AddMissingIndexesOnSpreeTables < ActiveRecord::Migration[4.2]
+ def change
+ if data_source_exists?(:spree_promotion_rules_users) && !index_exists?(:spree_promotion_rules_users,
+ [:user_id, :promotion_rule_id],
+ name: 'index_promotion_rules_users_on_user_id_and_promotion_rule_id')
+ add_index :spree_promotion_rules_users,
+ [:user_id, :promotion_rule_id],
+ name: 'index_promotion_rules_users_on_user_id_and_promotion_rule_id'
+ end
+
+ if data_source_exists?(:spree_products_promotion_rules) && !index_exists?(:spree_products_promotion_rules,
+ [:promotion_rule_id, :product_id],
+ name: 'index_products_promotion_rules_on_promotion_rule_and_product')
+ add_index :spree_products_promotion_rules,
+ [:promotion_rule_id, :product_id],
+ name: 'index_products_promotion_rules_on_promotion_rule_and_product'
+ end
+
+ unless index_exists? :spree_orders, :canceler_id
+ add_index :spree_orders, :canceler_id
+ end
+
+ unless index_exists? :spree_orders, :store_id
+ add_index :spree_orders, :store_id
+ end
+
+ if data_source_exists?(:spree_orders_promotions) && !index_exists?(:spree_orders_promotions, [:promotion_id, :order_id])
+ add_index :spree_orders_promotions, [:promotion_id, :order_id]
+ end
+
+ if data_source_exists?(:spree_properties_prototypes) && !index_exists?(:spree_properties_prototypes, :prototype_id)
+ add_index :spree_properties_prototypes, :prototype_id
+ end
+
+ if data_source_exists?(:spree_properties_prototypes) && !index_exists?(:spree_properties_prototypes,
+ [:prototype_id, :property_id],
+ name: 'index_properties_prototypes_on_prototype_and_property')
+ add_index :spree_properties_prototypes,
+ [:prototype_id, :property_id],
+ name: 'index_properties_prototypes_on_prototype_and_property'
+ end
+
+ if data_source_exists?(:spree_taxons_prototypes) && !index_exists?(:spree_taxons_prototypes, [:prototype_id, :taxon_id])
+ add_index :spree_taxons_prototypes, [:prototype_id, :taxon_id]
+ end
+
+ if data_source_exists?(:spree_option_types_prototypes) && !index_exists?(:spree_option_types_prototypes, :prototype_id)
+ add_index :spree_option_types_prototypes, :prototype_id
+ end
+
+ if data_source_exists?(:spree_option_types_prototypes) && !index_exists?(:spree_option_types_prototypes,
+ [:prototype_id, :option_type_id],
+ name: 'index_option_types_prototypes_on_prototype_and_option_type')
+ add_index :spree_option_types_prototypes,
+ [:prototype_id, :option_type_id],
+ name: 'index_option_types_prototypes_on_prototype_and_option_type'
+ end
+
+ if data_source_exists?(:spree_option_values_variants) && !index_exists?(:spree_option_values_variants,
+ [:option_value_id, :variant_id],
+ name: 'index_option_values_variants_on_option_value_and_variant')
+ add_index :spree_option_values_variants,
+ [:option_value_id, :variant_id],
+ name: 'index_option_values_variants_on_option_value_and_variant'
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145950_remove_duplicated_indexes_from_multi_columns.spree.rb b/spec/dummy/db/migrate/20200218145950_remove_duplicated_indexes_from_multi_columns.spree.rb
new file mode 100644
index 0000000..deb4011
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145950_remove_duplicated_indexes_from_multi_columns.spree.rb
@@ -0,0 +1,19 @@
+# This migration comes from spree (originally 20150317174308)
+class RemoveDuplicatedIndexesFromMultiColumns < ActiveRecord::Migration[4.2]
+ def change
+ remove_index :spree_adjustments, name: "index_adjustments_on_order_id"
+ remove_index :spree_option_types_prototypes, :prototype_id
+ add_index :spree_option_types_prototypes, :option_type_id
+ remove_index :spree_option_values_variants, name: 'index_option_values_variants_on_option_value_and_variant'
+ remove_index :spree_option_values_variants, :variant_id
+ add_index :spree_option_values_variants, :option_value_id
+ remove_index :spree_orders, :user_id
+ remove_index :spree_orders_promotions, [:order_id, :promotion_id]
+ add_index :spree_orders_promotions, :order_id
+ remove_index :spree_products_promotion_rules, name: "index_products_promotion_rules_on_promotion_rule_id"
+ remove_index :spree_promotion_rules_users, name: "index_promotion_rules_users_on_user_id"
+ remove_index :spree_properties_prototypes, :prototype_id
+ remove_index :spree_stock_items, :stock_location_id
+ remove_index :spree_taxons_prototypes, :prototype_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145951_remove_user_index_from_spree_state_changes.spree.rb b/spec/dummy/db/migrate/20200218145951_remove_user_index_from_spree_state_changes.spree.rb
new file mode 100644
index 0000000..f8eee7c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145951_remove_user_index_from_spree_state_changes.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20150324104002)
+class RemoveUserIndexFromSpreeStateChanges < ActiveRecord::Migration[4.2]
+ def up
+ if index_exists? :spree_state_changes, :user_id
+ remove_index :spree_state_changes, :user_id
+ end
+
+ end
+
+ def down
+ unless index_exists? :spree_state_changes, :user_id
+ add_index :spree_state_changes, :user_id
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145952_fix_adjustment_order_id.spree.rb b/spec/dummy/db/migrate/20200218145952_fix_adjustment_order_id.spree.rb
new file mode 100644
index 0000000..26cc07e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145952_fix_adjustment_order_id.spree.rb
@@ -0,0 +1,71 @@
+# This migration comes from spree (originally 20150515211137)
+class FixAdjustmentOrderId < ActiveRecord::Migration[4.2]
+ def change
+ say 'Populate order_id from adjustable_id where appropriate'
+ execute(<<-SQL.squish)
+ UPDATE
+ spree_adjustments
+ SET
+ order_id = adjustable_id
+ WHERE
+ adjustable_type = 'Spree::Order'
+ ;
+ SQL
+
+ # Submitter of change does not care about MySQL, as it is not officially supported.
+ # Still spree officials decided to provide a working code path for MySQL users, hence
+ # submitter made a AR code path he could validate on PostgreSQL.
+ #
+ # Whoever runs a big enough MySQL installation where the AR solution hurts:
+ # Will have to write a better MySQL specific equivalent.
+ if Spree::Order.connection.adapter_name.eql?('MySQL')
+ Spree::Adjustment.where(adjustable_type: 'Spree::LineItem').find_each do |adjustment|
+ adjustment.update_columns(order_id: Spree::LineItem.find(adjustment.adjustable_id).order_id)
+ end
+ else
+ execute(<<-SQL.squish)
+ UPDATE
+ spree_adjustments
+ SET
+ order_id =
+ (SELECT order_id FROM spree_line_items WHERE spree_line_items.id = spree_adjustments.adjustable_id)
+ WHERE
+ adjustable_type = 'Spree::LineItem'
+ SQL
+ end
+
+ say 'Fix schema for spree_adjustments order_id column'
+ change_table :spree_adjustments do |t|
+ t.change :order_id, :integer, null: false
+ end
+
+ # Improved schema for postgresql, uncomment if you like it:
+ #
+ # # Negated Logical implication.
+ # #
+ # # When adjustable_type is 'Spree::Order' (p) the adjustable_id must be order_id (q).
+ # #
+ # # When adjustable_type is NOT 'Spree::Order' the adjustable id allowed to be any value (including of order_id in
+ # # case foreign keys match). XOR does not work here.
+ # #
+ # # Postgresql does not have an operator for logical implication. So we need to build the following truth table
+ # # via AND with OR:
+ # #
+ # # p q | CHECK = !(p -> q)
+ # # -----------
+ # # t t | t
+ # # t f | f
+ # # f t | t
+ # # f f | t
+ # #
+ # # According to de-morgans law the logical implication q -> p is equivalent to !p || q
+ # #
+ # execute(<<-SQL.squish)
+ # ALTER TABLE ONLY spree_adjustments
+ # ADD CONSTRAINT fk_spree_adjustments FOREIGN KEY (order_id)
+ # REFERENCES spree_orders(id) ON UPDATE RESTRICT ON DELETE RESTRICT,
+ # ADD CONSTRAINT check_spree_adjustments_order_id CHECK
+ # (adjustable_type <> 'Spree::Order' OR order_id = adjustable_id);
+ # SQL
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145953_add_position_to_spree_payment_methods.spree.rb b/spec/dummy/db/migrate/20200218145953_add_position_to_spree_payment_methods.spree.rb
new file mode 100644
index 0000000..a1dca8c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145953_add_position_to_spree_payment_methods.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20150522071831)
+class AddPositionToSpreePaymentMethods < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_payment_methods, :position, :integer, default: 0
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145954_add_deleted_at_to_friendly_id_slugs.spree.rb b/spec/dummy/db/migrate/20200218145954_add_deleted_at_to_friendly_id_slugs.spree.rb
new file mode 100644
index 0000000..7e89dbe
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145954_add_deleted_at_to_friendly_id_slugs.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20150522181728)
+class AddDeletedAtToFriendlyIdSlugs < ActiveRecord::Migration[4.2]
+ def change
+ add_column :friendly_id_slugs, :deleted_at, :datetime
+ add_index :friendly_id_slugs, :deleted_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145955_increase_scale_on_pre_tax_amounts.spree.rb b/spec/dummy/db/migrate/20200218145955_increase_scale_on_pre_tax_amounts.spree.rb
new file mode 100644
index 0000000..7b6b613
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145955_increase_scale_on_pre_tax_amounts.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20150609093816)
+class IncreaseScaleOnPreTaxAmounts < ActiveRecord::Migration[4.2]
+ def change
+ # set pre_tax_amount on shipments to discounted_amount - included_tax_total
+ # so that the null: false option on the shipment pre_tax_amount doesn't generate
+ # errors.
+ #
+ execute(<<-SQL)
+ UPDATE spree_shipments
+ SET pre_tax_amount = (cost + promo_total) - included_tax_total
+ WHERE pre_tax_amount IS NULL;
+ SQL
+
+ change_column :spree_line_items, :pre_tax_amount, :decimal, precision: 12, scale: 4, default: 0.0, null: false
+ change_column :spree_shipments, :pre_tax_amount, :decimal, precision: 12, scale: 4, default: 0.0, null: false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145956_add_taxable_adjustment_total_to_line_item.spree.rb b/spec/dummy/db/migrate/20200218145956_add_taxable_adjustment_total_to_line_item.spree.rb
new file mode 100644
index 0000000..74598ab
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145956_add_taxable_adjustment_total_to_line_item.spree.rb
@@ -0,0 +1,20 @@
+# This migration comes from spree (originally 20150626181949)
+class AddTaxableAdjustmentTotalToLineItem < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_line_items, :taxable_adjustment_total, :decimal,
+ precision: 10, scale: 2, default: 0.0, null: false
+ add_column :spree_line_items, :non_taxable_adjustment_total, :decimal,
+ precision: 10, scale: 2, default: 0.0, null: false
+
+ add_column :spree_shipments, :taxable_adjustment_total, :decimal,
+ precision: 10, scale: 2, default: 0.0, null: false
+ add_column :spree_shipments, :non_taxable_adjustment_total, :decimal,
+ precision: 10, scale: 2, default: 0.0, null: false
+
+ add_column :spree_orders, :taxable_adjustment_total, :decimal,
+ precision: 10, scale: 2, default: 0.0, null: false
+ add_column :spree_orders, :non_taxable_adjustment_total, :decimal,
+ precision: 10, scale: 2, default: 0.0, null: false
+ # TODO migration that updates old orders
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145957_migrate_payment_methods_display.spree.rb b/spec/dummy/db/migrate/20200218145957_migrate_payment_methods_display.spree.rb
new file mode 100644
index 0000000..957da5e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145957_migrate_payment_methods_display.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20150627090949)
+class MigratePaymentMethodsDisplay < ActiveRecord::Migration[4.2]
+ def change
+ Spree::PaymentMethod.all.each do |method|
+ if method.display_on.blank?
+ method.display_on = "both"
+ method.save
+ end
+ end
+
+ change_column :spree_payment_methods, :display_on, :string, default: "both"
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145958_enable_acts_as_paranoid_on_calculators.spree.rb b/spec/dummy/db/migrate/20200218145958_enable_acts_as_paranoid_on_calculators.spree.rb
new file mode 100644
index 0000000..b8fca5c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145958_enable_acts_as_paranoid_on_calculators.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20150707204155)
+class EnableActsAsParanoidOnCalculators < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_calculators, :deleted_at, :datetime
+ add_index :spree_calculators, :deleted_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145959_spree_payment_method_store_credits.spree.rb b/spec/dummy/db/migrate/20200218145959_spree_payment_method_store_credits.spree.rb
new file mode 100644
index 0000000..bf5dea2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145959_spree_payment_method_store_credits.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20150714154102)
+class SpreePaymentMethodStoreCredits < ActiveRecord::Migration[4.2]
+ def up
+ # Reload to pick up new position column for acts_as_list
+ Spree::PaymentMethod.reset_column_information
+ Spree::PaymentMethod::StoreCredit.find_or_create_by(name: 'Store Credit', description: 'Store Credit',
+ active: true, display_on: 'back_end')
+ end
+
+ def down
+ Spree::PaymentMethod.find_by(type: 'Spree::PaymentMethod::StoreCredit', name: 'Store Credit').try(&:destroy)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145960_rename_has_and_belongs_to_associations_to_model_names.spree.rb b/spec/dummy/db/migrate/20200218145960_rename_has_and_belongs_to_associations_to_model_names.spree.rb
new file mode 100644
index 0000000..4ee2c71
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145960_rename_has_and_belongs_to_associations_to_model_names.spree.rb
@@ -0,0 +1,19 @@
+# This migration comes from spree (originally 20150726141425)
+class RenameHasAndBelongsToAssociationsToModelNames < ActiveRecord::Migration[4.2]
+ def change
+ {
+ 'spree_option_types_prototypes' => 'spree_option_type_prototypes',
+ 'spree_option_values_variants' => 'spree_option_value_variants',
+ 'spree_orders_promotions' => 'spree_order_promotions',
+ 'spree_products_promotion_rules' => 'spree_product_promotion_rules',
+ 'spree_taxons_promotion_rules' => 'spree_promotion_rule_taxons',
+ 'spree_promotion_rules_users' => 'spree_promotion_rule_users',
+ 'spree_properties_prototypes' => 'spree_property_prototypes',
+ 'spree_taxons_prototypes' => 'spree_prototype_taxons',
+ 'spree_roles_users' => 'spree_role_users',
+ 'spree_shipping_methods_zones' => 'spree_shipping_method_zones'
+ }.each do |old_name, new_name|
+ rename_table old_name, new_name
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145961_spree_store_credit_types.spree.rb b/spec/dummy/db/migrate/20200218145961_spree_store_credit_types.spree.rb
new file mode 100644
index 0000000..74dd3b2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145961_spree_store_credit_types.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20150727191614)
+class SpreeStoreCreditTypes < ActiveRecord::Migration[4.2]
+ def up
+ Spree::StoreCreditType.find_or_create_by(name: 'Expiring', priority: 1)
+ Spree::StoreCreditType.find_or_create_by(name: 'Non-expiring', priority: 2)
+ end
+
+ def down
+ Spree::StoreCreditType.find_by(name: 'Expiring').try(&:destroy)
+ Spree::StoreCreditType.find_by(name: 'Non-expiring').try(&:destroy)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145962_add_discontinued_to_products_and_variants.spree.rb b/spec/dummy/db/migrate/20200218145962_add_discontinued_to_products_and_variants.spree.rb
new file mode 100644
index 0000000..0e55be5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145962_add_discontinued_to_products_and_variants.spree.rb
@@ -0,0 +1,69 @@
+# This migration comes from spree (originally 20150819154308)
+class AddDiscontinuedToProductsAndVariants < ActiveRecord::Migration[4.2]
+ def up
+ add_column :spree_products, :discontinue_on, :datetime, after: :available_on
+ add_column :spree_variants, :discontinue_on, :datetime, after: :deleted_at
+
+ add_index :spree_products, :discontinue_on
+ add_index :spree_variants, :discontinue_on
+
+ puts "Warning: This migration changes the meaning of 'deleted'. Before this change, 'deleted' meant products that were no longer being sold in your store. After this change, you can only delete a product or variant if it has not already been sold to a customer (a model-level check enforces this). Instead, you should use the new field 'discontinue_on' for products or variants which were sold in the past but no longer for sale. This fixes bugs when other objects are attached to deleted products and variants. (Even though acts_as_paranoid gem keeps the records in the database, most associations are automatically scoped to exclude the deleted records.) In thew meaning of 'deleted,' you can still use the delete function on products & variants which are *truly user-error mistakes*, specifically before an order has been placed or the items have gone on sale. You also must use the soft-delete function (which still works after this change) to clean up slug (product) and SKU (variant) duplicates. Otherwise, you should generally over ever need to discontinue products.
+
+Data Fix: We will attempt to reverse engineer the old meaning of 'deleted' (no longer for sale) to the new database field 'discontinue_on'. However, since Slugs and SKUs cannot be duplicated on Products and Variants, we cannot gaurantee this to be foolproof if you have deteled Products and Variants that have duplicate Slugs or SKUs in non-deleted records. In these cases, we recommend you use the additional rake task to clean up your old records (see rake db:fix_orphan_line_items). If you have such records, this migration will leave them in place, preferring the non-deleted records over the deleted ones. However, since old line items will still be associated with deleted objects, you will still the bugs in your app until you run:
+
+rake db:fix_orphan_line_items
+
+We will print out a report of the data we are fixing now: "
+
+ Spree::Product.only_deleted.each do |product|
+ # determine if there is a slug duplicate
+ the_dup = Spree::Product.find_by(slug: product.slug)
+ if the_dup.nil?
+ # check to see if there are line items attached to any variants
+ if Spree::Variant.with_deleted.where(product_id: product.id).map(&:line_items).any?
+ puts "recovering deleted product id #{product.id} ... this will un-delete the record and set it to be discontinued"
+
+ old_deleted = product.deleted_at
+ product.update_column(:deleted_at, nil) # for some reason .recover doesn't appear to be a method
+ product.update_column(:discontinue_on, old_deleted)
+ else
+ puts "leaving product id #{product.id} deleted because there are no line items attached to it..."
+ end
+ else
+ puts "leaving product id #{product.id} deleted because there is a duplicate slug for '#{product.slug}' (product id #{the_dup.id}) "
+ if product.variants.map(&:line_items).any?
+ puts "WARNING: You may still have bugs with product id #{product.id} (#{product.name}) until you run rake db:fix_orphan_line_items"
+ end
+ end
+ end
+
+ Spree::Variant.only_deleted.each do |variant|
+ # determine if there is a slug duplicate
+ the_dup = Spree::Variant.find_by(sku: variant.sku)
+ if the_dup.nil?
+ # check to see if there are line items attached to any variants
+ if variant.line_items.any?
+ puts "recovering deleted variant id #{variant.id} ... this will un-delete the record and set it to be discontinued"
+ old_deleted = variant.deleted_at
+ variant.update_column(:deleted_at, nil) # for some reason .recover doesn't appear to be a method
+ variant.update_column(:discontinue_on, old_deleted)
+ else
+ puts "leaving variant id #{variant.id} deleted because there are no line items attached to it..."
+ end
+ else
+ puts "leaving variant id #{variant.id} deleted because there is a duplicate SKU for '#{variant.sku}' (variant id #{the_dup.id}) "
+ if variant.line_items.any?
+ puts "WARNING: You may still have bugs with variant id #{variant.id} (#{variant.name}) until you run rake db:fix_orphan_line_items"
+ end
+ end
+ end
+ end
+
+ def down
+ execute "UPDATE spree_products SET deleted_at = discontinue_on WHERE deleted_at IS NULL"
+ execute "UPDATE spree_variants SET deleted_at = discontinue_on WHERE deleted_at IS NULL"
+
+ remove_column :spree_products, :discontinue_on
+ remove_column :spree_variants, :discontinue_on
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145963_remove_shipping_method_id_from_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145963_remove_shipping_method_id_from_spree_orders.spree.rb
new file mode 100644
index 0000000..383f9ae
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145963_remove_shipping_method_id_from_spree_orders.spree.rb
@@ -0,0 +1,14 @@
+# This migration comes from spree (originally 20151220072838)
+class RemoveShippingMethodIdFromSpreeOrders < ActiveRecord::Migration[4.2]
+ def up
+ if column_exists?(:spree_orders, :shipping_method_id, :integer)
+ remove_column :spree_orders, :shipping_method_id, :integer
+ end
+ end
+
+ def down
+ unless column_exists?(:spree_orders, :shipping_method_id, :integer)
+ add_column :spree_orders, :shipping_method_id, :integer
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145964_add_id_column_to_earlier_habtm_tables.spree.rb b/spec/dummy/db/migrate/20200218145964_add_id_column_to_earlier_habtm_tables.spree.rb
new file mode 100644
index 0000000..ff258a8
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145964_add_id_column_to_earlier_habtm_tables.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20160207191757)
+class AddIdColumnToEarlierHabtmTables < ActiveRecord::Migration[4.2]
+ def up
+ add_column :spree_option_type_prototypes, :id, :primary_key
+ add_column :spree_option_value_variants, :id, :primary_key
+ add_column :spree_order_promotions, :id, :primary_key
+ add_column :spree_product_promotion_rules, :id, :primary_key
+ add_column :spree_promotion_rule_users, :id, :primary_key
+ add_column :spree_property_prototypes, :id, :primary_key
+ add_column :spree_role_users, :id, :primary_key
+ add_column :spree_shipping_method_zones, :id, :primary_key
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145965_add_indexes.spree.rb b/spec/dummy/db/migrate/20200218145965_add_indexes.spree.rb
new file mode 100644
index 0000000..acd5871
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145965_add_indexes.spree.rb
@@ -0,0 +1,15 @@
+# This migration comes from spree (originally 20160219165458)
+class AddIndexes < ActiveRecord::Migration[4.2]
+ def change
+ add_index :spree_assets, :position
+ add_index :spree_option_types, :name
+ add_index :spree_option_values, :name
+ add_index :spree_prices, :variant_id
+ add_index :spree_properties, :name
+ add_index :spree_roles, :name
+ add_index :spree_shipping_categories, :name
+ add_index :spree_taxons, :lft
+ add_index :spree_taxons, :rgt
+ add_index :spree_taxons, :name
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145966_remove_counter_cache_from_spree_variants_to_spree_stock_items.spree.rb b/spec/dummy/db/migrate/20200218145966_remove_counter_cache_from_spree_variants_to_spree_stock_items.spree.rb
new file mode 100644
index 0000000..9f148e4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145966_remove_counter_cache_from_spree_variants_to_spree_stock_items.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20160509064646)
+class RemoveCounterCacheFromSpreeVariantsToSpreeStockItems < ActiveRecord::Migration[4.2]
+ def up
+ if column_exists?(:spree_variants, :stock_items_count)
+ remove_column :spree_variants, :stock_items_count
+ end
+ end
+
+ def down
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145967_add_zipcode_required_to_spree_countries.spree.rb b/spec/dummy/db/migrate/20200218145967_add_zipcode_required_to_spree_countries.spree.rb
new file mode 100644
index 0000000..83de5a6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145967_add_zipcode_required_to_spree_countries.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20160608090604)
+class AddZipcodeRequiredToSpreeCountries < ActiveRecord::Migration[4.2]
+ def change
+ add_column :spree_countries, :zipcode_required, :boolean, default: true
+ Spree::Country.reset_column_information
+ Spree::Country.where(iso: Spree::Address::NO_ZIPCODE_ISO_CODES).update_all(zipcode_required: false)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145968_add_created_at_to_variant.spree.rb b/spec/dummy/db/migrate/20200218145968_add_created_at_to_variant.spree.rb
new file mode 100644
index 0000000..0727fc5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145968_add_created_at_to_variant.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20161014145148)
+class AddCreatedAtToVariant < ActiveRecord::Migration[5.0]
+ def change
+ add_column :spree_variants, :created_at, :datetime
+ Spree::Variant.reset_column_information
+ Spree::Variant.unscoped.where.not(updated_at: nil).update_all('created_at = updated_at')
+ Spree::Variant.unscoped.where(updated_at: nil).update_all(created_at: Time.current, updated_at: Time.current)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145969_add_null_false_to_spree_variants_timestamps.spree.rb b/spec/dummy/db/migrate/20200218145969_add_null_false_to_spree_variants_timestamps.spree.rb
new file mode 100644
index 0000000..c4f81d2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145969_add_null_false_to_spree_variants_timestamps.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20161014152814)
+class AddNullFalseToSpreeVariantsTimestamps < ActiveRecord::Migration[5.0]
+ def change
+ change_column_null :spree_variants, :created_at, false
+ change_column_null :spree_variants, :updated_at, false
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145970_add_quantity_to_inventory_units.spree.rb b/spec/dummy/db/migrate/20200218145970_add_quantity_to_inventory_units.spree.rb
new file mode 100644
index 0000000..23c1f56
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145970_add_quantity_to_inventory_units.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20161125065505)
+class AddQuantityToInventoryUnits < ActiveRecord::Migration[5.0]
+ def change
+ add_column :spree_inventory_units, :quantity, :integer, default: 1
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145971_add_original_return_item_id_to_spree_inventory_units.spree.rb b/spec/dummy/db/migrate/20200218145971_add_original_return_item_id_to_spree_inventory_units.spree.rb
new file mode 100644
index 0000000..f9e2958
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145971_add_original_return_item_id_to_spree_inventory_units.spree.rb
@@ -0,0 +1,30 @@
+# This migration comes from spree (originally 20170119122701)
+class AddOriginalReturnItemIdToSpreeInventoryUnits < ActiveRecord::Migration[5.0]
+ def up
+ add_reference :spree_inventory_units, :original_return_item, references: :spree_return_items, index: true
+
+ Spree::InventoryUnit.reset_column_information
+
+ Spree::ReturnItem.where.not(exchange_inventory_unit_id: nil).find_each do |return_item|
+ if (inventory_unit = Spree::InventoryUnit.find_by(id: return_item.exchange_inventory_unit_id)).present?
+ inventory_unit.update_column(:original_return_item_id, return_item.id)
+ end
+ end
+
+ remove_column :spree_return_items, :exchange_inventory_unit_id
+ end
+
+ def down
+ add_reference :spree_return_items, :exchange_inventory_unit, references: :spree_inventory_units, index: true
+
+ Spree::InventoryUnit.reset_column_information
+
+ Spree::InventoryUnit.where.not(original_return_item_id: nil).find_each do |inventory_unit|
+ if (return_item = Spree::ReturnItem.find_by(id: inventory_unit.original_return_item_id)).present?
+ return_item.update_column(:exchange_inventory_unit_id, inventory_unit.id)
+ end
+ end
+
+ remove_reference :spree_inventory_units, :original_return_item
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145972_add_unique_index_on_number_to_spree_orders.spree.rb b/spec/dummy/db/migrate/20200218145972_add_unique_index_on_number_to_spree_orders.spree.rb
new file mode 100644
index 0000000..432d8db
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145972_add_unique_index_on_number_to_spree_orders.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20170315152755)
+class AddUniqueIndexOnNumberToSpreeOrders < ActiveRecord::Migration[5.0]
+ def change
+ unless index_exists?(:spree_orders, :number, unique: true)
+ numbers = Spree::Order.group(:number).having('sum(1) > 1').pluck(:number)
+ orders = Spree::Order.where(number: numbers)
+
+ orders.find_each do |order|
+ order.number = order.class.number_generator.method(:generate_permalink).call(order.class)
+ order.save
+ end
+
+ remove_index :spree_orders, :number if index_exists?(:spree_orders, :number)
+ add_index :spree_orders, :number, unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145973_add_unique_index_on_number_to_spree_stock_transfer.spree.rb b/spec/dummy/db/migrate/20200218145973_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
new file mode 100644
index 0000000..0c7bdbd
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145973_add_unique_index_on_number_to_spree_stock_transfer.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20170316154338)
+class AddUniqueIndexOnNumberToSpreeStockTransfer < ActiveRecord::Migration[5.0]
+ def change
+ unless index_exists?(:spree_stock_transfers, :number, unique: true)
+ numbers = Spree::StockTransfer.group(:number).having('sum(1) > 1').pluck(:number)
+ transfers = Spree::StockTransfer.where(number: numbers)
+
+ transfers.find_each do |transfer|
+ transfer.number = transfer.class.number_generator.method(:generate_permalink).call(transfer.class)
+ transfer.save
+ end
+
+ remove_index :spree_stock_transfers, :number if index_exists?(:spree_stock_transfers, :number)
+ add_index :spree_stock_transfers, :number, unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145974_add_unique_index_on_number_to_spree_shipment.spree.rb b/spec/dummy/db/migrate/20200218145974_add_unique_index_on_number_to_spree_shipment.spree.rb
new file mode 100644
index 0000000..fef9469
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145974_add_unique_index_on_number_to_spree_shipment.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20170316205511)
+class AddUniqueIndexOnNumberToSpreeShipment < ActiveRecord::Migration[5.0]
+ def change
+ unless index_exists?(:spree_shipments, :number, unique: true)
+ numbers = Spree::Shipment.group(:number).having('sum(1) > 1').pluck(:number)
+ shipments = Spree::Shipment.where(number: numbers)
+
+ shipments.find_each do |shipment|
+ shipment.number = shipment.class.number_generator.method(:generate_permalink).call(shipment.class)
+ shipment.save
+ end
+
+ remove_index :spree_shipments, :number if index_exists?(:spree_shipments, :number)
+ add_index :spree_shipments, :number, unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145975_add_unique_index_on_number_to_spree_payments.spree.rb b/spec/dummy/db/migrate/20200218145975_add_unique_index_on_number_to_spree_payments.spree.rb
new file mode 100644
index 0000000..e8a4c7a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145975_add_unique_index_on_number_to_spree_payments.spree.rb
@@ -0,0 +1,18 @@
+# This migration comes from spree (originally 20170320134043)
+class AddUniqueIndexOnNumberToSpreePayments < ActiveRecord::Migration[5.0]
+ def change
+ unless index_exists?(:spree_payments, :number, unique: true)
+ # default scope in Spree::Payment disturbs Postgres, hence `unscoped` is needed.
+ numbers = Spree::Payment.unscoped.group(:number).having('sum(1) > 1').pluck(:number)
+ payments = Spree::Payment.where(number: numbers)
+
+ payments.find_each do |payment|
+ payment.number = payment.class.number_generator.method(:generate_permalink).call(payment.class)
+ payment.save
+ end
+
+ remove_index :spree_payments, :number if index_exists?(:spree_payments, :number)
+ add_index :spree_payments, :number, unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145976_add_unique_index_on_number_to_spree_return_authorizations.spree.rb b/spec/dummy/db/migrate/20200218145976_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
new file mode 100644
index 0000000..5ebece2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145976_add_unique_index_on_number_to_spree_return_authorizations.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20170320142750)
+class AddUniqueIndexOnNumberToSpreeReturnAuthorizations < ActiveRecord::Migration[5.0]
+ def change
+ unless index_exists?(:spree_return_authorizations, :number, unique: true)
+ numbers = Spree::ReturnAuthorization.group(:number).having('sum(1) > 1').pluck(:number)
+ authorizations = Spree::ReturnAuthorization.where(number: numbers)
+
+ authorizations.find_each do |authorization|
+ authorization.number = authorization.class.number_generator.method(:generate_permalink).call(authorization.class)
+ authorization.save
+ end
+
+ remove_index :spree_return_authorizations, :number if index_exists?(:spree_return_authorizations, :number)
+ add_index :spree_return_authorizations, :number, unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145977_add_unique_index_on_number_to_spree_customer_returns.spree.rb b/spec/dummy/db/migrate/20200218145977_add_unique_index_on_number_to_spree_customer_returns.spree.rb
new file mode 100644
index 0000000..2a8f3cd
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145977_add_unique_index_on_number_to_spree_customer_returns.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20170320145040)
+class AddUniqueIndexOnNumberToSpreeCustomerReturns < ActiveRecord::Migration[5.0]
+ def change
+ unless index_exists?(:spree_customer_returns, :number, unique: true)
+ numbers = Spree::CustomerReturn.group(:number).having('sum(1) > 1').pluck(:number)
+ returns = Spree::CustomerReturn.where(number: numbers)
+
+ returns.find_each do |r|
+ r.number = r.class.number_generator.method(:generate_permalink).call(r.class)
+ r.save
+ end
+
+ remove_index :spree_customer_returns, :number if index_exists?(:spree_customer_returns, :number)
+ add_index :spree_customer_returns, :number, unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145978_add_unique_index_on_number_to_spree_reimbursements.spree.rb b/spec/dummy/db/migrate/20200218145978_add_unique_index_on_number_to_spree_reimbursements.spree.rb
new file mode 100644
index 0000000..9bee6ba
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145978_add_unique_index_on_number_to_spree_reimbursements.spree.rb
@@ -0,0 +1,17 @@
+# This migration comes from spree (originally 20170320145518)
+class AddUniqueIndexOnNumberToSpreeReimbursements < ActiveRecord::Migration[5.0]
+ def change
+ unless index_exists?(:spree_reimbursements, :number, unique: true)
+ numbers = Spree::Reimbursement.group(:number).having('sum(1) > 1').pluck(:number)
+ reimbursements = Spree::Reimbursement.where(number: numbers)
+
+ reimbursements.find_each do |reimbursement|
+ reimbursement.number = reimbursement.class.number_generator.method(:generate_permalink).call(reimbursement.class)
+ reimbursement.save
+ end
+
+ remove_index :spree_reimbursements, :number if index_exists?(:spree_reimbursements, :number)
+ add_index :spree_reimbursements, :number, unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145979_add_missing_unique_indexes_for_unique_attributes.spree.rb b/spec/dummy/db/migrate/20200218145979_add_missing_unique_indexes_for_unique_attributes.spree.rb
new file mode 100644
index 0000000..d9c65d2
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145979_add_missing_unique_indexes_for_unique_attributes.spree.rb
@@ -0,0 +1,38 @@
+# This migration comes from spree (originally 20170323151450)
+class AddMissingUniqueIndexesForUniqueAttributes < ActiveRecord::Migration[5.0]
+ def change
+ tables = {
+ country: [:name, :iso_name],
+ refund_reason: [:name],
+ reimbursement_type: [:name],
+ return_authorization_reason: [:name],
+ role: [:name],
+ store: [:code]
+ }
+
+ tables.each do |table, columns|
+ table_class = "Spree::#{table.to_s.classify}".constantize
+ table_name = table_class.table_name
+
+ columns.each do |column|
+ unless index_exists?(table_name, column, unique: true)
+ attributes = table_class.unscoped.group(column).having('sum(1) > 1').pluck(column)
+ instances = table_class.where(column => [nil, attributes])
+
+ instances.find_each do |instance|
+ column_value = 'Unique String ' + SecureRandom.urlsafe_base64(8).upcase.delete('/+=_-')[0, 8]
+ instance.send("#{column}=", column_value)
+ instance.save
+ end
+
+ remove_index table_name, column if index_exists?(table_name, column)
+ if supports_expression_index?
+ add_index table_name, "(lower(#{column}))", unique: true
+ else
+ add_index table_name, column, unique: true
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145980_add_index_on_stock_location_to_spree_customer_returns.spree.rb b/spec/dummy/db/migrate/20200218145980_add_index_on_stock_location_to_spree_customer_returns.spree.rb
new file mode 100644
index 0000000..e6050ab
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145980_add_index_on_stock_location_to_spree_customer_returns.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170329110859)
+class AddIndexOnStockLocationToSpreeCustomerReturns < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_customer_returns, :stock_location_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145981_add_index_on_prototype_to_spree_option_type_prototype.spree.rb b/spec/dummy/db/migrate/20200218145981_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
new file mode 100644
index 0000000..70e37c7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145981_add_index_on_prototype_to_spree_option_type_prototype.spree.rb
@@ -0,0 +1,20 @@
+# This migration comes from spree (originally 20170329113917)
+class AddIndexOnPrototypeToSpreeOptionTypePrototype < ActiveRecord::Migration[5.0]
+ def change
+ duplicates = Spree::OptionTypePrototype.group(:prototype_id, :option_type_id).having('sum(1) > 1').size
+
+ duplicates.each do |f|
+ prototype_id, option_type_id = f.first
+ count = f.last - 1 # we want to leave one record
+ otp = Spree::OptionTypePrototype.where(prototype_id: prototype_id, option_type_id: option_type_id).last(count)
+ otp.map(&:destroy)
+ end
+
+ if index_exists? :spree_option_type_prototypes, [:prototype_id, :option_type_id]
+ remove_index :spree_option_type_prototypes, [:prototype_id, :option_type_id]
+ add_index :spree_option_type_prototypes, [:prototype_id, :option_type_id], unique: true, name: 'spree_option_type_prototypes_prototype_id_option_type_id'
+ end
+
+ add_index :spree_option_type_prototypes, :prototype_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145982_add_indexes_to_spree_option_value_variant.spree.rb b/spec/dummy/db/migrate/20200218145982_add_indexes_to_spree_option_value_variant.spree.rb
new file mode 100644
index 0000000..eca6593
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145982_add_indexes_to_spree_option_value_variant.spree.rb
@@ -0,0 +1,20 @@
+# This migration comes from spree (originally 20170330082155)
+class AddIndexesToSpreeOptionValueVariant < ActiveRecord::Migration[5.0]
+ def change
+ duplicates = Spree::OptionValueVariant.group(:variant_id, :option_value_id).having('sum(1) > 1').size
+
+ duplicates.each do |f|
+ variant_id, option_value_id = f.first
+ count = f.last - 1 # we want to leave one record
+ ov = Spree::OptionValueVariant.where(variant_id: variant_id, option_value_id: option_value_id).last(count)
+ ov.map(&:destroy)
+ end
+
+ if index_exists? :spree_option_value_variants, [:variant_id, :option_value_id], name: "index_option_values_variants_on_variant_id_and_option_value_id"
+ remove_index :spree_option_value_variants, [:variant_id, :option_value_id]
+ add_index :spree_option_value_variants, [:variant_id, :option_value_id], unique: true, name: "index_option_values_variants_on_variant_id_and_option_value_id"
+ end
+
+ add_index :spree_option_value_variants, :variant_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145983_add_index_on_promotion_id_to_order_promotions.spree.rb b/spec/dummy/db/migrate/20200218145983_add_index_on_promotion_id_to_order_promotions.spree.rb
new file mode 100644
index 0000000..b025bb7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145983_add_index_on_promotion_id_to_order_promotions.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170330132215)
+class AddIndexOnPromotionIdToOrderPromotions < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_order_promotions, :promotion_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145984_add_indexes_for_property_prototype.spree.rb b/spec/dummy/db/migrate/20200218145984_add_indexes_for_property_prototype.spree.rb
new file mode 100644
index 0000000..7f153e0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145984_add_indexes_for_property_prototype.spree.rb
@@ -0,0 +1,21 @@
+# This migration comes from spree (originally 20170331101758)
+class AddIndexesForPropertyPrototype < ActiveRecord::Migration[5.0]
+ def change
+ duplicates = Spree::PropertyPrototype.group(:prototype_id, :property_id).having('sum(1) > 1').size
+
+ duplicates.each do |f|
+ prototype_id, property_id = f.first
+ count = f.last - 1 # we want to leave one record
+ prototypes = Spree::PropertyPrototype.where(prototype_id: prototype_id, property_id: property_id).last(count)
+ prototypes.map(&:destroy)
+ end
+
+ if index_exists? :spree_property_prototypes, [:prototype_id, :property_id]
+ remove_index :spree_property_prototypes, [:prototype_id, :property_id]
+ add_index :spree_property_prototypes, [:prototype_id, :property_id], unique: true, name: 'index_property_prototypes_on_prototype_id_and_property_id'
+ end
+
+ add_index :spree_property_prototypes, :prototype_id
+ add_index :spree_property_prototypes, :property_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145985_add_index_for_prototype_id_to_prototype_taxons.spree.rb b/spec/dummy/db/migrate/20200218145985_add_index_for_prototype_id_to_prototype_taxons.spree.rb
new file mode 100644
index 0000000..ddefb69
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145985_add_index_for_prototype_id_to_prototype_taxons.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170331103334)
+class AddIndexForPrototypeIdToPrototypeTaxons < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_prototype_taxons, :prototype_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145986_add_indexes_to_refunds.spree.rb b/spec/dummy/db/migrate/20200218145986_add_indexes_to_refunds.spree.rb
new file mode 100644
index 0000000..9dd3207
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145986_add_indexes_to_refunds.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20170331110454)
+class AddIndexesToRefunds < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_refunds, :payment_id
+ add_index :spree_refunds, :reimbursement_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145987_add_indexes_to_reimbursement_credits.spree.rb b/spec/dummy/db/migrate/20200218145987_add_indexes_to_reimbursement_credits.spree.rb
new file mode 100644
index 0000000..1411c48
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145987_add_indexes_to_reimbursement_credits.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20170331111757)
+class AddIndexesToReimbursementCredits < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_reimbursement_credits, :reimbursement_id
+ add_index :spree_reimbursement_credits, [:creditable_id, :creditable_type], name: 'index_reimbursement_credits_on_creditable_id_and_type'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145988_add_indexes_to_return_authorizations.spree.rb b/spec/dummy/db/migrate/20200218145988_add_indexes_to_return_authorizations.spree.rb
new file mode 100644
index 0000000..dd5189b
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145988_add_indexes_to_return_authorizations.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20170331115246)
+class AddIndexesToReturnAuthorizations < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_return_authorizations, :order_id
+ add_index :spree_return_authorizations, :stock_location_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145989_add_indexes_to_return_items.spree.rb b/spec/dummy/db/migrate/20200218145989_add_indexes_to_return_items.spree.rb
new file mode 100644
index 0000000..7afd82a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145989_add_indexes_to_return_items.spree.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree (originally 20170331120125)
+class AddIndexesToReturnItems < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_return_items, :return_authorization_id
+ add_index :spree_return_items, :inventory_unit_id
+ add_index :spree_return_items, :reimbursement_id
+ add_index :spree_return_items, :exchange_variant_id
+ add_index :spree_return_items, :preferred_reimbursement_type_id
+ add_index :spree_return_items, :override_reimbursement_type_id
+ end
+end
+
diff --git a/spec/dummy/db/migrate/20200218145990_add_index_to_role_users.spree.rb b/spec/dummy/db/migrate/20200218145990_add_index_to_role_users.spree.rb
new file mode 100644
index 0000000..7173d9e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145990_add_index_to_role_users.spree.rb
@@ -0,0 +1,19 @@
+# This migration comes from spree (originally 20170331121725)
+class AddIndexToRoleUsers < ActiveRecord::Migration[5.0]
+ def change
+
+ duplicates = Spree::RoleUser.group(:role_id, :user_id).having('sum(1) > 1').size
+
+ duplicates.each do |f|
+ role_id, user_id = f.first
+ count = f.last - 1 # we want to leave one record
+ roles = Spree::RoleUser.where(role_id: role_id, user_id: user_id).last(count)
+ roles.map(&:destroy)
+ end
+
+ if index_exists? :spree_role_users, [:role_id, :user_id]
+ remove_index :spree_role_users, [:role_id, :user_id]
+ add_index :spree_role_users, [:role_id, :user_id], unique: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145991_add_index_to_shipping_method_categories.spree.rb b/spec/dummy/db/migrate/20200218145991_add_index_to_shipping_method_categories.spree.rb
new file mode 100644
index 0000000..5722249
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145991_add_index_to_shipping_method_categories.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170331123625)
+class AddIndexToShippingMethodCategories < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_shipping_method_categories, :shipping_category_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145992_add_index_to_shipping_method_zones.spree.rb b/spec/dummy/db/migrate/20200218145992_add_index_to_shipping_method_zones.spree.rb
new file mode 100644
index 0000000..f86b9d5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145992_add_index_to_shipping_method_zones.spree.rb
@@ -0,0 +1,21 @@
+# This migration comes from spree (originally 20170331123832)
+class AddIndexToShippingMethodZones < ActiveRecord::Migration[5.0]
+ def change
+ duplicates = Spree::ShippingMethodZone.group(:shipping_method_id, :zone_id).having('sum(1) > 1').size
+
+ duplicates.each do |f|
+ shipping_method_id, zone_id = f.first
+ count = f.last - 1 # we want to leave one record
+ zones = Spree::ShippingMethodZone.where(shipping_method_id: shipping_method_id, zone_id: zone_id).last(count)
+ zones.map(&:destroy)
+ end
+
+ if index_exists? :spree_shipping_method_zones, [:shipping_method_id, :zone_id]
+ remove_index :spree_shipping_method_zones, [:shipping_method_id, :zone_id]
+ add_index :spree_shipping_method_zones, [:shipping_method_id, :zone_id], unique: true
+ end
+
+ add_index :spree_shipping_method_zones, :zone_id
+ add_index :spree_shipping_method_zones, :shipping_method_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145993_add_index_to_spree_shipping_rates.spree.rb b/spec/dummy/db/migrate/20200218145993_add_index_to_spree_shipping_rates.spree.rb
new file mode 100644
index 0000000..7bf55ba
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145993_add_index_to_spree_shipping_rates.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20170331124251)
+class AddIndexToSpreeShippingRates < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_shipping_rates, :shipment_id
+ add_index :spree_shipping_rates, :shipping_method_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145994_add_index_to_spree_stock_items.spree.rb b/spec/dummy/db/migrate/20200218145994_add_index_to_spree_stock_items.spree.rb
new file mode 100644
index 0000000..0533fcd
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145994_add_index_to_spree_stock_items.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170331124513)
+class AddIndexToSpreeStockItems < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_stock_items, :stock_location_id
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145995_add_index_to_spree_stock_movement.spree.rb b/spec/dummy/db/migrate/20200218145995_add_index_to_spree_stock_movement.spree.rb
new file mode 100644
index 0000000..cf14454
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145995_add_index_to_spree_stock_movement.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170331124924)
+class AddIndexToSpreeStockMovement < ActiveRecord::Migration[5.0]
+ def change
+ add_index :spree_stock_movements, [:originator_id, :originator_type], name: 'index_stock_movements_on_originator_id_and_originator_type'
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145996_change_indexes_on_friendly_id_slugs.spree.rb b/spec/dummy/db/migrate/20200218145996_change_indexes_on_friendly_id_slugs.spree.rb
new file mode 100644
index 0000000..1240ff4
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145996_change_indexes_on_friendly_id_slugs.spree.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree (originally 20170413211707)
+class ChangeIndexesOnFriendlyIdSlugs < ActiveRecord::Migration[5.0]
+ def change
+ # Updating indexes to reflect changes in friendly_id v5.2
+ # See: https://github.com/norman/friendly_id/pull/694/commits/9f107f07ec9d2a58bda5a712b6e79a8d8013e0ab
+ remove_index :friendly_id_slugs, [:slug, :sluggable_type]
+ remove_index :friendly_id_slugs, [:slug, :sluggable_type, :scope]
+ add_index :friendly_id_slugs, [:slug, :sluggable_type], length: { name: 100, slug: 20, sluggable_type: 20 }
+ add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], length: { name: 100, slug: 20, sluggable_type: 20, scope: 20 }, unique: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145997_add_analytics_kind_to_spree_trackers.spree.rb b/spec/dummy/db/migrate/20200218145997_add_analytics_kind_to_spree_trackers.spree.rb
new file mode 100644
index 0000000..cc536c6
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145997_add_analytics_kind_to_spree_trackers.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170722102643)
+class AddAnalyticsKindToSpreeTrackers < ActiveRecord::Migration[5.1]
+ def change
+ add_column :spree_trackers, :kind, :integer, default: 0, null: false, index: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145998_rename_tracker_kind_field.spree.rb b/spec/dummy/db/migrate/20200218145998_rename_tracker_kind_field.spree.rb
new file mode 100644
index 0000000..631b631
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145998_rename_tracker_kind_field.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20170727103056)
+class RenameTrackerKindField < ActiveRecord::Migration[5.1]
+ def change
+ rename_column :spree_trackers, :kind, :engine
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218145999_remove_icon_from_taxons.spree.rb b/spec/dummy/db/migrate/20200218145999_remove_icon_from_taxons.spree.rb
new file mode 100644
index 0000000..ca15690
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218145999_remove_icon_from_taxons.spree.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree (originally 20171004223836)
+class RemoveIconFromTaxons < ActiveRecord::Migration[5.1]
+ def change
+ remove_column :spree_taxons, :icon_file_name if column_exists? :spree_taxons, :icon_file_name
+ remove_column :spree_taxons, :icon_content_type if column_exists? :spree_taxons, :icon_content_type
+ remove_column :spree_taxons, :icon_file_size if column_exists? :spree_taxons, :icon_file_size
+ remove_column :spree_taxons, :icon_updated_at if column_exists? :spree_taxons, :icon_updated_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146000_add_unique_index_on_spree_promotions_code.spree.rb b/spec/dummy/db/migrate/20200218146000_add_unique_index_on_spree_promotions_code.spree.rb
new file mode 100644
index 0000000..234d68c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146000_add_unique_index_on_spree_promotions_code.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20180222133746)
+class AddUniqueIndexOnSpreePromotionsCode < ActiveRecord::Migration[5.1]
+ def change
+ remove_index :spree_promotions, :code
+ add_index :spree_promotions, :code, unique: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146001_rename_guest_token_to_token_in_orders.spree.rb b/spec/dummy/db/migrate/20200218146001_rename_guest_token_to_token_in_orders.spree.rb
new file mode 100644
index 0000000..8ff786c
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146001_rename_guest_token_to_token_in_orders.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20180613080857)
+class RenameGuestTokenToTokenInOrders < ActiveRecord::Migration[5.2]
+ def change
+ rename_column :spree_orders, :guest_token, :token
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146002_add_timestamps_to_spree_prices.spree.rb b/spec/dummy/db/migrate/20200218146002_add_timestamps_to_spree_prices.spree.rb
new file mode 100644
index 0000000..ab37ab7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146002_add_timestamps_to_spree_prices.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20180915160001)
+class AddTimestampsToSpreePrices < ActiveRecord::Migration[5.2]
+ def up
+ add_timestamps :spree_prices, default: Time.current
+ change_column_default :spree_prices, :created_at, nil
+ change_column_default :spree_prices, :updated_at, nil
+ end
+
+ def down
+ remove_column :spree_prices, :created_at
+ remove_column :spree_prices, :updated_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146003_add_deleted_at_to_spree_credit_cards.spree.rb b/spec/dummy/db/migrate/20200218146003_add_deleted_at_to_spree_credit_cards.spree.rb
new file mode 100644
index 0000000..7a67528
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146003_add_deleted_at_to_spree_credit_cards.spree.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree (originally 20181024100754)
+class AddDeletedAtToSpreeCreditCards < ActiveRecord::Migration[5.2]
+ def change
+ add_column :spree_credit_cards, :deleted_at, :datetime
+ add_index :spree_credit_cards, :deleted_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146004_add_iso_and_iso3_validation_on_presence_and_uniqueness.spree.rb b/spec/dummy/db/migrate/20200218146004_add_iso_and_iso3_validation_on_presence_and_uniqueness.spree.rb
new file mode 100644
index 0000000..34a5c33
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146004_add_iso_and_iso3_validation_on_presence_and_uniqueness.spree.rb
@@ -0,0 +1,19 @@
+# This migration comes from spree (originally 20190305121659)
+class AddIsoAndIso3ValidationOnPresenceAndUniqueness < ActiveRecord::Migration[5.2]
+ def up
+ Spree::Country.where.not(id: Spree::Country.group(:iso).select("min(id)")).destroy_all
+ Spree::Country.where.not(id: Spree::Country.group(:iso3).select("min(id)")).destroy_all
+
+ change_column_null(:spree_countries, :iso, false)
+ change_column_null(:spree_countries, :iso3, false)
+ add_index :spree_countries, :iso, unique: true
+ add_index :spree_countries, :iso3, unique: true
+ end
+
+ def down
+ change_column_null(:spree_countries, :iso, true)
+ change_column_null(:spree_countries, :iso3, true)
+ remove_index :spree_countries, :iso, unique: true
+ remove_index :spree_countries, :iso3, unique: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146005_add_user_id_and_deleted_at_to_spree_addresses.spree.rb b/spec/dummy/db/migrate/20200218146005_add_user_id_and_deleted_at_to_spree_addresses.spree.rb
new file mode 100644
index 0000000..8b6203a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146005_add_user_id_and_deleted_at_to_spree_addresses.spree.rb
@@ -0,0 +1,13 @@
+# This migration comes from spree (originally 20190523092729)
+# this migration does the same as this two from SpreeAddressBook
+# https://github.com/spree-contrib/spree_address_book/blob/master/db/migrate/20110302102208_add_user_id_and_deleted_at_to_addresses.rb
+# https://github.com/spree-contrib/spree_address_book/blob/master/db/migrate/20170405133031_add_missing_indexes.rb
+class AddUserIdAndDeletedAtToSpreeAddresses < ActiveRecord::Migration[5.2]
+ def change
+ add_column :spree_addresses, :user_id, :integer unless column_exists?(:spree_addresses, :user_id)
+ add_index :spree_addresses, :user_id unless index_exists?(:spree_addresses, :user_id)
+
+ add_column :spree_addresses, :deleted_at, :datetime unless column_exists?(:spree_addresses, :deleted_at)
+ add_index :spree_addresses, :deleted_at unless index_exists?(:spree_addresses, :deleted_at)
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146006_add_store_id_to_payment_methods.spree.rb b/spec/dummy/db/migrate/20200218146006_add_store_id_to_payment_methods.spree.rb
new file mode 100644
index 0000000..3cd82bb
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146006_add_store_id_to_payment_methods.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20191005121504)
+class AddStoreIdToPaymentMethods < ActiveRecord::Migration[5.2]
+ def change
+ unless column_exists?(:spree_payment_methods, :store_id)
+ add_reference :spree_payment_methods, :store, references: :spree_stores, index: true
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146007_add_deafult_value_for_store_default_currency.spree.rb b/spec/dummy/db/migrate/20200218146007_add_deafult_value_for_store_default_currency.spree.rb
new file mode 100644
index 0000000..a6fa1a7
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146007_add_deafult_value_for_store_default_currency.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20191016134113)
+class AddDeafultValueForStoreDefaultCurrency < ActiveRecord::Migration[6.0]
+ def change
+ Spree::Store.where(default_currency: nil).update_all(default_currency: Spree::Config[:currency])
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146008_add_social_to_spree_stores.spree.rb b/spec/dummy/db/migrate/20200218146008_add_social_to_spree_stores.spree.rb
new file mode 100644
index 0000000..4b6b639
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146008_add_social_to_spree_stores.spree.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree (originally 20200102141311)
+class AddSocialToSpreeStores < ActiveRecord::Migration[6.0]
+ def change
+ add_column :spree_stores, :facebook, :string
+ add_column :spree_stores, :twitter, :string
+ add_column :spree_stores, :instagram, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146009_add_hide_from_nav_to_taxons.spree.rb b/spec/dummy/db/migrate/20200218146009_add_hide_from_nav_to_taxons.spree.rb
new file mode 100644
index 0000000..efa22ce
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146009_add_hide_from_nav_to_taxons.spree.rb
@@ -0,0 +1,6 @@
+# This migration comes from spree (originally 20200212144523)
+class AddHideFromNavToTaxons < ActiveRecord::Migration[6.0]
+ def change
+ add_column :spree_taxons, :hide_from_nav, :boolean, default: false, index: true
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146010_add_api_key_to_spree_users.spree_api.rb b/spec/dummy/db/migrate/20200218146010_add_api_key_to_spree_users.spree_api.rb
new file mode 100644
index 0000000..87d38cc
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146010_add_api_key_to_spree_users.spree_api.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree_api (originally 20100107141738)
+class AddApiKeyToSpreeUsers < ActiveRecord::Migration[4.2]
+ def change
+ unless defined?(User)
+ add_column :spree_users, :api_key, :string, limit: 40
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146011_resize_api_key_field.spree_api.rb b/spec/dummy/db/migrate/20200218146011_resize_api_key_field.spree_api.rb
new file mode 100644
index 0000000..4282004
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146011_resize_api_key_field.spree_api.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree_api (originally 20120411123334)
+class ResizeApiKeyField < ActiveRecord::Migration[4.2]
+ def change
+ unless defined?(User)
+ change_column :spree_users, :api_key, :string, limit: 48
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146012_rename_api_key_to_spree_api_key.spree_api.rb b/spec/dummy/db/migrate/20200218146012_rename_api_key_to_spree_api_key.spree_api.rb
new file mode 100644
index 0000000..60747db
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146012_rename_api_key_to_spree_api_key.spree_api.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree_api (originally 20120530054546)
+class RenameApiKeyToSpreeApiKey < ActiveRecord::Migration[4.2]
+ def change
+ unless defined?(User)
+ rename_column :spree_users, :api_key, :spree_api_key
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146013_add_index_to_user_spree_api_key.spree_api.rb b/spec/dummy/db/migrate/20200218146013_add_index_to_user_spree_api_key.spree_api.rb
new file mode 100644
index 0000000..ab7b732
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146013_add_index_to_user_spree_api_key.spree_api.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree_api (originally 20131017162334)
+class AddIndexToUserSpreeApiKey < ActiveRecord::Migration[4.2]
+ def change
+ unless defined?(User)
+ add_index :spree_users, :spree_api_key
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146014_create_doorkeeper_tables.spree_api.rb b/spec/dummy/db/migrate/20200218146014_create_doorkeeper_tables.spree_api.rb
new file mode 100644
index 0000000..2494d8e
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146014_create_doorkeeper_tables.spree_api.rb
@@ -0,0 +1,70 @@
+# This migration comes from spree_api (originally 20180320110726)
+class CreateDoorkeeperTables < ActiveRecord::Migration[5.1]
+ def change
+ create_table :spree_oauth_applications do |t|
+ t.string :name, null: false
+ t.string :uid, null: false
+ t.string :secret, null: false
+ t.text :redirect_uri, null: false
+ t.string :scopes, null: false, default: ''
+ t.boolean :confidential, null: false, default: true
+ t.timestamps null: false
+ end
+
+ add_index :spree_oauth_applications, :uid, unique: true
+
+ create_table :spree_oauth_access_grants do |t|
+ t.integer :resource_owner_id, null: false
+ t.references :application, null: false
+ t.string :token, null: false
+ t.integer :expires_in, null: false
+ t.text :redirect_uri, null: false
+ t.datetime :created_at, null: false
+ t.datetime :revoked_at
+ t.string :scopes
+ end
+
+ add_index :spree_oauth_access_grants, :token, unique: true
+ add_foreign_key(
+ :spree_oauth_access_grants,
+ :spree_oauth_applications,
+ column: :application_id
+ )
+
+ create_table :spree_oauth_access_tokens do |t|
+ t.integer :resource_owner_id
+ t.references :application
+
+ # If you use a custom token generator you may need to change this column
+ # from string to text, so that it accepts tokens larger than 255
+ # characters. More info on custom token generators in:
+ # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
+ #
+ # t.text :token, null: false
+ t.string :token, null: false
+
+ t.string :refresh_token
+ t.integer :expires_in
+ t.datetime :revoked_at
+ t.datetime :created_at, null: false
+ t.string :scopes
+
+ # If there is a previous_refresh_token column,
+ # refresh tokens will be revoked after a related access token is used.
+ # If there is no previous_refresh_token column,
+ # previous tokens are revoked as soon as a new access token is created.
+ # Comment out this line if you'd rather have refresh tokens
+ # instantly revoked.
+ t.string :previous_refresh_token, null: false, default: ""
+ end
+
+ add_index :spree_oauth_access_tokens, :token, unique: true
+ add_index :spree_oauth_access_tokens, :resource_owner_id
+ add_index :spree_oauth_access_tokens, :refresh_token, unique: true
+ add_foreign_key(
+ :spree_oauth_access_tokens,
+ :spree_oauth_applications,
+ column: :application_id
+ )
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146015_create_users.spree_auth.rb b/spec/dummy/db/migrate/20200218146015_create_users.spree_auth.rb
new file mode 100644
index 0000000..c06e70a
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146015_create_users.spree_auth.rb
@@ -0,0 +1,30 @@
+# This migration comes from spree_auth (originally 20101026184949)
+class CreateUsers < SpreeExtension::Migration[4.2]
+ def up
+ unless data_source_exists?("spree_users")
+ create_table "spree_users", force: true do |t|
+ t.string "crypted_password", limit: 128
+ t.string "salt", limit: 128
+ t.string "email"
+ t.string "remember_token"
+ t.string "remember_token_expires_at"
+ t.string "persistence_token"
+ t.string "single_access_token"
+ t.string "perishable_token"
+ t.integer "login_count", default: 0, null: false
+ t.integer "failed_login_count", default: 0, null: false
+ t.datetime "last_request_at"
+ t.datetime "current_login_at"
+ t.datetime "last_login_at"
+ t.string "current_login_ip"
+ t.string "last_login_ip"
+ t.string "login"
+ t.integer "ship_address_id"
+ t.integer "bill_address_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "openid_identifier"
+ end
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146016_rename_columns_for_devise.spree_auth.rb b/spec/dummy/db/migrate/20200218146016_rename_columns_for_devise.spree_auth.rb
new file mode 100644
index 0000000..e417608
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146016_rename_columns_for_devise.spree_auth.rb
@@ -0,0 +1,38 @@
+# This migration comes from spree_auth (originally 20101026184950)
+class RenameColumnsForDevise < SpreeExtension::Migration[4.2]
+ def up
+ return if column_exists?(:spree_users, :password_salt)
+ rename_column :spree_users, :crypted_password, :encrypted_password
+ rename_column :spree_users, :salt, :password_salt
+ rename_column :spree_users, :remember_token_expires_at, :remember_created_at
+ rename_column :spree_users, :login_count, :sign_in_count
+ rename_column :spree_users, :failed_login_count, :failed_attempts
+ rename_column :spree_users, :single_access_token, :reset_password_token
+ rename_column :spree_users, :current_login_at, :current_sign_in_at
+ rename_column :spree_users, :last_login_at, :last_sign_in_at
+ rename_column :spree_users, :current_login_ip, :current_sign_in_ip
+ rename_column :spree_users, :last_login_ip, :last_sign_in_ip
+ add_column :spree_users, :authentication_token, :string
+ add_column :spree_users, :unlock_token, :string
+ add_column :spree_users, :locked_at, :datetime
+ remove_column :spree_users, :openid_identifier
+ end
+
+ def down
+ remove_column :spree_users, :authentication_token
+ remove_column :spree_users, :locked_at
+ remove_column :spree_users, :unlock_token
+ rename_column :spree_users, :last_sign_in_ip, :last_login_ip
+ rename_column :spree_users, :current_sign_in_ip, :current_login_ip
+ rename_column :spree_users, :last_sign_in_at, :last_login_at
+ rename_column :spree_users, :current_sign_in_at, :current_login_at
+ rename_column :spree_users, :reset_password_token, :single_access_token
+ rename_column :spree_users, :failed_attempts, :failed_login_count
+ rename_column :spree_users, :sign_in_count, :login_count
+ rename_column :spree_users, :remember_created_at, :remember_token_expires_at
+ rename_column :spree_users, :password_salt, :salt
+ rename_column :spree_users, :encrypted_password, :crypted_password
+ add_column :spree_users, :unlock_token, :string
+ add_column :spree_users, :openid_identifier, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146017_convert_user_remember_field.spree_auth.rb b/spec/dummy/db/migrate/20200218146017_convert_user_remember_field.spree_auth.rb
new file mode 100644
index 0000000..00fa1bb
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146017_convert_user_remember_field.spree_auth.rb
@@ -0,0 +1,12 @@
+# This migration comes from spree_auth (originally 20101214150824)
+class ConvertUserRememberField < SpreeExtension::Migration[4.2]
+ def up
+ remove_column :spree_users, :remember_created_at
+ add_column :spree_users, :remember_created_at, :datetime
+ end
+
+ def down
+ remove_column :spree_users, :remember_created_at
+ add_column :spree_users, :remember_created_at, :string
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146018_add_reset_password_sent_at_to_spree_users.spree_auth.rb b/spec/dummy/db/migrate/20200218146018_add_reset_password_sent_at_to_spree_users.spree_auth.rb
new file mode 100644
index 0000000..b30894f
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146018_add_reset_password_sent_at_to_spree_users.spree_auth.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree_auth (originally 20120203010234)
+class AddResetPasswordSentAtToSpreeUsers < SpreeExtension::Migration[4.2]
+ def change
+ Spree::User.reset_column_information
+ unless Spree::User.column_names.include?("reset_password_sent_at")
+ add_column :spree_users, :reset_password_sent_at, :datetime
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146019_make_users_email_index_unique.spree_auth.rb b/spec/dummy/db/migrate/20200218146019_make_users_email_index_unique.spree_auth.rb
new file mode 100644
index 0000000..5a12c06
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146019_make_users_email_index_unique.spree_auth.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree_auth (originally 20120605211305)
+class MakeUsersEmailIndexUnique < SpreeExtension::Migration[4.2]
+ def up
+ add_index "spree_users", ["email"], name: "email_idx_unique", unique: true
+ end
+
+ def down
+ remove_index "spree_users", name: "email_idx_unique"
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146020_add_deleted_at_to_users.spree_auth.rb b/spec/dummy/db/migrate/20200218146020_add_deleted_at_to_users.spree_auth.rb
new file mode 100644
index 0000000..e2c9901
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146020_add_deleted_at_to_users.spree_auth.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree_auth (originally 20140904000425)
+class AddDeletedAtToUsers < SpreeExtension::Migration[4.2]
+ def change
+ add_column :spree_users, :deleted_at, :datetime
+ add_index :spree_users, :deleted_at
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146021_add_confirmable_to_users.spree_auth.rb b/spec/dummy/db/migrate/20200218146021_add_confirmable_to_users.spree_auth.rb
new file mode 100644
index 0000000..84bed06
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146021_add_confirmable_to_users.spree_auth.rb
@@ -0,0 +1,8 @@
+# This migration comes from spree_auth (originally 20141002154641)
+class AddConfirmableToUsers < SpreeExtension::Migration[4.2]
+ def change
+ add_column :spree_users, :confirmation_token, :string
+ add_column :spree_users, :confirmed_at, :datetime
+ add_column :spree_users, :confirmation_sent_at, :datetime
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146022_add_missing_indices_on_user.spree_auth.rb b/spec/dummy/db/migrate/20200218146022_add_missing_indices_on_user.spree_auth.rb
new file mode 100644
index 0000000..4559432
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146022_add_missing_indices_on_user.spree_auth.rb
@@ -0,0 +1,11 @@
+# This migration comes from spree_auth (originally 20150416152553)
+class AddMissingIndicesOnUser < SpreeExtension::Migration[4.2]
+ def change
+ unless index_exists?(:spree_users, :bill_address_id)
+ add_index :spree_users, :bill_address_id
+ end
+ unless index_exists?(:spree_users, :ship_address_id)
+ add_index :spree_users, :ship_address_id
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146023_update_braintree_payment_method_type.spree_gateway.rb b/spec/dummy/db/migrate/20200218146023_update_braintree_payment_method_type.spree_gateway.rb
new file mode 100644
index 0000000..ce8bd02
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146023_update_braintree_payment_method_type.spree_gateway.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree_gateway (originally 20121017004102)
+class UpdateBraintreePaymentMethodType < SpreeExtension::Migration[4.2]
+ def up
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::Braintree").update_all(:type => "Spree::Gateway::BraintreeGateway")
+ end
+
+ def down
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::BraintreeGateway").update_all(:type => "Spree::Gateway::Braintree")
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146024_update_stripe_payment_method_type.spree_gateway.rb b/spec/dummy/db/migrate/20200218146024_update_stripe_payment_method_type.spree_gateway.rb
new file mode 100644
index 0000000..ddd43c0
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146024_update_stripe_payment_method_type.spree_gateway.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree_gateway (originally 20130213222555)
+class UpdateStripePaymentMethodType < SpreeExtension::Migration[4.2]
+ def up
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::Stripe").update_all(:type => "Spree::Gateway::StripeGateway")
+ end
+
+ def down
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::StripeGateway").update_all(:type => "Spree::Gateway::Stripe")
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146025_update_balanced_payment_method_type.spree_gateway.rb b/spec/dummy/db/migrate/20200218146025_update_balanced_payment_method_type.spree_gateway.rb
new file mode 100644
index 0000000..8a527a3
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146025_update_balanced_payment_method_type.spree_gateway.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree_gateway (originally 20130415222802)
+class UpdateBalancedPaymentMethodType < SpreeExtension::Migration[4.2]
+ def up
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::Balanced").update_all(:type => "Spree::Gateway::BalancedGateway")
+ end
+
+ def down
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::BalancedGateway").update_all(:type => "Spree::Gateway::Balanced")
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146026_update_paypal_payment_method_type.spree_gateway.rb b/spec/dummy/db/migrate/20200218146026_update_paypal_payment_method_type.spree_gateway.rb
new file mode 100644
index 0000000..690ac14
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146026_update_paypal_payment_method_type.spree_gateway.rb
@@ -0,0 +1,10 @@
+# This migration comes from spree_gateway (originally 20131008221012)
+class UpdatePaypalPaymentMethodType < SpreeExtension::Migration[4.2]
+ def up
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::PayPal").update_all(:type => "Spree::Gateway::PayPalGateway")
+ end
+
+ def down
+ Spree::PaymentMethod.where(:type => "Spree::Gateway::PayPalGateway").update_all(:type => "Spree::Gateway::PayPal")
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146027_migrate_stripe_preferences.spree_gateway.rb b/spec/dummy/db/migrate/20200218146027_migrate_stripe_preferences.spree_gateway.rb
new file mode 100644
index 0000000..8bc15c5
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146027_migrate_stripe_preferences.spree_gateway.rb
@@ -0,0 +1,9 @@
+# This migration comes from spree_gateway (originally 20131112133401)
+class MigrateStripePreferences < SpreeExtension::Migration[4.2]
+ def up
+ Spree::Preference.where("#{ActiveRecord::Base.connection.quote_column_name("key")} LIKE 'spree/gateway/stripe_gateway/login%'").each do |pref|
+ pref.key = pref.key.gsub('login', 'secret_key')
+ pref.save
+ end
+ end
+end
diff --git a/spec/dummy/db/migrate/20200218146028_create_digitals.spree_digital.rb b/spec/dummy/db/migrate/20200218146028_create_digitals.spree_digital.rb
new file mode 100644
index 0000000..609d801
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146028_create_digitals.spree_digital.rb
@@ -0,0 +1,31 @@
+# This migration comes from spree_digital (originally 20110410134726)
+class CreateDigitals < SpreeExtension::Migration[4.2]
+
+ def self.up
+ create_table :digitals do |t|
+ t.integer :variant_id
+ t.string :attachment_file_name
+ t.string :attachment_content_type
+ t.integer :attachment_file_size
+ t.timestamps
+ end
+ add_index :digitals, :variant_id
+
+ create_table :digital_links, :force => true do |t|
+ t.integer :digital_id
+ t.integer :line_item_id
+ t.string :secret
+ t.integer :access_counter
+ t.timestamps
+ end
+ add_index :digital_links, :digital_id
+ add_index :digital_links, :line_item_id
+ add_index :digital_links, :secret
+ end
+
+ def self.down
+ drop_table :digitals
+ drop_table :digital_links
+ end
+
+end
diff --git a/spec/dummy/db/migrate/20200218146029_rename_digital_to_namespace.spree_digital.rb b/spec/dummy/db/migrate/20200218146029_rename_digital_to_namespace.spree_digital.rb
new file mode 100644
index 0000000..2fd9b04
--- /dev/null
+++ b/spec/dummy/db/migrate/20200218146029_rename_digital_to_namespace.spree_digital.rb
@@ -0,0 +1,7 @@
+# This migration comes from spree_digital (originally 20111207121840)
+class RenameDigitalToNamespace < SpreeExtension::Migration[4.2]
+ def change
+ rename_table :digitals, :spree_digitals
+ rename_table :digital_links, :spree_digital_links
+ end
+end
diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb
new file mode 100644
index 0000000..57f063b
--- /dev/null
+++ b/spec/dummy/db/schema.rb
@@ -0,0 +1,1156 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# This file is the source Rails uses to define your schema when running `rails
+# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
+# be faster and is potentially less error prone than running all of your
+# migrations from scratch. Old migrations may fail to apply correctly if those
+# migrations use external dependencies or application code.
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 2020_02_18_146029) do
+
+ create_table "action_mailbox_inbound_emails", force: :cascade do |t|
+ t.integer "status", default: 0, null: false
+ t.string "message_id", null: false
+ t.string "message_checksum", null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["message_id", "message_checksum"], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
+ end
+
+ create_table "action_text_rich_texts", force: :cascade do |t|
+ t.string "name", null: false
+ t.text "body"
+ t.string "record_type", null: false
+ t.integer "record_id", null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
+ end
+
+ create_table "active_storage_attachments", force: :cascade do |t|
+ t.string "name", null: false
+ t.string "record_type", null: false
+ t.integer "record_id", null: false
+ t.integer "blob_id", null: false
+ t.datetime "created_at", null: false
+ t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
+ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
+ end
+
+ create_table "active_storage_blobs", force: :cascade do |t|
+ t.string "key", null: false
+ t.string "filename", null: false
+ t.string "content_type"
+ t.text "metadata"
+ t.bigint "byte_size", null: false
+ t.string "checksum", null: false
+ t.datetime "created_at", null: false
+ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
+ end
+
+ create_table "friendly_id_slugs", force: :cascade do |t|
+ t.string "slug", null: false
+ t.integer "sluggable_id", null: false
+ t.string "sluggable_type", limit: 50
+ t.string "scope"
+ t.datetime "created_at"
+ t.datetime "deleted_at"
+ t.index ["deleted_at"], name: "index_friendly_id_slugs_on_deleted_at"
+ t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true
+ t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type"
+ t.index ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id"
+ t.index ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type"
+ end
+
+ create_table "spree_addresses", force: :cascade do |t|
+ t.string "firstname"
+ t.string "lastname"
+ t.string "address1"
+ t.string "address2"
+ t.string "city"
+ t.string "zipcode"
+ t.string "phone"
+ t.string "state_name"
+ t.string "alternative_phone"
+ t.string "company"
+ t.integer "state_id"
+ t.integer "country_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "user_id"
+ t.datetime "deleted_at"
+ t.index ["country_id"], name: "index_spree_addresses_on_country_id"
+ t.index ["deleted_at"], name: "index_spree_addresses_on_deleted_at"
+ t.index ["firstname"], name: "index_addresses_on_firstname"
+ t.index ["lastname"], name: "index_addresses_on_lastname"
+ t.index ["state_id"], name: "index_spree_addresses_on_state_id"
+ t.index ["user_id"], name: "index_spree_addresses_on_user_id"
+ end
+
+ create_table "spree_adjustments", force: :cascade do |t|
+ t.string "source_type"
+ t.integer "source_id"
+ t.string "adjustable_type"
+ t.integer "adjustable_id"
+ t.decimal "amount", precision: 10, scale: 2
+ t.string "label"
+ t.boolean "mandatory"
+ t.boolean "eligible", default: true
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "state"
+ t.integer "order_id", null: false
+ t.boolean "included", default: false
+ t.index ["adjustable_id", "adjustable_type"], name: "index_spree_adjustments_on_adjustable_id_and_adjustable_type"
+ t.index ["eligible"], name: "index_spree_adjustments_on_eligible"
+ t.index ["order_id"], name: "index_spree_adjustments_on_order_id"
+ t.index ["source_id", "source_type"], name: "index_spree_adjustments_on_source_id_and_source_type"
+ end
+
+ create_table "spree_assets", force: :cascade do |t|
+ t.string "viewable_type"
+ t.integer "viewable_id"
+ t.integer "attachment_width"
+ t.integer "attachment_height"
+ t.integer "attachment_file_size"
+ t.integer "position"
+ t.string "attachment_content_type"
+ t.string "attachment_file_name"
+ t.string "type", limit: 75
+ t.datetime "attachment_updated_at"
+ t.text "alt"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.index ["position"], name: "index_spree_assets_on_position"
+ t.index ["viewable_id"], name: "index_assets_on_viewable_id"
+ t.index ["viewable_type", "type"], name: "index_assets_on_viewable_type_and_type"
+ end
+
+ create_table "spree_calculators", force: :cascade do |t|
+ t.string "type"
+ t.string "calculable_type"
+ t.integer "calculable_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.text "preferences"
+ t.datetime "deleted_at"
+ t.index ["calculable_id", "calculable_type"], name: "index_spree_calculators_on_calculable_id_and_calculable_type"
+ t.index ["deleted_at"], name: "index_spree_calculators_on_deleted_at"
+ t.index ["id", "type"], name: "index_spree_calculators_on_id_and_type"
+ end
+
+ create_table "spree_countries", force: :cascade do |t|
+ t.string "iso_name"
+ t.string "iso", null: false
+ t.string "iso3", null: false
+ t.string "name"
+ t.integer "numcode"
+ t.boolean "states_required", default: false
+ t.datetime "updated_at"
+ t.boolean "zipcode_required", default: true
+ t.index "(lower(iso_name))", name: "index_spree_countries_on_lower_iso_name", unique: true
+ t.index "(lower(name))", name: "index_spree_countries_on_lower_name", unique: true
+ t.index ["iso"], name: "index_spree_countries_on_iso", unique: true
+ t.index ["iso3"], name: "index_spree_countries_on_iso3", unique: true
+ end
+
+ create_table "spree_credit_cards", force: :cascade do |t|
+ t.string "month"
+ t.string "year"
+ t.string "cc_type"
+ t.string "last_digits"
+ t.integer "address_id"
+ t.string "gateway_customer_profile_id"
+ t.string "gateway_payment_profile_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "name"
+ t.integer "user_id"
+ t.integer "payment_method_id"
+ t.boolean "default", default: false, null: false
+ t.datetime "deleted_at"
+ t.index ["address_id"], name: "index_spree_credit_cards_on_address_id"
+ t.index ["deleted_at"], name: "index_spree_credit_cards_on_deleted_at"
+ t.index ["payment_method_id"], name: "index_spree_credit_cards_on_payment_method_id"
+ t.index ["user_id"], name: "index_spree_credit_cards_on_user_id"
+ end
+
+ create_table "spree_customer_returns", force: :cascade do |t|
+ t.string "number"
+ t.integer "stock_location_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["number"], name: "index_spree_customer_returns_on_number", unique: true
+ t.index ["stock_location_id"], name: "index_spree_customer_returns_on_stock_location_id"
+ end
+
+ create_table "spree_digital_links", force: :cascade do |t|
+ t.integer "digital_id"
+ t.integer "line_item_id"
+ t.string "secret"
+ t.integer "access_counter"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.index ["digital_id"], name: "index_spree_digital_links_on_digital_id"
+ t.index ["line_item_id"], name: "index_spree_digital_links_on_line_item_id"
+ t.index ["secret"], name: "index_spree_digital_links_on_secret"
+ end
+
+ create_table "spree_digitals", force: :cascade do |t|
+ t.integer "variant_id"
+ t.string "attachment_file_name"
+ t.string "attachment_content_type"
+ t.integer "attachment_file_size"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.index ["variant_id"], name: "index_spree_digitals_on_variant_id"
+ end
+
+ create_table "spree_gateways", force: :cascade do |t|
+ t.string "type"
+ t.string "name"
+ t.text "description"
+ t.boolean "active", default: true
+ t.string "environment", default: "development"
+ t.string "server", default: "test"
+ t.boolean "test_mode", default: true
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.text "preferences"
+ t.index ["active"], name: "index_spree_gateways_on_active"
+ t.index ["test_mode"], name: "index_spree_gateways_on_test_mode"
+ end
+
+ create_table "spree_inventory_units", force: :cascade do |t|
+ t.string "state"
+ t.integer "variant_id"
+ t.integer "order_id"
+ t.integer "shipment_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.boolean "pending", default: true
+ t.integer "line_item_id"
+ t.integer "quantity", default: 1
+ t.integer "original_return_item_id"
+ t.index ["line_item_id"], name: "index_spree_inventory_units_on_line_item_id"
+ t.index ["order_id"], name: "index_inventory_units_on_order_id"
+ t.index ["original_return_item_id"], name: "index_spree_inventory_units_on_original_return_item_id"
+ t.index ["shipment_id"], name: "index_inventory_units_on_shipment_id"
+ t.index ["variant_id"], name: "index_inventory_units_on_variant_id"
+ end
+
+ create_table "spree_line_items", force: :cascade do |t|
+ t.integer "variant_id"
+ t.integer "order_id"
+ t.integer "quantity", null: false
+ t.decimal "price", precision: 10, scale: 2, null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "currency"
+ t.decimal "cost_price", precision: 10, scale: 2
+ t.integer "tax_category_id"
+ t.decimal "adjustment_total", precision: 10, scale: 2, default: "0.0"
+ t.decimal "additional_tax_total", precision: 10, scale: 2, default: "0.0"
+ t.decimal "promo_total", precision: 10, scale: 2, default: "0.0"
+ t.decimal "included_tax_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.decimal "pre_tax_amount", precision: 12, scale: 4, default: "0.0", null: false
+ t.decimal "taxable_adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.decimal "non_taxable_adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.index ["order_id"], name: "index_spree_line_items_on_order_id"
+ t.index ["tax_category_id"], name: "index_spree_line_items_on_tax_category_id"
+ t.index ["variant_id"], name: "index_spree_line_items_on_variant_id"
+ end
+
+ create_table "spree_log_entries", force: :cascade do |t|
+ t.string "source_type"
+ t.integer "source_id"
+ t.text "details"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["source_id", "source_type"], name: "index_spree_log_entries_on_source_id_and_source_type"
+ end
+
+ create_table "spree_oauth_access_grants", force: :cascade do |t|
+ t.integer "resource_owner_id", null: false
+ t.integer "application_id", null: false
+ t.string "token", null: false
+ t.integer "expires_in", null: false
+ t.text "redirect_uri", null: false
+ t.datetime "created_at", null: false
+ t.datetime "revoked_at"
+ t.string "scopes"
+ t.index ["application_id"], name: "index_spree_oauth_access_grants_on_application_id"
+ t.index ["token"], name: "index_spree_oauth_access_grants_on_token", unique: true
+ end
+
+ create_table "spree_oauth_access_tokens", force: :cascade do |t|
+ t.integer "resource_owner_id"
+ t.integer "application_id"
+ t.string "token", null: false
+ t.string "refresh_token"
+ t.integer "expires_in"
+ t.datetime "revoked_at"
+ t.datetime "created_at", null: false
+ t.string "scopes"
+ t.string "previous_refresh_token", default: "", null: false
+ t.index ["application_id"], name: "index_spree_oauth_access_tokens_on_application_id"
+ t.index ["refresh_token"], name: "index_spree_oauth_access_tokens_on_refresh_token", unique: true
+ t.index ["resource_owner_id"], name: "index_spree_oauth_access_tokens_on_resource_owner_id"
+ t.index ["token"], name: "index_spree_oauth_access_tokens_on_token", unique: true
+ end
+
+ create_table "spree_oauth_applications", force: :cascade do |t|
+ t.string "name", null: false
+ t.string "uid", null: false
+ t.string "secret", null: false
+ t.text "redirect_uri", null: false
+ t.string "scopes", default: "", null: false
+ t.boolean "confidential", default: true, null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["uid"], name: "index_spree_oauth_applications_on_uid", unique: true
+ end
+
+ create_table "spree_option_type_prototypes", force: :cascade do |t|
+ t.integer "prototype_id"
+ t.integer "option_type_id"
+ t.index ["option_type_id"], name: "index_spree_option_type_prototypes_on_option_type_id"
+ t.index ["prototype_id", "option_type_id"], name: "spree_option_type_prototypes_prototype_id_option_type_id", unique: true
+ t.index ["prototype_id"], name: "index_spree_option_type_prototypes_on_prototype_id"
+ end
+
+ create_table "spree_option_types", force: :cascade do |t|
+ t.string "name", limit: 100
+ t.string "presentation", limit: 100
+ t.integer "position", default: 0, null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["name"], name: "index_spree_option_types_on_name"
+ t.index ["position"], name: "index_spree_option_types_on_position"
+ end
+
+ create_table "spree_option_value_variants", force: :cascade do |t|
+ t.integer "variant_id"
+ t.integer "option_value_id"
+ t.index ["option_value_id"], name: "index_spree_option_value_variants_on_option_value_id"
+ t.index ["variant_id", "option_value_id"], name: "index_option_values_variants_on_variant_id_and_option_value_id", unique: true
+ t.index ["variant_id"], name: "index_spree_option_value_variants_on_variant_id"
+ end
+
+ create_table "spree_option_values", force: :cascade do |t|
+ t.integer "position"
+ t.string "name"
+ t.string "presentation"
+ t.integer "option_type_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["name"], name: "index_spree_option_values_on_name"
+ t.index ["option_type_id"], name: "index_spree_option_values_on_option_type_id"
+ t.index ["position"], name: "index_spree_option_values_on_position"
+ end
+
+ create_table "spree_order_promotions", force: :cascade do |t|
+ t.integer "order_id"
+ t.integer "promotion_id"
+ t.index ["order_id"], name: "index_spree_order_promotions_on_order_id"
+ t.index ["promotion_id", "order_id"], name: "index_spree_order_promotions_on_promotion_id_and_order_id"
+ t.index ["promotion_id"], name: "index_spree_order_promotions_on_promotion_id"
+ end
+
+ create_table "spree_orders", force: :cascade do |t|
+ t.string "number", limit: 32
+ t.decimal "item_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.decimal "total", precision: 10, scale: 2, default: "0.0", null: false
+ t.string "state"
+ t.decimal "adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.integer "user_id"
+ t.datetime "completed_at"
+ t.integer "bill_address_id"
+ t.integer "ship_address_id"
+ t.decimal "payment_total", precision: 10, scale: 2, default: "0.0"
+ t.string "shipment_state"
+ t.string "payment_state"
+ t.string "email"
+ t.text "special_instructions"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "currency"
+ t.string "last_ip_address"
+ t.integer "created_by_id"
+ t.decimal "shipment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.decimal "additional_tax_total", precision: 10, scale: 2, default: "0.0"
+ t.decimal "promo_total", precision: 10, scale: 2, default: "0.0"
+ t.string "channel", default: "spree"
+ t.decimal "included_tax_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.integer "item_count", default: 0
+ t.integer "approver_id"
+ t.datetime "approved_at"
+ t.boolean "confirmation_delivered", default: false
+ t.boolean "considered_risky", default: false
+ t.string "token"
+ t.datetime "canceled_at"
+ t.integer "canceler_id"
+ t.integer "store_id"
+ t.integer "state_lock_version", default: 0, null: false
+ t.decimal "taxable_adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.decimal "non_taxable_adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.index ["approver_id"], name: "index_spree_orders_on_approver_id"
+ t.index ["bill_address_id"], name: "index_spree_orders_on_bill_address_id"
+ t.index ["canceler_id"], name: "index_spree_orders_on_canceler_id"
+ t.index ["completed_at"], name: "index_spree_orders_on_completed_at"
+ t.index ["confirmation_delivered"], name: "index_spree_orders_on_confirmation_delivered"
+ t.index ["considered_risky"], name: "index_spree_orders_on_considered_risky"
+ t.index ["created_by_id"], name: "index_spree_orders_on_created_by_id"
+ t.index ["number"], name: "index_spree_orders_on_number", unique: true
+ t.index ["ship_address_id"], name: "index_spree_orders_on_ship_address_id"
+ t.index ["store_id"], name: "index_spree_orders_on_store_id"
+ t.index ["token"], name: "index_spree_orders_on_token"
+ t.index ["user_id", "created_by_id"], name: "index_spree_orders_on_user_id_and_created_by_id"
+ end
+
+ create_table "spree_payment_capture_events", force: :cascade do |t|
+ t.decimal "amount", precision: 10, scale: 2, default: "0.0"
+ t.integer "payment_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["payment_id"], name: "index_spree_payment_capture_events_on_payment_id"
+ end
+
+ create_table "spree_payment_methods", force: :cascade do |t|
+ t.string "type"
+ t.string "name"
+ t.text "description"
+ t.boolean "active", default: true
+ t.datetime "deleted_at"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "display_on", default: "both"
+ t.boolean "auto_capture"
+ t.text "preferences"
+ t.integer "position", default: 0
+ t.integer "store_id"
+ t.index ["id", "type"], name: "index_spree_payment_methods_on_id_and_type"
+ t.index ["store_id"], name: "index_spree_payment_methods_on_store_id"
+ end
+
+ create_table "spree_payments", force: :cascade do |t|
+ t.decimal "amount", precision: 10, scale: 2, default: "0.0", null: false
+ t.integer "order_id"
+ t.string "source_type"
+ t.integer "source_id"
+ t.integer "payment_method_id"
+ t.string "state"
+ t.string "response_code"
+ t.string "avs_response"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "number"
+ t.string "cvv_response_code"
+ t.string "cvv_response_message"
+ t.index ["number"], name: "index_spree_payments_on_number", unique: true
+ t.index ["order_id"], name: "index_spree_payments_on_order_id"
+ t.index ["payment_method_id"], name: "index_spree_payments_on_payment_method_id"
+ t.index ["source_id", "source_type"], name: "index_spree_payments_on_source_id_and_source_type"
+ end
+
+ create_table "spree_preferences", force: :cascade do |t|
+ t.text "value"
+ t.string "key"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["key"], name: "index_spree_preferences_on_key", unique: true
+ end
+
+ create_table "spree_prices", force: :cascade do |t|
+ t.integer "variant_id", null: false
+ t.decimal "amount", precision: 10, scale: 2
+ t.string "currency"
+ t.datetime "deleted_at"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["deleted_at"], name: "index_spree_prices_on_deleted_at"
+ t.index ["variant_id", "currency"], name: "index_spree_prices_on_variant_id_and_currency"
+ t.index ["variant_id"], name: "index_spree_prices_on_variant_id"
+ end
+
+ create_table "spree_product_option_types", force: :cascade do |t|
+ t.integer "position"
+ t.integer "product_id"
+ t.integer "option_type_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["option_type_id"], name: "index_spree_product_option_types_on_option_type_id"
+ t.index ["position"], name: "index_spree_product_option_types_on_position"
+ t.index ["product_id"], name: "index_spree_product_option_types_on_product_id"
+ end
+
+ create_table "spree_product_promotion_rules", force: :cascade do |t|
+ t.integer "product_id"
+ t.integer "promotion_rule_id"
+ t.index ["product_id"], name: "index_products_promotion_rules_on_product_id"
+ t.index ["promotion_rule_id", "product_id"], name: "index_products_promotion_rules_on_promotion_rule_and_product"
+ end
+
+ create_table "spree_product_properties", force: :cascade do |t|
+ t.string "value"
+ t.integer "product_id"
+ t.integer "property_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "position", default: 0
+ t.index ["position"], name: "index_spree_product_properties_on_position"
+ t.index ["product_id"], name: "index_product_properties_on_product_id"
+ t.index ["property_id"], name: "index_spree_product_properties_on_property_id"
+ end
+
+ create_table "spree_products", force: :cascade do |t|
+ t.string "name", default: "", null: false
+ t.text "description"
+ t.datetime "available_on"
+ t.datetime "deleted_at"
+ t.string "slug"
+ t.text "meta_description"
+ t.string "meta_keywords"
+ t.integer "tax_category_id"
+ t.integer "shipping_category_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.boolean "promotionable", default: true
+ t.string "meta_title"
+ t.datetime "discontinue_on"
+ t.index ["available_on"], name: "index_spree_products_on_available_on"
+ t.index ["deleted_at"], name: "index_spree_products_on_deleted_at"
+ t.index ["discontinue_on"], name: "index_spree_products_on_discontinue_on"
+ t.index ["name"], name: "index_spree_products_on_name"
+ t.index ["shipping_category_id"], name: "index_spree_products_on_shipping_category_id"
+ t.index ["slug"], name: "index_spree_products_on_slug", unique: true
+ t.index ["tax_category_id"], name: "index_spree_products_on_tax_category_id"
+ end
+
+ create_table "spree_products_taxons", force: :cascade do |t|
+ t.integer "product_id"
+ t.integer "taxon_id"
+ t.integer "position"
+ t.index ["position"], name: "index_spree_products_taxons_on_position"
+ t.index ["product_id"], name: "index_spree_products_taxons_on_product_id"
+ t.index ["taxon_id"], name: "index_spree_products_taxons_on_taxon_id"
+ end
+
+ create_table "spree_promotion_action_line_items", force: :cascade do |t|
+ t.integer "promotion_action_id"
+ t.integer "variant_id"
+ t.integer "quantity", default: 1
+ t.index ["promotion_action_id"], name: "index_spree_promotion_action_line_items_on_promotion_action_id"
+ t.index ["variant_id"], name: "index_spree_promotion_action_line_items_on_variant_id"
+ end
+
+ create_table "spree_promotion_actions", force: :cascade do |t|
+ t.integer "promotion_id"
+ t.integer "position"
+ t.string "type"
+ t.datetime "deleted_at"
+ t.index ["deleted_at"], name: "index_spree_promotion_actions_on_deleted_at"
+ t.index ["id", "type"], name: "index_spree_promotion_actions_on_id_and_type"
+ t.index ["promotion_id"], name: "index_spree_promotion_actions_on_promotion_id"
+ end
+
+ create_table "spree_promotion_categories", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "code"
+ end
+
+ create_table "spree_promotion_rule_taxons", force: :cascade do |t|
+ t.integer "taxon_id"
+ t.integer "promotion_rule_id"
+ t.index ["promotion_rule_id"], name: "index_spree_promotion_rule_taxons_on_promotion_rule_id"
+ t.index ["taxon_id"], name: "index_spree_promotion_rule_taxons_on_taxon_id"
+ end
+
+ create_table "spree_promotion_rule_users", force: :cascade do |t|
+ t.integer "user_id"
+ t.integer "promotion_rule_id"
+ t.index ["promotion_rule_id"], name: "index_promotion_rules_users_on_promotion_rule_id"
+ t.index ["user_id", "promotion_rule_id"], name: "index_promotion_rules_users_on_user_id_and_promotion_rule_id"
+ end
+
+ create_table "spree_promotion_rules", force: :cascade do |t|
+ t.integer "promotion_id"
+ t.integer "user_id"
+ t.integer "product_group_id"
+ t.string "type"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "code"
+ t.text "preferences"
+ t.index ["product_group_id"], name: "index_promotion_rules_on_product_group_id"
+ t.index ["promotion_id"], name: "index_spree_promotion_rules_on_promotion_id"
+ t.index ["user_id"], name: "index_promotion_rules_on_user_id"
+ end
+
+ create_table "spree_promotions", force: :cascade do |t|
+ t.string "description"
+ t.datetime "expires_at"
+ t.datetime "starts_at"
+ t.string "name"
+ t.string "type"
+ t.integer "usage_limit"
+ t.string "match_policy", default: "all"
+ t.string "code"
+ t.boolean "advertise", default: false
+ t.string "path"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "promotion_category_id"
+ t.index ["advertise"], name: "index_spree_promotions_on_advertise"
+ t.index ["code"], name: "index_spree_promotions_on_code", unique: true
+ t.index ["expires_at"], name: "index_spree_promotions_on_expires_at"
+ t.index ["id", "type"], name: "index_spree_promotions_on_id_and_type"
+ t.index ["promotion_category_id"], name: "index_spree_promotions_on_promotion_category_id"
+ t.index ["starts_at"], name: "index_spree_promotions_on_starts_at"
+ end
+
+ create_table "spree_properties", force: :cascade do |t|
+ t.string "name"
+ t.string "presentation", null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["name"], name: "index_spree_properties_on_name"
+ end
+
+ create_table "spree_property_prototypes", force: :cascade do |t|
+ t.integer "prototype_id"
+ t.integer "property_id"
+ t.index ["property_id"], name: "index_spree_property_prototypes_on_property_id"
+ t.index ["prototype_id", "property_id"], name: "index_property_prototypes_on_prototype_id_and_property_id", unique: true
+ t.index ["prototype_id"], name: "index_spree_property_prototypes_on_prototype_id"
+ end
+
+ create_table "spree_prototype_taxons", force: :cascade do |t|
+ t.integer "taxon_id"
+ t.integer "prototype_id"
+ t.index ["prototype_id", "taxon_id"], name: "index_spree_prototype_taxons_on_prototype_id_and_taxon_id"
+ t.index ["prototype_id"], name: "index_spree_prototype_taxons_on_prototype_id"
+ t.index ["taxon_id"], name: "index_spree_prototype_taxons_on_taxon_id"
+ end
+
+ create_table "spree_prototypes", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ end
+
+ create_table "spree_refund_reasons", force: :cascade do |t|
+ t.string "name"
+ t.boolean "active", default: true
+ t.boolean "mutable", default: true
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index "(lower(name))", name: "index_spree_refund_reasons_on_lower_name", unique: true
+ end
+
+ create_table "spree_refunds", force: :cascade do |t|
+ t.integer "payment_id"
+ t.decimal "amount", precision: 10, scale: 2, default: "0.0", null: false
+ t.string "transaction_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "refund_reason_id"
+ t.integer "reimbursement_id"
+ t.index ["payment_id"], name: "index_spree_refunds_on_payment_id"
+ t.index ["refund_reason_id"], name: "index_refunds_on_refund_reason_id"
+ t.index ["reimbursement_id"], name: "index_spree_refunds_on_reimbursement_id"
+ end
+
+ create_table "spree_reimbursement_credits", force: :cascade do |t|
+ t.decimal "amount", precision: 10, scale: 2, default: "0.0", null: false
+ t.integer "reimbursement_id"
+ t.integer "creditable_id"
+ t.string "creditable_type"
+ t.index ["creditable_id", "creditable_type"], name: "index_reimbursement_credits_on_creditable_id_and_type"
+ t.index ["reimbursement_id"], name: "index_spree_reimbursement_credits_on_reimbursement_id"
+ end
+
+ create_table "spree_reimbursement_types", force: :cascade do |t|
+ t.string "name"
+ t.boolean "active", default: true
+ t.boolean "mutable", default: true
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "type"
+ t.index "(lower(name))", name: "index_spree_reimbursement_types_on_lower_name", unique: true
+ t.index ["type"], name: "index_spree_reimbursement_types_on_type"
+ end
+
+ create_table "spree_reimbursements", force: :cascade do |t|
+ t.string "number"
+ t.string "reimbursement_status"
+ t.integer "customer_return_id"
+ t.integer "order_id"
+ t.decimal "total", precision: 10, scale: 2
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["customer_return_id"], name: "index_spree_reimbursements_on_customer_return_id"
+ t.index ["number"], name: "index_spree_reimbursements_on_number", unique: true
+ t.index ["order_id"], name: "index_spree_reimbursements_on_order_id"
+ end
+
+ create_table "spree_return_authorization_reasons", force: :cascade do |t|
+ t.string "name"
+ t.boolean "active", default: true
+ t.boolean "mutable", default: true
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index "(lower(name))", name: "index_spree_return_authorization_reasons_on_lower_name", unique: true
+ end
+
+ create_table "spree_return_authorizations", force: :cascade do |t|
+ t.string "number"
+ t.string "state"
+ t.integer "order_id"
+ t.text "memo"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "stock_location_id"
+ t.integer "return_authorization_reason_id"
+ t.index ["number"], name: "index_spree_return_authorizations_on_number", unique: true
+ t.index ["order_id"], name: "index_spree_return_authorizations_on_order_id"
+ t.index ["return_authorization_reason_id"], name: "index_return_authorizations_on_return_authorization_reason_id"
+ t.index ["stock_location_id"], name: "index_spree_return_authorizations_on_stock_location_id"
+ end
+
+ create_table "spree_return_items", force: :cascade do |t|
+ t.integer "return_authorization_id"
+ t.integer "inventory_unit_id"
+ t.integer "exchange_variant_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.decimal "pre_tax_amount", precision: 12, scale: 4, default: "0.0", null: false
+ t.decimal "included_tax_total", precision: 12, scale: 4, default: "0.0", null: false
+ t.decimal "additional_tax_total", precision: 12, scale: 4, default: "0.0", null: false
+ t.string "reception_status"
+ t.string "acceptance_status"
+ t.integer "customer_return_id"
+ t.integer "reimbursement_id"
+ t.text "acceptance_status_errors"
+ t.integer "preferred_reimbursement_type_id"
+ t.integer "override_reimbursement_type_id"
+ t.boolean "resellable", default: true, null: false
+ t.index ["customer_return_id"], name: "index_return_items_on_customer_return_id"
+ t.index ["exchange_variant_id"], name: "index_spree_return_items_on_exchange_variant_id"
+ t.index ["inventory_unit_id"], name: "index_spree_return_items_on_inventory_unit_id"
+ t.index ["override_reimbursement_type_id"], name: "index_spree_return_items_on_override_reimbursement_type_id"
+ t.index ["preferred_reimbursement_type_id"], name: "index_spree_return_items_on_preferred_reimbursement_type_id"
+ t.index ["reimbursement_id"], name: "index_spree_return_items_on_reimbursement_id"
+ t.index ["return_authorization_id"], name: "index_spree_return_items_on_return_authorization_id"
+ end
+
+ create_table "spree_role_users", force: :cascade do |t|
+ t.integer "role_id"
+ t.integer "user_id"
+ t.index ["role_id"], name: "index_spree_role_users_on_role_id"
+ t.index ["user_id"], name: "index_spree_role_users_on_user_id"
+ end
+
+ create_table "spree_roles", force: :cascade do |t|
+ t.string "name"
+ t.index "(lower(name))", name: "index_spree_roles_on_lower_name", unique: true
+ end
+
+ create_table "spree_shipments", force: :cascade do |t|
+ t.string "tracking"
+ t.string "number"
+ t.decimal "cost", precision: 10, scale: 2, default: "0.0"
+ t.datetime "shipped_at"
+ t.integer "order_id"
+ t.integer "address_id"
+ t.string "state"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "stock_location_id"
+ t.decimal "adjustment_total", precision: 10, scale: 2, default: "0.0"
+ t.decimal "additional_tax_total", precision: 10, scale: 2, default: "0.0"
+ t.decimal "promo_total", precision: 10, scale: 2, default: "0.0"
+ t.decimal "included_tax_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.decimal "pre_tax_amount", precision: 12, scale: 4, default: "0.0", null: false
+ t.decimal "taxable_adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.decimal "non_taxable_adjustment_total", precision: 10, scale: 2, default: "0.0", null: false
+ t.index ["address_id"], name: "index_spree_shipments_on_address_id"
+ t.index ["number"], name: "index_spree_shipments_on_number", unique: true
+ t.index ["order_id"], name: "index_spree_shipments_on_order_id"
+ t.index ["stock_location_id"], name: "index_spree_shipments_on_stock_location_id"
+ end
+
+ create_table "spree_shipping_categories", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["name"], name: "index_spree_shipping_categories_on_name"
+ end
+
+ create_table "spree_shipping_method_categories", force: :cascade do |t|
+ t.integer "shipping_method_id", null: false
+ t.integer "shipping_category_id", null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["shipping_category_id", "shipping_method_id"], name: "unique_spree_shipping_method_categories", unique: true
+ t.index ["shipping_category_id"], name: "index_spree_shipping_method_categories_on_shipping_category_id"
+ t.index ["shipping_method_id"], name: "index_spree_shipping_method_categories_on_shipping_method_id"
+ end
+
+ create_table "spree_shipping_method_zones", force: :cascade do |t|
+ t.integer "shipping_method_id"
+ t.integer "zone_id"
+ t.index ["shipping_method_id"], name: "index_spree_shipping_method_zones_on_shipping_method_id"
+ t.index ["zone_id"], name: "index_spree_shipping_method_zones_on_zone_id"
+ end
+
+ create_table "spree_shipping_methods", force: :cascade do |t|
+ t.string "name"
+ t.string "display_on"
+ t.datetime "deleted_at"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "tracking_url"
+ t.string "admin_name"
+ t.integer "tax_category_id"
+ t.string "code"
+ t.index ["deleted_at"], name: "index_spree_shipping_methods_on_deleted_at"
+ t.index ["tax_category_id"], name: "index_spree_shipping_methods_on_tax_category_id"
+ end
+
+ create_table "spree_shipping_rates", force: :cascade do |t|
+ t.integer "shipment_id"
+ t.integer "shipping_method_id"
+ t.boolean "selected", default: false
+ t.decimal "cost", precision: 8, scale: 2, default: "0.0"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "tax_rate_id"
+ t.index ["selected"], name: "index_spree_shipping_rates_on_selected"
+ t.index ["shipment_id", "shipping_method_id"], name: "spree_shipping_rates_join_index", unique: true
+ t.index ["shipment_id"], name: "index_spree_shipping_rates_on_shipment_id"
+ t.index ["shipping_method_id"], name: "index_spree_shipping_rates_on_shipping_method_id"
+ t.index ["tax_rate_id"], name: "index_spree_shipping_rates_on_tax_rate_id"
+ end
+
+ create_table "spree_state_changes", force: :cascade do |t|
+ t.string "name"
+ t.string "previous_state"
+ t.integer "stateful_id"
+ t.integer "user_id"
+ t.string "stateful_type"
+ t.string "next_state"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["stateful_id", "stateful_type"], name: "index_spree_state_changes_on_stateful_id_and_stateful_type"
+ end
+
+ create_table "spree_states", force: :cascade do |t|
+ t.string "name"
+ t.string "abbr"
+ t.integer "country_id"
+ t.datetime "updated_at"
+ t.index ["country_id"], name: "index_spree_states_on_country_id"
+ end
+
+ create_table "spree_stock_items", force: :cascade do |t|
+ t.integer "stock_location_id"
+ t.integer "variant_id"
+ t.integer "count_on_hand", default: 0, null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.boolean "backorderable", default: false
+ t.datetime "deleted_at"
+ t.index ["backorderable"], name: "index_spree_stock_items_on_backorderable"
+ t.index ["deleted_at"], name: "index_spree_stock_items_on_deleted_at"
+ t.index ["stock_location_id", "variant_id"], name: "stock_item_by_loc_and_var_id"
+ t.index ["stock_location_id"], name: "index_spree_stock_items_on_stock_location_id"
+ t.index ["variant_id"], name: "index_spree_stock_items_on_variant_id"
+ end
+
+ create_table "spree_stock_locations", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.boolean "default", default: false, null: false
+ t.string "address1"
+ t.string "address2"
+ t.string "city"
+ t.integer "state_id"
+ t.string "state_name"
+ t.integer "country_id"
+ t.string "zipcode"
+ t.string "phone"
+ t.boolean "active", default: true
+ t.boolean "backorderable_default", default: false
+ t.boolean "propagate_all_variants", default: true
+ t.string "admin_name"
+ t.index ["active"], name: "index_spree_stock_locations_on_active"
+ t.index ["backorderable_default"], name: "index_spree_stock_locations_on_backorderable_default"
+ t.index ["country_id"], name: "index_spree_stock_locations_on_country_id"
+ t.index ["propagate_all_variants"], name: "index_spree_stock_locations_on_propagate_all_variants"
+ t.index ["state_id"], name: "index_spree_stock_locations_on_state_id"
+ end
+
+ create_table "spree_stock_movements", force: :cascade do |t|
+ t.integer "stock_item_id"
+ t.integer "quantity", default: 0
+ t.string "action"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "originator_type"
+ t.integer "originator_id"
+ t.index ["originator_id", "originator_type"], name: "index_stock_movements_on_originator_id_and_originator_type"
+ t.index ["stock_item_id"], name: "index_spree_stock_movements_on_stock_item_id"
+ end
+
+ create_table "spree_stock_transfers", force: :cascade do |t|
+ t.string "type"
+ t.string "reference"
+ t.integer "source_location_id"
+ t.integer "destination_location_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "number"
+ t.index ["destination_location_id"], name: "index_spree_stock_transfers_on_destination_location_id"
+ t.index ["number"], name: "index_spree_stock_transfers_on_number", unique: true
+ t.index ["source_location_id"], name: "index_spree_stock_transfers_on_source_location_id"
+ end
+
+ create_table "spree_store_credit_categories", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ end
+
+ create_table "spree_store_credit_events", force: :cascade do |t|
+ t.integer "store_credit_id", null: false
+ t.string "action", null: false
+ t.decimal "amount", precision: 8, scale: 2
+ t.string "authorization_code", null: false
+ t.decimal "user_total_amount", precision: 8, scale: 2, default: "0.0", null: false
+ t.integer "originator_id"
+ t.string "originator_type"
+ t.datetime "deleted_at"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["originator_id", "originator_type"], name: "spree_store_credit_events_originator"
+ t.index ["store_credit_id"], name: "index_spree_store_credit_events_on_store_credit_id"
+ end
+
+ create_table "spree_store_credit_types", force: :cascade do |t|
+ t.string "name"
+ t.integer "priority"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["priority"], name: "index_spree_store_credit_types_on_priority"
+ end
+
+ create_table "spree_store_credits", force: :cascade do |t|
+ t.integer "user_id"
+ t.integer "category_id"
+ t.integer "created_by_id"
+ t.decimal "amount", precision: 8, scale: 2, default: "0.0", null: false
+ t.decimal "amount_used", precision: 8, scale: 2, default: "0.0", null: false
+ t.text "memo"
+ t.datetime "deleted_at"
+ t.string "currency"
+ t.decimal "amount_authorized", precision: 8, scale: 2, default: "0.0", null: false
+ t.integer "originator_id"
+ t.string "originator_type"
+ t.integer "type_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["deleted_at"], name: "index_spree_store_credits_on_deleted_at"
+ t.index ["originator_id", "originator_type"], name: "spree_store_credits_originator"
+ t.index ["type_id"], name: "index_spree_store_credits_on_type_id"
+ t.index ["user_id"], name: "index_spree_store_credits_on_user_id"
+ end
+
+ create_table "spree_stores", force: :cascade do |t|
+ t.string "name"
+ t.string "url"
+ t.text "meta_description"
+ t.text "meta_keywords"
+ t.string "seo_title"
+ t.string "mail_from_address"
+ t.string "default_currency"
+ t.string "code"
+ t.boolean "default", default: false, null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "facebook"
+ t.string "twitter"
+ t.string "instagram"
+ t.index "(lower(code))", name: "index_spree_stores_on_lower_code", unique: true
+ t.index ["default"], name: "index_spree_stores_on_default"
+ t.index ["url"], name: "index_spree_stores_on_url"
+ end
+
+ create_table "spree_tax_categories", force: :cascade do |t|
+ t.string "name"
+ t.string "description"
+ t.boolean "is_default", default: false
+ t.datetime "deleted_at"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "tax_code"
+ t.index ["deleted_at"], name: "index_spree_tax_categories_on_deleted_at"
+ t.index ["is_default"], name: "index_spree_tax_categories_on_is_default"
+ end
+
+ create_table "spree_tax_rates", force: :cascade do |t|
+ t.decimal "amount", precision: 8, scale: 5
+ t.integer "zone_id"
+ t.integer "tax_category_id"
+ t.boolean "included_in_price", default: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "name"
+ t.boolean "show_rate_in_label", default: true
+ t.datetime "deleted_at"
+ t.index ["deleted_at"], name: "index_spree_tax_rates_on_deleted_at"
+ t.index ["included_in_price"], name: "index_spree_tax_rates_on_included_in_price"
+ t.index ["show_rate_in_label"], name: "index_spree_tax_rates_on_show_rate_in_label"
+ t.index ["tax_category_id"], name: "index_spree_tax_rates_on_tax_category_id"
+ t.index ["zone_id"], name: "index_spree_tax_rates_on_zone_id"
+ end
+
+ create_table "spree_taxonomies", force: :cascade do |t|
+ t.string "name", null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "position", default: 0
+ t.index ["position"], name: "index_spree_taxonomies_on_position"
+ end
+
+ create_table "spree_taxons", force: :cascade do |t|
+ t.integer "parent_id"
+ t.integer "position", default: 0
+ t.string "name", null: false
+ t.string "permalink"
+ t.integer "taxonomy_id"
+ t.integer "lft"
+ t.integer "rgt"
+ t.text "description"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "meta_title"
+ t.string "meta_description"
+ t.string "meta_keywords"
+ t.integer "depth"
+ t.boolean "hide_from_nav", default: false
+ t.index ["lft"], name: "index_spree_taxons_on_lft"
+ t.index ["name"], name: "index_spree_taxons_on_name"
+ t.index ["parent_id"], name: "index_taxons_on_parent_id"
+ t.index ["permalink"], name: "index_taxons_on_permalink"
+ t.index ["position"], name: "index_spree_taxons_on_position"
+ t.index ["rgt"], name: "index_spree_taxons_on_rgt"
+ t.index ["taxonomy_id"], name: "index_taxons_on_taxonomy_id"
+ end
+
+ create_table "spree_trackers", force: :cascade do |t|
+ t.string "analytics_id"
+ t.boolean "active", default: true
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.integer "engine", default: 0, null: false
+ t.index ["active"], name: "index_spree_trackers_on_active"
+ end
+
+ create_table "spree_users", force: :cascade do |t|
+ t.string "encrypted_password", limit: 128
+ t.string "password_salt", limit: 128
+ t.string "email"
+ t.string "remember_token"
+ t.string "persistence_token"
+ t.string "reset_password_token"
+ t.string "perishable_token"
+ t.integer "sign_in_count", default: 0, null: false
+ t.integer "failed_attempts", default: 0, null: false
+ t.datetime "last_request_at"
+ t.datetime "current_sign_in_at"
+ t.datetime "last_sign_in_at"
+ t.string "current_sign_in_ip"
+ t.string "last_sign_in_ip"
+ t.string "login"
+ t.integer "ship_address_id"
+ t.integer "bill_address_id"
+ t.string "authentication_token"
+ t.string "unlock_token"
+ t.datetime "locked_at"
+ t.datetime "reset_password_sent_at"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "spree_api_key", limit: 48
+ t.datetime "remember_created_at"
+ t.datetime "deleted_at"
+ t.string "confirmation_token"
+ t.datetime "confirmed_at"
+ t.datetime "confirmation_sent_at"
+ t.index ["bill_address_id"], name: "index_spree_users_on_bill_address_id"
+ t.index ["deleted_at"], name: "index_spree_users_on_deleted_at"
+ t.index ["email"], name: "email_idx_unique", unique: true
+ t.index ["ship_address_id"], name: "index_spree_users_on_ship_address_id"
+ t.index ["spree_api_key"], name: "index_spree_users_on_spree_api_key"
+ end
+
+ create_table "spree_variants", force: :cascade do |t|
+ t.string "sku", default: "", null: false
+ t.decimal "weight", precision: 8, scale: 2, default: "0.0"
+ t.decimal "height", precision: 8, scale: 2
+ t.decimal "width", precision: 8, scale: 2
+ t.decimal "depth", precision: 8, scale: 2
+ t.datetime "deleted_at"
+ t.boolean "is_master", default: false
+ t.integer "product_id"
+ t.decimal "cost_price", precision: 10, scale: 2
+ t.integer "position"
+ t.string "cost_currency"
+ t.boolean "track_inventory", default: true
+ t.integer "tax_category_id"
+ t.datetime "updated_at", null: false
+ t.datetime "discontinue_on"
+ t.datetime "created_at", null: false
+ t.index ["deleted_at"], name: "index_spree_variants_on_deleted_at"
+ t.index ["discontinue_on"], name: "index_spree_variants_on_discontinue_on"
+ t.index ["is_master"], name: "index_spree_variants_on_is_master"
+ t.index ["position"], name: "index_spree_variants_on_position"
+ t.index ["product_id"], name: "index_spree_variants_on_product_id"
+ t.index ["sku"], name: "index_spree_variants_on_sku"
+ t.index ["tax_category_id"], name: "index_spree_variants_on_tax_category_id"
+ t.index ["track_inventory"], name: "index_spree_variants_on_track_inventory"
+ end
+
+ create_table "spree_zone_members", force: :cascade do |t|
+ t.string "zoneable_type"
+ t.integer "zoneable_id"
+ t.integer "zone_id"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["zone_id"], name: "index_spree_zone_members_on_zone_id"
+ t.index ["zoneable_id", "zoneable_type"], name: "index_spree_zone_members_on_zoneable_id_and_zoneable_type"
+ end
+
+ create_table "spree_zones", force: :cascade do |t|
+ t.string "name"
+ t.string "description"
+ t.boolean "default_tax", default: false
+ t.integer "zone_members_count", default: 0
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.string "kind"
+ t.index ["default_tax"], name: "index_spree_zones_on_default_tax"
+ t.index ["kind"], name: "index_spree_zones_on_kind"
+ end
+
+ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
+ add_foreign_key "spree_oauth_access_grants", "spree_oauth_applications", column: "application_id"
+ add_foreign_key "spree_oauth_access_tokens", "spree_oauth_applications", column: "application_id"
+end
diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb
new file mode 100644
index 0000000..19f3c23
--- /dev/null
+++ b/spec/dummy/db/seeds.rb
@@ -0,0 +1,3 @@
+
+Spree::Core::Engine.load_seed if defined?(Spree::Core)
+Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
diff --git a/spec/dummy/lib/assets/.keep b/spec/dummy/lib/assets/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/spec/dummy/log/.keep b/spec/dummy/log/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/spec/dummy/spree_sandbox.thor b/spec/dummy/spree_sandbox.thor
new file mode 100644
index 0000000..14e4e01
--- /dev/null
+++ b/spec/dummy/spree_sandbox.thor
@@ -0,0 +1,6 @@
+
+require 'datashift'
+require 'datashift_spree'
+
+DatashiftSpree::load_commands
+DataShift::load_commands
diff --git a/spec/dummy/spree_sandbox_installed.txt b/spec/dummy/spree_sandbox_installed.txt
new file mode 100644
index 0000000..df6e243
--- /dev/null
+++ b/spec/dummy/spree_sandbox_installed.txt
@@ -0,0 +1 @@
+2020-02-18 16:00:33 +0100
\ No newline at end of file
diff --git a/spec/dummy/vendor/assets/javascripts/spree/backend/all.js b/spec/dummy/vendor/assets/javascripts/spree/backend/all.js
new file mode 100644
index 0000000..63e301e
--- /dev/null
+++ b/spec/dummy/vendor/assets/javascripts/spree/backend/all.js
@@ -0,0 +1,11 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require spree/backend
+
+//= require_tree .
diff --git a/spec/dummy/vendor/assets/javascripts/spree/frontend/all.js b/spec/dummy/vendor/assets/javascripts/spree/frontend/all.js
new file mode 100644
index 0000000..4601b40
--- /dev/null
+++ b/spec/dummy/vendor/assets/javascripts/spree/frontend/all.js
@@ -0,0 +1,12 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require accounting.min
+//= require spree/frontend
+
+//= require_tree .
diff --git a/spec/dummy/vendor/assets/stylesheets/spree/backend/all.css b/spec/dummy/vendor/assets/stylesheets/spree/backend/all.css
new file mode 100644
index 0000000..3319270
--- /dev/null
+++ b/spec/dummy/vendor/assets/stylesheets/spree/backend/all.css
@@ -0,0 +1,10 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require spree/backend
+
+ *= require_self
+ *= require_tree .
+*/
diff --git a/spec/dummy/vendor/assets/stylesheets/spree/frontend/all.css b/spec/dummy/vendor/assets/stylesheets/spree/frontend/all.css
new file mode 100644
index 0000000..1fc8378
--- /dev/null
+++ b/spec/dummy/vendor/assets/stylesheets/spree/frontend/all.css
@@ -0,0 +1,10 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require spree/frontend
+
+ *= require_self
+ *= require_tree .
+*/
diff --git a/spec/datashift_spree/spree_exporter_spec.rb b/spec/models/spree_exporter_spec.rb
similarity index 76%
rename from spec/datashift_spree/spree_exporter_spec.rb
rename to spec/models/spree_exporter_spec.rb
index 726df8d..ccde84d 100644
--- a/spec/datashift_spree/spree_exporter_spec.rb
+++ b/spec/models/spree_exporter_spec.rb
@@ -1,6 +1,5 @@
-# Copyright:: (c) Autotelik Media Ltd 2016
+# Copyright:: (c) Autotelik B.V 2016
# Author :: Tom Statter
-# Date :: Summer 2012
#
# License:: MIT - Free, OpenSource
#
@@ -9,10 +8,7 @@
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
# Spree Products, associations and Images
#
-require "spec_helper"
-
-require 'excel_exporter'
-require 'csv_exporter'
+require "rails_helper"
describe 'SpreeExporter' do
@@ -21,12 +17,11 @@
end
before(:each) do
-
# Create some test data
- root = @Taxonomy_klass.create( :name => 'Paintings' )
+ root = ::Spree::Taxonomy.create( :name => 'Paintings' )
- @Taxon_klass.create( :name => 'Landscape', :description => "Nice paintings", :taxonomy_id => root.id )
- @Taxon_klass.create( :name => 'Sea', :description => "Waves and sand", :taxonomy_id => root.id )
+ ::Spree::Taxon.create( :name => 'Landscape', :description => "Nice paintings", :taxonomy_id => root.id )
+ ::Spree::Taxon.create( :name => 'Sea', :description => "Waves and sand", :taxonomy_id => root.id )
end
it "should export any Spree model to .xls spreedsheet" do
@@ -38,7 +33,7 @@
exporter = DataShift::ExcelExporter.new
- items = @Taxon_klass.all
+ items = ::Spree::Taxon.all
exporter.export(expect, items)
@@ -51,9 +46,9 @@
exporter = DataShift::ExcelExporter.new
- items = @Taxon_klass.all
+ items = ::Spree::Taxon.all
- exporter.export_with_associations(expect, @Taxon_klass, items)
+ exporter.export_with_associations(expect, ::Spree::Taxon, items)
expect(File.exists?(expect)).to eq true
diff --git a/spec/datashift_spree/spree_generator_spec.rb b/spec/models/spree_generator_spec.rb
similarity index 70%
rename from spec/datashift_spree/spree_generator_spec.rb
rename to spec/models/spree_generator_spec.rb
index 52f3ac7..dcc35a3 100644
--- a/spec/datashift_spree/spree_generator_spec.rb
+++ b/spec/models/spree_generator_spec.rb
@@ -1,6 +1,5 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Summer 2011
#
# License:: MIT - Free, OpenSource
#
@@ -9,12 +8,9 @@
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
# Spree Products, associations and Images
#
-require "spec_helper"
-
-require 'excel_generator'
-
-module DataShift
+require 'rails_helper'
+module DatashiftSpree
describe 'SpreeGenerator' do
@@ -23,15 +19,10 @@ module DataShift
before do
# Create some test data
- root = @Taxonomy_klass.create( :name => 'Paintings' )
-
- if(DataShift::SpreeEcom::version.to_f > 1 )
- root.taxons.create( :name => 'Landscape' )
- root.taxons.create( :name => 'Sea' )
- else
- @Taxon_klass.create( :name => 'Landscape', :taxonomy => root )
- @Taxon_klass.create( :name => 'Sea', :taxonomy => root )
- end
+ root = ::Spree::Taxonomy.create( :name => 'Paintings' )
+
+ root.taxons.create( :name => 'Landscape' )
+ root.taxons.create( :name => 'Sea' )
end
it "should export any Spree model to .xls spreedsheet" do
@@ -40,7 +31,7 @@ module DataShift
excel = DataShift::ExcelGenerator.new
- excel.generate(expected, @Taxonomy_klass)
+ excel.generate(expected, ::Spree::Taxonomy)
expect(File.exists?(expected)).to eq true
@@ -50,7 +41,7 @@ module DataShift
excel.file_name = expected
- excel.generate(expected, @Taxon_klass)
+ excel.generate(expected, ::Spree::Taxon)
expect(File.exists?(expected)).to eq true
@@ -68,7 +59,7 @@ module DataShift
expect(File.exists?(expected)).to eq true
- excel = Excel.new
+ excel = DataShift::Excel.new
excel.open(expected)
expect(excel.worksheets.size).to eq 1
diff --git a/spec/datashift_spree/spree_images_loader_spec.rb b/spec/models/spree_images_loader_spec.rb
similarity index 82%
rename from spec/datashift_spree/spree_images_loader_spec.rb
rename to spec/models/spree_images_loader_spec.rb
index 34b76aa..7c371a2 100644
--- a/spec/datashift_spree/spree_images_loader_spec.rb
+++ b/spec/models/spree_images_loader_spec.rb
@@ -1,6 +1,5 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Summer 2011
#
# License:: MIT - Free, OpenSource
#
@@ -14,11 +13,9 @@
#
# These are marked with :passes_only_in_spec_dir => true do
#
-require "spec_helper"
+require "rails_helper"
-require 'image_loader'
-
-module DataShift
+module DatashiftSpree
describe 'SpreeImageLoading' do
@@ -30,7 +27,7 @@ module DataShift
DataShift::Configuration.call.mandatory = ['sku', 'name', 'price']
end
- it "should report errors in Image paths during CSV Product loading" do
+ it "should report errors in Image paths during CSV Product loading", ffs: true do
report_errors_tests 'SpreeProductsWithBadImages.csv'
end
@@ -40,7 +37,8 @@ module DataShift
def report_errors_tests( x )
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file(x))
+ puts "Load ", ifixture_file(x)
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file(x))
product_loader.run
@@ -54,13 +52,13 @@ def report_errors_tests( x )
p = Spree::Product.find_by_name("Demo Product for AR Loader")
- p.should be_nil
+ expect(p).to be_nil
end
it "should create Image from path in Product loading column from CSV" do
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProductsWithImages.csv'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProductsWithImages.csv'))
product_loader.run
@@ -84,7 +82,7 @@ def report_errors_tests( x )
it "should create Image from path in Product loading column from .xls" do
# Spreadsheet contains paths relative to here
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProductsWithImages.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProductsWithImages.xls'))
product_loader.run
@@ -110,7 +108,7 @@ def report_errors_tests( x )
# Base of the fixtures path, will create a FULL path to each image
Configuration.call.image_path_prefix = rspec_spec_path
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProductsWithImages.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProductsWithImages.xls'))
product_loader.run
@@ -134,7 +132,7 @@ def report_errors_tests( x )
expect(Spree::Product.count).to eq 0
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProducts.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProducts.xls'))
product_loader.run
@@ -150,7 +148,7 @@ def report_errors_tests( x )
Configuration.call.image_path_prefix = rspec_spec_path
pending "This should now be a Populator"
- DataShift::SpreeEcom::ImageLoader.new.run( ifixture_file('SpreeImagesBySku.xls') )
+ DatashiftSpree::ImageLoader.new.run( ifixture_file('SpreeImagesBySku.xls') )
expect(Spree::Image.count).to eq 3
@@ -163,7 +161,7 @@ def report_errors_tests( x )
expect(Spree::Product.count).to eq 0
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProducts.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProducts.xls'))
product_loader.run
@@ -176,7 +174,7 @@ def report_errors_tests( x )
expect(p.images.size).to eq 0
pending "This should now be a Populator"
- loader = DataShift::SpreeEcom::ImageLoader.new
+ loader = DatashiftSpree::ImageLoader.new
loader.run(ifixture_file('SpreeImagesByName.xls'))
@@ -195,14 +193,14 @@ def report_errors_tests( x )
Configuration.call.image_path_prefix = rspec_spec_path
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProductsWithMultipleImages.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProductsWithMultipleImages.xls'))
product_loader.run
expect(Spree::Product.count).to eq 2
expect(Spree::Image.count).to eq 5
- p = DataShift::SpreeEcom::get_image_owner( Spree::Product.find_by_name("Demo Product 001") )
+ p = DatashiftSpree::get_image_owner( Spree::Product.find_by_name("Demo Product 001") )
expect(p.sku).to eq 'MULTI_001'
expect(p.images.size).to eq 3
@@ -210,7 +208,7 @@ def report_errors_tests( x )
expect(p.images[0].alt).to eq ''
expect(p.images[1].alt).to eq 'alt text for multi 001'
- p = DataShift::SpreeEcom::get_image_owner( Spree::Product.find_by_name("Demo Product 002") )
+ p = DatashiftSpree::get_image_owner( Spree::Product.find_by_name("Demo Product 002") )
expect(p.sku).to eq 'MULTI_002'
expect(p.images.size).to eq 2
@@ -222,7 +220,7 @@ def report_errors_tests( x )
# first load some products with SKUs that match the image names
expect(Spree::Product.count).to eq 0
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProducts.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProducts.xls'))
product_loader.run
@@ -231,7 +229,7 @@ def report_errors_tests( x )
# now the test - find files, chew up name, find product, create image, attach
- image_klass = DataShift::SpreeEcom::get_spree_class('Image' )
+ image_klass = DatashiftSpree::get_spree_class('Image' )
raise "Cannot find Attachment Class" unless image_klass
diff --git a/spec/datashift_spree/spree_images_over_http_spec.rb b/spec/models/spree_images_over_http_spec.rb
similarity index 94%
rename from spec/datashift_spree/spree_images_over_http_spec.rb
rename to spec/models/spree_images_over_http_spec.rb
index b3a842c..f386010 100644
--- a/spec/datashift_spree/spree_images_over_http_spec.rb
+++ b/spec/models/spree_images_over_http_spec.rb
@@ -1,6 +1,5 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Summer 2011
#
# License:: MIT - Free, OpenSource
#
@@ -14,10 +13,7 @@
#
# These are marked with :passes_only_in_spec_dir => true do
#
-require "spec_helper"
-
-require 'product_loader'
-require 'image_loader'
+require "rails_helper"
describe 'SpreeImageLoading' do
diff --git a/spec/datashift_spree/spree_loader_spec.rb b/spec/models/spree_loader_spec.rb
similarity index 87%
rename from spec/datashift_spree/spree_loader_spec.rb
rename to spec/models/spree_loader_spec.rb
index 8d4d66f..367d493 100644
--- a/spec/datashift_spree/spree_loader_spec.rb
+++ b/spec/models/spree_loader_spec.rb
@@ -1,6 +1,5 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Summer 2011
#
# License:: MIT - Free, OpenSource
#
@@ -9,7 +8,7 @@
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
# Spree Products, associations and Images
#
-require "spec_helper"
+require "rails_helper"
describe 'SpreeLoader' do
@@ -52,7 +51,7 @@
# should perform identically regardless of source, whether csv, .xls etc
- it "should load basic Products .xls via Spree loader" do
+ it "should load basic Products .xls via Spree loader", ffs: true do
test_basic_product('SpreeProductsSimple.xls')
end
@@ -62,7 +61,7 @@
def test_basic_product( source )
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file(source))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file(source))
product_loader.run
@@ -77,28 +76,23 @@ def test_basic_product( source )
expect(loader.failed_count).to eq 0
expect(loader.loaded_count).to eq 3
- expect(loader.loaded_count).to eq Spree::Product.count
+ expect(loader.loaded_count).to eq Spree::Product.count
p = Spree::Product.first
+ pp p
expect(p.sku).to eq "SIMPLE_001"
expect(p.price).to eq 345.78
expect(p.name).to eq "Simple Product for AR Loader"
expect(p.description).to eq "blah blah"
expect(p.cost_price).to eq 320.00
- expect(p.option_types.size).to eq 1
expect(p.option_types.size).to eq 1
expect(p.has_variants?).to eq false
- if(DataShift::SpreeEcom::version.to_f < 2 )
- expect(p.master.count_on_hand).to eq 12
- expect(Spree::Product.last.master.count_on_hand).to eq 23
- else
- puts p.master.stock_items.first.count_on_hand.inspect
- # expect(p.master.stock_items.first.count_on_hand).to eq 12
- end
+ puts p.master.stock_items.first.count_on_hand.inspect
+ expect(p.master.stock_items.first.count_on_hand).to eq 12
end
@@ -120,14 +114,14 @@ def test_basic_product( source )
factory.set_prefix_on(Spree::Product, 'SKU', 'SPEC_')
end
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProductsMandatoryOnly.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProductsMandatoryOnly.xls'))
test_default_values(product_loader)
end
it "should support default values from config for Spree Products loader" do
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file('SpreeProductsMandatoryOnly.xls'))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file('SpreeProductsMandatoryOnly.xls'))
product_loader.configure_from( ifixture_file('SpreeProductsDefaults.yml') )
@@ -181,7 +175,7 @@ def test_default_values(product_loader)
def test_properties_creation( source )
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file(source))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file(source))
# want to test both lookup and dynamic creation - this Prop should be found, rest created
Spree::Property.create( :name => 'test_pp_001', :presentation => 'Test PP 001' )
@@ -228,7 +222,7 @@ def expected_multi_column_properties
end
let(:product_loader) {
- DataShift::SpreeEcom::ProductLoader.new(negative_fixture_file('SpreeProdMissManyMandatory.xls'))
+ DatashiftSpree::ProductLoader.new(negative_fixture_file('SpreeProdMissManyMandatory.xls'))
}
it "should raise exception when mandatory columns missing from .xls", :ex => true do
diff --git a/spec/datashift_spree/spree_taxons_loader_spec.rb b/spec/models/spree_taxons_loader_spec.rb
similarity index 70%
rename from spec/datashift_spree/spree_taxons_loader_spec.rb
rename to spec/models/spree_taxons_loader_spec.rb
index 5bc708f..89257db 100644
--- a/spec/datashift_spree/spree_taxons_loader_spec.rb
+++ b/spec/models/spree_taxons_loader_spec.rb
@@ -1,6 +1,5 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Summer 2011
#
# License:: MIT - Free, OpenSource
#
@@ -9,9 +8,7 @@
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
# Spree Products, associations and Images
#
-require "spec_helper"
-
-require 'product_loader'
+require "rails_helper"
describe 'SpreeLoader' do
@@ -42,13 +39,13 @@ def test_taxon_creation( source )
x = root.taxons.create( :name => 'Landscape')
root.root.children << x
- Spree::Taxonomy.count.should == 1
- Spree::Taxon.count.should == 2
+ expect(Spree::Taxonomy.count).to eq 1
+ expect(Spree::Taxon.count).to eq 2
expect(root.root.children.size).to eq 1
expect(root.root.children[0].name).to eq 'Landscape'
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file(source))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file(source))
product_loader.run
@@ -65,8 +62,7 @@ def expected_multi_column_taxons
# Paintings >Nature>Seascape + Paintings>Landscape
# Drawings
- Spree::Taxonomy.all.collect(&:name).sort.should == ["Drawings", "Oils", "Paintings", "WaterColour"]
-
+ expect(Spree::Taxonomy.all.collect(&:name).sort).to eq ["Drawings", "Oils", "Paintings", "WaterColour"]
expect(Spree::Taxonomy.count).to eq 4
expect(Spree::Taxon.count).to eq 7
@@ -76,31 +72,31 @@ def expected_multi_column_taxons
p = @Variant_klass.where(sku: "DEMO_001").first.product
expect(p.taxons.size).to eq 2
- p.taxons.collect(&:name).sort.should == ['Paintings','WaterColour']
+ expect(p.taxons.collect(&:name).sort).to eq ['Paintings','WaterColour']
p2 = @Variant_klass.find_by_sku("DEMO_002").product
expect(p2.taxons.size).to eq 4
- p2.taxons.collect(&:name).sort.should == ['Nature','Oils','Paintings','Seascape']
+ expect(p2.taxons.collect(&:name).sort).to eq ['Nature','Oils','Paintings','Seascape']
paint_parent = Spree::Taxonomy.find_by_name('Paintings')
expect(paint_parent.taxons.size).to eq 4 # 3 children + all Taxonomies have a root Taxon
-
- paint_parent.taxons.collect(&:name).sort.should == ['Landscape','Nature','Paintings','Seascape']
+
+ expect(paint_parent.taxons.collect(&:name).sort).to eq ['Landscape','Nature','Paintings','Seascape']
tn = Spree::Taxon.find_by_name('Nature') # child with children
ts = Spree::Taxon.find_by_name('Seascape') # last child
- ts.should_not be_nil
- tn.should_not be_nil
-
- p2.taxons.collect( &:id ).should include(ts.id)
- p2.taxons.collect( &:id ).should include(tn.id)
+ expect(ts).to_not be_nil
+ expect(tn).to_not be_nil
+
+ expect(p2.taxons.collect( &:id )).to include(ts.id)
+ expect(p2.taxons.collect( &:id )).to include(tn.id)
-
- tn.parent.id.should == paint_parent.root.id
- ts.parent.id.should == tn.id
+
+ expect(tn.parent.id).to eq paint_parent.root.id
+ expect(ts.parent.id).to eq tn.id
expect(tn.children.size).to eq 1
expect(ts.children.size).to eq 0
@@ -112,8 +108,8 @@ def expected_multi_column_taxons
Spree::Taxonomy.delete_all
Spree::Taxon.delete_all
- Spree::Taxonomy.count.should == 0
- Spree::Taxon.count.should == 0
+ expect(Spree::Taxonomy.count).to eq 0
+ expect(Spree::Taxon.count).to eq 0
expected_nested_multi_column_taxons 'SpreeProductsComplexTaxons.xls'
end
@@ -121,17 +117,17 @@ def expected_multi_column_taxons
it "should load nested Taxons correctly even when same names from xls", :taxons => true do
Spree::Taxonomy.delete_all
- Spree::Taxon.delete_all
-
- Spree::Taxonomy.count.should == 0
- Spree::Taxon.count.should == 0
+ Spree::Taxon.delete_all
+
+ expect(Spree::Taxonomy.count).to eq 0
+ expect(Spree::Taxon.count).to eq 0
expected_nested_multi_column_taxons 'SpreeProductsComplexTaxons.csv'
end
def expected_nested_multi_column_taxons(source)
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file(source) )
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file(source) )
product_loader.run
@@ -150,18 +146,18 @@ def expected_nested_multi_column_taxons(source)
puts Spree::Taxonomy.all.collect(&:name).sort.inspect
expect(Spree::Taxonomy.count).to eq 5
-
- Spree::Taxonomy.all.collect(&:name).sort.should == ['Drawings', 'Landscape', 'Oils', 'Paintings','WaterColour']
-
- Spree::Taxonomy.all.collect(&:root).collect(&:name).sort.should == ['Drawings', 'Landscape', 'Oils', 'Paintings','WaterColour']
+
+ expect(Spree::Taxonomy.all.collect(&:name).sort).to eq ['Drawings', 'Landscape', 'Oils', 'Paintings','WaterColour']
+
+ expect(Spree::Taxonomy.all.collect(&:root).collect(&:name).sort).to eq ['Drawings', 'Landscape', 'Oils', 'Paintings','WaterColour']
taxons = Spree::Taxon.all.collect(&:name).sort
#puts "#{taxons.inspect} (#{taxons.size})"
expect(Spree::Taxon.count).to eq 12
-
- taxons.should == ['Bristol', 'Cliffs', 'Drawings', 'Landscape', 'Landscape', 'Landscape', 'Landscape', 'Nature', 'Oils', 'Paintings', 'Seascape','WaterColour']
+
+ expect(taxons).to eq ['Bristol', 'Cliffs', 'Drawings', 'Landscape', 'Landscape', 'Landscape', 'Landscape', 'Nature', 'Oils', 'Paintings', 'Seascape','WaterColour']
# drill down acts_as_nested_set ensure structures correct
@@ -178,7 +174,7 @@ def expected_nested_multi_column_taxons(source)
painting = painting_onomy.root
expect(painting.children.size).to eq 2
- painting.children.collect(&:name).sort.should == ["Landscape", "Nature"]
+ expect(painting.children.collect(&:name).sort).to eq ["Landscape", "Nature"]
expect(painting.descendants.size).to eq 5
@@ -186,42 +182,41 @@ def expected_nested_multi_column_taxons(source)
nature = nil
Spree::Taxon.each_with_level(painting.self_and_descendants) do |t, i|
-
-
+
if(t.name == 'Nature')
nature = t
- i.should == 1
+ expect(i).to eq 1
expect(t.children.size).to eq 2
- t.children.collect(&:name).should == ["Landscape", "Seascape"]
+ expect(t.children.collect(&:name)).to == ["Landscape", "Seascape"]
expect(t.descendants.size).to eq 3
- t.descendants.collect(&:name).sort.should == ["Cliffs", "Landscape", "Seascape"]
+ expect(t.descendants.collect(&:name).sort).to == ["Cliffs", "Landscape", "Seascape"]
elsif(t.name == 'Landscape')
lscape[i] = t
end
end
- nature.should_not be_nil
-
- lscape.size.should be 2
- lscape[1].name.should == 'Landscape'
- lscape[1].parent.id.should == painting.id
+ expect(nature).to_not be_nil
+
+ expect(lscape.size).to eq 2
+ expect(lscape[1].name).to eq 'Landscape'
+ expect(lscape[1].parent.id).to eq painting.id
- lscape[2].name.should == 'Landscape'
- lscape[2].parent.id.should == nature.id
+ expect(lscape[2].name).to eq 'Landscape'
+ expect(lscape[2].parent.id).to eq nature.id
seascape = Spree::Taxon.find_by_name('Seascape')
expect(seascape.children.size).to eq 1
- seascape.leaf?.should be false
+ expect(seascape.leaf?).to be false
cliffs = Spree::Taxon.find_by_name('Cliffs')
expect(cliffs.children.size).to eq 0
- cliffs.leaf?.should be true
+ expect(cliffs.leaf?).to be_truthy
- Spree::Taxon.find_by_name('Seascape').ancestors.collect(&:name).sort.should == ["Nature", "Paintings"]
+ expect(Spree::Taxon.find_by_name('Seascape').ancestors.collect(&:name).sort).to eq ["Nature", "Paintings"]
# Landscape appears multiple times, under different parents
expect(Spree::Taxon.where( :name => 'Landscape').size).to eq 4
@@ -239,15 +234,15 @@ def expected_nested_multi_column_taxons(source)
b = dl.find_by_name('Bristol')
expect(b.children.size).to eq 0
- b.ancestors.collect(&:name).sort.should == ["Drawings", "Landscape"]
+ expect(b.ancestors.collect(&:name).sort).to eq ["Drawings", "Landscape"]
# empty top level taxons
['Oils', 'Landscape'].each do |t|
tx = Spree::Taxonomy.find_by_name(t)
expect(tx.taxons.size).to eq 1
- tx.root.name.should == t
+ expect(tx.root.name).to eq t
expect(tx.root.children.size).to eq 0
- tx.root.leaf?.should be true
+ expect(tx.root.leaf?).to be_truthy
end
end
diff --git a/spec/datashift_spree/spree_thor_spec.rb b/spec/models/spree_thor_spec.rb
similarity index 86%
rename from spec/datashift_spree/spree_thor_spec.rb
rename to spec/models/spree_thor_spec.rb
index 5d93d36..527d078 100644
--- a/spec/datashift_spree/spree_thor_spec.rb
+++ b/spec/models/spree_thor_spec.rb
@@ -1,28 +1,24 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Mar 2013
#
# License:: MIT - Free, OpenSource
#
# Details:: Specification for loading Spree Digitals
#
-require "spec_helper"
-require 'thor'
-require 'thor/runner'
-require 'datashift'
+require "rails_helper"
describe 'Datshift Spree Thor tasks' do
- let(:spree_sandbox_app_path) { DataShift::SpreeEcom::spree_sandbox_path }
+ let(:spree_sandbox_app_path) { DatashiftSpree::spree_sandbox_path }
before(:all) do
DataShift.load_commands
- DataShift::SpreeEcom.load_commands
+ DatashiftSpree.load_commands
end
it 'should list available datashift thor tasks' do
x = run_in(spree_sandbox_app_path) do
- capture(:stdout){ Thor::Runner.start(["list"]) }
+ capture(:stdout){ ::Thor::Runner.start(["list"]) }
end
expect(x).to include("datashift_spree\n--------")
@@ -72,8 +68,6 @@
puts "Running attach with: #{args}"
run_in(@spree_sandbox_app_path) do
-
-
x = capture(:stdout){ system("bundle exec thor datashift:paperclip:attach " + args) }
x.should start_with("datashift\n--------")
x.should =~ / csv -i/
diff --git a/spec/datashift_spree/spree_variants_loader_spec.rb b/spec/models/spree_variants_loader_spec.rb
similarity index 93%
rename from spec/datashift_spree/spree_variants_loader_spec.rb
rename to spec/models/spree_variants_loader_spec.rb
index 696c040..01b328c 100644
--- a/spec/datashift_spree/spree_variants_loader_spec.rb
+++ b/spec/models/spree_variants_loader_spec.rb
@@ -1,6 +1,5 @@
-# Copyright:: (c) Autotelik Media Ltd 2011
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Summer 2011
#
# License:: MIT - Free, OpenSource
#
@@ -9,9 +8,7 @@
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
# Spree Products, associations and Images
#
-require "spec_helper"
-
-require 'product_loader'
+require "rails_helper"
describe 'Spree Variants Loader' do
@@ -26,11 +23,11 @@
# want to test both lookup and dynamic creation - this Taxonomy should be found, rest created
root = Spree::Taxonomy.create( :name => 'Paintings' )
- t = @Taxon_klass.new( :name => 'Landscape' )
+ t = ::Spree::Taxon.new( :name => 'Landscape' )
t.taxonomy = root
t.save
- @Taxon_klass.count.should == 2
+ ::Spree::Taxon.count.should == 2
rescue => e
puts e.inspect
puts e.backtrace
@@ -54,7 +51,7 @@
def test_variants_creation( source )
- product_loader = DataShift::SpreeEcom::ProductLoader.new(ifixture_file(source))
+ product_loader = DatashiftSpree::ProductLoader.new(ifixture_file(source))
expect(Spree::Product.count).to eq 0
expect(Spree::Variant.count).to eq 0
@@ -130,7 +127,7 @@ def expected_multi_column_variants
context("Multiple Variants") do
let(:product_loader) {
- DataShift::SpreeEcom::ProductLoader.new( ifixture_file('SpreeMultiVariant.csv'))
+ DatashiftSpree::ProductLoader.new( ifixture_file('SpreeMultiVariant.csv'))
}
# Composite Variant Syntax is option_type_A_name:value;option_type_B_name:value
diff --git a/spec/datashift_spree/users_loader_spec.rb b/spec/models/users_loader_spec.rb
similarity index 87%
rename from spec/datashift_spree/users_loader_spec.rb
rename to spec/models/users_loader_spec.rb
index c6f95ed..dcb6185 100644
--- a/spec/datashift_spree/users_loader_spec.rb
+++ b/spec/models/users_loader_spec.rb
@@ -1,4 +1,4 @@
-# Copyright:: (c) Autotelik Media Ltd 2015
+# Copyright:: (c) Autotelik B.V 2015
# Author :: Tom Statter
# Date :: Summer 2015
#
@@ -10,12 +10,11 @@
#
# thor datashift:config:import -m Spree::User -r ../fixtures/config/spree_user_config.yaml
#
-require "spec_helper"
-
+require "rails_helper"
describe 'User Loading' do
- let(:user_klass) { Spree::User }
+ let(:user_klass) { ::Spree::User }
let(:loader) { DataShift::CsvLoader.new }
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
new file mode 100644
index 0000000..a20e571
--- /dev/null
+++ b/spec/rails_helper.rb
@@ -0,0 +1,119 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+require 'spec_helper'
+ENV['RAILS_ENV'] ||= 'test'
+
+# sandbox = File.expand_path( File.join(File.dirname(__FILE__), 'dummy', 'spree_sandbox_installed.txt') )
+#
+# unless File.exists?(sandbox)
+#
+# require File.join(File.expand_path('support', __dir__), 'sandbox_helper')
+#
+# DatashiftSpree::Sandbox.install_spree
+# exit
+# end
+
+ENV['BUNDLE_GEMFILE'] = File.expand_path('dummy/Gemfile', __dir__)
+
+require File.expand_path('dummy/config/environment', __dir__)
+
+# Prevent database truncation if the environment is production
+abort("The Rails environment is running in production mode!") if Rails.env.production?
+require 'rspec/rails'
+
+# Requires supporting ruby files with custom matchers and macros, etc, in
+# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
+# run as spec files by default. This means that files in spec/support that end
+# in _spec.rb will both be required and run as specs, causing the specs to be
+# run twice. It is recommended that you do not name files matching this glob to
+# end with _spec.rb. You can configure this pattern with the --pattern
+# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
+#
+# The following line is provided for convenience purposes. It has the downside
+# of increasing the boot-up time by auto-requiring all files in the support
+# directory. Alternatively, in the individual `*_spec.rb` files, manually
+# require only the support files necessary.
+
+# N.B Rails.root will be path : 'spec/dummy'
+
+ENGINE_ROOT = File.join(File.dirname(__FILE__), '../') unless defined? ENGINE_ROOT
+
+Dir[File.join(File.expand_path('support', __dir__), '**', '*.rb')].each { |f| pp f; require f }
+
+# Add additional requires below this line. Rails is not loaded until this point!
+
+# Checks for pending migrations and applies them before tests are run.
+# If you are not using ActiveRecord, you can remove these lines.
+begin
+ ActiveRecord::Migrator.migrations_paths = File.join(ENGINE_ROOT, 'spec/dummy/db/migrate')
+ ActiveRecord::Migration.maintain_test_schema!
+rescue ActiveRecord::PendingMigrationError => e
+ puts e.to_s.strip
+ exit 1
+end
+
+RSpec.configure do |config|
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # RSpec Rails can automatically mix in different behaviours to your tests
+ # based on their file location, for example enabling you to call `get` and
+ # `post` in specs under `spec/controllers`.
+ #
+ # You can disable this behaviour by removing the line below, and instead
+ # explicitly tag your specs with their type, e.g.:
+ #
+ # RSpec.describe UsersController, :type => :controller do
+ # # ...
+ # end
+ #
+ # The different available types are documented in the features, such as in
+ # https://relishapp.com/rspec/rspec-rails/docs
+ config.infer_spec_type_from_file_location!
+
+ # Filter lines from Rails gems in backtraces.
+ config.filter_rails_from_backtrace!
+
+ # arbitrary gems may also be filtered via:
+ # config.filter_gems_from_backtrace("gem name")
+ #
+ def rspec_spree_thor_path
+ @spec_thor_path ||= File.join( File.dirname(__FILE__), '..', 'lib', 'thor', 'spree')
+ end
+
+ def fixtures_path()
+ File.expand_path(File.dirname(__FILE__) + '/fixtures')
+ end
+
+ def rspec_spec_path
+ File.expand_path(File.dirname(__FILE__))
+ end
+
+ def ifixture_file( name )
+ File.join(fixtures_path(), name)
+ end
+
+ def results_path
+ File.join(fixtures_path(), 'results')
+ end
+
+ # Return location of an expected results file and ensure tree clean before test
+ def result_file( name )
+ expect = File.join(results_path, name)
+
+ begin FileUtils.rm(expect); rescue; end
+
+ expect
+ end
+
+ def results_clear
+ begin FileUtils.rm_rf(results_path); rescue; end
+
+ FileUtils.mkdir(results_path) unless File.exists?(results_path);
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index ef8b7dc..ce33d66 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,256 +1,96 @@
-# Copyright:: (c) Autotelik Media Ltd 2016
-# Author :: Tom Statter
-# Date :: Aug 2016
-# License:: MIT
+# This file was generated by the `rails generate rspec:install` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# The generated `.rspec` file contains `--require spec_helper` which will cause
+# this file to always be loaded, without a need to explicitly require it in any
+# files.
#
-# Details:: Spec Helper for Active Record Loader
+# Given that it is always loaded, you are encouraged to keep this file as
+# light-weight as possible. Requiring heavyweight dependencies from this file
+# will add to the boot time of your test suite on EVERY test run, even for an
+# individual file that may not need all of that loaded. Instead, consider making
+# a separate helper file that requires the additional dependencies and performs
+# the additional setup, and require it from the spec files that actually need
+# it.
#
-#
-# We are not setup as a Rails project so need to mimic an active record database setup so
-# we have some AR models to test against. Create an in memory database from scratch.
-#
-#require 'active_record'
-#require 'bundler'
-#require 'stringio'
-#require 'database_cleaner'
-#require 'spree'
-
-#$:.unshift '.' # 1.9.3 quite strict, '.' must be in load path for relative paths to work from here
-
-# Requires supporting ruby files with custom matchers and macros, etc,
-# in spec/support/ and its subdirectories.
-Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
-
-DatashiftSpreeLibraryBase = File.expand_path( File.join(File.dirname(__FILE__), '..') )
-
-require File.join(DatashiftSpreeLibraryBase, 'lib/datashift_spree')
-
-puts "Running tests with ActiveSupport version : #{Gem.loaded_specs['active_support'].inspect}"
-
-puts "Running tests with Rails version : #{Gem.loaded_specs['rails'].version.version.inspect}"
-
-def run_in(dir )
- puts "RSpec .. running test in path [#{dir}]"
- original_dir = Dir.pwd
- begin
- Dir.chdir dir
- yield
- ensure
- Dir.chdir original_dir
- end
-end
-
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
-
- config.before do
- ARGV.replace []
- end
-
- config.before(:suite) do
- puts "Booting spree rails app - version #{DataShift::SpreeEcom::version}"
-
- spree_boot
-
- puts "Testing Spree standalone - version #{DataShift::SpreeEcom::version}"
- end
-
- config.before(:each) do
-
- set_spree_class_helpers
-
- DatabaseCleaner.strategy = :transaction
-
- DatabaseCleaner.start
- end
-
- config.after(:each) do
- DatabaseCleaner.clean
- end
-
- def capture(stream)
- begin
- stream = stream.to_s
- eval "$#{stream} = StringIO.new"
- yield
- result = eval("$#{stream}").string
- ensure
- eval("$#{stream} = #{stream.upcase}")
- end
-
- result
- end
-
- alias :silence :capture
-
- def rspec_spree_thor_path
- @spec_thor_path ||= File.join( File.dirname(__FILE__), '..', 'lib', 'thor', 'spree')
- end
-
- def fixtures_path()
- File.expand_path(File.dirname(__FILE__) + '/fixtures')
- end
-
- def rspec_spec_path
- File.expand_path(File.dirname(__FILE__))
- end
-
- def ifixture_file( name )
- File.join(fixtures_path(), name)
- end
-
- def results_path
- File.join(fixtures_path(), 'results')
- end
-
- def negative_fixture_path
- File.join(fixtures_path, 'negative')
- end
-
- def negative_fixture_file( source )
- File.join(negative_fixture_path, source)
- end
-
- # Return location of an expected results file and ensure tree clean before test
- def result_file( name )
- expect = File.join(results_path, name)
-
- begin FileUtils.rm(expect); rescue; end
-
- expect
- end
-
- def results_clear
- begin FileUtils.rm_rf(results_path); rescue; end
-
- FileUtils.mkdir(results_path) unless File.exists?(results_path);
- end
-
-
- def spree_fixture( source)
- ifixture_file(source)
- end
-
- def bundler_setup(gemfile)
- ENV['BUNDLE_GEMFILE'] = gemfile
-
- begin
- Bundler.setup(:default, :development)
- rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
- end
- end
-
- def set_logger( name = 'datashift_spree_spec.log')
-
- require 'logger'
- logdir = File.join(File.dirname(__FILE__), 'log')
- FileUtils.mkdir_p(logdir) unless File.exists?(logdir)
- ActiveRecord::Base.logger = Logger.new( File.join(logdir, name) )
- end
-
-
- def db_connect( env = 'development' )
- # Some active record stuff seems to rely on the RAILS_ENV being set ?
-
- ENV['RAILS_ENV'] = env
-
- configuration = {}
-
- database_yml_path = File.join(DataShift::SpreeEcom::spree_sandbox_path, 'config', 'database.yml')
-
- configuration[:database_configuration] = YAML::load( ERB.new( IO.read(database_yml_path) ).result )
- db = configuration[:database_configuration][ env ]
-
- set_logger
-
- puts "Connecting to DB"
-
- ActiveRecord::Base.establish_connection( db )
-
- puts "Connected to DB"
- end
-
- # Datashift is NOT a Rails engine. It can be used in any Ruby project,
- # pulled in by a parent/host application via standard Gemfile
- #
- # Here we have to hack our way around the fact that datashift is not a Rails/Spree app/engine
- # so that we can ** run our specs ** directly in datashift library
- # i.e without ever having to install datashift in a host application
- #
- # NOTES:
- # => Will chdir into the sandbox to load environment as need to mimic being at root of a rails project
- # chdir back after environment loaded
-
- def spree_boot()
-
- spree_sandbox_app_path = DataShift::SpreeEcom::spree_sandbox_path
-
- unless(File.exists?(spree_sandbox_app_path))
- puts "Creating new Rails sandbox for Spree : #{spree_sandbox_app_path}"
-
- DataShift::SpreeEcom::build_sandbox
-
- original_dir = Dir.pwd
-
- # TOFIX - this don't work ... but works if run straight after the task
- # maybe the env not right using system ?
- begin
- Dir.chdir DataShift::SpreeEcom::spree_sandbox_path
- puts "Running bundle install"
- system('bundle install')
- ensure
- Dir.chdir original_dir
- end
- end
-
- puts "Using Rails sandbox for Spree : #{spree_sandbox_app_path}"
-
- run_in(spree_sandbox_app_path) {
-
- puts "Running db_connect from #{Dir.pwd}"
-
- db_connect
-
- require 'spree'
-
- begin
- puts "Booting Spree #{DataShift::SpreeEcom::version} in sandbox"
- load 'config/environment.rb'
- puts "Booted Spree using version #{DataShift::SpreeEcom::version}"
- rescue => e
- #somethign in deface seems to blow up suddenly on 1.1
- puts "Warning - Potential issue initializing Spree sandbox:"
- puts e.backtrace
- puts "#{e.inspect}"
- end
- }
-
- puts "Booted Spree using version #{DataShift::SpreeEcom::version}"
- end
-
- def set_spree_class_helpers
- @spree_klass_list = %w{Image OptionType OptionValue Property ProductProperty Variant Taxon Taxonomy Zone}
-
- @spree_klass_list.each do |k|
- instance_variable_set("@#{k}_klass", DataShift::SpreeEcom::get_spree_class(k))
- end
- end
-
- def self.load_models( report_errors = nil )
- puts 'Loading Spree models from', DataShift::SpreeEcom::root
- Dir[DataShift::SpreeEcom::root + '/app/models/**/*.rb'].each {|r|
- begin
- require r if File.file?(r)
- rescue => e
- puts("WARNING failed to load #{r}", e.inspect) if(report_errors == true)
- end
- }
- end
-
- def self.migrate_up
- ActiveRecord::Migrator.up( File.join(DataShift::SpreeEcom::root, 'db/migrate') )
- end
-
+ # rspec-expectations config goes here. You can use an alternate
+ # assertion/expectation library such as wrong or the stdlib/minitest
+ # assertions if you prefer.
+ config.expect_with :rspec do |expectations|
+ # This option will default to `true` in RSpec 4. It makes the `description`
+ # and `failure_message` of custom matchers include text for helper methods
+ # defined using `chain`, e.g.:
+ # be_bigger_than(2).and_smaller_than(4).description
+ # # => "be bigger than 2 and smaller than 4"
+ # ...rather than:
+ # # => "be bigger than 2"
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ # rspec-mocks config goes here. You can use an alternate test double
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
+ config.mock_with :rspec do |mocks|
+ # Prevents you from mocking or stubbing a method that does not exist on
+ # a real object. This is generally recommended, and will default to
+ # `true` in RSpec 4.
+ mocks.verify_partial_doubles = true
+ end
+
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
+ # have no way to turn it off -- the option exists only for backwards
+ # compatibility in RSpec 3). It causes shared context metadata to be
+ # inherited by the metadata hash of host groups and examples, rather than
+ # triggering implicit auto-inclusion in groups with matching metadata.
+ config.shared_context_metadata_behavior = :apply_to_host_groups
+
+# The settings below are suggested to provide a good initial experience
+# with RSpec, but feel free to customize to your heart's content.
+=begin
+ # This allows you to limit a spec run to individual examples or groups
+ # you care about by tagging them with `:focus` metadata. When nothing
+ # is tagged with `:focus`, all examples get run. RSpec also provides
+ # aliases for `it`, `describe`, and `context` that include `:focus`
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
+ config.filter_run_when_matching :focus
+
+ # Allows RSpec to persist some state between runs in order to support
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
+ # you configure your source control system to ignore this file.
+ config.example_status_persistence_file_path = "spec/examples.txt"
+
+ # Limits the available syntax to the non-monkey patched syntax that is
+ # recommended. For more details, see:
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
+ config.disable_monkey_patching!
+
+ # Many RSpec users commonly either run the entire suite or an individual
+ # file, and it's useful to allow more verbose output when running an
+ # individual spec file.
+ if config.files_to_run.one?
+ # Use the documentation formatter for detailed output,
+ # unless a formatter has already been configured
+ # (e.g. via a command-line flag).
+ config.default_formatter = "doc"
+ end
+
+ # Print the 10 slowest examples and example groups at the
+ # end of the spec run, to help surface which specs are running
+ # particularly slow.
+ config.profile_examples = 10
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = :random
+
+ # Seed global randomization in this process using the `--seed` CLI option.
+ # Setting this allows you to use `--seed` to deterministically reproduce
+ # test failures related to randomization by passing the same `--seed` value
+ # as the one that triggered the failure.
+ Kernel.srand config.seed
+=end
end
diff --git a/spec/support/product_loading.rb b/spec/support/product_loading.rb
index 4723d42..df32e75 100644
--- a/spec/support/product_loading.rb
+++ b/spec/support/product_loading.rb
@@ -1,39 +1,30 @@
-# Copyright:: (c) Autotelik Media Ltd 2016
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: Aug 2016
# License:: MIT
#
# Details:: Spec Helpers/Shared examples for Spree Product Loading
#
-RSpec.configure do |config|
+RSpec.shared_context 'Populate dictionary ready for Product loading' do
- shared_context 'Populate dictionary ready for Product loading' do
+ let(:product_klass) { ::Spree::Product }
- set_spree_class_helpers
+ let(:image_klass) { ::Spree::Image }
- let(:product_klass) { Spree::Product }
-
- let(:image_klass) { DataShift::SpreeEcom::get_spree_class 'Image' }
-
- config.before(:each) do
- DataShift::Configuration.reset
- DataShift::Exporters::Configuration.reset
- DataShift::Loaders::Configuration.reset
- DataShift::Transformation::Factory.reset
- end
-
- before do
- begin
-
- DataShift::ModelMethods::Catalogue.clear
- DataShift::ModelMethods::Manager.clear
+ before(:each) do
+ DataShift::Configuration.reset
+ DataShift::Exporters::Configuration.reset
+ DataShift::Loaders::Configuration.reset
+ DataShift::Transformation::Factory.reset
+ end
- rescue => e
- puts e.inspect
- puts e.backtrace
- raise e
- end
+ before(:all) do
+ begin
+ DataShift::ModelMethods::Catalogue.clear
+ DataShift::ModelMethods::Manager.clear
+ rescue => e
+ puts e.inspect
+ puts e.backtrace
+ raise e
end
end
-
end
diff --git a/spec/support/sandbox_helper.rb b/spec/support/sandbox_helper.rb
index e1deafe..fe097de 100644
--- a/spec/support/sandbox_helper.rb
+++ b/spec/support/sandbox_helper.rb
@@ -1,18 +1,12 @@
-# Copyright:: (c) Autotelik Media Ltd 2014
+# Copyright:: (c) Autotelik B.V 2020
# Author :: Tom Statter
-# Date :: June 2014
# License:: MIT
#
-# Details:: Helper for creating testing sandbox
+# Details:: Helper for creating a Spree store in a Rails engine 'dummy' sandbox
#
+module DatashiftSpree
-$:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
-
-require 'datashift_spree'
-
-module DataShift
-
- module SpreeEcom
+ class Sandbox
def self.run_in(dir)
puts "Running cmd in [#{dir}]"
@@ -30,7 +24,19 @@ def self.spree_sandbox_name
end
def self.spree_sandbox_path
- File.join(DatashiftSpreeLibraryBase, 'spec', spree_sandbox_name)
+ @spree_sandbox_path ||= File.expand_path( File.join(File.dirname(__FILE__), '../', spree_sandbox_name) )
+ end
+
+ def self.installed_flag_file
+ "#{spree_sandbox_path}/spree_sandbox_installed.txt"
+ end
+
+ def self.flag_installed
+ File.open(installed_flag_file, 'w') { |f| f << Time.now.to_s }
+ end
+
+ def self.installed?
+ File.exists?(installed_flag_file)
end
# The SPREE INSTALL COMMANDS based on current Gemfile Spree versions
@@ -38,41 +44,28 @@ def self.spree_sandbox_path
# SEE https://github.com/spree/spree#getting-started
#
def self.spree_install_cmds
- system("rails g spree:install --user_class=Spree::User --auto-accept --migrate --no-seed")
- system("rails g spree:auth:install")
- system("rails g spree_gateway:install")
- system('rails g spree_digital:install --auto-run-migrations')
- end
+ system("bundle exec rails g spree:install --force --user_class=Spree::User --sample=false --seed=false --copy_storefront=false")
+ system("bundle exec rails g spree:auth:install")
+ system("bundle exec rails g spree_gateway:install")
- def self.build_sandbox
+ #system('rails g spree_digital:install --auto-run-migrations')
+ end
- spree_sandbox_path = DataShift::SpreeEcom::spree_sandbox_path
+ def self.install_spree
- puts "Creating new Rails sandbox for Spree : #{spree_sandbox_path}"
+ pp File.exists?(installed_flag_file)
- FileUtils::rm_rf(spree_sandbox_path) if(File.exists?(spree_sandbox_path))
+ return if installed?
- rails_sandbox_root = File.expand_path("#{spree_sandbox_path}/..")
+ puts "Creating new Spree store in Rails sandbox : #{spree_sandbox_path}"
- run_in(rails_sandbox_root) do
- system('rails new ' + spree_sandbox_name)
+ run_in(spree_sandbox_path) do
+ system("bundle install")
end
- # Now add any gems required specifically for datashift_spree to the Gemfile
-
- gem_string = "\n\n#RSPEC datashift-spree testing\ngem 'datashift_spree', :path => \"#{File.expand_path(rails_sandbox_root + '/..')}\"\n"
-
- gem_string += "\ngem 'datashift', :git => 'https://github.com/autotelik/datashift.git', branch: :master\n"
-
- gem_string += "\ngem 'spree_digital', github: 'spree-contrib/spree_digital', :branch => spree_version\n"
-
- File.open("#{spree_sandbox_path}/Gemfile", 'a') { |f| f << gem_string }
-
- # ***** SPREE INSTALL COMMANDS ****
-
- run_in(spree_sandbox_path) do
+ run_in(spree_sandbox_path) do
+ puts "Running SPREE INSTALLATION"
spree_install_cmds
-
end
puts "Created Spree sandbox store : #{spree_sandbox_path}"
@@ -85,12 +78,15 @@ def self.build_sandbox
require 'datashift'
require 'datashift_spree'
-DataShift::SpreeEcom::load_commands
+DatashiftSpree::load_commands
DataShift::load_commands
EOS
f << thor_code
end
-
+
+ flag_installed
+
end
end
+
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 0000000..15ef533
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,19 @@
+# Configure Rails Environment
+ENV["RAILS_ENV"] = "test"
+
+require_relative "../test/dummy/config/environment"
+ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
+ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__)
+require "rails/test_help"
+
+# Filter out the backtrace from minitest while preserving the one from other libraries.
+Minitest.backtrace_filter = Minitest::BacktraceFilter.new
+
+
+# Load fixtures from the engine
+if ActiveSupport::TestCase.respond_to?(:fixture_path=)
+ ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
+ ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
+ ActiveSupport::TestCase.fixtures :all
+end