mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Re add test for invalid cloned products
There is no easy way to make the original product invalid, but we can make sure the cloned product will be invalid. The cloned product add "COPe OF " in front of the product's name, so by starting with a name that's long enough, the cloned product will have a name longer that 255 char and will then be invalid.
This commit is contained in:
@@ -68,6 +68,21 @@ RSpec.describe Spree::Core::ProductDuplicator do
|
||||
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
|
||||
# starting with "COPY OF <product.name>". So we set a name with 254 char to make sure the
|
||||
# cloned product will be invalid
|
||||
let(:product) {
|
||||
create(:product).tap{ |v| v.update_columns(name: "l" * 254) }
|
||||
}
|
||||
|
||||
subject { Spree::Core::ProductDuplicator.new(product).duplicate }
|
||||
|
||||
it "raises RecordInvalid error" do
|
||||
expect{ subject }.to raise_error(ActiveRecord::ActiveRecordError)
|
||||
end
|
||||
end
|
||||
|
||||
context "invalid variant" do
|
||||
let(:variant) {
|
||||
# tax_category is required when products_require_tax_category
|
||||
|
||||
@@ -17,6 +17,13 @@ module Spree
|
||||
expect(clone.sku).to eq ""
|
||||
expect(clone.image).to eq product.image
|
||||
end
|
||||
|
||||
it 'fails to duplicate invalid product' do
|
||||
# cloned product will be invalid
|
||||
product.update_columns(name: "l" * 254)
|
||||
|
||||
expect{ product.duplicate }.to raise_error(ActiveRecord::ActiveRecordError)
|
||||
end
|
||||
end
|
||||
|
||||
context "product has variants" do
|
||||
|
||||
@@ -294,6 +294,21 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "shows error message when cloning invalid record" do
|
||||
# The cloned product will be invalid
|
||||
product_a.update_columns(name: "L" * 254)
|
||||
|
||||
# The page has not been reloaded so the product's name is still "Apples"
|
||||
click_product_clone "Apples"
|
||||
|
||||
expect(page).to have_content "Unable to clone the product"
|
||||
|
||||
within "table.products" do
|
||||
# Products does not include the cloned product.
|
||||
expect(all_input_values).not_to match /COPY OF #{('L' * 254)}/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete" do
|
||||
|
||||
Reference in New Issue
Block a user