Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

refactor tests, make scope :for_template_promotion_id skip args sanitizing

Mateusz Porębski440fabc7bd13
diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rb
index f93b834bc1..c83ae3114b 100644
--- a/core/app/models/spree/promotion.rb
+++ b/core/app/models/spree/promotion.rb
@@ -56,6 +56,9 @@ module Spree
self.whitelisted_ransackable_attributes = ['path', 'promotion_category_id', 'promotion_batch_id', 'code']
self.whitelisted_ransackable_scopes = ['for_template_promotion_id']
+ def self.ransackable_scopes_skip_sanitize_args
+ [:for_template_promotion_id]
+ end
def self.with_coupon_code(coupon_code)
where("lower(#{table_name}.code) = ?", coupon_code.strip.downcase).
diff --git a/core/spec/services/spree/promotion_batches/generate_code_spec.rb b/core/spec/services/spree/promotion_batches/generate_code_spec.rb
index 1409bca587..30c68642a6 100644
--- a/core/spec/services/spree/promotion_batches/generate_code_spec.rb
+++ b/core/spec/services/spree/promotion_batches/generate_code_spec.rb
@@ -21,7 +21,7 @@ module Spree
let(:prefix) { 'MYCAMPAIGN_' }
it 'returns prefix and randomly generated code' do
- expect(subject).to start_with('MYCAMPAIGN_')
+ expect(subject).to match('^MYCAMPAIGN_[A-Z0-9]{4}$')
end
end
@@ -29,7 +29,7 @@ module Spree
let(:suffix) { '_RETAIL' }
it 'returns randomly generated code with suffix' do
- expect(subject).to end_with('_RETAIL')
+ expect(subject).to match('^[A-Z0-9]{4}_RETAIL$')
end
end
@@ -38,8 +38,7 @@ module Spree
let(:suffix) { '_ONLINE' }
it 'returns randomly generated code with prefix and suffix' do
- expect(subject).to start_with('TESTCAMPAIGN_')
- expect(subject).to end_with('_ONLINE')
+ expect(subject).to match('^TESTCAMPAIGN_[A-Z0-9]{4}_ONLINE$')
end
end
end