Skip to content

Commit

Permalink
Merge pull request #284 from solidusio/waiting-for-dev/fix_ci
Browse files Browse the repository at this point in the history
Only use the newer Solidus event system
  • Loading branch information
waiting-for-dev authored May 3, 2023
2 parents 4f70b9d + 04a0a77 commit b98abd0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 103 deletions.
90 changes: 34 additions & 56 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,45 @@ orbs:
solidusio_extensions: solidusio/extensions@volatile

jobs:
run-specs-with-mysql:
executor:
name: solidusio_extensions/mysql
ruby_version: <<parameters.ruby_version>>
steps:
- checkout
- solidusio_extensions/run-tests-solidus-older
- solidusio_extensions/run-tests-solidus-current
- solidusio_extensions/run-tests-solidus-master
- solidusio_extensions/store-test-results
run-specs:
parameters:
ruby_version:
solidus:
type: string
default: '2.7'
run-specs-with-postgres:
executor:
name: solidusio_extensions/postgres
ruby_version: <<parameters.ruby_version>>
steps:
- checkout
- solidusio_extensions/run-tests-solidus-older
- solidusio_extensions/run-tests-solidus-current
- solidusio_extensions/run-tests-solidus-master
- solidusio_extensions/store-test-results
parameters:
ruby_version:
default: master
db:
type: string
default: "postgres"
ruby:
type: string
default: '3.0'
run-specs-with-sqlite:
default: "3.2"
executor:
name: solidusio_extensions/sqlite
ruby_version: <<parameters.ruby_version>>
name: solidusio_extensions/<< parameters.db >>
ruby_version: << parameters.ruby >>
steps:
- checkout
- solidusio_extensions/run-tests-solidus-older
- solidusio_extensions/run-tests-solidus-current
- solidusio_extensions/run-tests-solidus-master
- solidusio_extensions/store-test-results
parameters:
ruby_version:
type: string
default: '3.1'
- solidusio_extensions/run-tests-solidus-<< parameters.solidus >>
lint-code:
executor: solidusio_extensions/sqlite-memory
executor:
name: solidusio_extensions/sqlite-memory
ruby_version: 2.5
steps:
- solidusio_extensions/lint-code

workflows:
"Run specs on supported Solidus versions":
jobs:
- run-specs-with-mysql:
ruby_version: '2.7'
name: run-specs-with-mysql-ruby-2.7
- run-specs-with-postgres:
ruby_version: '3.0'
name: run-specs-with-postgres-ruby-3.0
- run-specs-with-sqlite:
ruby_version: '3.1'
name: run-specs-with-sqlite-ruby-3.1
- lint-code
- run-specs:
name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>"
matrix:
parameters: { solidus: ["master"], ruby: ["3.2"], db: ["postgres"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] }

