summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/solidus_subscriptions/subscription.rb1
-rw-r--r--config/locales/en.yml2
-rw-r--r--db/migrate/20210205140422_add_currency_to_subscription.rb5
-rw-r--r--lib/solidus_subscriptions/subscription_generator.rb1
-rw-r--r--lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb1
-rw-r--r--spec/lib/solidus_subscriptions/subscription_generator_spec.rb1
-rw-r--r--spec/models/solidus_subscriptions/subscription_spec.rb7
7 files changed, 17 insertions, 1 deletions
diff --git a/app/models/solidus_subscriptions/subscription.rb b/app/models/solidus_subscriptions/subscription.rb
index e78b516..3190ab6 100644
--- a/app/models/solidus_subscriptions/subscription.rb
+++ b/app/models/solidus_subscriptions/subscription.rb
@@ -26,6 +26,7 @@ module SolidusSubscriptions
validates :interval_length, numericality: { greater_than: 0 }
validates :payment_method, presence: true, if: -> { payment_source }
validates :payment_source, presence: true, if: -> { payment_method&.source_required? }
+ validates :currency, inclusion: { in: ::Money::Currency.all.map(&:iso_code) }
accepts_nested_attributes_for :shipping_address
accepts_nested_attributes_for :billing_address
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9f855d7..97dc9b7 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -114,3 +114,5 @@ en:
exceeded: >
This subscription has exceeded the maximum configured skip
limit. It can no longer be skipped.
+ currency:
+ inclusion: "is not a valid currency code"
diff --git a/db/migrate/20210205140422_add_currency_to_subscription.rb b/db/migrate/20210205140422_add_currency_to_subscription.rb
new file mode 100644
index 0000000..1a4f7af
--- /dev/null
+++ b/db/migrate/20210205140422_add_currency_to_subscription.rb
@@ -0,0 +1,5 @@
+class AddCurrencyToSubscription < ActiveRecord::Migration[5.2]
+ def change
+ add_column :solidus_subscriptions_subscriptions, :currency, :string
+ end
+end
diff --git a/lib/solidus_subscriptions/subscription_generator.rb b/lib/solidus_subscriptions/subscription_generator.rb
index 8153912..4f675a7 100644
--- a/lib/solidus_subscriptions/subscription_generator.rb
+++ b/lib/solidus_subscriptions/subscription_generator.rb
@@ -29,6 +29,7 @@ module SolidusSubscriptions
billing_address: order.bill_address,
payment_source: order.payments.valid.last&.payment_source,
payment_method: order.payments.valid.last&.payment_method,
+ currency: order.currency,
**configuration.to_h
}
diff --git a/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb b/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
index 2898d36..4cd3a1c 100644
--- a/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
+++ b/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb
@@ -5,6 +5,7 @@ FactoryBot.define do
store
interval_length { 1 }
interval_units { :month }
+ currency { 'USD' }
user do
new_user = create(:user, :subscription_user)
diff --git a/spec/lib/solidus_subscriptions/subscription_generator_spec.rb b/spec/lib/solidus_subscriptions/subscription_generator_spec.rb
index b7d73b8..bbf4e74 100644
--- a/spec/lib/solidus_subscriptions/subscription_generator_spec.rb
+++ b/spec/lib/solidus_subscriptions/subscription_generator_spec.rb
@@ -25,6 +25,7 @@ RSpec.describe SolidusSubscriptions::SubscriptionGenerator do
interval_units: subscription_line_item.interval_units,
end_date: subscription_line_item.end_date,
store: subscription_line_item.order.store,
+ currency: subscription_line_item.order.currency
)
end
diff --git a/spec/models/solidus_subscriptions/subscription_spec.rb b/spec/models/solidus_subscriptions/subscription_spec.rb
index 2267dbf..6acc1b3 100644
--- a/spec/models/solidus_subscriptions/subscription_spec.rb
+++ b/spec/models/solidus_subscriptions/subscription_spec.rb
@@ -6,9 +6,14 @@ RSpec.describe SolidusSubscriptions::Subscription, type: :model do
it { is_expected.to validate_presence_of :successive_skip_count }
it { is_expected.to validate_numericality_of(:skip_count).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:successive_skip_count).is_greater_than_or_equal_to(0) }
-
it { is_expected.to accept_nested_attributes_for(:line_items) }
+ it 'validates currency correctly' do
+ expect(subject).to validate_inclusion_of(:currency).
+ in_array(::Money::Currency.all.map(&:iso_code)).
+ with_message('is not a valid currency code')
+ end
+
describe 'creating a subscription' do
it 'tracks the creation' do
stub_const('Spree::Event', class_spy(Spree::Event))