mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-08 07:46:59 +00:00
Compare commits
13 Commits
dependabot
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff4b8c82fa | ||
|
|
b0a28aed49 | ||
|
|
7120828123 | ||
|
|
2601a7efd3 | ||
|
|
6b79765622 | ||
|
|
b9eef83753 | ||
|
|
05f0e71545 | ||
|
|
734af38386 | ||
|
|
b11ce2cdfe | ||
|
|
9eda07064d | ||
|
|
78ee53f728 | ||
|
|
3daabe70ed | ||
|
|
6a6a1298df |
@@ -1 +1 @@
|
||||
24.10.0
|
||||
24.14.1
|
||||
|
||||
24
Gemfile.lock
24
Gemfile.lock
@@ -207,7 +207,7 @@ GEM
|
||||
bcp47_spec (0.2.1)
|
||||
bcrypt (3.1.22)
|
||||
benchmark (0.5.0)
|
||||
bigdecimal (4.1.0)
|
||||
bigdecimal (3.3.1)
|
||||
bindata (2.5.1)
|
||||
bindex (0.8.1)
|
||||
bootsnap (1.23.0)
|
||||
@@ -441,7 +441,7 @@ GEM
|
||||
thor (>= 0.14, < 2.0)
|
||||
jquery-ui-rails (4.2.1)
|
||||
railties (>= 3.2.16)
|
||||
json (2.19.2)
|
||||
json (2.19.3)
|
||||
json-canonicalization (1.0.0)
|
||||
json-jwt (1.17.0)
|
||||
activesupport (>= 4.2)
|
||||
@@ -696,13 +696,19 @@ GEM
|
||||
rb-fsevent (0.11.2)
|
||||
rb-inotify (0.11.1)
|
||||
ffi (~> 1.0)
|
||||
rdf (3.3.1)
|
||||
rdf (3.3.4)
|
||||
bcp47_spec (~> 0.2)
|
||||
bigdecimal (~> 3.1, >= 3.1.5)
|
||||
link_header (~> 0.0, >= 0.0.8)
|
||||
logger (~> 1.5)
|
||||
ostruct (~> 0.6)
|
||||
readline (~> 0.0)
|
||||
rdoc (7.2.0)
|
||||
erb
|
||||
psych (>= 4.0.0)
|
||||
tsort
|
||||
readline (0.0.4)
|
||||
reline
|
||||
redcarpet (3.6.1)
|
||||
redis (5.4.1)
|
||||
redis-client (>= 0.22.0)
|
||||
@@ -900,7 +906,8 @@ GEM
|
||||
tilt (2.7.0)
|
||||
timeout (0.6.1)
|
||||
tsort (0.2.0)
|
||||
ttfunk (1.7.0)
|
||||
ttfunk (1.8.0)
|
||||
bigdecimal (~> 3.1)
|
||||
turbo-rails (2.0.23)
|
||||
actionpack (>= 7.1.0)
|
||||
railties (>= 7.1.0)
|
||||
@@ -1162,7 +1169,7 @@ CHECKSUMS
|
||||
bcp47_spec (0.2.1) sha256=3fd62edf96c126bd9624e4319ac74082a966081859d1ee0ef3c3041640a37810
|
||||
bcrypt (3.1.22) sha256=1f0072e88c2d705d94aff7f2c5cb02eb3f1ec4b8368671e19112527489f29032
|
||||
benchmark (0.5.0) sha256=465df122341aedcb81a2a24b4d3bd19b6c67c1530713fd533f3ff034e419236c
|
||||
bigdecimal (4.1.0) sha256=6dc07767aa3dc456ccd48e7ae70a07b474e9afd7c5bc576f80bd6da5c8dd6cae
|
||||
bigdecimal (3.3.1) sha256=eaa01e228be54c4f9f53bf3cc34fe3d5e845c31963e7fcc5bedb05a4e7d52218
|
||||
bindata (2.5.1) sha256=53186a1ec2da943d4cb413583d680644eb810aacbf8902497aac8f191fad9e58
|
||||
bindex (0.8.1) sha256=7b1ecc9dc539ed8bccfc8cb4d2732046227b09d6f37582ff12e50a5047ceb17e
|
||||
bootsnap (1.23.0) sha256=c1254f458d58558b58be0f8eb8f6eec2821456785b7cdd1e16248e2020d3f214
|
||||
@@ -1262,7 +1269,7 @@ CHECKSUMS
|
||||
jmespath (1.6.2) sha256=238d774a58723d6c090494c8879b5e9918c19485f7e840f2c1c7532cf84ebcb1
|
||||
jquery-rails (4.4.0) sha256=b1048e5bf181b94dcac82d28a4696cd79c6200167a024a07f57607ab28aa7036
|
||||
jquery-ui-rails (4.2.1) sha256=5b349e7066150b16d7a784183f040c083d51af3357937b8564aa0cc8b1cd59bd
|
||||
json (2.19.2) sha256=e7e1bd318b2c37c4ceee2444841c86539bc462e81f40d134cf97826cb14e83cf
|
||||
json (2.19.3) sha256=289b0bb53052a1fa8c34ab33cc750b659ba14a5c45f3fcf4b18762dc67c78646
|
||||
json-canonicalization (1.0.0) sha256=d4848a8cca7534455c6721f2d9fc9e5e9adca49486864a898810024f67d59446
|
||||
json-jwt (1.17.0) sha256=6ff99026b4c54281a9431179f76ceb81faa14772d710ef6169785199caadc4cc
|
||||
json-ld (3.3.2) sha256=b9531893bf5bdc01db428e96953845a23adb1097125ce918ae0f97c4a6e1ab27
|
||||
@@ -1358,8 +1365,9 @@ CHECKSUMS
|
||||
ransack (4.1.1) sha256=01db200ede29be9f147a2c433eb0005b36df24bc7f8b624a6eeea62d50788901
|
||||
rb-fsevent (0.11.2) sha256=43900b972e7301d6570f64b850a5aa67833ee7d87b458ee92805d56b7318aefe
|
||||
rb-inotify (0.11.1) sha256=a0a700441239b0ff18eb65e3866236cd78613d6b9f78fea1f9ac47a85e47be6e
|
||||
rdf (3.3.1) sha256=dda6a2c95198915fc63d66ee270e35d4a76d431720747a2cf97ecd92062fa150
|
||||
rdf (3.3.4) sha256=a77fa0821e5b4e2bea9fdbb7c9d980564c89d27e81979690ce5c9e6bc80859c1
|
||||
rdoc (7.2.0) sha256=8650f76cd4009c3b54955eb5d7e3a075c60a57276766ebf36f9085e8c9f23192
|
||||
readline (0.0.4) sha256=6138eef17be2b98298b672c3ea63bf9cb5158d401324f26e1e84f235879c1d6a
|
||||
redcarpet (3.6.1) sha256=d444910e6aa55480c6bcdc0cdb057626e8a32c054c29e793fa642ba2f155f445
|
||||
redis (5.4.1) sha256=b5e675b57ad22b15c9bcc765d5ac26f60b675408af916d31527af9bd5a81faae
|
||||
redis-client (0.26.4) sha256=3ad70beff5da2653e02dfeae996e7d8d7147a558da12b16b2282ad345e4c7120
|
||||
@@ -1435,7 +1443,7 @@ CHECKSUMS
|
||||
tilt (2.7.0) sha256=0d5b9ba69f6a36490c64b0eee9f6e9aad517e20dcc848800a06eb116f08c6ab3
|
||||
timeout (0.6.1) sha256=78f57368a7e7bbadec56971f78a3f5ecbcfb59b7fcbb0a3ed6ddc08a5094accb
|
||||
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
|
||||
ttfunk (1.7.0) sha256=2370ba484b1891c70bdcafd3448cfd82a32dd794802d81d720a64c15d3ef2a96
|
||||
ttfunk (1.8.0) sha256=a7cbc7e489cc46e979dde04d34b5b9e4f5c8f1ee5fc6b1a7be39b829919d20ca
|
||||
turbo-rails (2.0.23) sha256=ee0d90733aafff056cf51ff11e803d65e43cae258cc55f6492020ec1f9f9315f
|
||||
turbo_power (0.7.0) sha256=ad95d147e0fa761d0023ad9ca00528c7b7ddf6bba8ca2e23755d5b21b290d967
|
||||
tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
|
||||
|
||||
@@ -92,7 +92,7 @@ module Orders
|
||||
end
|
||||
|
||||
def translation_scope
|
||||
"orders.customer_credit_service"
|
||||
"customer_credit_service"
|
||||
end
|
||||
|
||||
class Response
|
||||
|
||||
@@ -5220,8 +5220,7 @@ en:
|
||||
credit_payment_method_missing: Credit payment method is missing
|
||||
no_credit_available: No credit available
|
||||
not_enough_credit_available: Not enough credit available
|
||||
orders:
|
||||
customer_credit_service:
|
||||
no_credit_owed: No credit owed
|
||||
credit_payment_method_missing: Customer credit payment method is missing, please check configuration
|
||||
refund_sucessful: Refund successful!
|
||||
customer_credit_service:
|
||||
no_credit_owed: No credit owed
|
||||
credit_payment_method_missing: Customer credit payment method is missing, please check configuration
|
||||
refund_sucessful: Refund successful!
|
||||
|
||||
@@ -32,9 +32,12 @@ module Spree
|
||||
end
|
||||
|
||||
def duplicate_variants
|
||||
product.variants.map do |variant|
|
||||
# Create a hash with mapping: { <orig-variant>: <new-variant>, }
|
||||
mapped_variants = product.variants.index_with do |variant|
|
||||
duplicate_variant(variant)
|
||||
end
|
||||
duplicate_variant_links(mapped_variants)
|
||||
mapped_variants.values
|
||||
end
|
||||
|
||||
def duplicate_variant(variant)
|
||||
@@ -47,6 +50,19 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
def duplicate_variant_links(mapped_variants)
|
||||
# Find any links between orig variants (links to/from another product are ignored)
|
||||
variant_links = VariantLink.where(source_variant: [mapped_variants.keys],
|
||||
target_variant: [mapped_variants.keys])
|
||||
# Link the new variants
|
||||
variant_links.find_each do |variant_link|
|
||||
source_variant = mapped_variants[variant_link.source_variant]
|
||||
target_variant = mapped_variants[variant_link.target_variant]
|
||||
|
||||
target_variant.variant_links_as_target.new(source_variant:)
|
||||
end
|
||||
end
|
||||
|
||||
def duplicate_image(image)
|
||||
new_image = image.dup
|
||||
new_image.attachment.attach(image.attachment_blob)
|
||||
|
||||
@@ -36,6 +36,7 @@ RSpec.describe Spree::Core::ProductDuplicator do
|
||||
|
||||
it "can duplicate a product" do
|
||||
duplicator = Spree::Core::ProductDuplicator.new(product)
|
||||
allow(duplicator).to receive(:duplicate_variant_links) # tested elsewhere
|
||||
expect(new_product).to receive(:name=).with("COPY OF foo")
|
||||
expect(new_product).to receive(:sku=).with("")
|
||||
expect(new_product).to receive(:product_properties=).with([new_property])
|
||||
@@ -65,6 +66,92 @@ RSpec.describe Spree::Core::ProductDuplicator do
|
||||
end
|
||||
end
|
||||
|
||||
describe "duplicating" do
|
||||
subject { described_class.new(product).duplicate }
|
||||
|
||||
context "with multiple variant links" do
|
||||
let(:product) { create(:product) }
|
||||
|
||||
before do
|
||||
src_variant = product.variants.first.tap { it.update! display_name: "SRC" }
|
||||
user = src_variant.supplier.owner
|
||||
src_variant.create_linked_variant(user).tap { it.update! display_name: "LNK1" }
|
||||
src_variant.create_linked_variant(user).tap { it.update! display_name: "LNK2" }
|
||||
end
|
||||
|
||||
it "duplicates variant links" do
|
||||
expect(subject).to be_a Spree::Product
|
||||
expect(subject.variants.count).to eq 3
|
||||
|
||||
new_src_variant = subject.variants.find { it.display_name == "SRC" }
|
||||
new_lnk_variant1 = subject.variants.find { it.display_name == "LNK1" }
|
||||
new_lnk_variant2 = subject.variants.find { it.display_name == "LNK2" }
|
||||
|
||||
expect(new_src_variant.target_variants).to eq [new_lnk_variant1, new_lnk_variant2]
|
||||
expect(new_lnk_variant1.source_variants).to eq [new_src_variant]
|
||||
expect(new_lnk_variant2.source_variants).to eq [new_src_variant]
|
||||
end
|
||||
|
||||
it "minimises(?) database queries" do
|
||||
expect { subject }.to query_database [
|
||||
"Spree::ProductProperty Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Price Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Price Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Price Load",
|
||||
"VariantLink Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Variant Load",
|
||||
"TRANSACTION",
|
||||
"Spree::ShippingCategory Load",
|
||||
"Spree::Taxon Load",
|
||||
"Enterprise Load",
|
||||
"Spree::ShippingCategory Load",
|
||||
"Spree::Taxon Load",
|
||||
"Enterprise Load",
|
||||
"Spree::ShippingCategory Load",
|
||||
"Spree::Taxon Load",
|
||||
"Enterprise Load",
|
||||
"Spree::Product Create",
|
||||
"Spree::Variant Create",
|
||||
"Spree::Price Create",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Create",
|
||||
"ActsAsTaggableOn::Tagging Load",
|
||||
"Spree::Variant Update",
|
||||
"Spree::Variant Create",
|
||||
"Spree::Price Create",
|
||||
"VariantLink Create",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Create",
|
||||
"ActsAsTaggableOn::Tagging Load",
|
||||
"Spree::Variant Update",
|
||||
"Spree::Variant Create",
|
||||
"Spree::Price Create",
|
||||
"VariantLink Create",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Create",
|
||||
"ActsAsTaggableOn::Tagging Load",
|
||||
"Spree::Variant Update",
|
||||
"Spree::Product Update",
|
||||
"Enterprise Update",
|
||||
"Enterprise Update All",
|
||||
"Spree::Taxon Update",
|
||||
"TRANSACTION"
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "errors" do
|
||||
context "with invalid product" do
|
||||
# Name has a max length of 255 char, when cloning a product the cloned product has a name
|
||||
|
||||
@@ -220,13 +220,9 @@ RSpec.describe '
|
||||
let(:product) { create(:simple_product) }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
around do |example|
|
||||
I18n.default_locale = :es
|
||||
example.run
|
||||
I18n.default_locale = :en
|
||||
end
|
||||
|
||||
before do
|
||||
allow(I18n).to receive(:default_locale).and_return(:es)
|
||||
|
||||
variant.update( unit_value: 1, unit_description: 'foo' )
|
||||
|
||||
# When I view the variant
|
||||
|
||||
Reference in New Issue
Block a user