From 51800a82770b234d374bbf4752857f1b091f4061 Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Mon, 2 Mar 2020 10:23:28 -0600 Subject: [PATCH 1/9] Ignore rubymine dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 75ebb57..904044a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ spec/dummy/db/*.sqlite3 spec/dummy/db/schema.rb spec/dummy/db/migrate/*.rb spec/dummy/public/* +.idea From 1809a91058ae822e9a62cedb994a28e181e1ec5a Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Mon, 2 Mar 2020 10:23:49 -0600 Subject: [PATCH 2/9] Add support for Spree 4 --- spree_purchase_order.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spree_purchase_order.gemspec b/spree_purchase_order.gemspec index 769b3ef..1ae6637 100644 --- a/spree_purchase_order.gemspec +++ b/spree_purchase_order.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.requirements << 'none' - s.add_dependency 'spree_core', '~> 3.7.0' + s.add_dependency 'spree_core', '~> 4.0' s.add_development_dependency 'sqlite3' s.add_development_dependency 'rspec-rails' From 017a394cd25b7f8a5af0d6f390adb1fb3b3d29ce Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Fri, 6 Nov 2020 09:50:09 -0600 Subject: [PATCH 3/9] Ignore .generators --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 904044a..7f34a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ spec/dummy/db/schema.rb spec/dummy/db/migrate/*.rb spec/dummy/public/* .idea +.generators From f69de0d322f65bdf4d593b765ce3bd859e7c0428 Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Fri, 6 Nov 2020 12:16:31 -0600 Subject: [PATCH 4/9] Make load with zeitwerk --- spec/dummy/config/application.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 92edec9..d54e193 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -21,6 +21,8 @@ class Application < Rails::Application Rails.configuration.cache_classes ? require(c) : load(c) end end + + config.load_defaults 6.0 end end From 1f8c64fa6dbfb5e26baac9d53e5176233e801176 Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Fri, 6 Nov 2020 12:16:50 -0600 Subject: [PATCH 5/9] Decorate Spree::Payment in a way that makes zeitwerk happy --- app/models/spree/payment_decorator.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index 857c413..439ca6b 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -1,7 +1,15 @@ -Spree::Payment.class_eval do - scope :from_purchase_order, -> { where(source_type: 'Spree::PurchaseOrder') } +module Spree + module PaymentDecorator + def self.prepended(base) + base.scope :from_purchase_order, -> { where(source_type: 'Spree::PurchaseOrder') } + end - def po? - source_type == 'Spree::PurchaseOrder' + def po? + source_type == 'Spree::PurchaseOrder' + end end end + +if ::Spree::Payment.included_modules.exclude?(::Spree::PaymentDecorator) + ::Spree::Payment.prepend ::Spree::PaymentDecorator +end From 76bb21403db227124aca380a84b887aef8a567d7 Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Tue, 10 Nov 2020 15:38:40 -0600 Subject: [PATCH 6/9] Make template use Spree 4 styles --- .../checkout/payment/_purchaseorder.html.erb | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/views/spree/checkout/payment/_purchaseorder.html.erb b/app/views/spree/checkout/payment/_purchaseorder.html.erb index 9a17932..b87a568 100644 --- a/app/views/spree/checkout/payment/_purchaseorder.html.erb +++ b/app/views/spree/checkout/payment/_purchaseorder.html.erb @@ -1,15 +1,13 @@ -
+
<% param_prefix = "payment_source[#{payment_method.id}]" %> -

- <%= label_tag :po_number do %> - <%= Spree.t(:po_number) %>* - <% end %> - <%= text_field_tag "#{param_prefix}[po_number]", '', id: :po_number, class: 'form-control required', size: 10, maxlength: 10, autocomplete: "off" %> -

-

- <%= label_tag :organization_name do %> - <%= Spree.t(:organization_name) %>* - <% end %> - <%= text_field_tag "#{param_prefix}[organization_name]", '', id: :organization_name, class: 'form-control required'%> -

+ +
+
+ <%= text_field_tag "#{param_prefix}[po_number]", '', id: 'po_number', class: 'spree-flat-input', placeholder: Spree.t(:po_number) %> +
+ +
+ <%= text_field_tag "#{param_prefix}[organization_name]", '', id: 'organization_name', class: 'spree-flat-input', placeholder: Spree.t(:organization_name) %> +
+
From 05b053636629e314e17e0fa84bfa5e0aead8aba3 Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Tue, 10 Nov 2020 15:46:45 -0600 Subject: [PATCH 7/9] Add required attributes --- Gemfile | 4 ++++ app/views/spree/checkout/payment/_purchaseorder.html.erb | 4 ++-- spec/factories/purchase_orders.rb | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index fa75df1..1714397 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,7 @@ source 'https://rubygems.org' gemspec + +group :development, :test do + gem 'spree_auth_devise' +end diff --git a/app/views/spree/checkout/payment/_purchaseorder.html.erb b/app/views/spree/checkout/payment/_purchaseorder.html.erb index b87a568..b990ded 100644 --- a/app/views/spree/checkout/payment/_purchaseorder.html.erb +++ b/app/views/spree/checkout/payment/_purchaseorder.html.erb @@ -3,11 +3,11 @@
- <%= text_field_tag "#{param_prefix}[po_number]", '', id: 'po_number', class: 'spree-flat-input', placeholder: Spree.t(:po_number) %> + <%= text_field_tag "#{param_prefix}[po_number]", '', id: 'po_number', class: 'spree-flat-input', placeholder: Spree.t(:po_number), required: true %>
- <%= text_field_tag "#{param_prefix}[organization_name]", '', id: 'organization_name', class: 'spree-flat-input', placeholder: Spree.t(:organization_name) %> + <%= text_field_tag "#{param_prefix}[organization_name]", '', id: 'organization_name', class: 'spree-flat-input', placeholder: Spree.t(:organization_name), required: true %>
diff --git a/spec/factories/purchase_orders.rb b/spec/factories/purchase_orders.rb index 2d8f8a8..46b9d60 100644 --- a/spec/factories/purchase_orders.rb +++ b/spec/factories/purchase_orders.rb @@ -37,6 +37,7 @@ name { 'Spree Test Store' } url { 'www.example.com' } mail_from_address { 'spree@example.org' } + default_currency { 'USD' } end # factory :user, class: Spree.user_class do From cf8e31228cb0664c654ef171244b33f334e7bd95 Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Tue, 10 Nov 2020 15:57:39 -0600 Subject: [PATCH 8/9] Lint --- app/models/spree/payment_decorator.rb | 7 ++++++- app/models/spree/payment_method/purchase_order.rb | 2 ++ app/models/spree/purchase_order.rb | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index 439ca6b..e45c0b2 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -1,7 +1,12 @@ +# frozen_string_literal: true + module Spree module PaymentDecorator def self.prepended(base) - base.scope :from_purchase_order, -> { where(source_type: 'Spree::PurchaseOrder') } + base.scope( + :from_purchase_order, + -> { where(source_type: 'Spree::PurchaseOrder') } + ) end def po? diff --git a/app/models/spree/payment_method/purchase_order.rb b/app/models/spree/payment_method/purchase_order.rb index 4f1956d..ed7aa90 100644 --- a/app/models/spree/payment_method/purchase_order.rb +++ b/app/models/spree/payment_method/purchase_order.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class PaymentMethod::PurchaseOrder < PaymentMethod def payment_source_class diff --git a/app/models/spree/purchase_order.rb b/app/models/spree/purchase_order.rb index 7c3980f..25268bc 100644 --- a/app/models/spree/purchase_order.rb +++ b/app/models/spree/purchase_order.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class PurchaseOrder < Spree::Base belongs_to :payment_method From b4b8b1f49ecf3cba2e450c01ec6f5969d9474411 Mon Sep 17 00:00:00 2001 From: Tegan Rauh Date: Tue, 10 Nov 2020 15:59:43 -0600 Subject: [PATCH 9/9] Use newer form of presence validation --- app/models/spree/purchase_order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/purchase_order.rb b/app/models/spree/purchase_order.rb index 25268bc..77df302 100644 --- a/app/models/spree/purchase_order.rb +++ b/app/models/spree/purchase_order.rb @@ -5,7 +5,7 @@ class PurchaseOrder < Spree::Base belongs_to :payment_method has_many :payments, as: :source - validates_presence_of :po_number, :organization_name + validates :po_number, :organization_name, presence: true def actions %w(complete void)