Consider deleted products when creating permalinks

https://github.com/openfoodfoundation/openfoodnetwork/issues/3844

Spree's implementation and our implementation to create a unique
permalink failed to notice conflicts with soft-deleted products. This
patch looks at deleted products as well.
This commit is contained in:
Maikel Linke
2019-06-11 18:03:42 +10:00
parent 568e3003ba
commit a10bb5acbd
3 changed files with 44 additions and 1 deletions

View File

@@ -35,6 +35,25 @@ module Spree
end
end
describe "permalink" do
let(:name) { "Banana Permanenta" }
it "generates a unique permalink" do
product1 = create(:product, name: "Banana Permanenta", permalink: nil)
product2 = create(:product, name: "Banana Permanenta", permalink: nil)
expect(product2.permalink).to_not eq product1.permalink
# "banana-permanenta" != "banana-permanenta-1" # generated by Spree
end
it "generates a unique permalink considering deleted products" do
product1 = create(:product, name: "Banana Permanenta", permalink: nil)
product1.destroy
product2 = create(:product, name: "Banana Permanenta", permalink: nil)
expect(product2.permalink).to_not eq product1.permalink
# "banana-permanenta" != "banana-permanenta1" # generated by OFN
end
end
describe "tax category" do
context "when a tax category is required" do
it "is invalid when a tax category is not provided" do