"Weekly run specs against master":
triggers:
Expand All @@ -78,12 +57,11 @@ workflows:
only:
- master
jobs:
- run-specs-with-mysql:
ruby_version: '2.7'
name: run-specs-with-mysql-ruby-2.7
- run-specs-with-postgres:
ruby_version: '3.0'
name: run-specs-with-postgres-ruby-3.0
- run-specs-with-sqlite:
ruby_version: '3.1'
name: run-specs-with-sqlite-ruby-3.1
- run-specs:
name: *name
matrix:
parameters: { solidus: ["master"], ruby: ["3.2"], db: ["postgres"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
17 changes: 8 additions & 9 deletions app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# frozen_string_literal: true

module SolidusSubscriptions
module ChurnBusterSubscriber
include ::Spree::Event::Subscriber
include ::SolidusSupport::LegacyEventCompat::Subscriber

event_action :report_subscription_cancellation, event_name: 'solidus_subscriptions.subscription_canceled'
event_action :report_subscription_ending, event_name: 'solidus_subscriptions.subscription_ended'
event_action :report_payment_success, event_name: 'solidus_subscriptions.installment_succeeded'
event_action :report_payment_failure, event_name: 'solidus_subscriptions.installment_failed_payment'
event_action :report_payment_method_change, event_name: 'solidus_subscriptions.subscription_payment_method_changed'
class ChurnBusterSubscriber
include Omnes::Subscriber

handle :"solidus_subscriptions.subscription_canceled", with: :report_subscription_cancellation
handle :"solidus_subscriptions.subscription_ended", with: :report_subscription_ending
handle :"solidus_subscriptions.installment_succeeded", with: :report_payment_success
handle :"solidus_subscriptions.installment_failed_payment", with: :report_payment_failure
handle :"solidus_subscriptions.subscription_payment_method_changed", with: :report_payment_method_change

def report_subscription_cancellation(event)
churn_buster&.report_subscription_cancellation(event.payload.fetch(:subscription))
Expand Down
19 changes: 9 additions & 10 deletions app/subscribers/solidus_subscriptions/event_storage_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# frozen_string_literal: true

module SolidusSubscriptions
module EventStorageSubscriber
include ::Spree::Event::Subscriber
include ::SolidusSupport::LegacyEventCompat::Subscriber
class EventStorageSubscriber
include Omnes::Subscriber

event_action :track_subscription_created, event_name: 'solidus_subscriptions.subscription_created'
event_action :track_subscription_activated, event_name: 'solidus_subscriptions.subscription_activated'
event_action :track_subscription_canceled, event_name: 'solidus_subscriptions.subscription_canceled'
event_action :track_subscription_ended, event_name: 'solidus_subscriptions.subscription_ended'
event_action :track_subscription_shipping_address_changed, event_name: 'solidus_subscriptions.subscription_shipping_address_changed'
event_action :track_subscription_billing_address_changed, event_name: 'solidus_subscriptions.subscription_billing_address_changed'
event_action :track_subscription_frequency_changed, event_name: 'solidus_subscriptions.subscription_frequency_changed'
handle :"solidus_subscriptions.subscription_created", with: :track_subscription_created
handle :"solidus_subscriptions.subscription_activated", with: :track_subscription_activated
handle :"solidus_subscriptions.subscription_canceled", with: :track_subscription_canceled
handle :"solidus_subscriptions.subscription_ended", with: :track_subscription_ended
handle :"solidus_subscriptions.subscription_shipping_address_changed", with: :track_subscription_shipping_address_changed
handle :"solidus_subscriptions.subscription_billing_address_changed", with: :track_subscription_billing_address_changed
handle :"solidus_subscriptions.subscription_frequency_changed", with: :track_subscription_frequency_changed

def track_subscription_created(event)
event.payload.fetch(:subscription).events.create!(
Expand Down
9 changes: 3 additions & 6 deletions app/subscribers/solidus_subscriptions/order_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# frozen_string_literal: true

module SolidusSubscriptions
module OrderSubscriber
include ::Spree::Event::Subscriber
include ::SolidusSupport::LegacyEventCompat::Subscriber
class OrderSubscriber
include Omnes::Subscriber

event_action :create_subscription, event_name: 'order_finalized'

private
handle :order_finalized, with: :create_subscription

def create_subscription(event)
SolidusSubscriptions::CreateSubscriptionJob.perform_later(event.payload[:order])
Expand Down
42 changes: 20 additions & 22 deletions lib/solidus_subscriptions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,27 @@ class Engine < Rails::Engine
end

initializer 'solidus_subscriptions.pub_sub' do |app|
unless SolidusSupport::LegacyEventCompat.using_legacy?
app.reloader.to_prepare do
%i[
subscription_created
subscription_activated
subscription_canceled
subscription_ended
subscription_skipped
subscription_resumed
subscription_paused
subscription_frequency_changed
subscription_shipping_address_changed
subscription_billing_address_changed
installment_succeeded
installment_failed_payment
subscription_payment_method_changed
].each do |event_name|
::Spree::Bus.register(:"solidus_subscriptions.#{event_name}")
end
SolidusSubscriptions::ChurnBusterSubscriber.omnes_subscriber.subscribe_to(::Spree::Bus)
SolidusSubscriptions::EventStorageSubscriber.omnes_subscriber.subscribe_to(::Spree::Bus)
SolidusSubscriptions::OrderSubscriber.omnes_subscriber.subscribe_to(::Spree::Bus)
app.reloader.to_prepare do
%i[
subscription_created
subscription_activated
subscription_canceled
subscription_ended
subscription_skipped
subscription_resumed
subscription_paused
subscription_frequency_changed
subscription_shipping_address_changed
subscription_billing_address_changed
installment_succeeded
installment_failed_payment
subscription_payment_method_changed
].each do |event_name|
::Spree::Bus.register(:"solidus_subscriptions.#{event_name}")
end
SolidusSubscriptions::ChurnBusterSubscriber.new.subscribe_to(::Spree::Bus)
SolidusSubscriptions::EventStorageSubscriber.new.subscribe_to(::Spree::Bus)
SolidusSubscriptions::OrderSubscriber.new.subscribe_to(::Spree::Bus)
end
end
end
Expand Down

0 comments on commit b98abd0

Please sign in to comment.