From 39eeb0e917befec59f3ba514fc6491f8830da1f0 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 26 Oct 2023 10:26:31 +1100 Subject: [PATCH] Add spec for truthiness It's generally expected that a #save method will return true on succes, and false on failure. --- spec/services/sets/product_set_spec.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/services/sets/product_set_spec.rb b/spec/services/sets/product_set_spec.rb index 18964d7f21..076ea25c0c 100644 --- a/spec/services/sets/product_set_spec.rb +++ b/spec/services/sets/product_set_spec.rb @@ -7,6 +7,7 @@ describe Sets::ProductSet do let(:product_set) do described_class.new(collection_attributes: collection_hash) end + subject{ product_set.save } context 'when the product does not exist yet' do let!(:stock_location) { create(:stock_location, backorderable_default: false) } @@ -33,6 +34,24 @@ describe Sets::ProductSet do end context 'when the product does exist' do + let(:product) { create(:simple_product, name: "product name") } + + context "with valid name" do + let(:collection_hash) { + { 0 => { id: product.id, name: "New season product" } } + } + + it { is_expected.to eq true } + end + + context "with invalid name" do + let(:collection_hash) { + { 0 => { id: product.id, name: "" } } # Product Name can't be blank + } + + it { is_expected.to eq false } + end + context 'when a different variant_unit is passed' do let!(:product) do create( @@ -68,7 +87,6 @@ describe Sets::ProductSet do context "when the product is in an order cycle" do let(:producer) { create(:enterprise) } - let(:product) { create(:simple_product) } let(:distributor) { create(:distributor_enterprise) } let!(:order_cycle) {